From a8017912ca2597f0305ca7e88bc0e65d45ea6702 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Wed, 29 Apr 2015 13:12:15 -0400 Subject: [PATCH 1/2] Fixes typo in CDMS raise statements --- Packages/cdms2/Lib/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/cdms2/Lib/dataset.py b/Packages/cdms2/Lib/dataset.py index e212dcb0fb..417ce54227 100644 --- a/Packages/cdms2/Lib/dataset.py +++ b/Packages/cdms2/Lib/dataset.py @@ -245,14 +245,14 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None): file = CdmsFile(uri,mode) return file except: - raise "Error in DODS open of: ",uri + raise CDMSError, "Error in DODS open of: ",uri else: try: datanode = loadURI(uri) return datanode except: datanode = loadURI(uri) - raise "Error in loadURI of: ",uri + raise CDMSError, "Error in loadURI of: ",uri else: raise SchemeNotSupported, scheme From fd11e799ec056a55cd72717272288164c8c0c759 Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Wed, 29 Apr 2015 20:18:10 -0400 Subject: [PATCH 2/2] Switches raise statements to new-style --- Packages/cdms2/Lib/dataset.py | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Packages/cdms2/Lib/dataset.py b/Packages/cdms2/Lib/dataset.py index 417ce54227..3c4cfc56be 100644 --- a/Packages/cdms2/Lib/dataset.py +++ b/Packages/cdms2/Lib/dataset.py @@ -84,26 +84,26 @@ def setCompressionWarnings(value=None): value = not _showCompressWarnings if isinstance(value,str): if not value.slower() in ['y','n','yes','no']: - raise CDMSError,"setCompressionWarnings flags must be yes/no or 1/0, or None to invert it" + raise CDMSError("setCompressionWarnings flags must be yes/no or 1/0, or None to invert it") if value.lower()[0]=='y': value = 1 else: value = 0 if not isinstance(value, (int,bool)): - raise CMDSError, "setCompressionWarnings flags must be yes/no or 1/0, or None to invert it" + raise CMDSError("setCompressionWarnings flags must be yes/no or 1/0, or None to invert it") if value in [1,True]: _showCompressWarnings = True elif value in [0,False]: _showCompressWarnings = False else: - raise CMDSError, "setCompressionWarnings flags must be yes/no or 1/0, or None to invert it" + raise CMDSError("setCompressionWarnings flags must be yes/no or 1/0, or None to invert it") return _showCompressWarnings def setNetcdfClassicFlag(value): """ Sets NetCDF classic flag value""" if value not in [True,False,0,1]: - raise CDMSError, "Error NetCDF Classic flag must be 1/0 or true/False" + raise CDMSError("Error NetCDF Classic flag must be 1/0 or true/False") if value in [0,False]: Cdunif.CdunifSetNCFLAGS("classic",0) else: @@ -112,7 +112,7 @@ def setNetcdfClassicFlag(value): def setNetcdfShuffleFlag(value): """ Sets NetCDF shuffle flag value""" if value not in [True,False,0,1]: - raise CDMSError, "Error NetCDF Shuffle flag must be 1/0 or true/False" + raise CDMSError("Error NetCDF Shuffle flag must be 1/0 or true/False") if value in [0,False]: Cdunif.CdunifSetNCFLAGS("shuffle",0) else: @@ -121,7 +121,7 @@ def setNetcdfShuffleFlag(value): def setNetcdfDeflateFlag(value): """ Sets NetCDF deflate flag value""" if value not in [True,False,0,1]: - raise CDMSError, "Error NetCDF deflate flag must be 1/0 or true/False" + raise CDMSError("Error NetCDF deflate flag must be 1/0 or true/False") if value in [0,False]: Cdunif.CdunifSetNCFLAGS("deflate",0) else: @@ -214,7 +214,7 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None): root,ext = os.path.splitext(path) if ext in ['.xml','.cdml']: - if mode!='r': raise ModeNotSupported,mode + if mode!='r': raise ModeNotSupported(mode) datanode = load(path) else: # If the doesn't exist allow it to be created @@ -239,23 +239,23 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None): elif scheme in ['http', 'gridftp']: if (dods): - if mode!='r': raise ModeNotSupported,mode + if mode!='r': raise ModeNotSupported(mode) # DODS file? try: file = CdmsFile(uri,mode) return file except: - raise CDMSError, "Error in DODS open of: ",uri + raise CDMSError("Error in DODS open of: ",uri) else: try: datanode = loadURI(uri) return datanode except: datanode = loadURI(uri) - raise CDMSError, "Error in loadURI of: ",uri + raise CDMSError("Error in loadURI of: ",uri) else: - raise SchemeNotSupported, scheme + raise SchemeNotSupported(scheme) # Determine dpath, the absolute path to data files: # dpath = @@ -289,7 +289,7 @@ def parselist(text, f): n = 0 m = _ListStart.match(text) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[0:_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[0:_NPRINT]) result = [] n += m.end() s, nconsume = f(text[n:]) @@ -306,7 +306,7 @@ def parselist(text, f): n += nconsume m = _ListEnd.match(text[n:]) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[n:n+_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[n:n+_NPRINT]) n += m.end() return result, n @@ -321,7 +321,7 @@ def parseIndexList(text): m = _IndexList5.match(text) nindices = 5 if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[0:_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[0:_NPRINT]) result = [None]*(nindices+1) for i in range(nindices): s = m.group(i+1) @@ -333,7 +333,7 @@ def parseIndexList(text): def parseName(text): m = _Name.match(text) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[0:_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[0:_NPRINT]) return m.group(), m.end() def parseVarMap(text): @@ -341,7 +341,7 @@ def parseVarMap(text): n = 0 m = _ListStart.match(text) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[0:_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[0:_NPRINT]) result = [] n += m.end() s, nconsume = parselist(text[n:],parseName) @@ -349,14 +349,14 @@ def parseVarMap(text): n += nconsume m = _ListSep.match(text[n:]) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[n:n+_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[n:n+_NPRINT]) n += m.end() s, nconsume = parselist(text[n:], parseIndexList) result.append(s) n += nconsume m = _ListEnd.match(text[n:]) if m is None: - raise CDMSError, "Parsing cdms_filemap near "+text[n:n+_NPRINT] + raise CDMSError("Parsing cdms_filemap near "+text[n:n+_NPRINT]) n += m.end() return result, n @@ -370,7 +370,7 @@ def parseFileMap(text): """ result, n = parselist(text, parseVarMap) if n