Merge pull request #2811 from asherf/warns
Fix some 'DeprecationWarning: invalid escape sequence' warnings and use str.format for string interpolation.
This commit is contained in:
commit
4c8f6ad746
@ -196,13 +196,13 @@ def clean_json(resource_json, resources_map):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
fn_sub_value = clean_json(resource_json["Fn::Sub"], resources_map)
|
fn_sub_value = clean_json(resource_json["Fn::Sub"], resources_map)
|
||||||
to_sub = re.findall('(?=\${)[^!^"]*?}', fn_sub_value)
|
to_sub = re.findall(r'(?=\${)[^!^"]*?}', fn_sub_value)
|
||||||
literals = re.findall('(?=\${!)[^"]*?}', fn_sub_value)
|
literals = re.findall(r'(?=\${!)[^"]*?}', fn_sub_value)
|
||||||
for sub in to_sub:
|
for sub in to_sub:
|
||||||
if "." in sub:
|
if "." in sub:
|
||||||
cleaned_ref = clean_json(
|
cleaned_ref = clean_json(
|
||||||
{
|
{
|
||||||
"Fn::GetAtt": re.findall('(?<=\${)[^"]*?(?=})', sub)[
|
"Fn::GetAtt": re.findall(r'(?<=\${)[^"]*?(?=})', sub)[
|
||||||
0
|
0
|
||||||
].split(".")
|
].split(".")
|
||||||
},
|
},
|
||||||
@ -210,7 +210,7 @@ def clean_json(resource_json, resources_map):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
cleaned_ref = clean_json(
|
cleaned_ref = clean_json(
|
||||||
{"Ref": re.findall('(?<=\${)[^"]*?(?=})', sub)[0]},
|
{"Ref": re.findall(r'(?<=\${)[^"]*?(?=})', sub)[0]},
|
||||||
resources_map,
|
resources_map,
|
||||||
)
|
)
|
||||||
fn_sub_value = fn_sub_value.replace(sub, cleaned_ref)
|
fn_sub_value = fn_sub_value.replace(sub, cleaned_ref)
|
||||||
|
@ -347,7 +347,7 @@ class BotocoreEventMockAWS(BaseMockAWS):
|
|||||||
responses_mock.add(
|
responses_mock.add(
|
||||||
CallbackResponse(
|
CallbackResponse(
|
||||||
method=method,
|
method=method,
|
||||||
url=re.compile("https?://.+.amazonaws.com/.*"),
|
url=re.compile(r"https?://.+.amazonaws.com/.*"),
|
||||||
callback=not_implemented_callback,
|
callback=not_implemented_callback,
|
||||||
stream=True,
|
stream=True,
|
||||||
match_querystring=False,
|
match_querystring=False,
|
||||||
@ -356,7 +356,7 @@ class BotocoreEventMockAWS(BaseMockAWS):
|
|||||||
botocore_mock.add(
|
botocore_mock.add(
|
||||||
CallbackResponse(
|
CallbackResponse(
|
||||||
method=method,
|
method=method,
|
||||||
url=re.compile("https?://.+.amazonaws.com/.*"),
|
url=re.compile(r"https?://.+.amazonaws.com/.*"),
|
||||||
callback=not_implemented_callback,
|
callback=not_implemented_callback,
|
||||||
stream=True,
|
stream=True,
|
||||||
match_querystring=False,
|
match_querystring=False,
|
||||||
|
@ -95,7 +95,7 @@ def convert_regex_to_flask_path(url_path):
|
|||||||
match_name, match_pattern = reg.groups()
|
match_name, match_pattern = reg.groups()
|
||||||
return '<regex("{0}"):{1}>'.format(match_pattern, match_name)
|
return '<regex("{0}"):{1}>'.format(match_pattern, match_name)
|
||||||
|
|
||||||
url_path = re.sub("\(\?P<(.*?)>(.*?)\)", caller, url_path)
|
url_path = re.sub(r"\(\?P<(.*?)>(.*?)\)", caller, url_path)
|
||||||
|
|
||||||
if url_path.endswith("/?"):
|
if url_path.endswith("/?"):
|
||||||
# Flask does own handling of trailing slashes
|
# Flask does own handling of trailing slashes
|
||||||
|
@ -251,9 +251,9 @@ class ConditionExpressionParser:
|
|||||||
|
|
||||||
def _lex_one_node(self, remaining_expression):
|
def _lex_one_node(self, remaining_expression):
|
||||||
# TODO: Handle indexing like [1]
|
# TODO: Handle indexing like [1]
|
||||||
attribute_regex = "(:|#)?[A-z0-9\-_]+"
|
attribute_regex = r"(:|#)?[A-z0-9\-_]+"
|
||||||
patterns = [
|
patterns = [
|
||||||
(self.Nonterminal.WHITESPACE, re.compile("^ +")),
|
(self.Nonterminal.WHITESPACE, re.compile(r"^ +")),
|
||||||
(
|
(
|
||||||
self.Nonterminal.COMPARATOR,
|
self.Nonterminal.COMPARATOR,
|
||||||
re.compile(
|
re.compile(
|
||||||
@ -270,12 +270,14 @@ class ConditionExpressionParser:
|
|||||||
(
|
(
|
||||||
self.Nonterminal.OPERAND,
|
self.Nonterminal.OPERAND,
|
||||||
re.compile(
|
re.compile(
|
||||||
"^" + attribute_regex + "(\." + attribute_regex + "|\[[0-9]\])*"
|
r"^{attribute_regex}(\.{attribute_regex}|\[[0-9]\])*".format(
|
||||||
|
attribute_regex=attribute_regex
|
||||||
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(self.Nonterminal.COMMA, re.compile("^,")),
|
(self.Nonterminal.COMMA, re.compile(r"^,")),
|
||||||
(self.Nonterminal.LEFT_PAREN, re.compile("^\(")),
|
(self.Nonterminal.LEFT_PAREN, re.compile(r"^\(")),
|
||||||
(self.Nonterminal.RIGHT_PAREN, re.compile("^\)")),
|
(self.Nonterminal.RIGHT_PAREN, re.compile(r"^\)")),
|
||||||
]
|
]
|
||||||
|
|
||||||
for nonterminal, pattern in patterns:
|
for nonterminal, pattern in patterns:
|
||||||
@ -285,7 +287,7 @@ class ConditionExpressionParser:
|
|||||||
break
|
break
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Cannot parse condition starting at: " + remaining_expression
|
"Cannot parse condition starting at:{}".format(remaining_expression)
|
||||||
)
|
)
|
||||||
|
|
||||||
node = self.Node(
|
node = self.Node(
|
||||||
@ -318,7 +320,7 @@ class ConditionExpressionParser:
|
|||||||
for child in children:
|
for child in children:
|
||||||
self._assert(
|
self._assert(
|
||||||
child.nonterminal == self.Nonterminal.IDENTIFIER,
|
child.nonterminal == self.Nonterminal.IDENTIFIER,
|
||||||
"Cannot use %s in path" % child.text,
|
"Cannot use {} in path".format(child.text),
|
||||||
[node],
|
[node],
|
||||||
)
|
)
|
||||||
output.append(
|
output.append(
|
||||||
@ -392,7 +394,7 @@ class ConditionExpressionParser:
|
|||||||
elif name.startswith("["):
|
elif name.startswith("["):
|
||||||
# e.g. [123]
|
# e.g. [123]
|
||||||
if not name.endswith("]"): # pragma: no cover
|
if not name.endswith("]"): # pragma: no cover
|
||||||
raise ValueError("Bad path element %s" % name)
|
raise ValueError("Bad path element {}".format(name))
|
||||||
return self.Node(
|
return self.Node(
|
||||||
nonterminal=self.Nonterminal.IDENTIFIER,
|
nonterminal=self.Nonterminal.IDENTIFIER,
|
||||||
kind=self.Kind.LITERAL,
|
kind=self.Kind.LITERAL,
|
||||||
|
@ -403,7 +403,7 @@ class ECRBackend(BaseBackend):
|
|||||||
|
|
||||||
# If we have a digest, is it valid?
|
# If we have a digest, is it valid?
|
||||||
if "imageDigest" in image_id:
|
if "imageDigest" in image_id:
|
||||||
pattern = re.compile("^[0-9a-zA-Z_+\.-]+:[0-9a-fA-F]{64}")
|
pattern = re.compile(r"^[0-9a-zA-Z_+\.-]+:[0-9a-fA-F]{64}")
|
||||||
if not pattern.match(image_id.get("imageDigest")):
|
if not pattern.match(image_id.get("imageDigest")):
|
||||||
response["failures"].append(
|
response["failures"].append(
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ def parse_region_from_url(url):
|
|||||||
|
|
||||||
def metadata_from_headers(headers):
|
def metadata_from_headers(headers):
|
||||||
metadata = {}
|
metadata = {}
|
||||||
meta_regex = re.compile("^x-amz-meta-([a-zA-Z0-9\-_]+)$", flags=re.IGNORECASE)
|
meta_regex = re.compile(r"^x-amz-meta-([a-zA-Z0-9\-_]+)$", flags=re.IGNORECASE)
|
||||||
for header, value in headers.items():
|
for header, value in headers.items():
|
||||||
if isinstance(header, six.string_types):
|
if isinstance(header, six.string_types):
|
||||||
result = meta_regex.match(header)
|
result = meta_regex.match(header)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user