diff options
author | Christian Heimes <cheimes@redhat.com> | 2018-09-24 10:49:45 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2018-09-27 10:23:03 +0200 |
commit | 4a58adf79e8b6b1dfbd534f16bcec368a189131e (patch) | |
tree | 96b23960681e8c8422fc5995dcfdbb9767d0accf | |
parent | e1a30d3ce32aef2492689de8eff09360f5480a99 (diff) | |
download | freeipa-4a58adf79e8b6b1dfbd534f16bcec368a189131e.tar.gz freeipa-4a58adf79e8b6b1dfbd534f16bcec368a189131e.tar.xz freeipa-4a58adf79e8b6b1dfbd534f16bcec368a189131e.zip |
Sprinkle raw strings across the code base
tox / pytest is complaining about lots and lots of invalid escape
sequences in our code base. Sprinkle raw strings or backslash escapes
across the code base to fix most occurences of:
DeprecationWarning: invalid escape sequence
There is still one warning that keeps repeating, though:
source:264: DeprecationWarning: invalid escape sequence \d
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
25 files changed, 139 insertions, 122 deletions
diff --git a/ipalib/aci.py b/ipalib/aci.py index 2edcfb48d..aa8113645 100644 --- a/ipalib/aci.py +++ b/ipalib/aci.py @@ -127,7 +127,7 @@ class ACI(object): if var == 'targetattr': # Make a string of the form attr || attr || ... into a list - t = re.split('[^a-zA-Z0-9;\*]+', val) + t = re.split(r'[^a-zA-Z0-9;\*]+', val) self.target[var] = {} self.target[var]['operator'] = op self.target[var]['expression'] = t diff --git a/ipalib/util.py b/ipalib/util.py index dd83f1f46..3e8fab49d 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -158,8 +158,8 @@ def isvalid_base64(data): data = ''.join(data.split()) - if len(data) % 4 > 0 or \ - re.match('^[a-zA-Z0-9\+\/]+\={0,2}$', data) is None: + if (len(data) % 4 > 0 or + re.match(r'^[a-zA-Z0-9\+\/]+\={0,2}$', data) is None): return False else: return True diff --git a/ipapython/kerberos.py b/ipapython/kerberos.py index 21f81de20..946d3db5c 100644 --- a/ipapython/kerberos.py +++ b/ipapython/kerberos.py @@ -109,7 +109,7 @@ class Principal(object): return hash(self.components + (self.realm,)) def _parse_from_text(self, principal, realm=None): - """ + r""" parse individual principal name components from the string representation of the principal. This is done in three steps: 1.) split the string at the unescaped '@' diff --git a/ipaserver/advise/plugins/smart_card_auth.py b/ipaserver/advise/plugins/smart_card_auth.py index f2e3f863d..2f2e7aec9 100644 --- a/ipaserver/advise/plugins/smart_card_auth.py +++ b/ipaserver/advise/plugins/smart_card_auth.py @@ -167,8 +167,8 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config): ], commands_to_run_when_false=[ self._interpolate_ocsp_directive_file_into_command( - "sed -i.ipabkp '/<\/VirtualHost>/i {directive} on' " - "{filename}") + r"sed -i.ipabkp '/<\/VirtualHost>/i {directive} on' " + r"{filename}") ] ) diff --git a/ipaserver/install/plugins/dns.py b/ipaserver/install/plugins/dns.py index 3b7d2dc9a..baa19c38e 100644 --- a/ipaserver/install/plugins/dns.py +++ b/ipaserver/install/plugins/dns.py @@ -144,7 +144,7 @@ class update_ipaconfigstring_dnsversion_to_ipadnsversion(Updater): container_entry['objectclass'].append('ipadnscontainer') version = 0 for config_option in container_entry.get("ipaConfigString", []): - matched = re.match("^DNSVersion\s+(?P<version>\d+)$", + matched = re.match(r"^DNSVersion\s+(?P<version>\d+)$", config_option, flags=re.I) if matched: version = int(matched.group("version")) diff --git a/ipaserver/plugins/baseuser.py b/ipaserver/plugins/baseuser.py index 4dbf4b6f3..eed750e68 100644 --- a/ipaserver/plugins/baseuser.py +++ b/ipaserver/plugins/baseuser.py @@ -358,8 +358,12 @@ class baseuser(LDAPObject): ), Str('preferredlanguage?', label=_('Preferred Language'), - pattern='^(([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?(;q\=((0(\.[0-9]{0,3})?)|(1(\.0{0,3})?)))?' \ - + '(\s*,\s*[a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?(;q\=((0(\.[0-9]{0,3})?)|(1(\.0{0,3})?)))?)*)|(\*))$', + pattern=( + r'^(([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?' + r'(;q\=((0(\.[0-9]{0,3})?)|(1(\.0{0,3})?)))?' + r'(\s*,\s*[a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?' + r'(;q\=((0(\.[0-9]{0,3})?)|(1(\.0{0,3})?)))?)*)|(\*))$' + ), pattern_errmsg='must match RFC 2068 - 14.4, e.g., "da, en-gb;q=0.8, en;q=0.7"', ), Certificate('usercertificate*', diff --git a/ipaserver/plugins/certprofile.py b/ipaserver/plugins/certprofile.py index 5e8dbca04..6e2e91dc6 100644 --- a/ipaserver/plugins/certprofile.py +++ b/ipaserver/plugins/certprofile.py @@ -86,7 +86,7 @@ def ca_enabled_check(_api): raise errors.NotFound(reason=_('CA is not configured')) -profile_id_pattern = re.compile('^[a-zA-Z]\w*$') +profile_id_pattern = re.compile(r'^[a-zA-Z]\w*$') def validate_profile_id(ugettext, value): @@ -230,7 +230,7 @@ class certprofile_import(LDAPCreate): ), ) - PROFILE_ID_PATTERN = re.compile('^profileId=([a-zA-Z]\w*)', re.MULTILINE) + PROFILE_ID_PATTERN = re.compile(r'^profileId=([a-zA-Z]\w*)', re.MULTILINE) def pre_callback(self, ldap, dn, entry, entry_attrs, *keys, **options): ca_enabled_check(self.api) diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py index c638d41ab..9083f7e08 100644 --- a/ipaserver/plugins/dogtag.py +++ b/ipaserver/plugins/dogtag.py @@ -23,7 +23,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -''' +r''' ============================================== Backend plugin for RA using Dogtag (e.g. CMS) diff --git a/ipaserver/plugins/migration.py b/ipaserver/plugins/migration.py index 1138dd564..fffcb30ff 100644 --- a/ipaserver/plugins/migration.py +++ b/ipaserver/plugins/migration.py @@ -469,7 +469,7 @@ def construct_filter(template, oc_list): return template % oc_subfilter def validate_ldapuri(ugettext, ldapuri): - m = re.match('^ldaps?://[-\w\.]+(:\d+)?$', ldapuri) + m = re.match(r'^ldaps?://[-\w\.]+(:\d+)?$', ldapuri) if not m: err_msg = _('Invalid LDAP URI.') raise errors.ValidationError(name='ldap_uri', error=err_msg) diff --git a/ipatests/i18n.py b/ipatests/i18n.py index d45655cd8..9967d5a10 100644 --- a/ipatests/i18n.py +++ b/ipatests/i18n.py @@ -101,13 +101,13 @@ _shell_substitution_regexp = re.compile( # group 5: ending delimiter printf_fmt_re = re.compile( - r"%" # start - "(\d+\$)?" # fmt_arg (group 1) - "(([#0 +'I]|-(?!\d))*)" # flags (group 2) - "(([+-]?([1-9][0-9]*)?)|(\*|\*\d+\$))?" # width (group 4) - "(\.((-?\d*)|(\*|)|(\*\d+\$)))?" # precision (group 8) - "(h|hh|l|ll|L|j|z|t)?" # length (group 13) - "([diouxXeEfFgGaAcspnm%])") # conversion (group 14) + r"%" # start + r"(\d+\$)?" # fmt_arg (group 1) + r"(([#0 +'I]|-(?!\d))*)" # flags (group 2) + r"(([+-]?([1-9][0-9]*)?)|(\*|\*\d+\$))?" # width (group 4) + r"(\.((-?\d*)|(\*|)|(\*\d+\$)))?" # precision (group 8) + r"(h|hh|l|ll|L|j|z|t)?" # length (group 13) + r"([diouxXeEfFgGaAcspnm%])") # conversion (group 14) #------------------------------------------------------------------------------- diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index ccb0d31c0..f0c61381b 100644 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -229,7 +229,7 @@ def restore_files(host): rmname = os.path.join(host.config.test_dir, 'file_remove') # Prepare command for restoring context of the backed-up files - sed_remove_backupdir = 's/%s//g' % backupname.replace('/', '\/') + sed_remove_backupdir = 's/%s//g' % backupname.replace('/', r'\/') restorecon_command = ( "find %s | " "sed '%s' | " @@ -361,7 +361,7 @@ def domainlevel(host): kinit_admin(host, raiseonerr=False) result = host.run_command(['ipa', 'domainlevel-get'], raiseonerr=False) level = MIN_DOMAIN_LEVEL - domlevel_re = re.compile('.*(\d)') + domlevel_re = re.compile(r'.*(\d)') if result.returncode == 0: # "domainlevel-get" command doesn't exist on ipa versions prior to 4.3 level = int(domlevel_re.findall(result.stdout_text)[0]) @@ -601,7 +601,7 @@ def setup_sssd_debugging(host): # Add the debug directive to each section host.run_command(['sed', '-i', - '/\[*\]/ a\debug_level = 7', + r'/\[*\]/ a\debug_level = 7', paths.SSSD_CONF], raiseonerr=False) @@ -1000,7 +1000,7 @@ def two_connected_topo(master, replicas): @_topo('double-circle') def double_circle_topo(master, replicas, site_size=6): - """ + r""" R--R |\/| |/\| diff --git a/ipatests/test_integration/test_advise.py b/ipatests/test_integration/test_advise.py index 98c30c651..3b821c879 100644 --- a/ipatests/test_integration/test_advise.py +++ b/ipatests/test_integration/test_advise.py @@ -49,8 +49,8 @@ class TestAdvice(IntegrationTest): topology = 'line' def test_invalid_advice(self): - advice_id = 'invalid-advise-param' - advice_regex = "invalid[\s]+\'advice\'.*" + advice_id = r'invalid-advise-param' + advice_regex = r"invalid[\s]+\'advice\'.*" raiseerr = False run_advice(self.master, advice_id, advice_regex, raiseerr) @@ -58,9 +58,9 @@ class TestAdvice(IntegrationTest): def test_advice_FreeBSDNSSPAM(self): advice_id = 'config-freebsd-nss-pam-ldapd' - advice_regex = "\#\!\/bin\/sh.*" \ - "pkg_add[\s]+\-r[\s]+nss\-pam\-ldapd[\s]+curl.*" \ - "\/usr\/local\/etc\/rc\.d\/nslcd[\s]+restart" + advice_regex = r"\#\!\/bin\/sh.*" \ + r"pkg_add[\s]+\-r[\s]+nss\-pam\-ldapd[\s]+curl.*" \ + r"\/usr\/local\/etc\/rc\.d\/nslcd[\s]+restart" raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) @@ -68,21 +68,23 @@ class TestAdvice(IntegrationTest): def test_advice_GenericNSSPAM(self): advice_id = 'config-generic-linux-nss-pam-ldapd' - advice_regex = "\#\!\/bin\/sh.*" \ - "apt\-get[\s]+\-y[\s]+install[\s]+curl[\s]+openssl[\s]+" \ - "libnss\-ldapd[\s]+libpam\-ldapd[\s]+nslcd.*" \ - "service[\s]+nscd[\s]+stop[\s]+\&\&[\s]+service[\s]+" \ - "nslcd[\s]+restart" + advice_regex = ( + r"\#\!\/bin\/sh.*" + r"apt\-get[\s]+\-y[\s]+install[\s]+curl[\s]+openssl[\s]+" + r"libnss\-ldapd[\s]+libpam\-ldapd[\s]+nslcd.*" + r"service[\s]+nscd[\s]+stop[\s]+\&\&[\s]+service[\s]+" + r"nslcd[\s]+restart" + ) raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) def test_advice_GenericSSSDBefore19(self): - advice_id = 'config-generic-linux-sssd-before-1-9' - advice_regex = "\#\!\/bin\/sh.*" \ - "apt\-get[\s]+\-y[\s]+install sssd curl openssl.*" \ - "service[\s]+sssd[\s]+start" + advice_id = r'config-generic-linux-sssd-before-1-9' + advice_regex = r"\#\!\/bin\/sh.*" \ + r"apt\-get[\s]+\-y[\s]+install sssd curl openssl.*" \ + r"service[\s]+sssd[\s]+start" raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) @@ -90,12 +92,14 @@ class TestAdvice(IntegrationTest): def test_advice_RedHatNSS(self): advice_id = 'config-redhat-nss-ldap' - advice_regex = "\#\!\/bin\/sh.*" \ - "yum[\s]+install[\s]+\-y[\s]+curl[\s]+openssl[\s]+nss_ldap" \ - "[\s]+authconfig.*authconfig[\s]+\-\-updateall" \ - "[\s]+\-\-enableldap[\s]+\-\-enableldaptls"\ - "[\s]+\-\-enableldapauth[\s]+" \ - "\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" + advice_regex = ( + r"\#\!\/bin\/sh.*" + r"yum[\s]+install[\s]+\-y[\s]+curl[\s]+openssl[\s]+nss_ldap" + r"[\s]+authconfig.*authconfig[\s]+\-\-updateall" + r"[\s]+\-\-enableldap[\s]+\-\-enableldaptls" + r"[\s]+\-\-enableldapauth[\s]+" + r"\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" + ) raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) @@ -103,12 +107,12 @@ class TestAdvice(IntegrationTest): def test_advice_RedHatNSSPAM(self): advice_id = 'config-redhat-nss-pam-ldapd' - advice_regex = "\#\!\/bin\/sh.*" \ - "yum[\s]+install[\s]+\-y[\s]+curl[\s]+openssl[\s]+" \ - "nss\-pam\-ldapd[\s]+pam_ldap[\s]+authconfig.*" \ - "authconfig[\s]+\-\-updateall[\s]+\-\-enableldap"\ - "[\s]+\-\-enableldaptls[\s]+\-\-enableldapauth[\s]+" \ - "\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" + advice_regex = r"\#\!\/bin\/sh.*" \ + r"yum[\s]+install[\s]+\-y[\s]+curl[\s]+openssl[\s]+" \ + r"nss\-pam\-ldapd[\s]+pam_ldap[\s]+authconfig.*" \ + r"authconfig[\s]+\-\-updateall[\s]+\-\-enableldap"\ + r"[\s]+\-\-enableldaptls[\s]+\-\-enableldapauth[\s]+" \ + r"\-\-ldapserver=.*[\s]+\-\-ldapbasedn=.*" raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) @@ -116,9 +120,11 @@ class TestAdvice(IntegrationTest): def test_advice_RedHatSSSDBefore19(self): advice_id = 'config-redhat-sssd-before-1-9' - advice_regex = "\#\!\/bin\/sh.*" \ - "yum[\s]+install[\s]+\-y[\s]+sssd[\s]+authconfig[\s]+" \ - "curl[\s]+openssl.*service[\s]+sssd[\s]+start" + advice_regex = ( + r"\#\!\/bin\/sh.*" + r"yum[\s]+install[\s]+\-y[\s]+sssd[\s]+authconfig[\s]+" + r"curl[\s]+openssl.*service[\s]+sssd[\s]+start" + ) raiseerr = True run_advice(self.master, advice_id, advice_regex, raiseerr) diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py index 6279b35d5..c7db12bc6 100644 --- a/ipatests/test_integration/test_backup_and_restore.py +++ b/ipatests/test_integration/test_backup_and_restore.py @@ -91,7 +91,7 @@ def check_admin_in_id(host): def check_certs(host): result = host.run_command(['ipa', 'cert-find']) - assert re.search('^Number of entries returned [1-9]\d*$', + assert re.search(r'^Number of entries returned [1-9]\d*$', result.stdout_text, re.MULTILINE), result.stdout_text return result diff --git a/ipatests/test_integration/test_http_kdc_proxy.py b/ipatests/test_integration/test_http_kdc_proxy.py index ddbe223a2..1c8a2dad2 100644 --- a/ipatests/test_integration/test_http_kdc_proxy.py +++ b/ipatests/test_integration/test_http_kdc_proxy.py @@ -36,12 +36,12 @@ class TestHttpKdcProxy(IntegrationTest): '--dport', '88', '-j', 'DROP']) # configure client cls.clients[0].run_command( - "sed -i 's/ kdc = .*$/ kdc = https:\/\/%s\/KdcProxy/' %s" % ( + r"sed -i 's/ kdc = .*$/ kdc = https:\/\/%s\/KdcProxy/' %s" % ( cls.master.hostname, paths.KRB5_CONF) ) cls.clients[0].run_command( - "sed -i 's/master_kdc = .*$/master_kdc" - " = https:\/\/%s\/KdcProxy/' %s" % ( + r"sed -i 's/master_kdc = .*$/master_kdc" + r" = https:\/\/%s\/KdcProxy/' %s" % ( cls.master.hostname, paths.KRB5_CONF) ) # Workaround for https://fedorahosted.org/freeipa/ticket/6443 diff --git a/ipatests/test_integration/test_legacy_clients.py b/ipatests/test_integration/test_legacy_clients.py index faff7c3dd..545302008 100644 --- a/ipatests/test_integration/test_legacy_clients.py +++ b/ipatests/test_integration/test_legacy_clients.py @@ -90,8 +90,8 @@ class BaseTestLegacyClient(object): self.clear_sssd_caches() result = self.legacy_client.run_command(['getent', 'passwd', 'admin']) - admin_regex = "admin:\*:(\d+):(\d+):"\ - "Administrator:/home/admin:/bin/bash" + admin_regex = r"admin:\*:(\d+):(\d+):"\ + r"Administrator:/home/admin:/bin/bash" assert re.search(admin_regex, result.stdout_text) @@ -99,7 +99,7 @@ class BaseTestLegacyClient(object): self.clear_sssd_caches() result = self.legacy_client.run_command(['getent', 'group', 'admins']) - admin_group_regex = "admins:\*:(\d+):admin" + admin_group_regex = r"admins:\*:(\d+):admin" assert re.search(admin_group_regex, result.stdout_text) @@ -107,9 +107,9 @@ class BaseTestLegacyClient(object): self.clear_sssd_caches() result = self.legacy_client.run_command(['id', 'admin']) - uid_regex = "uid=(\d+)\(admin\)" - gid_regex = "gid=(\d+)\(admins\)" - groups_regex = "groups=(\d+)\(admins\)" + uid_regex = r"uid=(\d+)\(admin\)" + gid_regex = r"gid=(\d+)\(admins\)" + groups_regex = r"groups=(\d+)\(admins\)" assert re.search(uid_regex, result.stdout_text) assert re.search(gid_regex, result.stdout_text) @@ -120,8 +120,8 @@ class BaseTestLegacyClient(object): testuser = 'testuser@%s' % self.ad.domain.name result = self.legacy_client.run_command(['getent', 'passwd', testuser]) - testuser_regex = "testuser@%s:\*:%s:%s:"\ - "Test User:%s:/bin/sh"\ + testuser_regex = r"testuser@%s:\*:%s:%s:"\ + r"Test User:%s:/bin/sh"\ % (re.escape(self.ad.domain.name), self.testuser_uid_regex, self.testuser_gid_regex, @@ -137,7 +137,7 @@ class BaseTestLegacyClient(object): testgroup = 'testgroup@%s' % self.ad.domain.name result = self.legacy_client.run_command(['getent', 'group', testgroup]) - testgroup_regex = "%s:\*:%s:" % (testgroup, self.testuser_gid_regex) + testgroup_regex = r"%s:\*:%s:" % (testgroup, self.testuser_gid_regex) assert re.search(testgroup_regex, result.stdout_text) def test_id_ad_user(self): @@ -239,9 +239,9 @@ class BaseTestLegacyClient(object): testuser = 'subdomaintestuser@%s' % self.ad_subdomain result = self.legacy_client.run_command(['getent', 'passwd', testuser]) - testuser_regex = "subdomaintestuser@%s:\*:%s:%s:"\ - "Subdomaintest User:%s:"\ - "/bin/sh"\ + testuser_regex = r"subdomaintestuser@%s:\*:%s:%s:"\ + r"Subdomaintest User:%s:"\ + r"/bin/sh"\ % (re.escape(self.ad_subdomain), self.subdomain_testuser_uid_regex, self.subdomain_testuser_gid_regex, @@ -260,7 +260,7 @@ class BaseTestLegacyClient(object): testgroup = 'subdomaintestgroup@%s' % self.ad_subdomain result = self.legacy_client.run_command(['getent', 'group', testgroup]) - testgroup_stdout = "%s:\*:%s:" % (testgroup, + testgroup_stdout = r"%s:\*:%s:" % (testgroup, self.subdomain_testuser_gid_regex) assert re.search(testgroup_stdout, result.stdout_text) @@ -338,8 +338,8 @@ class BaseTestLegacyClient(object): testuser = 'treetestuser@{0}'.format(self.ad_treedomain) result = self.legacy_client.run_command(['getent', 'passwd', testuser]) - testuser_regex = ("treetestuser@{0}:\*:{1}:{2}:TreeTest User:" - "/home/{0}/treetestuser:/bin/sh".format( + testuser_regex = (r"treetestuser@{0}:\*:{1}:{2}:TreeTest User:" + r"/home/{0}/treetestuser:/bin/sh".format( re.escape(self.ad_treedomain), self.treedomain_testuser_uid_regex, self.treedomain_testuser_gid_regex)) @@ -354,7 +354,7 @@ class BaseTestLegacyClient(object): testgroup = 'treetestgroup@{0}'.format(self.ad_treedomain) result = self.legacy_client.run_command(['getent', 'group', testgroup]) - testgroup_stdout = "{0}:\*:{1}:".format( + testgroup_stdout = r"{0}:\*:{1}:".format( testgroup, self.treedomain_testuser_gid_regex) assert re.search(testgroup_stdout, result.stdout_text) @@ -518,12 +518,12 @@ class BaseTestLegacyClientPosix(BaseTestLegacyClient, class BaseTestLegacyClientNonPosix(BaseTestLegacyClient, trust_tests.TestBasicADTrust): - testuser_uid_regex = '(?!10042)(\d+)' - testuser_gid_regex = '(?!10047)(\d+)' - subdomain_testuser_uid_regex = '(?!10142)(\d+)' - subdomain_testuser_gid_regex = '(?!10147)(\d+)' - treedomain_testuser_uid_regex = '(?!10242)(\d+)' - treedomain_testuser_gid_regex = '(?!10247)(\d+)' + testuser_uid_regex = r'(?!10042)(\d+)' + testuser_gid_regex = r'(?!10047)(\d+)' + subdomain_testuser_uid_regex = r'(?!10142)(\d+)' + subdomain_testuser_gid_regex = r'(?!10147)(\d+)' + treedomain_testuser_uid_regex = r'(?!10242)(\d+)' + treedomain_testuser_gid_regex = r'(?!10247)(\d+)' def test_remove_nonposix_trust(self): pass diff --git a/ipatests/test_integration/test_topology.py b/ipatests/test_integration/test_topology.py index 6b92fef1b..6cd24ba2c 100644 --- a/ipatests/test_integration/test_topology.py +++ b/ipatests/test_integration/test_topology.py @@ -31,13 +31,13 @@ def find_segment(master, replica): class TestTopologyOptions(IntegrationTest): num_replicas = 2 topology = 'star' - rawsegment_re = ('Segment name: (?P<name>.*?)', - '\s+Left node: (?P<lnode>.*?)', - '\s+Right node: (?P<rnode>.*?)', - '\s+Connectivity: (?P<connectivity>\S+)') + rawsegment_re = (r'Segment name: (?P<name>.*?)', + r'\s+Left node: (?P<lnode>.*?)', + r'\s+Right node: (?P<rnode>.*?)', + r'\s+Connectivity: (?P<connectivity>\S+)') segment_re = re.compile("\n".join(rawsegment_re)) - noentries_re = re.compile("Number of entries returned (\d+)") - segmentnames_re = re.compile('.*Segment name: (\S+?)\n.*') + noentries_re = re.compile(r"Number of entries returned (\d+)") + segmentnames_re = re.compile(r'.*Segment name: (\S+?)\n.*') @classmethod def install(cls, mh): @@ -196,7 +196,7 @@ class TestCASpecificRUVs(IntegrationTest): "Certificate Server Replica" " Update Vectors" in res1.stdout_text), ( "CA-specific RUVs are not displayed") - ruvid_re = re.compile(".*%s:389: (\d+).*" % replica.hostname) + ruvid_re = re.compile(r".*%s:389: (\d+).*" % replica.hostname) replica_ruvs = ruvid_re.findall(res1.stdout_text) # Find out the number of RUVids assert(len(replica_ruvs) == 2), ( @@ -271,7 +271,7 @@ class TestReplicaManageDel(IntegrationTest): num_ruvs = result.stdout_text.count(replica.hostname) assert(num_ruvs == 1), ("Expected to find 1 replica's RUV, found %s" % num_ruvs) - ruvid_re = re.compile(".*%s:389: (\d+).*" % replica.hostname) + ruvid_re = re.compile(r".*%s:389: (\d+).*" % replica.hostname) replica_ruvs = ruvid_re.findall(result.stdout_text) master.run_command(['ipa-replica-manage', 'clean-ruv', '-f', '-p', master.config.dirman_password, @@ -294,7 +294,7 @@ class TestReplicaManageDel(IntegrationTest): master.config.dirman_password, replica.hostname]) result1 = master.run_command(['ipa-replica-manage', 'list-ruv', '-p', master.config.dirman_password]) - ruvid_re = re.compile(".*%s:389: (\d+).*" % replica.hostname) + ruvid_re = re.compile(r".*%s:389: (\d+).*" % replica.hostname) assert(ruvid_re.search(result1.stdout_text)), ( "Replica's RUV should not be removed under domain level 0") master.run_command(['ipa-replica-manage', 'clean-dangling-ruv', '-p', diff --git a/ipatests/test_integration/test_trust.py b/ipatests/test_integration/test_trust.py index d06910229..3538bbf09 100644 --- a/ipatests/test_integration/test_trust.py +++ b/ipatests/test_integration/test_trust.py @@ -172,8 +172,8 @@ class TestBasicADTrust(ADTrustBase): # This regex checks that Test User does not have UID 10042 nor belongs # to the group with GID 10047 - testuser_regex = "^testuser@%s:\*:(?!10042)(\d+):(?!10047)(\d+):"\ - "Test User:/home/%s/testuser:/bin/sh$"\ + testuser_regex = r"^testuser@%s:\*:(?!10042)(\d+):(?!10047)(\d+):"\ + r"Test User:/home/%s/testuser:/bin/sh$"\ % (re.escape(self.ad_domain), re.escape(self.ad_domain)) @@ -321,9 +321,9 @@ class TestExternalTrustWithSubdomain(ADTrustSubdomainBase): testuser = 'subdomaintestuser@{0}'.format(self.ad_subdomain) result = self.master.run_command(['getent', 'passwd', testuser]) - testuser_regex = ("^subdomaintestuser@{0}:\*:(?!10142)(\d+):" - "(?!10147)(\d+):Subdomaintest User:" - "/home/{1}/subdomaintestuser:/bin/sh$".format( + testuser_regex = (r"^subdomaintestuser@{0}:\*:(?!10142)(\d+):" + r"(?!10147)(\d+):Subdomaintest User:" + r"/home/{1}/subdomaintestuser:/bin/sh$".format( re.escape(self.ad_subdomain), re.escape(self.ad_subdomain))) @@ -388,9 +388,9 @@ class TestExternalTrustWithTreedomain(ADTrustTreedomainBase): testuser = 'treetestuser@{0}'.format(self.ad_treedomain) result = self.master.run_command(['getent', 'passwd', testuser]) - testuser_regex = ("^treetestuser@{0}:\*:(?!10242)(\d+):" - "(?!10247)(\d+):TreeTest User:" - "/home/{1}/treetestuser:/bin/sh$".format( + testuser_regex = (r"^treetestuser@{0}:\*:(?!10242)(\d+):" + r"(?!10247)(\d+):TreeTest User:" + r"/home/{1}/treetestuser:/bin/sh$".format( re.escape(self.ad_treedomain), re.escape(self.ad_treedomain))) @@ -483,9 +483,11 @@ class TestTrustWithUPN(ADTrustBase): self.upn_principal]) # result will contain AD domain, not UPN - upnuser_regex = "^{}@{}:\*:(\d+):(\d+):{}:/home/{}/{}:/bin/sh$".format( - self.upn_username, self.ad_domain, self.upn_name, - self.ad_domain, self.upn_username) + upnuser_regex = ( + r"^{}@{}:\*:(\d+):(\d+):{}:/home/{}/{}:/bin/sh$".format( + self.upn_username, self.ad_domain, self.upn_name, + self.ad_domain, self.upn_username) + ) assert re.search(upnuser_regex, result.stdout_text) def test_upn_user_authentication(self): diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py index 5db7aa5fc..9ab1857d3 100644 --- a/ipatests/test_ipalib/test_parameters.py +++ b/ipatests/test_ipalib/test_parameters.py @@ -866,7 +866,7 @@ class test_Bytes(ClassChecker): Test the `ipalib.parameters.Bytes._rule_pattern` method. """ # Test our assumptions about Python re module and Unicode: - pat = b'\w+$' + pat = br'\w+$' r = re.compile(pat) assert r.match(b'Hello_World') is not None assert r.match(utf8_bytes) is None @@ -1016,7 +1016,7 @@ class test_Str(ClassChecker): Test the `ipalib.parameters.Str._rule_pattern` method. """ # Test our assumptions about Python re module and Unicode: - pat = '\w{5}$' + pat = r'\w{5}$' r1 = re.compile(pat) r2 = re.compile(pat, re.UNICODE) if six.PY2: diff --git a/ipatests/test_ipalib/test_rpc.py b/ipatests/test_ipalib/test_rpc.py index e70ec4783..ab4311d37 100644 --- a/ipatests/test_ipalib/test_rpc.py +++ b/ipatests/test_ipalib/test_rpc.py @@ -389,7 +389,8 @@ class test_rpcclient_context(PluginTester): """ Test that session_cookie is set in `ipalib.rpc.rpcclient.connect` """ - fuzzy_cookie = Fuzzy('^ipa_session=MagBearerToken=[A-Za-z0-9+\/]+=*;$') + fuzzy_cookie = Fuzzy( + r'^ipa_session=MagBearerToken=[A-Za-z0-9+\/]+=*;$') session_cookie = getattr(context, 'session_cookie', None) # pylint-2 is incorrectly spewing Too many positional arguments diff --git a/ipatests/test_ipapython/test_kerberos.py b/ipatests/test_ipapython/test_kerberos.py index 284d8c2de..833ff67a4 100644 --- a/ipatests/test_ipapython/test_kerberos.py +++ b/ipatests/test_ipapython/test_kerberos.py @@ -16,7 +16,7 @@ valid_principals = { 'realm': u'REALM.TEST', 'username': u'tuser' }, - u'tuser\@tupn.test@REALM.TEST': { + u'tuser\\@tupn.test@REALM.TEST': { 'components': (u'tuser@tupn.test',), 'realm': u'REALM.TEST', 'username': u'tuser@tupn.test', @@ -54,11 +54,11 @@ valid_principals = { 'hostname': u'$%^.ipa.t%$t', 'service_name': u's$c' }, - u'test\/service/test\/host@REALM\@TEST': { + u'test\\/service/test\\/host@REALM\\@TEST': { 'components': (u'test/service', u'test/host'), 'realm': u'REALM@TEST', 'hostname': u'test/host', - 'service_name': u'test\/service' + 'service_name': r'test\/service' } } @@ -103,7 +103,7 @@ principals_properties = { 'property_true': ('is_service'), 'property_raises': ('username', 'upn_suffix') }, - u'user\@domain@REALM': { + u'user\\@domain@REALM': { 'property_true': ('is_user', 'is_enterprise'), 'property_raises': ('hostname', 'service_name') } diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py index b99adffba..20b252f24 100644 --- a/ipatests/test_webui/ui_driver.py +++ b/ipatests/test_webui/ui_driver.py @@ -914,7 +914,7 @@ class UI_driver(object): self.del_multivalued(name, value, parent) def check_option(self, name, value=None, parent=None): - """ + r""" Find checkbox or radio with name which matches ^NAME\d$ and check it by clicking on a label. """ @@ -929,7 +929,7 @@ class UI_driver(object): # Select only the one which matches exactly the name for o in opts: n = o.get_attribute("name") - if n == name or re.match("^%s\d+$" % name, n): + if n == name or re.match(r"^%s\d+$" % name, n): s = "label[for='%s']" % o.get_attribute("id") label = self.find(s, By.CSS_SELECTOR, parent, strict=True) checkbox = o diff --git a/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py b/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py index 8660e9823..30d57e6f4 100644 --- a/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py +++ b/ipatests/test_xmlrpc/test_kerberos_principal_aliases.py @@ -255,7 +255,7 @@ class TestKerberosAliasExceptions(XMLRPC_test): # Add an alias overlapping the trusted domain realm with pytest.raises(errors.ValidationError): krbalias_user.add_principal( - u'{username}\@{trusted_domain}@{realm}'.format( + u'{username}\\@{trusted_domain}@{realm}'.format( username=krbalias_user.name, trusted_domain=trusted_domain['name'], realm=api.env.realm @@ -273,7 +273,7 @@ class TestKerberosAliasExceptions(XMLRPC_test): with pytest.raises(errors.ValidationError): krbalias_user.add_principal( - u'{username}\@{trusted_domain}@{realm}'.format( + u'{username}\\@{trusted_domain}@{realm}'.format( username=krbalias_user.name, trusted_domain=upn_suffix, realm=api.env.realm @@ -291,7 +291,7 @@ class TestKerberosAliasExceptions(XMLRPC_test): with pytest.raises(errors.ValidationError): krbalias_user.add_principal( - u'{username}\@{trusted_domain}@{realm}'.format( + u'{username}\\@{trusted_domain}@{realm}'.format( username=krbalias_user.name, trusted_domain=netbios_name, realm=api.env.realm diff --git a/ipatests/test_xmlrpc/test_user_plugin.py b/ipatests/test_xmlrpc/test_user_plugin.py index d8176cd03..08d73f4b8 100644 --- a/ipatests/test_xmlrpc/test_user_plugin.py +++ b/ipatests/test_xmlrpc/test_user_plugin.py @@ -76,7 +76,7 @@ invalid_expiration_string = "2020-12-07 19:54:13" expired_expiration_string = "1991-12-07T19:54:13Z" # Date in ISO format (2013-12-10T12:00:00) -isodate_re = re.compile('^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$') +isodate_re = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$') @pytest.fixture(scope='class') diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py index 66459bda2..f989533a1 100644 --- a/ipatests/test_xmlrpc/xmlrpc_test.py +++ b/ipatests/test_xmlrpc/xmlrpc_test.py @@ -43,7 +43,7 @@ else: # Matches a gidnumber like '1391016742' # FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int` # or `long`? If not, we still need to return them as `unicode` instead of `str`. -fuzzy_digits = Fuzzy('^\d+$', type=six.string_types) +fuzzy_digits = Fuzzy(r'^\d+$', type=six.string_types) uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' @@ -71,7 +71,7 @@ def fuzzy_sequence_of(fuzzy): # Matches an automember task finish message fuzzy_automember_message = Fuzzy( - '^Automember rebuild task finished\. Processed \(\d+\) entries\.$' + r'^Automember rebuild task finished\. Processed \(\d+\) entries\.$' ) # Matches trusted domain GUID, like u'463bf2be-3456-4a57-979e-120304f2a0eb' @@ -109,19 +109,23 @@ fuzzy_caid = fuzzy_uuid fuzzy_ipauniqueid = Fuzzy('(?i)ipauniqueid=%s' % uuid_re) # Matches a hash signature, not enforcing length -fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types) +fuzzy_hash = Fuzzy( + r'^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types +) # Matches a date, like Tue Apr 26 17:45:35 2016 UTC -fuzzy_date = Fuzzy('^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$') +fuzzy_date = Fuzzy( + r'^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$' +) fuzzy_issuer = Fuzzy(type=six.string_types) -fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=six.string_types) +fuzzy_hex = Fuzzy(r'^0x[0-9a-fA-F]+$', type=six.string_types) # Matches password - password consists of all printable characters without # whitespaces. The only exception is space, but space cannot be at the # beginning or end of the pwd. -fuzzy_password = Fuzzy('^\S([\S ]*\S)*$') +fuzzy_password = Fuzzy(r'^\S([\S ]*\S)*$') # Matches generalized time value. Time format is: %Y%m%d%H%M%SZ fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime) diff --git a/ipatests/util.py b/ipatests/util.py index 1cbc7c45f..d02c288e0 100644 --- a/ipatests/util.py +++ b/ipatests/util.py @@ -203,7 +203,7 @@ class Fuzzy(object): The first optional argument *regex* is a regular expression pattern to match. For example, you could match a phone number like this: - >>> phone = Fuzzy('^\d{3}-\d{3}-\d{4}$') + >>> phone = Fuzzy(r'^\d{3}-\d{3}-\d{4}$') >>> u'123-456-7890' == phone True @@ -218,7 +218,7 @@ class Fuzzy(object): The *type* kwarg allows you to specify a type constraint, so you can force the above to work on ``str`` instances instead: - >>> '123-456-7890' == Fuzzy('^\d{3}-\d{3}-\d{4}$', type=str) + >>> '123-456-7890' == Fuzzy(r'^\d{3}-\d{3}-\d{4}$', type=str) True You can also use the *type* constraint on its own without the *regex*, for @@ -266,7 +266,7 @@ class Fuzzy(object): __hash__ = None def __init__(self, regex=None, type=None, test=None): - """ + r""" Initialize. :param regex: A regular expression pattern to match, e.g. @@ -593,7 +593,7 @@ class PluginTester(object): plugin = property(__get_plugin) def register(self, *plugins, **kw): - """ + r""" Create a testing api and register ``self.plugin``. This method returns an (api, home) tuple. |