running lib2to3.fixes.fix_idioms

This commit is contained in:
ilvalle committed 2016-05-29 08:31:20 +02:00
1 parent 9b9ed0ad0f
commit a5599f3eab
9 files changed
+26 -28

No files matched your search

+8 -9
View File
@@ -1010,7 +1010,7 @@ class Server(object):
else: else:
# Run as a server # Run as a server
oldUmask = None oldUmask = None
if type(self._bindAddress) is str: if isinstance(self._bindAddress, str):
# Unix socket # Unix socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try: try:
@@ -1021,7 +1021,7 @@ class Server(object):
oldUmask = os.umask(self._umask) oldUmask = os.umask(self._umask)
else: else:
# INET socket # INET socket
assert type(self._bindAddress) is tuple assert isinstance(self._bindAddress, tuple)
assert len(self._bindAddress) == 2 assert len(self._bindAddress) == 2
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -1209,7 +1209,7 @@ class WSGIServer(Server):
result = None result = None
def write(data): 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()' assert headers_set, 'write() before start_response()'
if not headers_sent: if not headers_sent:
@@ -1246,15 +1246,15 @@ class WSGIServer(Server):
else: else:
assert not headers_set, 'Headers already set!' 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 len(status) >= 4, 'Status must be at least 4 characters'
assert int(status[:3]), 'Status must begin with 3-digit code' assert int(status[:3]), 'Status must begin with 3-digit code'
assert status[3] == ' ', 'Status must have a space after 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__: if __debug__:
for name,val in response_headers: for name,val in response_headers:
assert type(name) is str, 'Header names must be strings' assert isinstance(name, str), 'Header names must be strings'
assert type(val) is str, 'Header values must be strings' assert isinstance(val, str), 'Header values must be strings'
headers_set[:] = [status, response_headers] headers_set[:] = [status, response_headers]
return write return write
@@ -1310,8 +1310,7 @@ if __name__ == '__main__':
'<body>\n' \ '<body>\n' \
'<p>Hello World!</p>\n' \ '<p>Hello World!</p>\n' \
'<table border="1">' '<table border="1">'
names = environ.keys() names = sorted(environ.keys())
names.sort()
for name in names: for name in names:
yield '<tr><td>%s</td><td>%s</td></tr>\n' % ( yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
name, cgi.escape(repr(environ[name]))) name, cgi.escape(repr(environ[name])))
+2 -2
View File
@@ -477,7 +477,7 @@ def ldap_auth(server='ldap',
ldap_groups_of_the_user = get_user_groups_from_ldap(username, password) ldap_groups_of_the_user = get_user_groups_from_ldap(username, password)
# search for allowed group names # search for allowed group names
if type(allowed_groups) != type(list()): if not isinstance(allowed_groups, type(list())):
allowed_groups = [allowed_groups] allowed_groups = [allowed_groups]
for group in allowed_groups: for group in allowed_groups:
if ldap_groups_of_the_user.count(group) > 0: if ldap_groups_of_the_user.count(group) > 0:
@@ -695,7 +695,7 @@ def ldap_auth(server='ldap',
ldap_groups_of_the_user = list() ldap_groups_of_the_user = list()
for group_row in group_search_result: for group_row in group_search_result:
group = group_row[1] 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]) ldap_groups_of_the_user.extend(group[group_name_attrib])
con.unbind() con.unbind()
+1 -2
View File
@@ -384,8 +384,7 @@ def _get_emf_dimensions( fin ):
header.HeightDevMM = get_LONG() # Height of reference device in millimeters header.HeightDevMM = get_LONG() # Height of reference device in millimeters
if 0: if 0:
klist = header.__dict__.keys() klist = sorted(header.__dict__.keys())
klist.sort()
for k in klist: for k in klist:
print "%20s:%s" % (k,header.__dict__[k]) print "%20s:%s" % (k,header.__dict__[k])
+1 -1
View File
@@ -17,7 +17,7 @@ from copy import deepcopy
# We need some basic Type like fonts, colours and paper definitions # We need some basic Type like fonts, colours and paper definitions
# #
def MakeAttributeName( value ) : def MakeAttributeName( value ) :
assert value and type( value ) is StringType assert value and isinstance(value, StringType)
value = value.replace( ' ', '' ) value = value.replace( ' ', '' )
return value return value
+3 -3
View File
@@ -602,7 +602,7 @@ class Frontend(object):
req = {'method': method, 'args': args, 'id': self.i} req = {'method': method, 'args': args, 'id': self.i}
self.send(req) self.send(req)
self.i += 1 # increment the id self.i += 1 # increment the id
while 1: while True:
# wait until command acknowledge (response id match the request) # wait until command acknowledge (response id match the request)
res = self.recv() res = self.recv()
if 'id' not in res or not res['id']: if 'id' not in res or not res['id']:
@@ -715,7 +715,7 @@ class Cli(Frontend, cmd.Cmd):
# redefine Frontend methods: # redefine Frontend methods:
def run(self): def run(self):
while 1: while True:
try: try:
Frontend.run(self) Frontend.run(self)
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -850,7 +850,7 @@ def test():
qdb = Test(front_conn) qdb = Test(front_conn)
time.sleep(5) time.sleep(5)
while 1: while True:
print "running..." print "running..."
Frontend.run(qdb) Frontend.run(qdb)
time.sleep(1) time.sleep(1)
+1 -1
View File
@@ -317,7 +317,7 @@ class RScheduler(Scheduler):
now = self.now() now = self.now()
status_keyset = self._nkey('worker_statuses') status_keyset = self._nkey('worker_statuses')
with r_server.pipeline() as pipe: with r_server.pipeline() as pipe:
while 1: while True:
try: try:
# making sure we're the only one doing the job # making sure we're the only one doing the job
pipe.watch('ASSIGN_TASKS') pipe.watch('ASSIGN_TASKS')
+2 -2
View File
@@ -678,7 +678,7 @@ class AutocompleteWidget(object):
def callback(self): def callback(self):
if self.keyword in self.request.vars: if self.keyword in self.request.vars:
field = self.fields[0] field = self.fields[0]
if type(field) is Field.Virtual: if isinstance(field, Field.Virtual):
records = [] records = []
table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby) table_rows = self.db(self.db[field.tablename]).select(orderby=self.orderby)
count = 0 count = 0
@@ -742,7 +742,7 @@ class AutocompleteWidget(object):
del attr['requires'] del attr['requires']
attr['_name'] = key2 attr['_name'] = key2
value = attr['value'] value = attr['value']
if type(self.fields[0]) is Field.Virtual: if isinstance(self.fields[0], Field.Virtual):
record = None record = None
table_rows = self.db(self.db[self.fields[0].tablename]).select(orderby=self.orderby) table_rows = self.db(self.db[self.fields[0].tablename]).select(orderby=self.orderby)
for row in table_rows: for row in table_rows:
+1 -1
View File
@@ -62,7 +62,7 @@ def _prepare_exec_for_file(filename):
raise 'The file provided (%s) does is not a valid Python file.' raise 'The file provided (%s) does is not a valid Python file.'
filename = os.path.realpath(filename) filename = os.path.realpath(filename)
dirpath = filename dirpath = filename
while 1: while True:
dirpath, extra = os.path.split(dirpath) dirpath, extra = os.path.split(dirpath)
module.append(extra) module.append(extra)
if not os.path.isfile(os.path.join(dirpath, '__init__.py')): if not os.path.isfile(os.path.join(dirpath, '__init__.py')):
+7 -7
View File
@@ -2096,7 +2096,7 @@ class IS_URL(Validator):
else: else:
raise SyntaxError("invalid mode '%s' in IS_URL" % self.mode) raise SyntaxError("invalid mode '%s' in IS_URL" % self.mode)
if type(value) != unicode: if not isinstance(value, unicode):
return subMethod(value) return subMethod(value)
else: else:
try: try:
@@ -3003,13 +3003,13 @@ class IS_STRONG(object):
if entropy < self.entropy: if entropy < self.entropy:
failures.append(translate("Entropy (%(have)s) less than required (%(need)s)") failures.append(translate("Entropy (%(have)s) less than required (%(need)s)")
% dict(have=entropy, need=self.entropy)) % 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: if not len(value) >= self.min:
failures.append(translate("Minimum length is %s") % 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: if not len(value) <= self.max:
failures.append(translate("Maximum length is %s") % 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] all_special = [ch in value for ch in self.specials]
if self.special > 0: if self.special > 0:
if not all_special.count(True) >= self.special: if not all_special.count(True) >= self.special:
@@ -3020,7 +3020,7 @@ class IS_STRONG(object):
if all_invalid.count(True) > 0: if all_invalid.count(True) > 0:
failures.append(translate("May not contain any of the following: %s") failures.append(translate("May not contain any of the following: %s")
% self.invalid) % self.invalid)
if type(self.upper) == int: if isinstance(self.upper, int):
all_upper = re.findall("[A-Z]", value) all_upper = re.findall("[A-Z]", value)
if self.upper > 0: if self.upper > 0:
if not len(all_upper) >= self.upper: if not len(all_upper) >= self.upper:
@@ -3030,7 +3030,7 @@ class IS_STRONG(object):
if len(all_upper) > 0: if len(all_upper) > 0:
failures.append( failures.append(
translate("May not include any upper case letters")) 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) all_lower = re.findall("[a-z]", value)
if self.lower > 0: if self.lower > 0:
if not len(all_lower) >= self.lower: if not len(all_lower) >= self.lower:
@@ -3040,7 +3040,7 @@ class IS_STRONG(object):
if len(all_lower) > 0: if len(all_lower) > 0:
failures.append( failures.append(
translate("May not include any lower case letters")) 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) all_number = re.findall("[0-9]", value)
if self.number > 0: if self.number > 0:
numbers = "number" numbers = "number"