From 7054143701a9f30294f316b81502b545c805fc32 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Thu, 10 Sep 2020 13:50:26 +0530 Subject: [PATCH] Fix deprecation warnings due to invalid escape sequences. (#3273) * Fix deprecation warnings due to invalid escape sequences. * Fix linter error. --- moto/apigateway/urls.py | 4 ++-- moto/ec2instanceconnect/urls.py | 2 +- moto/events/responses.py | 4 ++-- moto/managedblockchain/utils.py | 10 +++++----- moto/rds/urls.py | 2 +- moto/route53/urls.py | 16 ++++++++-------- moto/sqs/urls.py | 2 +- tests/test_awslambda/test_lambda.py | 2 +- tests/test_core/test_url_mapping.py | 10 +++++----- tests/test_ec2/test_key_pairs.py | 2 +- tests/test_ec2/test_tags.py | 6 +++--- tests/test_sns/test_publishing.py | 4 ++-- tests/test_sns/test_publishing_boto3.py | 6 +++--- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/moto/apigateway/urls.py b/moto/apigateway/urls.py index cb48e225f..7e8de1398 100644 --- a/moto/apigateway/urls.py +++ b/moto/apigateway/urls.py @@ -15,9 +15,9 @@ url_paths = { "{0}/restapis/(?P[^/]+)/deployments/(?P[^/]+)/?$": APIGatewayResponse().individual_deployment, "{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/?$": APIGatewayResponse().resource_individual, "{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/?$": APIGatewayResponse().resource_methods, - "{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/responses/(?P\d+)$": APIGatewayResponse().resource_method_responses, + r"{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/responses/(?P\d+)$": APIGatewayResponse().resource_method_responses, "{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/integration/?$": APIGatewayResponse().integrations, - "{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/integration/responses/(?P\d+)/?$": APIGatewayResponse().integration_responses, + r"{0}/restapis/(?P[^/]+)/resources/(?P[^/]+)/methods/(?P[^/]+)/integration/responses/(?P\d+)/?$": APIGatewayResponse().integration_responses, "{0}/apikeys$": APIGatewayResponse().apikeys, "{0}/apikeys/(?P[^/]+)": APIGatewayResponse().apikey_individual, "{0}/usageplans$": APIGatewayResponse().usage_plans, diff --git a/moto/ec2instanceconnect/urls.py b/moto/ec2instanceconnect/urls.py index e7078264f..d7b6b7ce4 100644 --- a/moto/ec2instanceconnect/urls.py +++ b/moto/ec2instanceconnect/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import Ec2InstanceConnectResponse -url_bases = ["https?://ec2-instance-connect\.(.+)\.amazonaws\.com"] +url_bases = [r"https?://ec2-instance-connect\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": Ec2InstanceConnectResponse.dispatch} diff --git a/moto/events/responses.py b/moto/events/responses.py index 76c590e16..c4e49fc80 100644 --- a/moto/events/responses.py +++ b/moto/events/responses.py @@ -183,9 +183,9 @@ class EventsHandler(BaseResponse): if sched_exp: if not ( - re.match("^cron\(.*\)", sched_exp) + re.match(r"^cron\(.*\)", sched_exp) or re.match( - "^rate\(\d*\s(minute|minutes|hour|hours|day|days)\)", sched_exp + r"^rate\(\d*\s(minute|minutes|hour|hours|day|days)\)", sched_exp ) ): return self.error( diff --git a/moto/managedblockchain/utils.py b/moto/managedblockchain/utils.py index c8118619e..d0485829b 100644 --- a/moto/managedblockchain/utils.py +++ b/moto/managedblockchain/utils.py @@ -14,7 +14,7 @@ def region_from_managedblckchain_url(url): def networkid_from_managedblockchain_url(full_url): - id_search = re.search("\/n-[A-Z0-9]{26}", full_url, re.IGNORECASE) + id_search = re.search(r"\/n-[A-Z0-9]{26}", full_url, re.IGNORECASE) return_id = None if id_search: return_id = id_search.group(0).replace("/", "") @@ -28,7 +28,7 @@ def get_network_id(): def memberid_from_managedblockchain_url(full_url): - id_search = re.search("\/m-[A-Z0-9]{26}", full_url, re.IGNORECASE) + id_search = re.search(r"\/m-[A-Z0-9]{26}", full_url, re.IGNORECASE) return_id = None if id_search: return_id = id_search.group(0).replace("/", "") @@ -42,7 +42,7 @@ def get_member_id(): def proposalid_from_managedblockchain_url(full_url): - id_search = re.search("\/p-[A-Z0-9]{26}", full_url, re.IGNORECASE) + id_search = re.search(r"\/p-[A-Z0-9]{26}", full_url, re.IGNORECASE) return_id = None if id_search: return_id = id_search.group(0).replace("/", "") @@ -56,7 +56,7 @@ def get_proposal_id(): def invitationid_from_managedblockchain_url(full_url): - id_search = re.search("\/in-[A-Z0-9]{26}", full_url, re.IGNORECASE) + id_search = re.search(r"\/in-[A-Z0-9]{26}", full_url, re.IGNORECASE) return_id = None if id_search: return_id = id_search.group(0).replace("/", "") @@ -107,7 +107,7 @@ def admin_password_ok(password): def nodeid_from_managedblockchain_url(full_url): - id_search = re.search("\/nd-[A-Z0-9]{26}", full_url, re.IGNORECASE) + id_search = re.search(r"\/nd-[A-Z0-9]{26}", full_url, re.IGNORECASE) return_id = None if id_search: return_id = id_search.group(0).replace("/", "") diff --git a/moto/rds/urls.py b/moto/rds/urls.py index 9c7570167..86e6ec00b 100644 --- a/moto/rds/urls.py +++ b/moto/rds/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import RDSResponse -url_bases = ["https?://rds(\..+)?.amazonaws.com"] +url_bases = [r"https?://rds(\..+)?.amazonaws.com"] url_paths = {"{0}/$": RDSResponse.dispatch} diff --git a/moto/route53/urls.py b/moto/route53/urls.py index a697d258a..c0fc93734 100644 --- a/moto/route53/urls.py +++ b/moto/route53/urls.py @@ -13,12 +13,12 @@ def tag_response2(*args, **kwargs): url_paths = { - "{0}/(?P[\d_-]+)/hostedzone$": Route53().list_or_create_hostzone_response, - "{0}/(?P[\d_-]+)/hostedzone/(?P[^/]+)$": Route53().get_or_delete_hostzone_response, - "{0}/(?P[\d_-]+)/hostedzone/(?P[^/]+)/rrset/?$": Route53().rrset_response, - "{0}/(?P[\d_-]+)/hostedzonesbyname": Route53().list_hosted_zones_by_name_response, - "{0}/(?P[\d_-]+)/healthcheck": Route53().health_check_response, - "{0}/(?P[\d_-]+)/tags/healthcheck/(?P[^/]+)$": tag_response1, - "{0}/(?P[\d_-]+)/tags/hostedzone/(?P[^/]+)$": tag_response2, - "{0}/(?P[\d_-]+)/trafficpolicyinstances/*": Route53().not_implemented_response, + r"{0}/(?P[\d_-]+)/hostedzone$": Route53().list_or_create_hostzone_response, + r"{0}/(?P[\d_-]+)/hostedzone/(?P[^/]+)$": Route53().get_or_delete_hostzone_response, + r"{0}/(?P[\d_-]+)/hostedzone/(?P[^/]+)/rrset/?$": Route53().rrset_response, + r"{0}/(?P[\d_-]+)/hostedzonesbyname": Route53().list_hosted_zones_by_name_response, + r"{0}/(?P[\d_-]+)/healthcheck": Route53().health_check_response, + r"{0}/(?P[\d_-]+)/tags/healthcheck/(?P[^/]+)$": tag_response1, + r"{0}/(?P[\d_-]+)/tags/hostedzone/(?P[^/]+)$": tag_response2, + r"{0}/(?P[\d_-]+)/trafficpolicyinstances/*": Route53().not_implemented_response, } diff --git a/moto/sqs/urls.py b/moto/sqs/urls.py index 3acf8591a..54fd44650 100644 --- a/moto/sqs/urls.py +++ b/moto/sqs/urls.py @@ -7,5 +7,5 @@ dispatch = SQSResponse().dispatch url_paths = { "{0}/$": dispatch, - "{0}/(?P\d+)/(?P[a-zA-Z0-9\-_\.]+)": dispatch, + r"{0}/(?P\d+)/(?P[a-zA-Z0-9\-_\.]+)": dispatch, } diff --git a/tests/test_awslambda/test_lambda.py b/tests/test_awslambda/test_lambda.py index ca05d4aa4..f7e7b3c7e 100644 --- a/tests/test_awslambda/test_lambda.py +++ b/tests/test_awslambda/test_lambda.py @@ -1663,7 +1663,7 @@ def test_update_function_s3(): def test_create_function_with_invalid_arn(): err = create_invalid_lambda("test-iam-role") err.exception.response["Error"]["Message"].should.equal( - "1 validation error detected: Value 'test-iam-role' at 'role' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:(aws[a-zA-Z-]*)?:iam::(\d{12}):role/?[a-zA-Z_0-9+=,.@\-_/]+" + r"1 validation error detected: Value 'test-iam-role' at 'role' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:(aws[a-zA-Z-]*)?:iam::(\d{12}):role/?[a-zA-Z_0-9+=,.@\-_/]+" ) diff --git a/tests/test_core/test_url_mapping.py b/tests/test_core/test_url_mapping.py index 4dccc4f21..9d0632e05 100644 --- a/tests/test_core/test_url_mapping.py +++ b/tests/test_core/test_url_mapping.py @@ -14,10 +14,10 @@ def test_flask_path_converting_simple(): def test_flask_path_converting_regex(): - convert_regex_to_flask_path("/(?P[a-zA-Z0-9\-_]+)").should.equal( - '/' + convert_regex_to_flask_path(r"/(?P[a-zA-Z0-9\-_]+)").should.equal( + r'/' ) - convert_regex_to_flask_path("(?P\d+)/(?P.*)$").should.equal( - '/' - ) + convert_regex_to_flask_path( + r"(?P\d+)/(?P.*)$" + ).should.equal(r'/') diff --git a/tests/test_ec2/test_key_pairs.py b/tests/test_ec2/test_key_pairs.py index d632c2478..09982ac7a 100644 --- a/tests/test_ec2/test_key_pairs.py +++ b/tests/test_ec2/test_key_pairs.py @@ -16,7 +16,7 @@ from .helpers import rsa_check_private_key RSA_PUBLIC_KEY_OPENSSH = b"""\ ssh-rsa \ AAAAB3NzaC1yc2EAAAADAQABAAABAQDusXfgTE4eBP50NglSzCSEGnIL6+cr6m3H\ -6cZANOQ+P1o/W4BdtcAL3sor4iGi7SOeJgo\8kweyMQrhrt6HaKGgromRiz37LQx\ +6cZANOQ+P1o/W4BdtcAL3sor4iGi7SOeJgo\\8kweyMQrhrt6HaKGgromRiz37LQx\ 4YIAcBi4Zd023mO/V7Rc2Chh18mWgLSmA6ng+j37ip6452zxtv0jHAz9pJolbKBp\ JzbZlPN45ZCTk9ck0fSVHRl6VRSSPQcpqi65XpRf+35zNOCGCc1mAOOTmw59Q2a6\ A3t8mL7r91aM5q6QOQm219lctFM8O7HRJnDgmhGpnjRwE1LyKktWTbgFZ4SNWU2X\ diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 92ed18dd4..8480f8bc0 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -287,13 +287,13 @@ def test_get_all_tags_value_filter(): tags = conn.get_all_tags(filters={"value": "*some*value*"}) tags.should.have.length_of(3) - tags = conn.get_all_tags(filters={"value": "*value\*"}) + tags = conn.get_all_tags(filters={"value": r"*value\*"}) tags.should.have.length_of(1) - tags = conn.get_all_tags(filters={"value": "*value\*\*"}) + tags = conn.get_all_tags(filters={"value": r"*value\*\*"}) tags.should.have.length_of(1) - tags = conn.get_all_tags(filters={"value": "*value\*\?"}) + tags = conn.get_all_tags(filters={"value": r"*value\*\?"}) tags.should.have.length_of(1) diff --git a/tests/test_sns/test_publishing.py b/tests/test_sns/test_publishing.py index 30fa80f15..cc7dbb8d6 100644 --- a/tests/test_sns/test_publishing.py +++ b/tests/test_sns/test_publishing.py @@ -54,7 +54,7 @@ def test_publish_to_sqs(): "us-east-1", ) acquired_message = re.sub( - "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", "2015-01-01T12:00:00.000Z", message.get_body(), ) @@ -98,7 +98,7 @@ def test_publish_to_sqs_in_different_region(): ) acquired_message = re.sub( - "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", "2015-01-01T12:00:00.000Z", message.get_body(), ) diff --git a/tests/test_sns/test_publishing_boto3.py b/tests/test_sns/test_publishing_boto3.py index 99e7ae7a4..c84f19694 100644 --- a/tests/test_sns/test_publishing_boto3.py +++ b/tests/test_sns/test_publishing_boto3.py @@ -49,7 +49,7 @@ def test_publish_to_sqs(): messages = queue.receive_messages(MaxNumberOfMessages=1) expected = MESSAGE_FROM_SQS_TEMPLATE % (message, published_message_id, "us-east-1") acquired_message = re.sub( - "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", "2015-01-01T12:00:00.000Z", messages[0].body, ) @@ -290,7 +290,7 @@ def test_publish_to_sqs_dump_json(): escaped = message.replace('"', '\\"') expected = MESSAGE_FROM_SQS_TEMPLATE % (escaped, published_message_id, "us-east-1") acquired_message = re.sub( - "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", "2015-01-01T12:00:00.000Z", messages[0].body, ) @@ -323,7 +323,7 @@ def test_publish_to_sqs_in_different_region(): messages = queue.receive_messages(MaxNumberOfMessages=1) expected = MESSAGE_FROM_SQS_TEMPLATE % (message, published_message_id, "us-west-1") acquired_message = re.sub( - "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", "2015-01-01T12:00:00.000Z", messages[0].body, )