Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

View file

@ -15,9 +15,9 @@ REQUEST_ID_LONG = string.digits + string.ascii_uppercase
def camelcase_to_underscores(argument):
''' Converts a camelcase param like theNewAttribute to the equivalent
python underscore variable like the_new_attribute'''
result = ''
""" Converts a camelcase param like theNewAttribute to the equivalent
python underscore variable like the_new_attribute"""
result = ""
prev_char_title = True
if not argument:
return argument
@ -41,18 +41,18 @@ def camelcase_to_underscores(argument):
def underscores_to_camelcase(argument):
''' Converts a camelcase param like the_new_attribute to the equivalent
""" Converts a camelcase param like the_new_attribute to the equivalent
camelcase version like theNewAttribute. Note that the first letter is
NOT capitalized by this function '''
result = ''
NOT capitalized by this function """
result = ""
previous_was_underscore = False
for char in argument:
if char != '_':
if char != "_":
if previous_was_underscore:
result += char.upper()
else:
result += char
previous_was_underscore = char == '_'
previous_was_underscore = char == "_"
return result
@ -69,12 +69,18 @@ def method_names_from_class(clazz):
def get_random_hex(length=8):
chars = list(range(10)) + ['a', 'b', 'c', 'd', 'e', 'f']
return ''.join(six.text_type(random.choice(chars)) for x in range(length))
chars = list(range(10)) + ["a", "b", "c", "d", "e", "f"]
return "".join(six.text_type(random.choice(chars)) for x in range(length))
def get_random_message_id():
return '{0}-{1}-{2}-{3}-{4}'.format(get_random_hex(8), get_random_hex(4), get_random_hex(4), get_random_hex(4), get_random_hex(12))
return "{0}-{1}-{2}-{3}-{4}".format(
get_random_hex(8),
get_random_hex(4),
get_random_hex(4),
get_random_hex(4),
get_random_hex(12),
)
def convert_regex_to_flask_path(url_path):
@ -97,7 +103,6 @@ def convert_regex_to_flask_path(url_path):
class convert_httpretty_response(object):
def __init__(self, callback):
self.callback = callback
@ -114,13 +119,12 @@ class convert_httpretty_response(object):
def __call__(self, request, url, headers, **kwargs):
result = self.callback(request, url, headers)
status, headers, response = result
if 'server' not in headers:
if "server" not in headers:
headers["server"] = "amazon.com"
return status, headers, response
class convert_flask_to_httpretty_response(object):
def __init__(self, callback):
self.callback = callback
@ -145,13 +149,12 @@ class convert_flask_to_httpretty_response(object):
status, headers, content = 200, {}, result
response = Response(response=content, status=status, headers=headers)
if request.method == "HEAD" and 'content-length' in headers:
response.headers['Content-Length'] = headers['content-length']
if request.method == "HEAD" and "content-length" in headers:
response.headers["Content-Length"] = headers["content-length"]
return response
class convert_flask_to_responses_response(object):
def __init__(self, callback):
self.callback = callback
@ -176,14 +179,14 @@ class convert_flask_to_responses_response(object):
def iso_8601_datetime_with_milliseconds(datetime):
return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z'
return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
def iso_8601_datetime_without_milliseconds(datetime):
return datetime.strftime("%Y-%m-%dT%H:%M:%S") + 'Z'
return datetime.strftime("%Y-%m-%dT%H:%M:%S") + "Z"
RFC1123 = '%a, %d %b %Y %H:%M:%S GMT'
RFC1123 = "%a, %d %b %Y %H:%M:%S GMT"
def rfc_1123_datetime(datetime):
@ -212,16 +215,16 @@ def gen_amz_crc32(response, headerdict=None):
crc = str(binascii.crc32(response))
if headerdict is not None and isinstance(headerdict, dict):
headerdict.update({'x-amz-crc32': crc})
headerdict.update({"x-amz-crc32": crc})
return crc
def gen_amzn_requestid_long(headerdict=None):
req_id = ''.join([random.choice(REQUEST_ID_LONG) for _ in range(0, 52)])
req_id = "".join([random.choice(REQUEST_ID_LONG) for _ in range(0, 52)])
if headerdict is not None and isinstance(headerdict, dict):
headerdict.update({'x-amzn-requestid': req_id})
headerdict.update({"x-amzn-requestid": req_id})
return req_id
@ -239,13 +242,13 @@ def amz_crc32(f):
else:
if len(response) == 2:
body, new_headers = response
status = new_headers.get('status', 200)
status = new_headers.get("status", 200)
else:
status, new_headers, body = response
headers.update(new_headers)
# Cast status to string
if "status" in headers:
headers['status'] = str(headers['status'])
headers["status"] = str(headers["status"])
try:
# Doesnt work on python2 for some odd unicode strings
@ -271,7 +274,7 @@ def amzn_request_id(f):
else:
if len(response) == 2:
body, new_headers = response
status = new_headers.get('status', 200)
status = new_headers.get("status", 200)
else:
status, new_headers, body = response
headers.update(new_headers)
@ -280,7 +283,7 @@ def amzn_request_id(f):
# Update request ID in XML
try:
body = re.sub(r'(?<=<RequestId>).*(?=<\/RequestId>)', request_id, body)
body = re.sub(r"(?<=<RequestId>).*(?=<\/RequestId>)", request_id, body)
except Exception: # Will just ignore if it cant work on bytes (which are str's on python2)
pass
@ -293,7 +296,7 @@ def path_url(url):
parsed_url = urlparse(url)
path = parsed_url.path
if not path:
path = '/'
path = "/"
if parsed_url.query:
path = path + '?' + parsed_url.query
path = path + "?" + parsed_url.query
return path