Changeset 1184


Ignore:
Timestamp:
03/02/09 16:08:19 (3 years ago)
Author:
Peter Peterson
Message:

Changed exception on EOD in getnext entry to return tuple and added function to get listing of all entries at the current level. Refs #101.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/python/nxs/napi.py

    r1172 r1184  
    596596    def getnextentry(self): 
    597597        """ 
    598         Return the next entry in the group as name,nxclass tuple. 
    599  
    600         Raises NeXusError if this fails, or if there is no next entry. 
     598        Return the next entry in the group as name,nxclass tuple. If 
     599        end of data is reached this returns the tuple (None, None) 
     600 
     601        Raises NeXusError if this fails. 
    601602 
    602603        Corresponds to NXgetnextentry(handle,name,nxclass,&storage). 
     
    616617        storage = c_int(0) 
    617618        status = nxlib.nxigetnextentry_(self.handle,name,nxclass,_ref(storage)) 
    618         if status == ERROR or status == EOD: 
     619        if status == EOD: 
     620            return (None, None) 
     621        if status == ERROR: 
    619622            raise NeXusError, \ 
    620623                "Could not get next entry: %s"%(self._loc()) 
     
    624627        #print "group next",nxclass.value, name.value, storage.value 
    625628        return name.value,nxclass.value 
     629 
     630    def getentries(self): 
     631        """ 
     632        Return a dictionary of the groups[name]=type below the 
     633        existing open one. 
     634 
     635        Raises NeXusError if this fails. 
     636        """ 
     637        self.initgroupdir() 
     638        result = {} 
     639        (name, nxclass) = self.getnextentry() 
     640        if (name, nxclass) != (None, None): 
     641            result[name] = nxclass 
     642        while (name, nxclass) != (None, None): 
     643            result[name] = nxclass 
     644            (name, nxclass) = self.getnextentry() 
     645        return result 
    626646 
    627647    def entries(self): 
Note: See TracChangeset for help on using the changeset viewer.