Skip to content

Commit

Permalink
Fix regex strings in Python 3.12 (#8925)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt authored Sep 17, 2024
1 parent 096f370 commit 8cc09c8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
6 changes: 3 additions & 3 deletions awscli/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ def _parse_release_file(firstline):
id = l[1]
return '', version, id

_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
_codename_file_re = re.compile("(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)
_distributor_id_file_re = re.compile(r"(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
_release_file_re = re.compile(r"(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
_codename_file_re = re.compile(r"(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)

def linux_distribution(
distname='',
Expand Down
33 changes: 24 additions & 9 deletions awscli/customizations/cloudtrail/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,24 @@ def assert_cloudtrail_arn_is_valid(trail_arn):
"""Ensures that the arn looks correct.
ARNs look like: arn:aws:cloudtrail:us-east-1:123456789012:trail/foo"""
pattern = re.compile('arn:.+:cloudtrail:.+:\d{12}:trail/.+')
pattern = re.compile(r'arn:.+:cloudtrail:.+:\d{12}:trail/.+')
if not pattern.match(trail_arn):
raise ValueError('Invalid trail ARN provided: %s' % trail_arn)


def create_digest_traverser(cloudtrail_client, organization_client,
s3_client_provider, trail_arn,
trail_source_region=None, on_invalid=None,
on_gap=None, on_missing=None, bucket=None,
prefix=None, account_id=None):
def create_digest_traverser(
cloudtrail_client,
organization_client,
s3_client_provider,
trail_arn,
trail_source_region=None,
on_invalid=None,
on_gap=None,
on_missing=None,
bucket=None,
prefix=None,
account_id=None,
):
"""Creates a CloudTrail DigestTraverser and its object graph.
:type cloudtrail_client: botocore.client.CloudTrail
Expand Down Expand Up @@ -244,9 +252,16 @@ class DigestProvider(object):
dict. This class is not responsible for validation or iterating from
one digest to the next.
"""
def __init__(self, s3_client_provider, account_id, trail_name,
trail_home_region, trail_source_region=None,
organization_id=None):

def __init__(
self,
s3_client_provider,
account_id,
trail_name,
trail_home_region,
trail_source_region=None,
organization_id=None,
):
self._client_provider = s3_client_provider
self.trail_name = trail_name
self.account_id = account_id
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/codedeploy/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Push(BasicCommand):
'revision to be uploaded to Amazon S3. You must specify both '
'a bucket and a key that represent the Amazon S3 bucket name '
'and the object key name. Content will be zipped before '
'uploading. Use the format s3://\<bucket\>/\<key\>'
)
'uploading. Use the format s3://<bucket>/<key>'
),
},
{
'name': 'ignore-hidden-files',
Expand Down
8 changes: 5 additions & 3 deletions awscli/customizations/emr/createcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ def _run_main_command(self, parsed_args, parsed_globals):
raise ValueError('aws: error: invalid json argument for '
'option --configurations')

if (parsed_args.release_label is None and
parsed_args.ami_version is not None):
is_valid_ami_version = re.match('\d?\..*', parsed_args.ami_version)
if (
parsed_args.release_label is None
and parsed_args.ami_version is not None
):
is_valid_ami_version = re.match(r'\d?\..*', parsed_args.ami_version)
if is_valid_ami_version is None:
raise exceptions.InvalidAmiVersionError(
ami_version=parsed_args.ami_version)
Expand Down
6 changes: 3 additions & 3 deletions awscli/shorthand.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ class ShorthandParser:

_SINGLE_QUOTED = _NamedRegex('singled quoted', r'\'(?:\\\\|\\\'|[^\'])*\'')
_DOUBLE_QUOTED = _NamedRegex('double quoted', r'"(?:\\\\|\\"|[^"])*"')
_START_WORD = '\!\#-&\(-\+\--\<\>-Z\\\\-z\u007c-\uffff'
_FIRST_FOLLOW_CHARS = '\s\!\#-&\(-\+\--\\\\\^-\|~-\uffff'
_SECOND_FOLLOW_CHARS = '\s\!\#-&\(-\+\--\<\>-\uffff'
_START_WORD = r'\!\#-&\(-\+\--\<\>-Z\\\\-z\u007c-\uffff'
_FIRST_FOLLOW_CHARS = r'\s\!\#-&\(-\+\--\\\\\^-\|~-\uffff'
_SECOND_FOLLOW_CHARS = r'\s\!\#-&\(-\+\--\<\>-\uffff'
_ESCAPED_COMMA = '(\\\\,)'
_FIRST_VALUE = _NamedRegex(
'first',
Expand Down

0 comments on commit 8cc09c8

Please sign in to comment.