Skip to content

Commit

Permalink
Merge pull request cms-sw#12746 from ericvaandering/futurize_1215
Browse files Browse the repository at this point in the history
Fix a few old python idioms that snuck back in
  • Loading branch information
davidlange6 committed Dec 15, 2015
2 parents 1a95cb6 + 66e48ed commit 9140dda
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 307 deletions.
22 changes: 11 additions & 11 deletions Alignment/MuonAlignment/python/svgfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ def totrans(expr, vars=("x", "y"), globals=None, locals=None):
"""

if callable(expr):
if expr.func_code.co_argcount == 2:
if expr.__code__.co_argcount == 2:
return expr

elif expr.func_code.co_argcount == 1:
elif expr.__code__.co_argcount == 1:
split = lambda z: (z.real, z.imag)
output = lambda x, y: split(expr(x + y*1j))
output.func_name = expr.func_name
output.__name__ = expr.__name__
return output

else:
Expand All @@ -624,7 +624,7 @@ def totrans(expr, vars=("x", "y"), globals=None, locals=None):
g = math.__dict__
if globals != None: g.update(globals)
output = eval("lambda %s, %s: (%s)" % (vars[0], vars[1], expr), g, locals)
output.func_name = "%s,%s -> %s" % (vars[0], vars[1], expr)
output.__name__ = "%s,%s -> %s" % (vars[0], vars[1], expr)
return output

elif len(vars) == 1:
Expand All @@ -633,7 +633,7 @@ def totrans(expr, vars=("x", "y"), globals=None, locals=None):
output = eval("lambda %s: (%s)" % (vars[0], expr), g, locals)
split = lambda z: (z.real, z.imag)
output2 = lambda x, y: split(output(x + y*1j))
output2.func_name = "%s -> %s" % (vars[0], expr)
output2.__name__ = "%s -> %s" % (vars[0], expr)
return output2

else:
Expand Down Expand Up @@ -698,7 +698,7 @@ def maybelog(t, it1, it2, ot1, ot2, logbase):

output = lambda x, y: (xfunc(x), yfunc(y))

output.func_name = "(%g, %g), (%g, %g) -> (%g, %g), (%g, %g)%s%s" % (ix1, ix2, iy1, iy2, ox1, ox2, oy1, oy2, xlogstr, ylogstr)
output.__name__ = "(%g, %g), (%g, %g) -> (%g, %g), (%g, %g)%s%s" % (ix1, ix2, iy1, iy2, ox1, ox2, oy1, oy2, xlogstr, ylogstr)
return output

def rotate(angle, cx=0, cy=0):
Expand Down Expand Up @@ -736,7 +736,7 @@ def __repr__(self):
elif isinstance(self.trans, basestring):
return "<Fig (%d items) x,y -> %s>" % (len(self.d), self.trans)
else:
return "<Fig (%d items) %s>" % (len(self.d), self.trans.func_name)
return "<Fig (%d items) %s>" % (len(self.d), self.trans.__name__)

def __init__(self, *d, **kwds):
self.d = list(d)
Expand Down Expand Up @@ -817,7 +817,7 @@ def __repr__(self):
if self.trans == None:
return "<Plot (%d items)>" % len(self.d)
else:
return "<Plot (%d items) %s>" % (len(self.d), self.trans.func_name)
return "<Plot (%d items) %s>" % (len(self.d), self.trans.__name__)

def __init__(self, xmin, xmax, ymin, ymax, *d, **kwds):
self.xmin, self.xmax, self.ymin, self.ymax = xmin, xmax, ymin, ymax
Expand Down Expand Up @@ -1462,7 +1462,7 @@ def funcRtoC(expr, var="t", globals=None, locals=None):
output = eval("lambda %s: (%s)" % (var, expr), g, locals)
split = lambda z: (z.real, z.imag)
output2 = lambda t: split(output(t))
output2.func_name = "%s -> %s" % (var, expr)
output2.__name__ = "%s -> %s" % (var, expr)
return output2

def funcRtoR2(expr, var="t", globals=None, locals=None):
Expand All @@ -1477,7 +1477,7 @@ def funcRtoR2(expr, var="t", globals=None, locals=None):
g = math.__dict__
if globals != None: g.update(globals)
output = eval("lambda %s: (%s)" % (var, expr), g, locals)
output.func_name = "%s -> %s" % (var, expr)
output.__name__ = "%s -> %s" % (var, expr)
return output

def funcRtoR(expr, var="x", globals=None, locals=None):
Expand All @@ -1492,7 +1492,7 @@ def funcRtoR(expr, var="x", globals=None, locals=None):
g = math.__dict__
if globals != None: g.update(globals)
output = eval("lambda %s: (%s, %s)" % (var, var, expr), g, locals)
output.func_name = "%s -> %s" % (var, expr)
output.__name__ = "%s -> %s" % (var, expr)
return output

class Curve:
Expand Down
10 changes: 5 additions & 5 deletions CondCore/Utilities/scripts/uploadConditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def getToken(self, username, password):

try:
self.token = json.loads( response.getvalue() )['token']
except Exception, e:
except Exception as e:
logging.error('http::getToken> got error from server: %s ', str(e) )
if 'No JSON object could be decoded' in str(e):
return None
Expand Down Expand Up @@ -411,7 +411,7 @@ def query(self, url, data = None, files = None, keepCookies = True):

def addToTarFile(tarFile, fileobj, arcname):
tarInfo = tarFile.gettarinfo(fileobj = fileobj, arcname = arcname)
tarInfo.mode = 0400
tarInfo.mode = 0o400
tarInfo.uid = tarInfo.gid = tarInfo.mtime = 0
tarInfo.uname = tarInfo.gname = 'root'
tarFile.addfile(tarInfo, fileobj)
Expand All @@ -434,7 +434,7 @@ def signIn(self, username, password):
logging.info('%s: Signing in user %s ...', self.hostname, username)
try:
self.token = self.http.getToken(username, password)
except Exception, e:
except Exception as e:
logging.error("Caught exception when trying to get token for user %s from %s: %s" % (username, self.hostname, str(e)) )
return False

Expand Down Expand Up @@ -498,7 +498,7 @@ def uploadFile(self, filename, backend = defaultBackend, temporaryFile = default

with open('%s.db' % basepath, 'rb') as data:
addToTarFile(tarFile, data, 'data.db')
except Exception, e:
except Exception as e:
msg = 'Error when creating tar file. \n'
msg += 'Please check that you have write access to the directory you are running,\n'
msg += 'and that you have enough space on this disk (df -h .)\n'
Expand Down Expand Up @@ -543,7 +543,7 @@ def uploadFile(self, filename, backend = defaultBackend, temporaryFile = default
'uploadedFile': fileHash,
}
)
except Exception, e:
except Exception as e:
logging.error('Error from uploading: %s' % str(e))
ret = json.dumps( { "status": -1, "upload" : { 'itemStatus' : { basename : {'status':'failed', 'info':str(e)}}}, "error" : str(e)} )

Expand Down
Loading

0 comments on commit 9140dda

Please sign in to comment.