Fixes 'not in' operator usage

Fixes bug #1111254

Change-Id: I297829049213732217332a969aa107525ac13600
This commit is contained in:
Zhongyue Luo 2013-01-31 14:18:12 +08:00
parent dfbdd5f457
commit d7be5c1982
8 changed files with 21 additions and 11 deletions

View File

@ -13,6 +13,16 @@ General
- Do not write "except:", use "except Exception:" at the very least
- Include your name with TODOs as in "#TODO(termie)"
- Do not name anything the same name as a built-in or reserved word
- Use the "not in" operator for collection membership evaluation. Example::
if not X in Y: # BAD, hard to understand
pass
if X not in Y: # OKAY, intuitive
pass
if not (X in Y or X is Z): # OKAY, still better than all those 'not's
pass
Imports

View File

@ -68,12 +68,12 @@ def validate_image_meta(req, values):
container_format = values.get('container_format')
if 'disk_format' in values:
if not disk_format in DISK_FORMATS:
if disk_format not in DISK_FORMATS:
msg = "Invalid disk format '%s' for image." % disk_format
raise HTTPBadRequest(explanation=msg, request=req)
if 'container_format' in values:
if not container_format in CONTAINER_FORMATS:
if container_format not in CONTAINER_FORMATS:
msg = "Invalid container format '%s' for image." % container_format
raise HTTPBadRequest(explanation=msg, request=req)
@ -604,11 +604,11 @@ class Controller(controller.BaseController):
def _validate_image_for_activation(self, req, id, values):
"""Ensures that all required image metadata values are valid."""
image = self.get_image_meta_or_404(req, id)
if not 'disk_format' in values:
if 'disk_format' not in values:
values['disk_format'] = image['disk_format']
if not 'container_format' in values:
if 'container_format' not in values:
values['container_format'] = image['container_format']
if not 'name' in values:
if 'name' not in values:
values['name'] = image['name']
values = validate_image_meta(req, values)

View File

@ -54,7 +54,7 @@ class Controller(object):
image_repo = self.gateway.get_repo(req.context)
try:
image = image_repo.get(image_id)
if not tag_value in image.tags:
if tag_value not in image.tags:
raise webob.exc.HTTPNotFound()
image.tags.remove(tag_value)
image_repo.save(image)

View File

@ -187,7 +187,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
def _get_request_body(self, request):
output = super(RequestDeserializer, self).default(request)
if not 'body' in output:
if 'body' not in output:
msg = _('Body expected in request.')
raise webob.exc.HTTPBadRequest(explanation=msg)
return output['body']

View File

@ -445,7 +445,7 @@ class Request(webob.Request):
def get_content_type(self, allowed_content_types):
"""Determine content type of the request body."""
if not "Content-Type" in self.headers:
if "Content-Type" not in self.headers:
raise exception.InvalidContentType(content_type=None)
content_type = self.content_type

View File

@ -690,7 +690,7 @@ def _set_properties_for_image(context, image_ref, properties,
if purge_props:
for key in orig_properties.keys():
if not key in properties:
if key not in properties:
prop_ref = orig_properties[key]
image_property_delete(context, prop_ref, session=session)

View File

@ -106,7 +106,7 @@ class FakeHTTPConnection(object):
hkeys.sort()
hashable = (method, url, body, ' '.join(hkeys))
if not hashable in self.reqs:
if hashable not in self.reqs:
options = []
for h in self.reqs:
options.append(repr(h))

View File

@ -128,7 +128,7 @@ def stub_out_swiftclient(stubs, swift_store_auth_version):
def fake_get_object(url, token, container, name, **kwargs):
# GET returns the tuple (list of headers, file object)
fixture_key = "%s/%s" % (container, name)
if not fixture_key in fixture_headers:
if fixture_key not in fixture_headers:
msg = "Object GET failed"
raise swiftclient.ClientException(msg,
http_status=httplib.NOT_FOUND)