Author: Alastair McKinstry <mckinstry@debian.org>
Description: Support for Python3.
Last-Updated: 2013-07-10
Forwarded: no

Index: python-cdo-1.2.1/cdo.py
===================================================================
--- python-cdo-1.2.1.orig/cdo.py	2013-07-10 16:33:06.000000000 +0100
+++ python-cdo-1.2.1/cdo.py	2013-07-10 16:33:31.000000000 +0100
@@ -1,6 +1,8 @@
+from __future__ import print_function, division
 import os,re,subprocess,tempfile,random,string
 import numpy as np
 
+
 # Copyright (C) 2011-2012 Ralf Mueller, ralf.mueller@zmaw.de
 # See COPYING file for copying and redistribution conditions.
 # 
@@ -57,7 +59,7 @@
         'tstepcount','vardes','vardup','varmul','varquot2test','varrms','vertwind','write_e5ml',
         'writegrid','writerandom','yearcount']
 
-    if os.environ.has_key('CDO'):
+    if 'CDO' in os.environ:
       self.CDO = os.environ['CDO']
     else:
       self.CDO = 'cdo'
@@ -78,9 +80,9 @@
 
   def call(self,cmd):
     if self.debug:
-      print '# DEBUG ====================================================================='
-      print 'CALL:'+' '.join(cmd)
-      print '# DEBUG ====================================================================='
+      print('# DEBUG =====================================================================')
+      print(('CALL:'+' '.join(cmd)))
+      print('# DEBUG =====================================================================')
 
     proc = subprocess.Popen(' '.join(cmd),
         shell  = True,
@@ -93,7 +95,7 @@
 
   def hasError(self,method_name,cmd,retvals):
     if (self.debug):
-      print("RETURNCODE:"+retvals["returncode"].__str__())
+      print(("RETURNCODE:"+retvals["returncode"].__str__()))
     if ( 0 != retvals["returncode"] ):
       print("Error in calling operator " + method_name + " with:")
       print(">>> "+' '.join(cmd)+"<<<")
@@ -127,7 +129,7 @@
         cmd     = [self.CDO,kwargs["options"],','.join(operator),' '.join(io)]
         retvals = self.call(cmd)
         if ( not self.hasError(method_name,cmd,retvals) ):
-          r = map(string.strip,retvals["stdout"].split(os.linesep))
+          r = list(map(string.strip,retvals["stdout"].split(os.linesep)))
           return r[:len(r)-1]
         else:
           raise CDOException(**retvals)
@@ -163,14 +165,14 @@
 
     if ((method_name in self.__dict__) or (method_name in self.operators)):
       if self.debug:
-        print("Found method:" + method_name)
+        print(("Found method:" + method_name))
 
       return get.__get__(self)
     else:
       # If the method isn't in our dictionary, act normal.
       print("#=====================================================")
       print("Cannot find method:" + method_name)
-      raise AttributeError, method_name
+      raise AttributeError( method_name)
 
   def getOperators(self):
     import os
@@ -194,7 +196,7 @@
         self.cdf    = cdf
         self.cdfMod = "netcdf4"
       except:
-        raise ImportError,"scipy or python-netcdf4 module is required to return numpy arrays."
+        raise ImportError("scipy or python-netcdf4 module is required to return numpy arrays.")
 
 
   def setReturnArray(self,value=True):
@@ -222,7 +224,7 @@
           stderr = subprocess.PIPE,
           stdout = subprocess.PIPE)
       retvals = proc.communicate()
-      print retvals
+      print(retvals)
 
   def setCdo(self,value):
     self.CDO       = value
@@ -246,7 +248,7 @@
     return match.group(1)
 
   def boundaryLevels(self,**kwargs):
-    ilevels         = map(float,self.showlevel(input = kwargs['input'])[0].split())
+    ilevels         = list(map(float,self.showlevel(input = kwargs['input'])[0].split()))
     bound_levels    = []
     bound_levels.insert(0,0)
     for i in range(1,len(ilevels)+1):
@@ -277,7 +279,7 @@
     elif ( "netcdf4" == self.cdfMod ):
       fileObj = self.cdf.Dataset(iFile)
     else:
-      raise ImportError,"Could not import data from file '" + iFile + "'"
+      raise ImportError("Could not import data from file '" + iFile + "'")
 
     retval = fileObj
     fileObj.close()
@@ -290,7 +292,7 @@
       # return the data array
       return filehandle.variables[varname][:]
     else:
-      print "Cannot find variable '" + varname +"'"
+      print(("Cannot find variable '" + varname +"'"))
       return False
 
   def readMaArray(self,iFile,varname):
Index: python-cdo-1.2.1/test/test_cdo.py
===================================================================
--- python-cdo-1.2.1.orig/test/test_cdo.py	2013-07-10 16:33:06.000000000 +0100
+++ python-cdo-1.2.1/test/test_cdo.py	2013-07-10 16:33:06.000000000 +0100
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
 import unittest,os,tempfile
 from stat import *
 from cdo import *
@@ -54,7 +56,7 @@
         cdo = Cdo()
         levels = cdo.showlevel(input = "-stdatm,0")
         info   = cdo.sinfo(input = "-stdatm,0")
-        self.assertEqual([0,0],map(float,levels))
+        self.assertEqual([0,0],list(map(float,levels)))
         self.assertEqual("File format: GRIB",info[0])
 
         values = cdo.outputkey("value",input="-stdatm,0")
@@ -72,12 +74,12 @@
         self.assertEqual([50.0, 100.0, 200.0, 300.0, 450.0, 600.0, 800.0, 1000.0, 1000.0, 1000.0],
                      cdo.thicknessOfLevels(input = ofile))
 
-    #def test_CDO_options(self):
-    #    cdo = Cdo()
-    #    names = cdo.showname(input = "-stdatm,0",options = "-f nc")
-    #    self.assertEqual(["P T"],names)
-    #    ofile = cdo.topo(options = "-z szip")
-    #    self.assertEqual(["GRIB SZIP"],cdo.showformat(input = ofile))
+    def test_CDO_options(self):
+        cdo = Cdo()
+        names = cdo.showname(input = "-stdatm,0",options = "-f nc")
+        self.assertEqual(["P T"],names)
+        ofile = cdo.topo(options = "-z szip")
+        self.assertEqual(["GRIB SZIP"],cdo.showformat(input = ofile))
 
     def test_chain(self):
         cdo = Cdo()
@@ -88,7 +90,7 @@
         cdo = Cdo()
         cdo.debug = True
         diffv = cdo.diffn(input = "-random,r1x1 -random,r1x1")
-        print diffv
+        print(diffv)
         self.assertEqual(diffv[1].split(' ')[-1],"random")
         self.assertEqual(diffv[1].split(' ')[-3],"0.53060")
         diff  = cdo.diff(input = "-random,r1x1 -random,r1x1")
@@ -267,13 +269,13 @@
     if 'thingol' == os.popen('hostname').read().strip():
         def testCall(self):
             cdo = Cdo()
-            print cdo.sinfov(input='/home/ram/data/icon/oce.nc')
+            print(cdo.sinfov(input='/home/ram/data/icon/oce.nc'))
         def test_readCdf(self):
             cdo = Cdo()
             input= "-settunits,days  -setyear,2000 -for,1,4"
             cdfFile = cdo.copy(options="-f nc",input=input)
             cdf     = cdo.readCdf(cdfFile)
-            self.assertEqual(['lat','lon','for','time'],cdf.variables.keys())
+            self.assertEqual(['lat','lon','for','time'],list(cdf.variables.keys()))
 
         def testTmp(self):
             cdo = Cdo()
