Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace 'dict.has_key' with 'in'

  • Loading branch information...
commit 8258e379d654e6c716381ab4b92bd2f98565c35a 1 parent 9539206
@gholms gholms authored
View
6 boto/auth.py
@@ -127,7 +127,7 @@ def add_auth(self, http_request, **kwargs):
headers = http_request.headers
method = http_request.method
auth_path = http_request.auth_path
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
if self._provider.security_token:
@@ -156,7 +156,7 @@ def __init__(self, host, config, provider):
def add_auth(self, http_request, **kwargs):
headers = http_request.headers
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
b64_hmac = self.sign_string(headers['Date'])
@@ -176,7 +176,7 @@ def __init__(self, host, config, provider):
def add_auth(self, http_request, **kwargs):
headers = http_request.headers
- if not headers.has_key('Date'):
+ if 'Date' not in headers:
headers['Date'] = formatdate(usegmt=True)
b64_hmac = self.sign_string(headers['Date'])
View
6 boto/connection.py
@@ -361,8 +361,8 @@ def authorize(self, connection, **kwargs):
self.headers['User-Agent'] = UserAgent
# I'm not sure if this is still needed, now that add_auth is
# setting the content-length for POST requests.
- if not self.headers.has_key('Content-Length'):
- if not self.headers.has_key('Transfer-Encoding') or \
+ if 'Content-Length' not in self.headers:
+ if 'Transfer-Encoding' not in self.headers or \
self.headers['Transfer-Encoding'] != 'chunked':
self.headers['Content-Length'] = str(len(self.body))
@@ -566,7 +566,7 @@ def handle_proxy(self, proxy, proxy_port, proxy_user, proxy_pass):
self.proxy_port = proxy_port
self.proxy_user = proxy_user
self.proxy_pass = proxy_pass
- if os.environ.has_key('http_proxy') and not self.proxy:
+ if 'http_proxy' in os.environ and not self.proxy:
pattern = re.compile(
'(?:http://)?' \
'(?:(?P<user>\w+):(?P<pass>.*)@)?' \
View
6 boto/ec2/image.py
@@ -307,17 +307,17 @@ def endElement(self, name, value, connection):
if name == 'launchPermission':
self.name = 'launch_permission'
elif name == 'group':
- if self.attrs.has_key('groups'):
+ if 'groups' in self.attrs:
self.attrs['groups'].append(value)
else:
self.attrs['groups'] = [value]
elif name == 'userId':
- if self.attrs.has_key('user_ids'):
+ if 'user_ids' in self.attrs:
self.attrs['user_ids'].append(value)
else:
self.attrs['user_ids'] = [value]
elif name == 'productCode':
- if self.attrs.has_key('product_codes'):
+ if 'product_codes' in self.attrs:
self.attrs['product_codes'].append(value)
else:
self.attrs['product_codes'] = [value]
View
4 boto/ec2/snapshot.py
@@ -127,12 +127,12 @@ def endElement(self, name, value, connection):
if name == 'createVolumePermission':
self.name = 'create_volume_permission'
elif name == 'group':
- if self.attrs.has_key('groups'):
+ if 'groups' in self.attrs:
self.attrs['groups'].append(value)
else:
self.attrs['groups'] = [value]
elif name == 'userId':
- if self.attrs.has_key('user_ids'):
+ if 'user_ids' in self.attrs:
self.attrs['user_ids'].append(value)
else:
self.attrs['user_ids'] = [value]
View
4 boto/gs/acl.py
@@ -189,7 +189,7 @@ def startElement(self, name, attrs, connection):
# __contains__() method works). At one time gsutil disallowed
# xmlplus-based parsers, until this more specific problem was
# determined.
- if not attrs.has_key(TYPE):
+ if TYPE not in attrs:
raise InvalidAclError('Missing "%s" in "%s" part of ACL' %
(TYPE, SCOPE))
self.scope = Scope(self, attrs[TYPE])
@@ -240,7 +240,7 @@ def __init__(self, parent, type=None, id=None, name=None,
self.id = id
self.domain = domain
self.email_address = email_address
- if not self.ALLOWED_SCOPE_TYPE_SUB_ELEMS.has_key(self.type.lower()):
+ if self.type.lower() not in self.ALLOWED_SCOPE_TYPE_SUB_ELEMS:
raise InvalidAclError('Invalid %s %s "%s" ' %
(SCOPE, TYPE, self.type))
View
4 boto/provider.py
@@ -176,14 +176,14 @@ def get_credentials(self, access_key=None, secret_key=None):
access_key_name, secret_key_name = self.CredentialMap[self.name]
if access_key is not None:
self.access_key = access_key
- elif os.environ.has_key(access_key_name.upper()):
+ elif access_key_name.upper() in os.environ:
self.access_key = os.environ[access_key_name.upper()]
elif config.has_option('Credentials', access_key_name):
self.access_key = config.get('Credentials', access_key_name)
if secret_key is not None:
self.secret_key = secret_key
- elif os.environ.has_key(secret_key_name.upper()):
+ elif secret_key_name.upper() in os.environ:
self.secret_key = os.environ[secret_key_name.upper()]
elif config.has_option('Credentials', secret_key_name):
self.secret_key = config.get('Credentials', secret_key_name)
View
2  boto/route53/connection.py
@@ -105,7 +105,7 @@ def get_all_hosted_zones(self, start_marker=None, zone_list=None):
h.parse(body)
if zone_list:
e['ListHostedZonesResponse']['HostedZones'].extend(zone_list)
- while e['ListHostedZonesResponse'].has_key('NextMarker'):
+ while 'NextMarker' in e['ListHostedZonesResponse']:
next_marker = e['ListHostedZonesResponse']['NextMarker']
zone_list = e['ListHostedZonesResponse']['HostedZones']
e = self.get_all_hosted_zones(next_marker, zone_list)
View
6 boto/s3/key.py
@@ -684,9 +684,9 @@ def sender(http_conn, method, path, data, headers):
headers['User-Agent'] = UserAgent
if self.storage_class != 'STANDARD':
headers[provider.storage_class_header] = self.storage_class
- if headers.has_key('Content-Encoding'):
+ if 'Content-Encoding' in headers:
self.content_encoding = headers['Content-Encoding']
- if headers.has_key('Content-Type'):
+ if 'Content-Type' in headers:
# Some use cases need to suppress sending of the Content-Type
# header and depend on the receiving server to set the content
# type. This can be achieved by setting headers['Content-Type']
@@ -1223,7 +1223,7 @@ def get_file(self, fp, headers=None, cb=None, num_cb=10,
cb(data_len, cb_size)
if m:
self.md5 = m.hexdigest()
- if self.size is None and not torrent and not headers.has_key("Range"):
+ if self.size is None and not torrent and "Range" not in headers:
self.size = data_len
self.close()
self.bucket.connection.debug = save_debug
View
10 boto/sdb/db/manager/sdbmanager.py
@@ -471,9 +471,9 @@ def get_blob_bucket(self, bucket_name=None):
def load_object(self, obj):
if not obj._loaded:
a = self.domain.get_attributes(obj.id,consistent_read=self.consistent)
- if a.has_key('__type__'):
+ if '__type__' in a:
for prop in obj.properties(hidden=False):
- if a.has_key(prop.name):
+ if prop.name in a:
value = self.decode_value(prop, a[prop.name])
value = prop.make_value_from_datastore(value)
try:
@@ -486,13 +486,13 @@ def get_object(self, cls, id, a=None):
obj = None
if not a:
a = self.domain.get_attributes(id,consistent_read=self.consistent)
- if a.has_key('__type__'):
+ if '__type__' in a:
if not cls or a['__type__'] != cls.__name__:
cls = find_class(a['__module__'], a['__type__'])
if cls:
params = {}
for prop in cls.properties(hidden=False):
- if a.has_key(prop.name):
+ if prop.name in a:
value = self.decode_value(prop, a[prop.name])
value = prop.make_value_from_datastore(value)
params[prop.name] = value
@@ -716,7 +716,7 @@ def delete_key_value(self, obj, name):
def get_key_value(self, obj, name):
a = self.domain.get_attributes(obj.id, name,consistent_read=self.consistent)
- if a.has_key(name):
+ if name in a:
return a[name]
else:
return None
View
2  boto/sdb/db/manager/xmlmanager.py
@@ -495,7 +495,7 @@ def delete_key_value(self, obj, name):
def get_key_value(self, obj, name):
a = self.domain.get_attributes(obj.id, name)
- if a.has_key(name):
+ if name in a:
return a[name]
else:
return None
View
2  boto/sdb/db/model.py
@@ -154,7 +154,7 @@ def __init__(self, id=None, **kw):
setattr(self, prop.name, prop.default_value())
except ValueError:
pass
- if kw.has_key('manager'):
+ if 'manager' in kw:
self._manager = kw['manager']
self.id = id
for key in kw:
View
6 boto/sdb/db/sequence.py
@@ -180,11 +180,11 @@ def get(self):
"""Get the value"""
val = self.db.get_attributes(self.id, consistent_read=True)
if val:
- if val.has_key('timestamp'):
+ if 'timestamp' in val:
self.timestamp = val['timestamp']
- if val.has_key('current_value'):
+ if 'current_value' in val:
self._value = self.item_type(val['current_value'])
- if val.has_key("last_value") and val['last_value'] != None:
+ if "last_value" in val and val['last_value'] != None:
self.last_value = self.item_type(val['last_value'])
return self._value
View
2  boto/sdb/domain.py
@@ -343,7 +343,7 @@ def endElement(self, name):
if self.value and self.attribute:
value = self.value.strip()
attr_name = self.attribute.strip()
- if self.attrs.has_key(attr_name):
+ if attr_name in self.attrs:
self.attrs[attr_name].append(value)
else:
self.attrs[attr_name] = [value]
View
2  boto/sdb/item.py
@@ -75,7 +75,7 @@ def endElement(self, name, value, connection):
else:
self.name = self.decode_value(value)
elif name == 'Value':
- if self.has_key(self.last_key):
+ if self.last_key in self:
if not isinstance(self[self.last_key], list):
self[self.last_key] = [self[self.last_key]]
value = self.decode_value(value)
View
4 boto/services/result.py
@@ -76,7 +76,7 @@ def process_record(self, record, path, get_file=True):
self.log_message(record, path)
self.calculate_stats(record)
outputs = record['OutputKey'].split(',')
- if record.has_key('OutputBucket'):
+ if 'OutputBucket' in record:
bucket = boto.lookup('s3', record['OutputBucket'])
else:
bucket = boto.lookup('s3', record['Bucket'])
@@ -92,7 +92,7 @@ def process_record(self, record, path, get_file=True):
def get_results_from_queue(self, path, get_file=True, delete_msg=True):
m = self.queue.read()
while m:
- if m.has_key('Batch') and m['Batch'] == self.batch:
+ if 'Batch' in m and m['Batch'] == self.batch:
self.process_record(m, path, get_file)
if delete_msg:
self.queue.delete_message(m)
View
4 boto/services/service.py
@@ -92,7 +92,7 @@ def put_file(self, bucket_name, file_path, key_name=None):
def save_results(self, results, input_message, output_message):
output_keys = []
for file, type in results:
- if input_message.has_key('OutputBucket'):
+ if 'OutputBucket' in input_message:
output_bucket = input_message['OutputBucket']
else:
output_bucket = input_message['Bucket']
@@ -105,7 +105,7 @@ def save_results(self, results, input_message, output_message):
def write_message(self, message):
message['Service-Write'] = get_ts()
message['Server'] = self.name
- if os.environ.has_key('HOSTNAME'):
+ if 'HOSTNAME' in os.environ:
message['Host'] = os.environ['HOSTNAME']
else:
message['Host'] = 'unknown'
View
4 boto/sqs/message.py
@@ -200,7 +200,7 @@ def encode(self, value):
return s
def __getitem__(self, key):
- if self._body.has_key(key):
+ if key in self._body:
return self._body[key]
else:
raise KeyError(key)
@@ -219,7 +219,7 @@ def items(self):
return self._body.items()
def has_key(self, key):
- return self._body.has_key(key)
+ return key in self._body
def update(self, d):
self._body.update(d)
View
6 boto/utils.py
@@ -98,13 +98,13 @@ def canonical_string(method, path, headers, expires=None,
interesting_headers[lk] = headers[key].strip()
# these keys get empty strings if they don't exist
- if not interesting_headers.has_key('content-type'):
+ if 'content-type' not in interesting_headers:
interesting_headers['content-type'] = ''
- if not interesting_headers.has_key('content-md5'):
+ if 'content-md5' not in interesting_headers:
interesting_headers['content-md5'] = ''
# just in case someone used this. it's not necessary in this lib.
- if interesting_headers.has_key(provider.date_header):
+ if provider.date_header in interesting_headers:
interesting_headers['date'] = ''
# if you're using expires for query string auth, then it trumps date
View
2  boto/vpc/dhcpoptions.py
@@ -38,7 +38,7 @@ class DhcpConfigSet(dict):
def startElement(self, name, attrs, connection):
if name == 'valueSet':
- if not self.has_key(self._name):
+ if self._name not in self:
self[self._name] = DhcpValueSet()
return self[self._name]
View
4 tests/dynamodb/test_layer2.py
@@ -189,9 +189,9 @@ def test_layer2_basic(self):
item1_updated = table.get_item(item1_key, item1_range,
consistent_read=True)
assert item1_updated['Replies'] == item1_attrs['Replies'] + 2
- self.assertFalse(item1_updated.has_key(removed_attr))
+ self.assertFalse(removed_attr in item1_updated)
self.assertTrue(removed_tag not in item1_updated['Tags'])
- self.assertTrue(item1_updated.has_key('RepliesBy'))
+ self.assertTrue('RepliesBy' in item1_updated)
self.assertTrue(item1_updated['RepliesBy'] == replies_by_set)
# Put a few more items into the table
View
4 tests/ec2/test_connection.py
@@ -48,14 +48,14 @@ def test_1_basic(self):
status = image.set_launch_permissions(group_names=['all'])
assert status
d = image.get_launch_permissions()
- assert d.has_key('groups')
+ assert 'groups' in d
assert len(d['groups']) > 0
# now remove that permission
status = image.remove_launch_permissions(group_names=['all'])
assert status
time.sleep(10)
d = image.get_launch_permissions()
- assert not d.has_key('groups')
+ assert 'groups' not in d
# create 2 new security groups
group1_name = 'test-%d' % int(time.time())
View
2  tests/s3/test_versioning.py
@@ -46,7 +46,7 @@ def tearDown(self):
def test_1_versions(self):
# check versioning off
d = self.bucket.get_versioning_status()
- self.assertFalse(d.has_key('Versioning'))
+ self.assertFalse('Versioning' in d)
# enable versioning
self.bucket.configure_versioning(versioning=True)
View
12 tests/sqs/test_connection.py
@@ -66,14 +66,14 @@ def test_1_basic(self):
# now try to get queue attributes
a = q.get_attributes()
- assert a.has_key('ApproximateNumberOfMessages')
- assert a.has_key('VisibilityTimeout')
+ assert 'ApproximateNumberOfMessages' in a
+ assert 'VisibilityTimeout' in a
a = q.get_attributes('ApproximateNumberOfMessages')
- assert a.has_key('ApproximateNumberOfMessages')
- assert not a.has_key('VisibilityTimeout')
+ assert 'ApproximateNumberOfMessages' in a
+ assert 'VisibilityTimeout' not in a
a = q.get_attributes('VisibilityTimeout')
- assert not a.has_key('ApproximateNumberOfMessages')
- assert a.has_key('VisibilityTimeout')
+ assert 'ApproximateNumberOfMessages' not in a
+ assert 'VisibilityTimeout' in a
# now change the visibility timeout
timeout = 45
Please sign in to comment.
Something went wrong with that request. Please try again.