NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 62

Show
Ignore:
Timestamp:
07/24/07 17:14:38
Author:
cbc
Message:

Refactor __getitem__ in Data and Header

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sodar/trunk/sodar/data.py

    r61 r62  
    2222 
    2323    def __getitem__(self,index): 
    24         """allow retrieval by sample time in header 
     24        """allow sample retrieval by sample time in header 
    2525        """ 
    2626        try: 
    27             int(index) 
    28         except ValueError: # string like YYYY-MM can't convert to int 
     27            return super(Data,self).__getitem__(index) 
     28        except TypeError: 
    2929            return self.find(index) 
    30         except TypeError: # something other than integer or string 
    31             raise TypeError,'Data index must be integer or YYYY-MM-DD-HH-MM' 
    32         try: 
    33             return super(Data,self).__getitem__(index) 
    34         except IndexError: # integer index out of range 
    35             raise IndexError, 'Data index out of range' 
    36         except TypeError: # string representation of integer index 
    37             raise ValueError,'Data index must be integer or YYYY-MM-DD-HH-MM' 
    3830 
    3931    def find(self,index): 
     
    4638        except ValueError: 
    4739            raise ValueError,'Data index by date must be "YYYY-MM-DD-HH-MM"' 
     40        except AttributeError: 
     41            raise AttributeError,'Data index by date must be "YYYY-MM-DD-HH-MM"' 
    4842        for sample in self: 
    4943            if sample.header['YEAR'].rjust(4,'0') != year: continue 
     
    125119        try: 
    126120            return super(Body,self).__getitem__(index) 
    127         except IndexError: # integer index out of range 
    128             raise IndexError, 'Body index out of range' 
    129         except TypeError: # possible string representation of integer index 
    130             try: 
    131                 int(index) # is string? 
    132             except ValueError: #bad string 
    133                 raise ValueError, \ 
    134                       'Body index must be position integer or altitude string' 
    135             except TypeError: # not a string 
    136                 raise TypeError, \ 
    137                       'Body index must be position integer or altitude string' 
     121        except TypeError: 
    138122            return self.find(index) 
    139123