Changeset 3099

Show
Ignore:
Timestamp:
07/08/08 15:10:21 (5 years ago)
Author:
getxsick
Message:

Added new util function get_item_by_name(). It's helpful till OrderedDict? will not be implemented.

Location:
branch/UMPA/umpa
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branch/UMPA/umpa/protocols/IP.py

    r3088 r3099  
    2222import base 
    2323from utils.my_exceptions import UMPAAttributeException 
     24from utils import get_item_by_name 
    2425 
    2526class HVersion(base.Field): 
     
    114115        '''Set value of the field.''' 
    115116        if self._is_valid(attr): 
    116             self._fields[valid_fields.index(attr)].set(val) 
     117            get_item_by_name(self._fields, self.valid_fields, attr).set(val) 
    117118        else: 
    118119            raise UMPAAttributeException, attr + ' not allowed' 
     
    121122        '''Return value of the field.''' 
    122123        if self._is_valid(attr): 
    123             return self._fields[valid_fields.index(attr)].get() 
     124            return get_item_by_name(self._fields, self.valid_fields, 
     125                                    attr).get() 
    124126        else: 
    125127            raise UMPAAttributeException, attr + ' not allowed' 
  • branch/UMPA/umpa/utils/__init__.py

    r3082 r3099  
    2828 
    2929def dict_from_sequence(seq): 
    30     '''Returns a dictionary based on a sequence.''' 
     30    '''Return a dictionary based on a sequence.''' 
    3131    return dict(_pairwise(seq)) 
     32 
     33def get_item_by_name(seq, seq_with_name, name): 
     34    '''Return an item from the sequence based on the another sequence 
     35    and position of the name there. 
     36    ''' 
     37    return seq[seq_with_name.index(name)]