Changeset 308:929642029897 in livinglogic.python.www for site/Python_xmlns.py

Show
Ignore:
Timestamp:
01/04/05 13:31:33 (15 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Modernize getitem code (Use isinstance() instead of "type(.) is .")

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • site/Python_xmlns.py

    r306 r308  
    9797 
    9898    def __getitem__(self, index): 
    99         if type(index) in (types.IntType, types.LongType): 
     99        if isinstance(index, (int, long)): 
    100100            return self.getChildByIndex(index) 
    101         elif type(index) in (types.StringType, types.UnicodeType): 
     101        elif isinstance(index, basestring): 
    102102            if index=="": 
    103103                index = [] 
    104104            else: 
    105105                index = index.split("/") 
    106         if type(index) in (types.ListType, types.TupleType): 
     106        if isinstance(index, (list, tuple)): 
    107107            result = self 
    108108            for i in index: 
    109                 if type(i) in (types.IntType, types.LongType): 
     109                if isinstance(i, (int, long)): 
    110110                    result = result.getChildByIndex(i) 
    111                 elif type(i) in (types.StringType, types.UnicodeType): 
     111                elif isinstance(i, basestring): 
    112112                    result = result.getChildByName(i) 
    113113                else: