running lib2to3.fixes.fix_idioms

This commit is contained in:
ilvalle
2016-05-29 08:31:20 +02:00
parent 9b9ed0ad0f
commit a5599f3eab
9 changed files with 26 additions and 28 deletions
+8 -9
View File
@@ -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__':
'<body>\n' \
'<p>Hello World!</p>\n' \
'<table border="1">'
names = environ.keys()
names.sort()
names = sorted(environ.keys())
for name in names:
yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
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)
# 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()
+1 -2
View File
@@ -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])
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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')
+2 -2
View File
@@ -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:
+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.'
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')):
+7 -7
View File
@@ -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"