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:
parent
89ef1f40f5
commit
8b09723a00
@ -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 tmp: path to tmp to use, defaults to None
|
||||||
:param pickle_protocol: protocol to pickle the obj with, defaults to 0
|
:param pickle_protocol: protocol to pickle the obj with, defaults to 0
|
||||||
"""
|
"""
|
||||||
if tmp == None:
|
if tmp is None:
|
||||||
tmp = os.path.dirname(dest)
|
tmp = os.path.dirname(dest)
|
||||||
fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
|
fd, tmppath = mkstemp(dir=tmp, suffix='.tmp')
|
||||||
with os.fdopen(fd, 'wb') as fo:
|
with os.fdopen(fd, 'wb') as fo:
|
||||||
|
@ -644,7 +644,7 @@ class ObjectController(object):
|
|||||||
file.metadata['ETag'] not in request.if_match:
|
file.metadata['ETag'] not in request.if_match:
|
||||||
file.close()
|
file.close()
|
||||||
return HTTPPreconditionFailed(request=request)
|
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:
|
if file.metadata['ETag'] in request.if_none_match:
|
||||||
resp = HTTPNotModified(request=request)
|
resp = HTTPNotModified(request=request)
|
||||||
resp.etag = file.metadata['ETag']
|
resp.etag = file.metadata['ETag']
|
||||||
|
@ -321,7 +321,7 @@ class Account(Base):
|
|||||||
format = parms.get('format', None)
|
format = parms.get('format', None)
|
||||||
if format not in [None, 'json', 'xml']:
|
if format not in [None, 'json', 'xml']:
|
||||||
raise RequestError('Invalid format: %s' % format)
|
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']
|
del parms['format']
|
||||||
|
|
||||||
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
||||||
@ -410,7 +410,7 @@ class Container(Base):
|
|||||||
format = parms.get('format', None)
|
format = parms.get('format', None)
|
||||||
if format not in [None, 'json', 'xml']:
|
if format not in [None, 'json', 'xml']:
|
||||||
raise RequestError('Invalid format: %s' % format)
|
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']
|
del parms['format']
|
||||||
|
|
||||||
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
status = self.conn.make_request('GET', self.path, hdrs=hdrs,
|
||||||
@ -591,7 +591,7 @@ class File(Base):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def random_data(cls, size=None):
|
def random_data(cls, size=None):
|
||||||
if size == None:
|
if size is None:
|
||||||
size = random.randint(1, 32768)
|
size = random.randint(1, 32768)
|
||||||
fd = open('/dev/urandom', 'r')
|
fd = open('/dev/urandom', 'r')
|
||||||
data = fd.read(size)
|
data = fd.read(size)
|
||||||
@ -674,9 +674,9 @@ class File(Base):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def chunked_write(self, data=None, hdrs={}, parms={}, cfg={}):
|
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)
|
self.conn.put_data(data, True)
|
||||||
elif data != None:
|
elif data is not None:
|
||||||
self.chunked_write_in_progress = True
|
self.chunked_write_in_progress = True
|
||||||
|
|
||||||
headers = self.make_headers(cfg=cfg)
|
headers = self.make_headers(cfg=cfg)
|
||||||
|
@ -81,7 +81,7 @@ class Utils:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_utf8_name(cls, length=None):
|
def create_utf8_name(cls, length=None):
|
||||||
if length == None:
|
if length is None:
|
||||||
length = 15
|
length = 15
|
||||||
else:
|
else:
|
||||||
length = int(length)
|
length = int(length)
|
||||||
@ -271,7 +271,7 @@ class TestAccount(Base):
|
|||||||
containers = self.env.account.containers(
|
containers = self.env.account.containers(
|
||||||
parms={'format':format,'marker':containers[-1]})
|
parms={'format':format,'marker':containers[-1]})
|
||||||
self.assertEquals(len(containers), 0)
|
self.assertEquals(len(containers), 0)
|
||||||
if format == None:
|
if format is None:
|
||||||
self.assert_status(204)
|
self.assert_status(204)
|
||||||
else:
|
else:
|
||||||
self.assert_status(200)
|
self.assert_status(200)
|
||||||
@ -320,7 +320,7 @@ class TestAccountNoContainers(Base):
|
|||||||
self.assert_(not self.env.account.containers(
|
self.assert_(not self.env.account.containers(
|
||||||
parms={'format':format}))
|
parms={'format':format}))
|
||||||
|
|
||||||
if format == None:
|
if format is None:
|
||||||
self.assert_status(204)
|
self.assert_status(204)
|
||||||
else:
|
else:
|
||||||
self.assert_status(200)
|
self.assert_status(200)
|
||||||
@ -529,7 +529,7 @@ class TestContainer(Base):
|
|||||||
parms={'format':format,'marker':files[-1]})
|
parms={'format':format,'marker':files[-1]})
|
||||||
self.assertEquals(len(files), 0)
|
self.assertEquals(len(files), 0)
|
||||||
|
|
||||||
if format == None:
|
if format is None:
|
||||||
self.assert_status(204)
|
self.assert_status(204)
|
||||||
else:
|
else:
|
||||||
self.assert_status(200)
|
self.assert_status(200)
|
||||||
|
@ -145,6 +145,6 @@ class MockTrue(object):
|
|||||||
def __repr__(*args, **kwargs):
|
def __repr__(*args, **kwargs):
|
||||||
return repr(True)
|
return repr(True)
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return other == True
|
return other is True
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return other != True
|
return other is not True
|
||||||
|
@ -607,7 +607,7 @@ class TestContainerBroker(unittest.TestCase):
|
|||||||
raise Exception('OMG')
|
raise Exception('OMG')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.assert_(broker.conn == None)
|
self.assert_(broker.conn is None)
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
""" Test swift.common.db.ContainerBroker.empty """
|
""" Test swift.common.db.ContainerBroker.empty """
|
||||||
@ -1535,7 +1535,7 @@ class TestAccountBroker(unittest.TestCase):
|
|||||||
raise Exception('OMG')
|
raise Exception('OMG')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.assert_(broker.conn == None)
|
self.assert_(broker.conn is None)
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
""" Test swift.common.db.AccountBroker.empty """
|
""" Test swift.common.db.AccountBroker.empty """
|
||||||
|
@ -483,7 +483,7 @@ class TestController(unittest.TestCase):
|
|||||||
cache_key = proxy_server.get_container_memcache_key(self.account,
|
cache_key = proxy_server.get_container_memcache_key(self.account,
|
||||||
self.container)
|
self.container)
|
||||||
cache_value = self.memcache.get(cache_key)
|
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'))
|
self.assertEquals(200, cache_value.get('status'))
|
||||||
|
|
||||||
proxy_server.http_connect = fake_http_connect()
|
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,
|
cache_key = proxy_server.get_container_memcache_key(self.account,
|
||||||
self.container)
|
self.container)
|
||||||
cache_value = self.memcache.get(cache_key)
|
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'))
|
self.assertEquals(404, cache_value.get('status'))
|
||||||
|
|
||||||
proxy_server.http_connect = fake_http_connect()
|
proxy_server.http_connect = fake_http_connect()
|
||||||
|
Loading…
Reference in New Issue
Block a user