Fun with whitespace (flake8 violation fixes)

This commit is contained in:
Don Kuntz 2019-08-14 16:19:30 -05:00
parent aa3b6085d1
commit f939531ae9
3 changed files with 18 additions and 12 deletions

View File

@ -524,6 +524,7 @@ class OperationNotPermitted3(EC2ClientError):
acceptor_region) acceptor_region)
) )
class InvalidLaunchTemplateNameError(EC2ClientError): class InvalidLaunchTemplateNameError(EC2ClientError):
def __init__(self): def __init__(self):
super(InvalidLaunchTemplateNameError, self).__init__( super(InvalidLaunchTemplateNameError, self).__init__(

View File

@ -19,8 +19,6 @@ from boto.ec2.instance import Instance as BotoInstance, Reservation
from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType
from boto.ec2.spotinstancerequest import SpotInstanceRequest as BotoSpotRequest from boto.ec2.spotinstancerequest import SpotInstanceRequest as BotoSpotRequest
from boto.ec2.launchspecification import LaunchSpecification from boto.ec2.launchspecification import LaunchSpecification
from xml.etree import ElementTree
from xml.dom import minidom
from moto.compat import OrderedDict from moto.compat import OrderedDict
from moto.core import BaseBackend from moto.core import BaseBackend
@ -4115,6 +4113,7 @@ class NatGatewayBackend(object):
def delete_nat_gateway(self, nat_gateway_id): def delete_nat_gateway(self, nat_gateway_id):
return self.nat_gateways.pop(nat_gateway_id) return self.nat_gateways.pop(nat_gateway_id)
class LaunchTemplateVersion(object): class LaunchTemplateVersion(object):
def __init__(self, template, number, data, description): def __init__(self, template, number, data, description):
self.template = template self.template = template
@ -4123,6 +4122,7 @@ class LaunchTemplateVersion(object):
self.description = description self.description = description
self.create_time = utc_date_and_time() self.create_time = utc_date_and_time()
class LaunchTemplate(TaggedEC2Resource): class LaunchTemplate(TaggedEC2Resource):
def __init__(self, backend, name, template_data, version_description): def __init__(self, backend, name, template_data, version_description):
self.ec2_backend = backend self.ec2_backend = backend
@ -4144,10 +4144,10 @@ class LaunchTemplate(TaggedEC2Resource):
return self.default_version == version.number return self.default_version == version.number
def get_version(self, num): def get_version(self, num):
return self.versions[num-1] return self.versions[num - 1]
def default_version(self): def default_version(self):
return self.versions[self.default_version_number-1] return self.versions[self.default_version_number - 1]
def latest_version(self): def latest_version(self):
return self.versions[-1] return self.versions[-1]
@ -4163,6 +4163,7 @@ class LaunchTemplate(TaggedEC2Resource):
return super(LaunchTemplate, self).get_filter_value( return super(LaunchTemplate, self).get_filter_value(
filter_name, "DescribeLaunchTemplates") filter_name, "DescribeLaunchTemplates")
class LaunchTemplateBackend(object): class LaunchTemplateBackend(object):
def __init__(self): def __init__(self):
self.launch_templates_by_name = {} self.launch_templates_by_name = {}

View File

@ -1,4 +1,3 @@
import json
import six import six
import uuid import uuid
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
@ -19,6 +18,7 @@ def xml_root(name):
return root return root
def xml_serialize(tree, key, value): def xml_serialize(tree, key, value):
if key: if key:
name = key[0].lower() + key[1:] name = key[0].lower() + key[1:]
@ -43,19 +43,21 @@ def xml_serialize(tree, key, value):
for item in value: for item in value:
xml_serialize(node, 'item', item) xml_serialize(node, 'item', item)
def pretty_xml(tree): def pretty_xml(tree):
rough = ElementTree.tostring(tree, 'utf-8') rough = ElementTree.tostring(tree, 'utf-8')
parsed = minidom.parseString(rough) parsed = minidom.parseString(rough)
return parsed.toprettyxml(indent=' ') return parsed.toprettyxml(indent=' ')
def parse_object(raw_data): def parse_object(raw_data):
out_data = {} out_data = {}
for key, value in six.iteritems(raw_data): for key, value in six.iteritems(raw_data):
key_fix_splits = key.split("_") key_fix_splits = key.split("_")
l = len(key_fix_splits) key_len = len(key_fix_splits)
new_key = "" new_key = ""
for i in range(0, l): for i in range(0, key_len):
new_key += key_fix_splits[i][0].upper() + key_fix_splits[i][1:] new_key += key_fix_splits[i][0].upper() + key_fix_splits[i][1:]
data = out_data data = out_data
@ -70,6 +72,7 @@ def parse_object(raw_data):
out_data = parse_lists(out_data) out_data = parse_lists(out_data)
return out_data return out_data
def parse_lists(data): def parse_lists(data):
for key, value in six.iteritems(data): for key, value in six.iteritems(data):
if isinstance(value, dict): if isinstance(value, dict):
@ -87,6 +90,7 @@ def parse_lists(data):
data[key] = new_value data[key] = new_value
return data return data
class LaunchTemplates(BaseResponse): class LaunchTemplates(BaseResponse):
def create_launch_template(self): def create_launch_template(self):
name = self._get_param('LaunchTemplateName') name = self._get_param('LaunchTemplateName')
@ -126,8 +130,6 @@ class LaunchTemplates(BaseResponse):
template = self.ec2_backend.get_launch_template_by_id(tmpl_id) template = self.ec2_backend.get_launch_template_by_id(tmpl_id)
version_description = self._get_param('VersionDescription') version_description = self._get_param('VersionDescription')
tag_spec = self._get_param('TagSpecifications')
# source_version = self._get_int_param('SourceVersion')
raw_template_data = self._get_dict_param('LaunchTemplateData.') raw_template_data = self._get_dict_param('LaunchTemplateData.')
template_data = parse_object(raw_template_data) template_data = parse_object(raw_template_data)
@ -148,7 +150,6 @@ class LaunchTemplates(BaseResponse):
}) })
return pretty_xml(tree) return pretty_xml(tree)
# def delete_launch_template(self): # def delete_launch_template(self):
# pass # pass
@ -191,9 +192,12 @@ class LaunchTemplates(BaseResponse):
else: else:
vMax = min_version + max_results vMax = min_version + max_results
ret_versions = template.versions[min_version-1:vMax-1] vMin = min_version - 1
vMax = vMax - 1
ret_versions = template.versions[vMin:vMax]
elif max_version: elif max_version:
ret_versions = template.versions[0:max_version-1] vMax = max_version - 1
ret_versions = template.versions[:vMax]
else: else:
ret_versions = template.versions ret_versions = template.versions