From a5599f3eab14155d9dff589e7275665892a39eb1 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Sun, 29 May 2016 08:20:18 +0200 Subject: [PATCH] running lib2to3.fixes.fix_idioms --- gluon/contrib/gateways/fcgi.py | 17 ++++++++--------- gluon/contrib/login_methods/ldap_auth.py | 4 ++-- gluon/contrib/pyrtf/Elements.py | 3 +-- gluon/contrib/pyrtf/PropertySets.py | 2 +- gluon/contrib/qdb.py | 6 +++--- gluon/contrib/redis_scheduler.py | 2 +- gluon/sqlhtml.py | 4 ++-- gluon/tests/test_dal.py | 2 +- gluon/validators.py | 14 +++++++------- 9 files changed, 26 insertions(+), 28 deletions(-) diff --git a/gluon/contrib/gateways/fcgi.py b/gluon/contrib/gateways/fcgi.py index fe7e8ab9..f27fe012 100644 --- a/gluon/contrib/gateways/fcgi.py +++ b/gluon/contrib/gateways/fcgi.py @@ -1010,7 +1010,7 @@ class Server(object): else: # Run as a server oldUmask = None - if type(self._bindAddress) is str: + if isinstance(self._bindAddress, str): # Unix socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: @@ -1021,7 +1021,7 @@ class Server(object): oldUmask = os.umask(self._umask) else: # INET socket - assert type(self._bindAddress) is tuple + assert isinstance(self._bindAddress, tuple) assert len(self._bindAddress) == 2 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -1209,7 +1209,7 @@ class WSGIServer(Server): result = None def write(data): - assert type(data) is str, 'write() argument must be string' + assert isinstance(data, str), 'write() argument must be string' assert headers_set, 'write() before start_response()' if not headers_sent: @@ -1246,15 +1246,15 @@ class WSGIServer(Server): else: assert not headers_set, 'Headers already set!' - assert type(status) is str, 'Status must be a string' + assert isinstance(status, str), 'Status must be a string' assert len(status) >= 4, 'Status must be at least 4 characters' assert int(status[:3]), 'Status must begin with 3-digit code' assert status[3] == ' ', 'Status must have a space after code' - assert type(response_headers) is list, 'Headers must be a list' + assert isinstance(response_headers, list), 'Headers must be a list' if __debug__: for name,val in response_headers: - assert type(name) is str, 'Header names must be strings' - assert type(val) is str, 'Header values must be strings' + assert isinstance(name, str), 'Header names must be strings' + assert isinstance(val, str), 'Header values must be strings' headers_set[:] = [status, response_headers] return write @@ -1310,8 +1310,7 @@ if __name__ == '__main__': '\n' \ '

Hello World!

\n' \ '' - names = environ.keys() - names.sort() + names = sorted(environ.keys()) for name in names: yield '\n' % ( name, cgi.escape(repr(environ[name]))) diff --git a/gluon/contrib/login_methods/ldap_auth.py b/gluon/contrib/login_methods/ldap_auth.py index 15718846..fa151115 100644 --- a/gluon/contrib/login_methods/ldap_auth.py +++ b/gluon/contrib/login_methods/ldap_auth.py @@ -477,7 +477,7 @@ def ldap_auth(server='ldap', ldap_groups_of_the_user = get_user_groups_from_ldap(username, password) # search for allowed group names - if type(allowed_groups) != type(list()): + if not isinstance(allowed_groups, type(list())): allowed_groups = [allowed_groups] for group in allowed_groups: if ldap_groups_of_the_user.count(group) > 0: @@ -695,7 +695,7 @@ def ldap_auth(server='ldap', ldap_groups_of_the_user = list() for group_row in group_search_result: group = group_row[1] - if type(group) == dict and group_name_attrib in group: + if isinstance(group, dict) and group_name_attrib in group: ldap_groups_of_the_user.extend(group[group_name_attrib]) con.unbind() diff --git a/gluon/contrib/pyrtf/Elements.py b/gluon/contrib/pyrtf/Elements.py index 6e133271..9df7d1e5 100644 --- a/gluon/contrib/pyrtf/Elements.py +++ b/gluon/contrib/pyrtf/Elements.py @@ -384,8 +384,7 @@ def _get_emf_dimensions( fin ): header.HeightDevMM = get_LONG() # Height of reference device in millimeters if 0: - klist = header.__dict__.keys() - klist.sort() + klist = sorted(header.__dict__.keys()) for k in klist: print "%20s:%s" % (k,header.__dict__[k]) diff --git a/gluon/contrib/pyrtf/PropertySets.py b/gluon/contrib/pyrtf/PropertySets.py index 6ca4c9e9..3816e5ca 100644 --- a/gluon/contrib/pyrtf/PropertySets.py +++ b/gluon/contrib/pyrtf/PropertySets.py @@ -17,7 +17,7 @@ from copy import deepcopy # We need some basic Type like fonts, colours and paper definitions # def MakeAttributeName( value ) : - assert value and type( value ) is StringType + assert value and isinstance(value, StringType) value = value.replace( ' ', '' ) return value diff --git a/gluon/contrib/qdb.py b/gluon/contrib/qdb.py index acc94ee5..cc897d84 100644 --- a/gluon/contrib/qdb.py +++ b/gluon/contrib/qdb.py @@ -602,7 +602,7 @@ class Frontend(object): req = {'method': method, 'args': args, 'id': self.i} self.send(req) self.i += 1 # increment the id - while 1: + while True: # wait until command acknowledge (response id match the request) res = self.recv() if 'id' not in res or not res['id']: @@ -715,7 +715,7 @@ class Cli(Frontend, cmd.Cmd): # redefine Frontend methods: def run(self): - while 1: + while True: try: Frontend.run(self) except KeyboardInterrupt: @@ -850,7 +850,7 @@ def test(): qdb = Test(front_conn) time.sleep(5) - while 1: + while True: print "running..." Frontend.run(qdb) time.sleep(1) diff --git a/gluon/contrib/redis_scheduler.py b/gluon/contrib/redis_scheduler.py index 8edf5a17..7bd3ffb5 100644 --- a/gluon/contrib/redis_scheduler.py +++ b/gluon/contrib/redis_scheduler.py @@ -317,7 +317,7 @@ class RScheduler(Scheduler): now = self.now() status_keyset = self._nkey('worker_statuses') with r_server.pipeline() as pipe: - while 1: + while True: try: # making sure we're the only one doing the job pipe.watch('ASSIGN_TASKS') diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index ac12c107..2d983f5f 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -678,7 +678,7 @@ class AutocompleteWidget(object): def callback(self): if self.keyword in self.request.vars: field = self.fields[0] - if type(field) is Field.Virtual: + if isinstance(field, Field.Virtual): records = [] table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby) count = 0 @@ -742,7 +742,7 @@ class AutocompleteWidget(object): del attr['requires'] attr['_name'] = key2 value = attr['value'] - if type(self.fields[0]) is Field.Virtual: + if isinstance(self.fields[0], Field.Virtual): record = None table_rows = self.db(self.db[self.fields[0].tablename]).select(orderby=self.orderby) for row in table_rows: diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index 423416cb..7c1f56f6 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -62,7 +62,7 @@ def _prepare_exec_for_file(filename): raise 'The file provided (%s) does is not a valid Python file.' filename = os.path.realpath(filename) dirpath = filename - while 1: + while True: dirpath, extra = os.path.split(dirpath) module.append(extra) if not os.path.isfile(os.path.join(dirpath, '__init__.py')): diff --git a/gluon/validators.py b/gluon/validators.py index c6cfcce0..012f868d 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -2096,7 +2096,7 @@ class IS_URL(Validator): else: raise SyntaxError("invalid mode '%s' in IS_URL" % self.mode) - if type(value) != unicode: + if not isinstance(value, unicode): return subMethod(value) else: try: @@ -3003,13 +3003,13 @@ class IS_STRONG(object): if entropy < self.entropy: failures.append(translate("Entropy (%(have)s) less than required (%(need)s)") % dict(have=entropy, need=self.entropy)) - if type(self.min) == int and self.min > 0: + if isinstance(self.min, int) and self.min > 0: if not len(value) >= self.min: failures.append(translate("Minimum length is %s") % self.min) - if type(self.max) == int and self.max > 0: + if isinstance(self.max, int) and self.max > 0: if not len(value) <= self.max: failures.append(translate("Maximum length is %s") % self.max) - if type(self.special) == int: + if isinstance(self.special, int): all_special = [ch in value for ch in self.specials] if self.special > 0: if not all_special.count(True) >= self.special: @@ -3020,7 +3020,7 @@ class IS_STRONG(object): if all_invalid.count(True) > 0: failures.append(translate("May not contain any of the following: %s") % self.invalid) - if type(self.upper) == int: + if isinstance(self.upper, int): all_upper = re.findall("[A-Z]", value) if self.upper > 0: if not len(all_upper) >= self.upper: @@ -3030,7 +3030,7 @@ class IS_STRONG(object): if len(all_upper) > 0: failures.append( translate("May not include any upper case letters")) - if type(self.lower) == int: + if isinstance(self.lower, int): all_lower = re.findall("[a-z]", value) if self.lower > 0: if not len(all_lower) >= self.lower: @@ -3040,7 +3040,7 @@ class IS_STRONG(object): if len(all_lower) > 0: failures.append( translate("May not include any lower case letters")) - if type(self.number) == int: + if isinstance(self.number, int): all_number = re.findall("[0-9]", value) if self.number > 0: numbers = "number"
%s%s