Permalink
Browse files

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
  • Loading branch information...
zyluo committed Jan 4, 2012
1 parent 89ef1f4 commit 8b09723a000e838c16631927e81506afad783ee6
View
@@ -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
@@ -644,7 +644,7 @@ def GET(self, request):
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
@@ -321,7 +321,7 @@ def containers(self, hdrs={}, parms={}, cfg={}):
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 @@ def files(self, hdrs={}, parms={}, cfg={}):
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 @@ def path(self):
@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 @@ def sync_metadata(self, metadata={}, cfg={}):
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
@@ -81,7 +81,7 @@ def create_ascii_name(cls, length=None):
@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 @@ def testLastContainerMarker(self):
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 @@ def testGetRequest(self):
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 @@ def testLastFileMarker(self):
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
@@ -145,6 +145,6 @@ def __call__(self, *args, **kwargs):
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
@@ -607,7 +607,7 @@ def test_exception(self):
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 @@ def test_exception(self):
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 """
@@ -483,7 +483,7 @@ def account_info(self, account, autocreate=False):
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 @@ def account_info(self, account, autocreate=False):
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()

0 comments on commit 8b09723

Please sign in to comment.