Move tags_from_query_string to core.utils

This commit is contained in:
Niels Laukens 2019-09-04 16:25:43 +02:00
parent 6f23a39fc2
commit 91fb408102
No known key found for this signature in database
GPG Key ID: D1397B5A6435A6D8
3 changed files with 19 additions and 18 deletions

View File

@ -297,3 +297,20 @@ def path_url(url):
if parsed_url.query: if parsed_url.query:
path = path + '?' + parsed_url.query path = path + '?' + parsed_url.query
return path return path
def tags_from_query_string(querystring_dict):
prefix = 'Tag'
suffix = 'Key'
response_values = {}
for key, value in querystring_dict.items():
if key.startswith(prefix) and key.endswith(suffix):
tag_index = key.replace(prefix + ".", "").replace("." + suffix, "")
tag_key = querystring_dict.get("Tag.{0}.Key".format(tag_index))[0]
tag_value_key = "Tag.{0}.Value".format(tag_index)
if tag_value_key in querystring_dict:
response_values[tag_key] = querystring_dict.get(tag_value_key)[
0]
else:
response_values[tag_key] = None
return response_values

View File

@ -2,7 +2,8 @@ from __future__ import unicode_literals
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
from moto.ec2.models import validate_resource_ids from moto.ec2.models import validate_resource_ids
from moto.ec2.utils import tags_from_query_string, filters_from_querystring from moto.ec2.utils import filters_from_querystring
from moto.core.utils import tags_from_query_string
class TagResponse(BaseResponse): class TagResponse(BaseResponse):

View File

@ -198,23 +198,6 @@ def split_route_id(route_id):
return values[0], values[1] return values[0], values[1]
def tags_from_query_string(querystring_dict):
prefix = 'Tag'
suffix = 'Key'
response_values = {}
for key, value in querystring_dict.items():
if key.startswith(prefix) and key.endswith(suffix):
tag_index = key.replace(prefix + ".", "").replace("." + suffix, "")
tag_key = querystring_dict.get("Tag.{0}.Key".format(tag_index))[0]
tag_value_key = "Tag.{0}.Value".format(tag_index)
if tag_value_key in querystring_dict:
response_values[tag_key] = querystring_dict.get(tag_value_key)[
0]
else:
response_values[tag_key] = None
return response_values
def dhcp_configuration_from_querystring(querystring, option=u'DhcpConfiguration'): def dhcp_configuration_from_querystring(querystring, option=u'DhcpConfiguration'):
""" """
turn: turn: