diff --git a/boto/auth.py b/boto/auth.py index 14bd0fa261..b8e00ef03a 100644 --- a/boto/auth.py +++ b/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']) diff --git a/boto/connection.py b/boto/connection.py index e170d0b324..d169a23c15 100644 --- a/boto/connection.py +++ b/boto/connection.py @@ -358,8 +358,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)) @@ -559,7 +559,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\w+):(?P.*)@)?' \ diff --git a/boto/ec2/image.py b/boto/ec2/image.py index de1b5d2656..0baf8889ad 100644 --- a/boto/ec2/image.py +++ b/boto/ec2/image.py @@ -300,17 +300,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] diff --git a/boto/ec2/snapshot.py b/boto/ec2/snapshot.py index d52abe4461..241cef260c 100644 --- a/boto/ec2/snapshot.py +++ b/boto/ec2/snapshot.py @@ -124,12 +124,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] diff --git a/boto/fps/connection.py b/boto/fps/connection.py index 27eef8f9f6..d2fcb58ca5 100644 --- a/boto/fps/connection.py +++ b/boto/fps/connection.py @@ -146,7 +146,7 @@ def make_marketplace_registration_url(self, returnURL, pipelineName, params["signatureMethod"] = 'HmacSHA256' params["signatureVersion"] = '2' - if(not params.has_key('callerReference')): + if('callerReference' not in params): params['callerReference'] = str(uuid.uuid4()) parts = '' @@ -191,7 +191,7 @@ def make_url(self, returnURL, paymentReason, pipelineName, params["signatureMethod"] = 'HmacSHA256' params["signatureVersion"] = '2' - if(not params.has_key('callerReference')): + if('callerReference' not in params): params['callerReference'] = str(uuid.uuid4()) parts = '' diff --git a/boto/gs/acl.py b/boto/gs/acl.py index 93bb4a9c26..02a5c9baed 100755 --- a/boto/gs/acl.py +++ b/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]) @@ -238,7 +238,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): + if self.type not in self.ALLOWED_SCOPE_TYPE_SUB_ELEMS: raise InvalidAclError('Invalid %s %s "%s" ' % (SCOPE, TYPE, self.type)) diff --git a/boto/provider.py b/boto/provider.py index 37ceae720d..e9a73975b8 100644 --- a/boto/provider.py +++ b/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) diff --git a/boto/route53/connection.py b/boto/route53/connection.py index 0ae63c14d2..a5183da14d 100644 --- a/boto/route53/connection.py +++ b/boto/route53/connection.py @@ -101,7 +101,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) diff --git a/boto/s3/key.py b/boto/s3/key.py index e8da98f34f..4a9a8296ad 100644 --- a/boto/s3/key.py +++ b/boto/s3/key.py @@ -628,9 +628,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'] @@ -1167,7 +1167,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 diff --git a/boto/sdb/db/manager/sdbmanager.py b/boto/sdb/db/manager/sdbmanager.py index 7f20350edc..ef7117fe6c 100644 --- a/boto/sdb/db/manager/sdbmanager.py +++ b/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 diff --git a/boto/sdb/db/manager/xmlmanager.py b/boto/sdb/db/manager/xmlmanager.py index 3608b2c254..aca2d7c27a 100644 --- a/boto/sdb/db/manager/xmlmanager.py +++ b/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 diff --git a/boto/sdb/db/model.py b/boto/sdb/db/model.py index eab82763f9..65a339636d 100644 --- a/boto/sdb/db/model.py +++ b/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: diff --git a/boto/sdb/db/sequence.py b/boto/sdb/db/sequence.py index a01330e854..10f1ac27c8 100644 --- a/boto/sdb/db/sequence.py +++ b/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 val.get('last_value') is not None: self.last_value = self.item_type(val['last_value']) return self._value diff --git a/boto/sdb/domain.py b/boto/sdb/domain.py index f348c8aa5a..d4faf04620 100644 --- a/boto/sdb/domain.py +++ b/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] diff --git a/boto/sdb/item.py b/boto/sdb/item.py index 86bc70cab2..999c7f0b31 100644 --- a/boto/sdb/item.py +++ b/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) diff --git a/boto/services/result.py b/boto/services/result.py index 32a6d6a627..8117673fb7 100644 --- a/boto/services/result.py +++ b/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) diff --git a/boto/services/service.py b/boto/services/service.py index 8ee1a8beed..e0e987ce86 100644 --- a/boto/services/service.py +++ b/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' diff --git a/boto/sqs/message.py b/boto/sqs/message.py index 8fabd47848..cdd2179564 100644 --- a/boto/sqs/message.py +++ b/boto/sqs/message.py @@ -198,7 +198,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) @@ -217,7 +217,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) diff --git a/boto/utils.py b/boto/utils.py index a2bf386dbe..55f91f37c9 100644 --- a/boto/utils.py +++ b/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 diff --git a/boto/vpc/dhcpoptions.py b/boto/vpc/dhcpoptions.py index 810d9cf8f4..7484683822 100644 --- a/boto/vpc/dhcpoptions.py +++ b/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] diff --git a/tests/dynamodb/test_layer2.py b/tests/dynamodb/test_layer2.py index 63708a1a08..6b361a5fba 100644 --- a/tests/dynamodb/test_layer2.py +++ b/tests/dynamodb/test_layer2.py @@ -199,9 +199,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 diff --git a/tests/ec2/test_connection.py b/tests/ec2/test_connection.py index 6b7ece1f74..bb1c5c890f 100644 --- a/tests/ec2/test_connection.py +++ b/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()) diff --git a/tests/s3/test_versioning.py b/tests/s3/test_versioning.py index 2d569af967..b3e74a5c34 100644 --- a/tests/s3/test_versioning.py +++ b/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) diff --git a/tests/sqs/test_connection.py b/tests/sqs/test_connection.py index 6996a54a3a..83c0073453 100644 --- a/tests/sqs/test_connection.py +++ b/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