Use correct raw string format

You're not supposed to just randomly put backslashes in front of other
characters that don't need escaping unless it's a raw string. This is
deprecated in Python 3.6.

Change-Id: I7a69ba6dd10412bb065f2b6ba405840d0a98663a
This commit is contained in:
Zane Bitter 2017-11-16 18:23:58 -05:00
parent 38f1975cf7
commit 22da551c8c
14 changed files with 34 additions and 32 deletions

View File

@ -20,7 +20,7 @@ import time
from heat.common.i18n import _ from heat.common.i18n import _
iso_duration_re = re.compile('PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$') iso_duration_re = re.compile(r'PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$')
wallclock = time.time wallclock = time.time

View File

@ -140,7 +140,7 @@ class MonascaNotification(resource.Resource):
} }
raise exception.StackValidationFailed(message=msg) raise exception.StackValidationFailed(message=msg)
elif (self.properties[self.TYPE] == self.EMAIL and elif (self.properties[self.TYPE] == self.EMAIL and
not re.match('^\S+@\S+$', address)): not re.match(r'^\S+@\S+$', address)):
msg = _('Address "%(addr)s" doesn\'t satisfies allowed format for ' msg = _('Address "%(addr)s" doesn\'t satisfies allowed format for '
'"%(email)s" type of "%(type)s" property') % { '"%(email)s" type of "%(type)s" property') % {
'addr': address, 'addr': address,

View File

@ -76,7 +76,7 @@ class SwiftUtilsTest(SwiftClientPluginTestCase):
url = self.swift_plugin.get_temp_url(container_name, obj_name) url = self.swift_plugin.get_temp_url(container_name, obj_name)
self.assertFalse(self.swift_client.post_account.called) self.assertFalse(self.swift_client.post_account.called)
regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s" regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s"
"/%s\?temp_url_sig=[0-9a-f]{40}&" r"/%s\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}" % "temp_url_expires=[0-9]{10}" %
(container_name, obj_name)) (container_name, obj_name))
self.assertThat(url, matchers.MatchesRegex(regexp)) self.assertThat(url, matchers.MatchesRegex(regexp))
@ -119,7 +119,7 @@ class SwiftUtilsTest(SwiftClientPluginTestCase):
self.assertTrue(self.swift_client.put_container.called) self.assertTrue(self.swift_client.put_container.called)
self.assertTrue(self.swift_client.put_object.called) self.assertTrue(self.swift_client.put_object.called)
regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s" regexp = ("http://fake-host.com:8080/v1/AUTH_demo/%s"
"/%s\?temp_url_sig=[0-9a-f]{40}&" r"/%s\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}" % "temp_url_expires=[0-9]{10}" %
(container_name, obj_name)) (container_name, obj_name))
self.assertThat(url, matchers.MatchesRegex(regexp)) self.assertThat(url, matchers.MatchesRegex(regexp))

View File

@ -245,7 +245,7 @@ class StackWatchTest(common.HeatTestCase):
state='NORMAL') state='NORMAL')
self.wr.store() self.wr.store()
for state in ["HGJHGJHG", "1234", "!\*(&%"]: for state in ["HGJHGJHG", "1234", "!\\*(&%"]:
self.assertRaises(ValueError, self.assertRaises(ValueError,
self.eng.set_watch_state, self.eng.set_watch_state,
self.ctx, watch_name="OverrideAlarm2", self.ctx, watch_name="OverrideAlarm2",
@ -253,7 +253,7 @@ class StackWatchTest(common.HeatTestCase):
calls = [mock.call("HGJHGJHG"), calls = [mock.call("HGJHGJHG"),
mock.call("1234"), mock.call("1234"),
mock.call("!\*(&%")] mock.call("!\\*(&%")]
mock_set.assert_has_calls(calls) mock_set.assert_has_calls(calls)
@mock.patch.object(watchrule.WatchRule, 'load') @mock.patch.object(watchrule.WatchRule, 'load')

View File

@ -372,8 +372,9 @@ class AodhAlarmTest(common.HeatTestCase):
# python 3.4.3 returns another error message # python 3.4.3 returns another error message
# so try to handle this by regexp # so try to handle this by regexp
msg = ("Property error: Resources.MEMAlarmHigh.Properties.%s: " msg = ("Property error: Resources.MEMAlarmHigh.Properties.%s: "
"int\(\) argument must be a string(, a bytes-like " r"int\(\) argument must be a string"
"object)? or a number, not 'list'" % p) "(, a bytes-like object)?"
" or a number, not 'list'" % p)
self.assertRaisesRegex(exception.StackValidationFailed, self.assertRaisesRegex(exception.StackValidationFailed,
msg, rsrc.validate) msg, rsrc.validate)

View File

@ -116,7 +116,7 @@ Resources:
self.assert_min('[0-9]', random_string, 1) self.assert_min('[0-9]', random_string, 1)
self.assert_min('[A-Z]', random_string, 1) self.assert_min('[A-Z]', random_string, 1)
self.assert_min('[a-z]', random_string, 20) self.assert_min('[a-z]', random_string, 20)
self.assert_min('[(),\[\]{}]', random_string, 1) self.assert_min(r'[(),\[\]{}]', random_string, 1)
self.assert_min('[$_]', random_string, 2) self.assert_min('[$_]', random_string, 2)
self.assert_min('@', random_string, 5) self.assert_min('@', random_string, 5)
self.assertEqual(secret3.FnGetRefId(), random_string) self.assertEqual(secret3.FnGetRefId(), random_string)
@ -132,7 +132,7 @@ Resources:
secret5 = stack['secret5'] secret5 = stack['secret5']
random_string = secret5.FnGetAtt('value') random_string = secret5.FnGetAtt('value')
self.assertEqual(10, len(random_string)) self.assertEqual(10, len(random_string))
self.assert_min('[(),\[\]{}]', random_string, 1) self.assert_min(r'[(),\[\]{}]', random_string, 1)
self.assert_min('[$_]', random_string, 2) self.assert_min('[$_]', random_string, 2)
self.assert_min('@', random_string, 5) self.assert_min('@', random_string, 5)
self.assertEqual(secret5.FnGetRefId(), random_string) self.assertEqual(secret5.FnGetRefId(), random_string)

View File

@ -137,7 +137,7 @@ class SwiftSignalHandleTest(common.HeatTestCase):
obj_name = "%s-%s-abcdefghijkl" % (st.name, handle.name) obj_name = "%s-%s-abcdefghijkl" % (st.name, handle.name)
regexp = ("http://fake-host.com:8080/v1/AUTH_test_tenant/%s/test_st-" regexp = ("http://fake-host.com:8080/v1/AUTH_test_tenant/%s/test_st-"
"test_wait_condition_handle-abcdefghijkl" "test_wait_condition_handle-abcdefghijkl"
"\?temp_url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}" r"\?temp_url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}"
% st.id) % st.id)
res_id = st.resources['test_wait_condition_handle'].resource_id res_id = st.resources['test_wait_condition_handle'].resource_id
self.assertEqual(res_id, handle.physical_resource_name()) self.assertEqual(res_id, handle.physical_resource_name())
@ -718,7 +718,7 @@ class SwiftSignalTest(common.HeatTestCase):
st.create() st.create()
self.assertEqual(('CREATE', 'COMPLETE'), st.state) self.assertEqual(('CREATE', 'COMPLETE'), st.state)
expected = ('http://fake-host.com:8080/v1/AUTH_test_tenant/%s/' expected = ('http://fake-host.com:8080/v1/AUTH_test_tenant/%s/'
'test_st-test_wait_condition_handle-abcdefghijkl\?temp_' r'test_st-test_wait_condition_handle-abcdefghijkl\?temp_'
'url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}') % st.id 'url_sig=[0-9a-f]{40}&temp_url_expires=[0-9]{10}') % st.id
self.assertThat(handle.FnGetAtt('endpoint'), self.assertThat(handle.FnGetAtt('endpoint'),
matchers.MatchesRegex(expected)) matchers.MatchesRegex(expected))
@ -749,7 +749,7 @@ class SwiftSignalTest(common.HeatTestCase):
self.assertEqual(('CREATE', 'COMPLETE'), st.state) self.assertEqual(('CREATE', 'COMPLETE'), st.state)
expected = ("curl -i -X PUT 'http://fake-host.com:8080/v1/" expected = ("curl -i -X PUT 'http://fake-host.com:8080/v1/"
"AUTH_test_tenant/%s/test_st-test_wait_condition_" "AUTH_test_tenant/%s/test_st-test_wait_condition_"
"handle-abcdefghijkl\?temp_url_sig=[0-9a-f]{40}&" r"handle-abcdefghijkl\?temp_url_sig=[0-9a-f]{40}&"
"temp_url_expires=[0-9]{10}'") % st.id "temp_url_expires=[0-9]{10}'") % st.id
self.assertThat(handle.FnGetAtt('curl_cli'), self.assertThat(handle.FnGetAtt('curl_cli'),
matchers.MatchesRegex(expected)) matchers.MatchesRegex(expected))

View File

@ -229,7 +229,7 @@ class ManilaShareTest(common.HeatTestCase):
stack = utils.parse_stack(tmp, stack_name='access_type') stack = utils.parse_stack(tmp, stack_name='access_type')
self.assertRaisesRegex( self.assertRaisesRegex(
exception.StackValidationFailed, exception.StackValidationFailed,
".* \"domain\" is not an allowed value \[ip, user, cert, cephx\]", r'.* "domain" is not an allowed value \[ip, user, cert, cephx\]',
stack.validate) stack.validate)
def test_get_live_state(self): def test_get_live_state(self):

View File

@ -844,7 +844,7 @@ class ResourceRegistryTest(common.HeatTestCase):
def test_list_type_with_invalid_type_name(self): def test_list_type_with_invalid_type_name(self):
registry = resources.global_env().registry registry = resources.global_env().registry
types = registry.get_types(type_name="r'[^\+]'") types = registry.get_types(type_name="r'[^\\+]'")
self.assertEqual([], types) self.assertEqual([], types)
def test_list_type_with_version(self): def test_list_type_with_version(self):

View File

@ -174,7 +174,7 @@ class FaultMiddlewareTest(common.HeatTestCase):
if hasattr(obj, 'msg_fmt'): if hasattr(obj, 'msg_fmt'):
kwargs = {} kwargs = {}
spec_names = re.findall('%\((\w+)\)([cdeEfFgGinorsxX])', spec_names = re.findall(r'%\((\w+)\)([cdeEfFgGinorsxX])',
obj.msg_fmt) obj.msg_fmt)
for key, convtype in spec_names: for key, convtype in spec_names:

View File

@ -784,8 +784,9 @@ class PropertyTest(common.HeatTestCase):
# python 3.4.3 returns another error message # python 3.4.3 returns another error message
# try to handle this by regexp # try to handle this by regexp
self.assertRaisesRegex( self.assertRaisesRegex(
TypeError, "int\(\) argument must be a string(, a bytes-like " TypeError, r"int\(\) argument must be a string"
"object)? or a number, not 'list'", p.get_value, [1]) "(, a bytes-like object)?"
" or a number, not 'list'", p.get_value, [1])
def test_str_from_int(self): def test_str_from_int(self):
schema = {'Type': 'String'} schema = {'Type': 'String'}

View File

@ -1280,8 +1280,8 @@ class StackTest(common.HeatTestCase):
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv') 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv')
stack_names = ['_foo', '1bad', '.kcats', 'test stack', ' teststack', stack_names = ['_foo', '1bad', '.kcats', 'test stack', ' teststack',
'^-^', '"stack"', '1234', 'cat|dog', '$(foo)', '^-^', '"stack"', '1234', 'cat|dog', '$(foo)',
'test/stack', 'test\stack', 'test::stack', 'test;stack', 'test/stack', 'test\\stack', 'test::stack',
'test~stack', '#test', gt_255_chars] 'test;stack', 'test~stack', '#test', gt_255_chars]
for stack_name in stack_names: for stack_name in stack_names:
ex = self.assertRaises( ex = self.assertRaises(
exception.StackValidationFailed, stack.Stack, exception.StackValidationFailed, stack.Stack,
@ -1879,7 +1879,7 @@ class StackTest(common.HeatTestCase):
self.assertRaisesRegex( self.assertRaisesRegex(
exception.StackValidationFailed, exception.StackValidationFailed,
('Outputs.Resource_attr.Value.Fn::GetAtt: The Referenced ' ('Outputs.Resource_attr.Value.Fn::GetAtt: The Referenced '
'Attribute \(AResource Bar\) is incorrect.'), r'Attribute \(AResource Bar\) is incorrect.'),
self.stack.validate) self.stack.validate)
def test_incorrect_outputs_cfn_incorrect_reference(self): def test_incorrect_outputs_cfn_incorrect_reference(self):
@ -2242,7 +2242,7 @@ class StackTest(common.HeatTestCase):
self.assertRaisesRegex( self.assertRaisesRegex(
exception.StackValidationFailed, exception.StackValidationFailed,
('outputs.resource_attr.value.get_attr: The Referenced Attribute ' ('outputs.resource_attr.value.get_attr: The Referenced Attribute '
'\(AResource Bar\) is incorrect.'), r'\(AResource Bar\) is incorrect.'),
self.stack.validate) self.stack.validate)
def test_snapshot_save_called_first(self): def test_snapshot_save_called_first(self):

View File

@ -82,7 +82,7 @@ class JsonToYamlTest(common.HeatTestCase):
with open(path, 'r') as f: with open(path, 'r') as f:
json_str = f.read() json_str = f.read()
yml_str = template_format.convert_json_to_yaml(json_str) yml_str = template_format.convert_json_to_yaml(json_str)
match = re.search('[\s,{]\d+\s*:', yml_str) match = re.search(r'[\s,{]\d+\s*:', yml_str)
# Check that there are no matches of integer-only keys # Check that there are no matches of integer-only keys
# lacking explicit quotes # lacking explicit quotes
self.assertIsNone(match) self.assertIsNone(match)

View File

@ -167,12 +167,12 @@ class HeatCustomGuidelines(object):
while idx < len(lines): while idx < len(lines):
if ('properties_schema' in lines[idx] or if ('properties_schema' in lines[idx] or
'attributes_schema' in lines[idx]): 'attributes_schema' in lines[idx]):
level = len(re.findall('(\{|\()', lines[idx])) level = len(re.findall(r'(\{|\()', lines[idx]))
level -= len(re.findall('(\}|\))', lines[idx])) level -= len(re.findall(r'(\}|\))', lines[idx]))
idx += 1 idx += 1
while level != 0: while level != 0:
level += len(re.findall('(\{|\()', lines[idx])) level += len(re.findall(r'(\{|\()', lines[idx]))
level -= len(re.findall('(\}|\))', lines[idx])) level -= len(re.findall(r'(\}|\))', lines[idx]))
if re.search("^((\'|\") )", lines[idx]): if re.search("^((\'|\") )", lines[idx]):
kwargs.update( kwargs.update(
{'details': 'line %s' % idx, {'details': 'line %s' % idx,
@ -180,8 +180,8 @@ class HeatCustomGuidelines(object):
'be on previous line'), 'be on previous line'),
'snippet': lines[idx]}) 'snippet': lines[idx]})
self.print_guideline_error(**kwargs) self.print_guideline_error(**kwargs)
elif (re.search("(\S(\'|\"))$", lines[idx - 1]) and elif (re.search("(\\S(\'|\"))$", lines[idx - 1]) and
re.search("^((\'|\")\S)", lines[idx])): re.search("^((\'|\")\\S)", lines[idx])):
kwargs.update( kwargs.update(
{'details': 'line %s' % (idx - 1), {'details': 'line %s' % (idx - 1),
'message': _('Omitted whitespace at the ' 'message': _('Omitted whitespace at the '
@ -205,7 +205,7 @@ class HeatCustomGuidelines(object):
'terminator at the end') % error_key.title(), 'terminator at the end') % error_key.title(),
'snippet': description}) 'snippet': description})
self.print_guideline_error(**error_kwargs) self.print_guideline_error(**error_kwargs)
if re.search("\s{2,}", description): if re.search(r"\s{2,}", description):
error_kwargs.update( error_kwargs.update(
{'message': _('%s description contains double or more ' {'message': _('%s description contains double or more '
'whitespaces') % error_key.title(), 'whitespaces') % error_key.title(),
@ -214,7 +214,7 @@ class HeatCustomGuidelines(object):
def _check_description_details(self, doclines, error_kwargs, def _check_description_details(self, doclines, error_kwargs,
error_key): error_key):
if re.search("\S", doclines[1]): if re.search(r"\S", doclines[1]):
error_kwargs.update( error_kwargs.update(
{'message': _('%s description summary and ' {'message': _('%s description summary and '
'main resource description should be ' 'main resource description should be '
@ -240,7 +240,7 @@ class HeatCustomGuidelines(object):
params = False params = False
for line in doclines[1:]: for line in doclines[1:]:
if re.search("\s{2,}", line): if re.search(r"\s{2,}", line):
error_kwargs.update( error_kwargs.update(
{'message': _('%s description ' {'message': _('%s description '
'contains double or more ' 'contains double or more '