Changeset 999


Ignore:
Timestamp:
13/06/08 11:44:48 (4 years ago)
Author:
Mark Koennecke
Message:

Made python binding compatible with python 2.4.3, refs #101

Location:
trunk/bindings/python
Files:
2 edited

Legend:

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

    r980 r999  
    259259        status = self.lib.nxiopen_(filename,mode,_ref(self.handle)) 
    260260        if status == ERROR: 
    261             op = 'open' if mode in [ACC_READ, ACC_RDWR] else 'create' 
     261            if mode in [ACC_READ, ACC_RDWR]: 
     262              op = 'open' 
     263            else: 
     264              op = 'create' 
    262265            raise RuntimeError, "Could not %s %s"%(op,filename) 
    263266        self.isopen = True 
     
    282285        """ 
    283286        if self.isopen: return 
    284         mode = ACC_READ if self.mode==ACC_READ else ACC_RDWR 
     287        if self.mode==ACC_READ: 
     288            mode = ACC_READ 
     289        else: 
     290            mode = ACC_RDWR 
    285291        status = self.lib.nxiopen_(self.filename,mode,_ref(self.handle)) 
    286292        if status == ERROR: 
     
    367373            raise ValueError, "Could not open %s in %s"%(path,self._loc()) 
    368374        n,path,nxclass = self.getgroupinfo() 
    369         self.path = path.split('/') if path != 'root' else [] 
     375        if path != 'root': 
     376            self.path = path.split('/') 
     377        else: 
     378            self.path = [] 
    370379         
    371380         
     
    386395            raise ValueError, "Could not open %s in %s"%(path,self.filename) 
    387396        n,path,nxclass = self.getgroupinfo() 
    388         self.path = path.split('/') if path != 'root' else [] 
     397        if path != 'root': 
     398            self.path = path.split('/') 
     399        else: 
     400            self.path = [] 
    389401         
    390402         
     
    505517        n,path,_ = self.getgroupinfo() 
    506518        #print "path",path 
    507         path = "/"+path if not path == "root" else "/" 
     519        if not path == "root": 
     520            path = "/"+path 
     521        else: 
     522            path = "/" 
    508523        self.initgroupdir() 
    509524        L = [] 
     
    10131028                target = self.getattr(name,length,dtype) 
    10141029                #print "target %s, path %s"%(target,pathstr) 
    1015                 return target if target != pathstr else None 
     1030                if target != pathstr: 
     1031                    return target 
     1032                else: 
     1033                    return None 
    10161034        return None 
    10171035 
     
    10661084        status = self.lib.nxiisexternalgroup_(self.handle,name,nxclass, 
    10671085                                              url,maxnamelen) 
    1068         return None if status == ERROR else url.value 
     1086        if status == ERROR: 
     1087            return None 
     1088        else: 
     1089            url.value 
    10691090 
    10701091 
     
    10761097        This is an extension to the NeXus API. 
    10771098        """ 
    1078         pathstr = "/".join(self.path) if not self.path == [] else "root" 
     1099        if not self.path == []: 
     1100            pathstr = "/".join(self.path) 
     1101        else: 
     1102            pathstr = "root" 
    10791103        return "%s(%s)"%(self.filename,pathstr) 
    10801104     
     
    11051129            size = data.nbytes 
    11061130        return datafn,pdata,size 
     1131 
     1132    def _nxany(self,iter): 
     1133        """ 
     1134        replace python 2.5 any() 
     1135        """ 
     1136        for e in iter: 
     1137            if e: 
     1138                return 1 
     1139            return 0 
    11071140     
    11081141    def _pinput(self, data, dtype, shape): 
     
    11271160            input_shape = numpy.array([i for i in data.shape if i != 1]) 
    11281161            target_shape = numpy.array([i for i in shape if i != 1]) 
    1129             if len(input_shape) != len(target_shape) or any(input_shape != target_shape): 
     1162            print input_shape 
     1163            print target_shape 
     1164#            if len(input_shape) != len(target_shape) or any(input_shape != target_shape): 
     1165            if len(input_shape) != len(target_shape) or self._nxany(input_shape != target_shape): 
    11301166                raise ValueError,\ 
    11311167                    "Shape mismatch %s!=%s: %s"%(data.shape,shape,self.filename) 
  • trunk/bindings/python/nxstest.py

    r976 r999  
    353353def test(): 
    354354    tests = 0 
    355     quiet = True if '-q' in sys.argv else False 
    356     external = True if '-x' in sys.argv else False 
     355    if '-q' in sys.argv: 
     356        quiet = True 
     357    else: 
     358        quiet = False 
     359    if '-x' in sys.argv: 
     360        external = True 
     361         
     362    else: 
     363        external = False 
    357364    if 'hdf4' in sys.argv:  
    358365        test_mode('w4',quiet,external) 
Note: See TracChangeset for help on using the changeset viewer.