From 9b46cccc33bedc8b4d538b159804b5b45b8b0ea7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 24 Aug 2011 17:12:53 -0700 Subject: [PATCH] python: Avoid shadowing standard or global names. Found by pychecker. --- python/ovs/db/schema.py | 4 ++-- python/ovs/db/types.py | 6 +++--- python/ovs/fatal_signal.py | 8 ++++---- python/ovs/json.py | 6 +++--- python/ovs/jsonrpc.py | 10 +++++----- python/ovs/util.py | 16 ++++++++-------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py index 29fe986a2..65ddca600 100644 --- a/python/ovs/db/schema.py +++ b/python/ovs/db/schema.py @@ -249,10 +249,10 @@ class ColumnSchema(object): parser = ovs.db.parser.Parser(json, "schema for column %s" % name) mutable = parser.get_optional("mutable", [bool], True) ephemeral = parser.get_optional("ephemeral", [bool], False) - type = types.Type.from_json(parser.get("type", [dict, unicode])) + type_ = types.Type.from_json(parser.get("type", [dict, unicode])) parser.finish() - return ColumnSchema(name, mutable, not ephemeral, type) + return ColumnSchema(name, mutable, not ephemeral, type_) def to_json(self): json = {"type": self.type.to_json()} diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py index 8b2900059..dc19f85c8 100644 --- a/python/ovs/db/types.py +++ b/python/ovs/db/types.py @@ -539,9 +539,9 @@ class Type(object): 'OVSDB_TYPE_VOID);' % (indent, var)) initMin = "%s%s.n_min = %s;" % (indent, var, self.n_min) if self.n_max == sys.maxint: - max = "UINT_MAX" + n_max = "UINT_MAX" else: - max = self.n_max - initMax = "%s%s.n_max = %s;" % (indent, var, max) + n_max = self.n_max + initMax = "%s%s.n_max = %s;" % (indent, var, n_max) return "\n".join((initKey, initValue, initMin, initMax)) diff --git a/python/ovs/fatal_signal.py b/python/ovs/fatal_signal.py index 765f68319..de8f37c01 100644 --- a/python/ovs/fatal_signal.py +++ b/python/ovs/fatal_signal.py @@ -68,8 +68,8 @@ def unlink_file_now(file): return error def _unlink_files(): - for file in _files: - _unlink(file) + for file_ in _files: + _unlink(file_) def _cancel_files(): global _added_hook @@ -77,9 +77,9 @@ def _cancel_files(): _added_hook = False _files = {} -def _unlink(file): +def _unlink(file_): try: - os.unlink(file) + os.unlink(file_) return 0 except OSError, e: return e.errno diff --git a/python/ovs/json.py b/python/ovs/json.py index 6283c9132..2d7e2ec37 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -23,9 +23,9 @@ escapes = {ord('"'): u"\\\"", ord("\n"): u"\\n", ord("\r"): u"\\r", ord("\t"): u"\\t"} -for i in range(32): - if i not in escapes: - escapes[i] = u"\\u%04x" % i +for esc in range(32): + if esc not in escapes: + escapes[esc] = u"\\u%04x" % esc def __dump_string(stream, s): stream.write(u'"%s"' % ''.join(escapes.get(ord(c), c) for c in s)) diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py index 511794413..7aea31b1b 100644 --- a/python/ovs/jsonrpc.py +++ b/python/ovs/jsonrpc.py @@ -119,7 +119,7 @@ class Message(object): params = json.pop("params", None) result = json.pop("result", None) error = json.pop("error", None) - id = json.pop("id", None) + id_ = json.pop("id", None) if len(json): return "message has unexpected member \"%s\"" % json.popitem()[0] @@ -127,12 +127,12 @@ class Message(object): msg_type = Message.T_REPLY elif error is not None: msg_type = Message.T_ERROR - elif id is not None: + elif id_ is not None: msg_type = Message.T_REQUEST else: msg_type = Message.T_NOTIFY - msg = Message(msg_type, method, params, result, error, id) + msg = Message(msg_type, method, params, result, error, id_) validation_error = msg.is_valid() if validation_error is not None: return validation_error @@ -289,13 +289,13 @@ class Connection(object): poller.block() def transact_block(self, request): - id = request.id + id_ = request.id error = self.send(request) reply = None while not error: error, reply = self.recv_block() - if reply and reply.type == Message.T_REPLY and reply.id == id: + if reply and reply.type == Message.T_REPLY and reply.id == id_: break return error, reply diff --git a/python/ovs/util.py b/python/ovs/util.py index aa4b9bc3d..d218d3d07 100644 --- a/python/ovs/util.py +++ b/python/ovs/util.py @@ -18,26 +18,26 @@ import sys PROGRAM_NAME = os.path.basename(sys.argv[0]) -def abs_file_name(dir, file_name): +def abs_file_name(dir_, file_name): """If 'file_name' starts with '/', returns a copy of 'file_name'. Otherwise, returns an absolute path to 'file_name' considering it relative - to 'dir', which itself must be absolute. 'dir' may be None or the empty + to 'dir_', which itself must be absolute. 'dir_' may be None or the empty string, in which case the current working directory is used. - Returns None if 'dir' is null and getcwd() fails. + Returns None if 'dir_' is None and getcwd() fails. This differs from os.path.abspath() in that it will never change the meaning of a file name.""" if file_name.startswith('/'): return file_name else: - if dir is None or dir == "": + if dir_ is None or dir_ == "": try: - dir = os.getcwd() + dir_ = os.getcwd() except OSError: return None - if dir.endswith('/'): - return dir + file_name + if dir_.endswith('/'): + return dir_ + file_name else: - return "%s/%s" % (dir, file_name) + return "%s/%s" % (dir_, file_name) -- 2.20.1