Some flake8 cleanup.

This commit is contained in:
Steve Pulec 2014-11-15 09:35:52 -05:00
commit 8bc8f09b47
20 changed files with 90 additions and 86 deletions

View file

@ -4,10 +4,10 @@ import datetime
import json
try:
from collections import OrderedDict
from collections import OrderedDict
except ImportError:
# python 2.6 or earlier, use backport
from ordereddict import OrderedDict
# python 2.6 or earlier, use backport
from ordereddict import OrderedDict
from moto.core import BaseBackend
@ -69,6 +69,7 @@ class DynamoType(object):
comparison_func = get_comparison_func(range_comparison)
return comparison_func(self.value, *range_values)
class Item(object):
def __init__(self, hash_key, hash_key_type, range_key, range_key_type, attrs):
self.hash_key = hash_key
@ -104,9 +105,10 @@ class Item(object):
"Item": included
}
class Table(object):
def __init__(self, table_name, schema=None, attr = None, throughput=None, indexes=None):
def __init__(self, table_name, schema=None, attr=None, throughput=None, indexes=None):
self.name = table_name
self.attr = attr
self.schema = schema
@ -122,7 +124,7 @@ class Table(object):
self.range_key_attr = elem["AttributeName"]
self.range_key_type = elem["KeyType"]
if throughput is None:
self.throughput = {u'WriteCapacityUnits': 10, u'ReadCapacityUnits': 10}
self.throughput = {'WriteCapacityUnits': 10, 'ReadCapacityUnits': 10}
else:
self.throughput = throughput
self.throughput["NumberOfDecreasesToday"] = 0
@ -133,15 +135,15 @@ class Table(object):
@property
def describe(self):
results = {
'Table': {
'AttributeDefinitions': self.attr,
'ProvisionedThroughput': self.throughput,
'TableSizeBytes': 0,
'TableName': self.name,
'TableStatus': 'ACTIVE',
'KeySchema': self.schema,
'ItemCount': len(self),
'CreationDateTime': unix_time(self.created_at)
'Table': {
'AttributeDefinitions': self.attr,
'ProvisionedThroughput': self.throughput,
'TableSizeBytes': 0,
'TableName': self.name,
'TableStatus': 'ACTIVE',
'KeySchema': self.schema,
'ItemCount': len(self),
'CreationDateTime': unix_time(self.created_at),
}
}
return results
@ -204,7 +206,7 @@ class Table(object):
results = []
last_page = True # Once pagination is implemented, change this
possible_results = [ item for item in list(self.all_items()) if item.hash_key == hash_key]
possible_results = [item for item in list(self.all_items()) if item.hash_key == hash_key]
if range_comparison:
for result in possible_results:
if result.range_key.compare(range_comparison, range_objs):
@ -285,17 +287,17 @@ class DynamoDBBackend(BaseBackend):
return table.hash_key_attr, table.range_key_attr
def get_keys_value(self, table, keys):
if not table.hash_key_attr in keys or (table.has_range_key and not table.range_key_attr in keys):
if table.hash_key_attr not in keys or (table.has_range_key and table.range_key_attr not in keys):
raise ValueError("Table has a range key, but no range key was passed into get_item")
hash_key = DynamoType(keys[table.hash_key_attr])
range_key = DynamoType(keys[table.range_key_attr]) if table.has_range_key else None
return hash_key,range_key
return hash_key, range_key
def get_item(self, table_name, keys):
table = self.tables.get(table_name)
if not table:
return None
hash_key,range_key = self.get_keys_value(table,keys)
hash_key, range_key = self.get_keys_value(table, keys)
return table.get_item(hash_key, range_key)
def query(self, table_name, hash_key_dict, range_comparison, range_value_dicts):

View file

@ -90,19 +90,19 @@ class DynamoHandler(BaseResponse):
def create_table(self):
body = self.body
#get the table name
# get the table name
table_name = body['TableName']
#get the throughput
# get the throughput
throughput = body["ProvisionedThroughput"]
#getting the schema
# getting the schema
key_schema = body['KeySchema']
#getting attribute definition
# getting attribute definition
attr = body["AttributeDefinitions"]
#getting the indexes
# getting the indexes
table = dynamodb_backend2.create_table(table_name,
schema = key_schema,
throughput = throughput,
attr = attr)
schema=key_schema,
throughput=throughput,
attr=attr)
return dynamo_json_dump(table.describe)
def delete_table(self):
@ -169,6 +169,7 @@ class DynamoHandler(BaseResponse):
}
return dynamo_json_dump(response)
def get_item(self):
name = self.body['TableName']
key = self.body['Key']
@ -178,7 +179,7 @@ class DynamoHandler(BaseResponse):
er = 'com.amazon.coral.validate#ValidationException'
return self.error(er, status=400)
if item:
item_dict = item.describe_attrs(attributes = None)
item_dict = item.describe_attrs(attributes=None)
item_dict['ConsumedCapacityUnits'] = 0.5
return dynamo_json_dump(item_dict)
else:
@ -190,7 +191,7 @@ class DynamoHandler(BaseResponse):
table_batches = self.body['RequestItems']
results = {
"ConsumedCapacity":[],
"ConsumedCapacity": [],
"Responses": {
},
"UnprocessedKeys": {
@ -198,10 +199,9 @@ class DynamoHandler(BaseResponse):
}
for table_name, table_request in table_batches.items():
items = []
keys = table_request['Keys']
attributes_to_get = table_request.get('AttributesToGet')
results["Responses"][table_name]=[]
results["Responses"][table_name] = []
for key in keys:
item = dynamodb_backend2.get_item(table_name, key)
if item:
@ -226,7 +226,7 @@ class DynamoHandler(BaseResponse):
range_comparison = None
range_values = []
else:
if range_key_name == None:
if range_key_name is None:
er = "com.amazon.coral.validate#ValidationException"
return self.error(er)
else:
@ -247,7 +247,7 @@ class DynamoHandler(BaseResponse):
items = items[:limit]
reversed = self.body.get("ScanIndexForward")
if reversed != False:
if reversed is not False:
items.reverse()
result = {