PEP8 swift cleanup

The None, True, and False values are singletons.

All variable *comparisons* to singletons should use 'is' or 'is not'.
All variable *evaluations* to boolean should use 'if' or 'if not'.
All Object type comparisons should use isinstance()
instead of comparing types directly.

Change-Id: I47863c4862791022670619f19b8bc15d8a93fd81
This commit is contained in:
lzyeval 2012-01-04 14:43:16 +08:00
parent 89ef1f40f5
commit 8b09723a00
7 changed files with 17 additions and 17 deletions

View File

@ -852,7 +852,7 @@ def write_pickle(obj, dest, tmp=None, pickle_protocol=0):
:param tmp: path to tmp to use, defaults to None
:param pickle_protocol: protocol to pickle the obj with, defaults to 0
"""
if tmp == None:
if tmp is None:
tmp = os.path.dirname(dest)
fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
with os.fdopen(fd, 'wb') as fo:

View File

@ -644,7 +644,7 @@ class ObjectController(object):
file.metadata['ETag'] not in request.if_match:
file.close()
return HTTPPreconditionFailed(request=request)
if request.headers.get('if-none-match') != None:
if request.headers.get('if-none-match') is not None:
if file.metadata['ETag'] in request.if_none_match:
resp = HTTPNotModified(request=request)
resp.etag = file.metadata['ETag']

View File

@ -321,7 +321,7 @@ class Account(Base):
format = parms.get('format', None)
if format not in [None, 'json', 'xml']:
raise RequestError('Invalid format: %s' % format)
if format == None and parms.has_key('format'):
if format is None and parms.has_key('format'):
del parms['format']
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
@ -410,7 +410,7 @@ class Container(Base):
format = parms.get('format', None)
if format not in [None, 'json', 'xml']:
raise RequestError('Invalid format: %s' % format)
if format == None and parms.has_key('format'):
if format is None and parms.has_key('format'):
del parms['format']
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
@ -591,7 +591,7 @@ class File(Base):
@classmethod
def random_data(cls, size=None):
if size == None:
if size is None:
size = random.randint(1, 32768)
fd = open('/dev/urandom', 'r')
data = fd.read(size)
@ -674,9 +674,9 @@ class File(Base):
return True
def chunked_write(self, data=None, hdrs={}, parms={}, cfg={}):
if data != None and self.chunked_write_in_progress:
if data is not None and self.chunked_write_in_progress:
self.conn.put_data(data, True)
elif data != None:
elif data is not None:
self.chunked_write_in_progress = True
headers = self.make_headers(cfg=cfg)

View File

@ -81,7 +81,7 @@ class Utils:
@classmethod
def create_utf8_name(cls, length=None):
if length == None:
if length is None:
length = 15
else:
length = int(length)
@ -271,7 +271,7 @@ class TestAccount(Base):
containers = self.env.account.containers(
parms={'format':format,'marker':containers[-1]})
self.assertEquals(len(containers), 0)
if format == None:
if format is None:
self.assert_status(204)
else:
self.assert_status(200)
@ -320,7 +320,7 @@ class TestAccountNoContainers(Base):
self.assert_(not self.env.account.containers(
parms={'format':format}))
if format == None:
if format is None:
self.assert_status(204)
else:
self.assert_status(200)
@ -529,7 +529,7 @@ class TestContainer(Base):
parms={'format':format,'marker':files[-1]})
self.assertEquals(len(files), 0)
if format == None:
if format is None:
self.assert_status(204)
else:
self.assert_status(200)

View File

@ -145,6 +145,6 @@ class MockTrue(object):
def __repr__(*args, **kwargs):
return repr(True)
def __eq__(self, other):
return other == True
return other is True
def __ne__(self, other):
return other != True
return other is not True

View File

@ -607,7 +607,7 @@ class TestContainerBroker(unittest.TestCase):
raise Exception('OMG')
except Exception:
pass
self.assert_(broker.conn == None)
self.assert_(broker.conn is None)
def test_empty(self):
""" Test swift.common.db.ContainerBroker.empty """
@ -1535,7 +1535,7 @@ class TestAccountBroker(unittest.TestCase):
raise Exception('OMG')
except Exception:
pass
self.assert_(broker.conn == None)
self.assert_(broker.conn is None)
def test_empty(self):
""" Test swift.common.db.AccountBroker.empty """

View File

@ -483,7 +483,7 @@ class TestController(unittest.TestCase):
cache_key = proxy_server.get_container_memcache_key(self.account,
self.container)
cache_value = self.memcache.get(cache_key)
self.assertEquals(dict, type(cache_value))
self.assertTrue(isinstance(cache_value, dict))
self.assertEquals(200, cache_value.get('status'))
proxy_server.http_connect = fake_http_connect()
@ -506,7 +506,7 @@ class TestController(unittest.TestCase):
cache_key = proxy_server.get_container_memcache_key(self.account,
self.container)
cache_value = self.memcache.get(cache_key)
self.assertEquals(dict, type(cache_value))
self.assertTrue(isinstance(cache_value, dict))
self.assertEquals(404, cache_value.get('status'))
proxy_server.http_connect = fake_http_connect()