fix: "invalid escape sequence" error in some regexp and strings.
Fixed "invalid escape sequence" errors caused by missing 'r' modifiers or incomplete escaping in some strings.
Problem
Sometimes aws-cli stopped by errors like following
aws: error: argument --role-arn: expected one argument
/usr/local/lib/python3.12/site-packages/awscli/compat.py:463: SyntaxWarning: invalid escape sequence '\s'
_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
/usr/local/lib/python3.12/site-packages/awscli/compat.py:464: SyntaxWarning: invalid escape sequence '\s'
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
/usr/local/lib/python3.12/site-packages/awscli/compat.py:465: SyntaxWarning: invalid escape sequence '\s'
_codename_file_re = re.compile("(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)
/usr/local/lib/python3.12/site-packages/awscli/shorthand.py:132: SyntaxWarning: invalid escape sequence '\!'
_START_WORD = u'\!\#-&\(-\+\--\<\>-Z\\\\-z\u007c-\uffff'
/usr/local/lib/python3.12/site-packages/awscli/shorthand.py:133: SyntaxWarning: invalid escape sequence '\s'
_FIRST_FOLLOW_CHARS = u'\s\!\#-&\(-\+\--\\\\\^-\|~-\uffff'
/usr/local/lib/python3.12/site-packages/awscli/shorthand.py:134: SyntaxWarning: invalid escape sequence '\s'
_SECOND_FOLLOW_CHARS = u'\s\!\#-&\(-\+\--\<\>-\uffff'
/usr/local/lib/python3.12/site-packages/awscli/customizations/cloudtrail/validation.py:76: SyntaxWarning: invalid escape sequence '\d'
pattern = re.compile('arn:.+:cloudtrail:.+:\d{12}:trail/.+')
/usr/local/lib/python3.12/site-packages/awscli/customizations/codedeploy/push.py:65: SyntaxWarning: invalid escape sequence '\<'
'uploading. Use the format s3://\<bucket\>/\<key\>'
/usr/local/lib/python3.12/site-packages/awscli/customizations/emr/createcluster.py:199: SyntaxWarning: invalid escape sequence '\d'
is_valid_ami_version = re.match('\d?\..*', parsed_args.ami_version)
Unable to locate credentials. You can configure credentials by running "aws configure".
I saw the errors at aws-cli version 1.30.5 (commit 1a1e73c2cd99edf98a037fb774cadb6e3cd3afc1).
Cause of Errors
The errors caused by missing 'r' modifiers or incomplete escaping.
Description of changes
This pull request fixes missing 'r' modifiers and escaping in those strings.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Thanks for reviewing :-)
Facing the same behavior
/app/.venv/lib/python3.12/site-packages/awscli/compat.py:463: SyntaxWarning: invalid escape sequence '\s'
_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
/app/.venv/lib/python3.12/site-packages/awscli/compat.py:464: SyntaxWarning: invalid escape sequence '\s'
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
...
Would appreciate reviewing it and merging
Thanks for creating this PR. Could you please create an issue outlining the steps to reproduce this, and all of the scenarios in which it occurs? There are several instances of help_text in customizations/* so I'm not sure if something more comprehensive is needed here or what we would need to address. If you create an issue then we can continue the discussion there going forward.