Skip to content

Commit

Permalink
Removes several pylint warnings.
Browse files Browse the repository at this point in the history
This patche removes 93 pylint deprecation warnings due to invalid escape
sequences (mostly 'invalid escape sequence \d') on unicode strings.

Signed-off-by: Rafael Guterres Jeffman <[email protected]>
Reviewed-By: Christian Heimes <[email protected]>
  • Loading branch information
rjeffman authored and tiran committed Sep 27, 2019
1 parent bc53544 commit c898be1
Show file tree
Hide file tree
Showing 32 changed files with 84 additions and 77 deletions.
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_114/automember.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Auto Membership Rule.
Bring clarity to the membership of hosts and users by configuring inclusive
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_114/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Groups of users
Manage groups of users. By default, new groups are POSIX groups. You
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_114/hbactest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Simulate use of Host-based access controls
HBAC rules control who can access what services on what hosts.
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_114/trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Cross-realm trusts
Manage trust relationship between IPA and Active Directory domains.
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_156/automember.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Auto Membership Rule.
Bring clarity to the membership of hosts and users by configuring inclusive
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_156/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Groups of users
Manage groups of users. By default, new groups are POSIX groups. You
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_156/hbactest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Simulate use of Host-based access controls
HBAC rules control who can access what services on what hosts.
Expand Down
2 changes: 1 addition & 1 deletion ipaclient/remote_plugins/2_156/trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if six.PY3:
unicode = str

__doc__ = _("""
__doc__ = _(r"""
Cross-realm trusts
Manage trust relationship between IPA and Active Directory domains.
Expand Down
10 changes: 6 additions & 4 deletions ipaclient/remote_plugins/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (C) 2016 FreeIPA Contributors see COPYING for license
#

from __future__ import unicode_literals

import importlib
import os
import re
Expand Down Expand Up @@ -42,19 +44,19 @@ def get_package(server_info, client):
if not is_valid:
if not client.isconnected():
client.connect(verbose=False)
env = client.forward(u'env', u'api_version', version=u'2.0')
env = client.forward('env', 'api_version', version='2.0')
try:
server_version = env['result']['api_version']
except KeyError:
ping = client.forward(u'ping', version=u'2.0')
ping = client.forward('ping', version='2.0')
try:
match = re.search(u'API version (2\.[0-9]+)', ping['summary'])
match = re.search(r'API version (2\.[0-9]+)', ping['summary'])
except KeyError:
match = None
if match is not None:
server_version = match.group(1)
else:
server_version = u'2.0'
server_version = '2.0'
server_info['version'] = server_version
server_info.update_validity()

Expand Down
6 changes: 4 additions & 2 deletions ipalib/plugable.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
you are unfamiliar with this Python feature, see
http://docs.python.org/ref/sequence-types.html
"""
from __future__ import unicode_literals

import logging
import operator
import re
Expand Down Expand Up @@ -173,7 +175,7 @@ def __doc_getter(cls):
def __summary_getter(cls):
doc = cls.doc
if not _(doc).msg:
return u'<%s.%s>' % (cls.__module__, cls.__name__)
return '<%s.%s>' % (cls.__module__, cls.__name__)
else:
return unicode(doc).split('\n\n', 1)[0].strip()

Expand Down Expand Up @@ -467,7 +469,7 @@ def bootstrap(self, parser=None, **overrides):
level = ipa_log_manager.convert_log_level(match.group(1))

value = getattr(self.env, attr)
regexps = re.split('\s*,\s*', value)
regexps = re.split(r'\s*,\s*', value)

# Add the regexp, it maps to the configured level
for regexp in regexps:
Expand Down
2 changes: 1 addition & 1 deletion ipapython/certdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def get_trust_chain(self, nickname):
chain = result.output.splitlines()

for c in chain:
m = re.match('\s*"(.*)" \[.*', c)
m = re.match(r'\s*"(.*)" \[.*', c)
if m:
root_nicknames.append(m.groups()[0])

Expand Down
2 changes: 1 addition & 1 deletion ipapython/dn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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'''
Goal
----
Expand Down
6 changes: 3 additions & 3 deletions ipapython/ipautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def template_str(txt, vars):
# eval() is a special string one can insert into a template to have the
# Python interpreter evaluate the string. This is intended to allow
# math to be performed in templates.
pattern = re.compile('(eval\s*\(([^()]*)\))')
pattern = re.compile(r'(eval\s*\(([^()]*)\))')
val = pattern.sub(lambda x: str(eval(x.group(2))), val)

return val
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def config_replace_variables(filepath, replacevars=dict(), appendvars=dict(),
One have to run restore_context(filepath) afterwards or
security context of the file will not be correct after modification
"""
pattern = re.compile('''
pattern = re.compile(r'''
(^
\s*
(?P<option> [^\#;]+?)
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def inifile_replace_variables(filepath, section, replacevars=dict(), appendvars=
One have to run restore_context(filepath) afterwards or
security context of the file will not be correct after modification
"""
pattern = re.compile('''
pattern = re.compile(r'''
(^
\[
(?P<section> .+) \]
Expand Down
16 changes: 8 additions & 8 deletions ipaserver/dcerpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Make sure we only run this module at the server where samba4-python
# package is installed to avoid issues with unavailable modules

from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

import logging
import re
Expand Down Expand Up @@ -634,7 +634,7 @@ def __sid_to_str(self, sid):
struct.unpack('<I', sid[8+4*i:12+4*i])[0]
for i in range(number_sub_id)
]
return u'S-%d-%d-%s' % (sid_rev_num, ia,
return 'S-%d-%d-%s' % (sid_rev_num, ia,
'-'.join([str(s) for s in subs]),)

def kinit_as_administrator(self, domain):
Expand Down Expand Up @@ -900,9 +900,9 @@ def __gen_lsa_bindings(self, remote_host):
We try NCACN_NP before NCACN_IP_TCP and use SMB2 before SMB1.
"""
transports = (u'ncacn_np', u'ncacn_ip_tcp')
options = (u'smb2,print', u'print')
return [u'%s:%s[%s]' % (t, remote_host, o)
transports = ('ncacn_np', 'ncacn_ip_tcp')
options = ('smb2,print', 'print')
return ['%s:%s[%s]' % (t, remote_host, o)
for t in transports for o in options]

def retrieve_anonymously(self, remote_host,
Expand Down Expand Up @@ -976,7 +976,7 @@ def retrieve(self, remote_host):
objectAttribute.sec_qos = lsa.QosInfo()
try:
self._policy_handle = \
self._pipe.OpenPolicy2(u"", objectAttribute,
self._pipe.OpenPolicy2("", objectAttribute,
security.SEC_FLAG_MAXIMUM_ALLOWED)
result = self._pipe.QueryInfoPolicy2(self._policy_handle,
lsa.LSA_POLICY_INFO_DNS)
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def establish_trust(self, another_domain, trustdom_secret,
"""
if self.info['name'] == another_domain.info['name']:
# Check that NetBIOS names do not clash
raise errors.ValidationError(name=u'AD Trust Setup',
raise errors.ValidationError(name='AD Trust Setup',
error=_('the IPA server and the '
'remote domain cannot share '
'the same NetBIOS name: %s')
Expand Down Expand Up @@ -1597,7 +1597,7 @@ def get_instance(local_flatname):
# realm admin is in DOMAIN\user format
# strip DOMAIN part as we'll enforce the one discovered
realm_admin = names[-1]
auth_string = u"%s\%s%%%s" \
auth_string = r"%s\%s%%%s" \
% (rd.info['name'], realm_admin, realm_passwd)
td = get_instance(local_flatname)
td.creds.parse_string(auth_string)
Expand Down
40 changes: 20 additions & 20 deletions ipaserver/dns_data_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2016 FreeIPA Contributors see COPYING for license
#

from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

import logging

Expand Down Expand Up @@ -31,23 +31,23 @@

IPA_DEFAULT_MASTER_SRV_REC = (
# srv record name, port
(DNSName(u'_ldap._tcp'), 389),
(DNSName(u'_kerberos._tcp'), 88),
(DNSName(u'_kerberos._udp'), 88),
(DNSName(u'_kerberos-master._tcp'), 88),
(DNSName(u'_kerberos-master._udp'), 88),
(DNSName(u'_kpasswd._tcp'), 464),
(DNSName(u'_kpasswd._udp'), 464),
(DNSName('_ldap._tcp'), 389),
(DNSName('_kerberos._tcp'), 88),
(DNSName('_kerberos._udp'), 88),
(DNSName('_kerberos-master._tcp'), 88),
(DNSName('_kerberos-master._udp'), 88),
(DNSName('_kpasswd._tcp'), 464),
(DNSName('_kpasswd._udp'), 464),
)

IPA_DEFAULT_ADTRUST_SRV_REC = (
# srv record name, port
(DNSName(u'_ldap._tcp.Default-First-Site-Name._sites.dc._msdcs'), 389),
(DNSName(u'_ldap._tcp.dc._msdcs'), 389),
(DNSName(u'_kerberos._tcp.Default-First-Site-Name._sites.dc._msdcs'), 88),
(DNSName(u'_kerberos._udp.Default-First-Site-Name._sites.dc._msdcs'), 88),
(DNSName(u'_kerberos._tcp.dc._msdcs'), 88),
(DNSName(u'_kerberos._udp.dc._msdcs'), 88),
(DNSName('_ldap._tcp.Default-First-Site-Name._sites.dc._msdcs'), 389),
(DNSName('_ldap._tcp.dc._msdcs'), 389),
(DNSName('_kerberos._tcp.Default-First-Site-Name._sites.dc._msdcs'), 88),
(DNSName('_kerberos._udp.Default-First-Site-Name._sites.dc._msdcs'), 88),
(DNSName('_kerberos._tcp.dc._msdcs'), 88),
(DNSName('_kerberos._udp.dc._msdcs'), 88),
)

IPA_DEFAULT_NTP_SRV_REC = (
Expand Down Expand Up @@ -83,7 +83,7 @@ def reload_data(self):
self.__init_data()

def __get_server_attrs(self, server_result):
weight = int(server_result.get('ipaserviceweight', [u'100'])[0])
weight = int(server_result.get('ipaserviceweight', ['100'])[0])
location = server_result.get('ipalocation_location', [None])[0]
roles = set(server_result.get('enabled_role_servrole', ()))

Expand All @@ -98,7 +98,7 @@ def __init_data(self, all_servers=False):
kwargs = dict(no_members=False)
if not all_servers:
# only active, fully installed masters]
kwargs["servrole"] = u"IPA master"
kwargs["servrole"] = "IPA master"
servers = self.api_instance.Command.server_find(**kwargs)

for s in servers['result']:
Expand Down Expand Up @@ -277,10 +277,10 @@ def __update_dns_records(
):
update_dict = self.__prepare_records_update_dict(nodes)
cname_template = {
'addattr': [u'objectclass=idnsTemplateObject'],
'addattr': ['objectclass=idnsTemplateObject'],
'setattr': [
u'idnsTemplateAttribute;cnamerecord=%s'
u'.\{substitutionvariable_ipalocation\}._locations' %
r'idnsTemplateAttribute;cnamerecord=%s'
r'.\{substitutionvariable_ipalocation\}._locations' %
record_name.relativize(self.domain_abs)
]
}
Expand Down Expand Up @@ -474,7 +474,7 @@ def records_list_from_node(cls, name, node):
for rdataset in node:
for rd in rdataset:
records.append(
u'{name} {ttl} {rdclass} {rdtype} {rdata}'.format(
'{name} {ttl} {rdclass} {rdtype} {rdata}'.format(
name=name.ToASCII(),
ttl=rdataset.ttl,
rdclass=rdataclass.to_text(rd.rdclass),
Expand Down
3 changes: 2 additions & 1 deletion ipaserver/install/adtrustinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ def __update_krb5_conf(self):

has_dns_lookup_kdc_true = False
for line in krb5conf:
if re.match("^\s*dns_lookup_kdc\s*=\s*[Tt][Rr][Uu][Ee]\s*$", line):
regex = r"^\s*dns_lookup_kdc\s*=\s*[Tt][Rr][Uu][Ee]\s*$"
if re.match(regex, line):
has_dns_lookup_kdc_true = True
break
krb5conf.close()
Expand Down
4 changes: 2 additions & 2 deletions ipaserver/install/bindinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

logger = logging.getLogger(__name__)

named_conf_section_ipa_start_re = re.compile('\s*dyndb\s+"ipa"\s+"[^"]+"\s+{')
named_conf_section_options_start_re = re.compile('\s*options\s+{')
named_conf_section_ipa_start_re = re.compile(r'\s*dyndb\s+"ipa"\s+"[^"]+"\s+{')
named_conf_section_options_start_re = re.compile(r'\s*options\s+{')
named_conf_section_end_re = re.compile('};')
named_conf_arg_ipa_re = re.compile(
r'(?P<indent>\s*)(?P<name>\S+)\s"(?P<value>[^"]+)";')
Expand Down
2 changes: 1 addition & 1 deletion ipaserver/install/dsinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def __configure_sasl_mappings(self):
('cn', 'config')),
objectclass=["top", "nsSaslMapping"],
cn=["Full Principal"],
nsSaslMapRegexString=['\(.*\)@\(.*\)'],
nsSaslMapRegexString=[r'\(.*\)@\(.*\)'],
nsSaslMapBaseDNTemplate=[self.suffix],
nsSaslMapFilterTemplate=['(krbPrincipalName=\\1@\\2)'],
nsSaslMapPriority=['10'],
Expand Down
4 changes: 2 additions & 2 deletions ipaserver/install/server/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def find_autoredirect(fqdn):
"""
filename = paths.HTTPD_IPA_REWRITE_CONF
if os.path.exists(filename):
pattern = "^RewriteRule \^/\$ https://%s/ipa/ui \[L,NC,R=301\]" % fqdn
pattern = r"^RewriteRule \^/\$ https://%s/ipa/ui \[L,NC,R=301\]" % fqdn
p = re.compile(pattern)
for line in fileinput.input(filename):
if p.search(line):
Expand All @@ -157,7 +157,7 @@ def find_version(filename):
If the file does not exist, returns -1.
"""
if os.path.exists(filename):
pattern = "^[\s#]*VERSION\s+([0-9]+)\s+.*"
pattern = r"^[\s#]*VERSION\s+([0-9]+)\s+.*"
p = re.compile(pattern)
for line in fileinput.input(filename):
if p.search(line):
Expand Down
6 changes: 3 additions & 3 deletions ipaserver/plugins/automember.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
Add the initial rule:
ipa automember-add --type=hostgroup webservers
ipa automember-add --type=group devel
""") + _("""
""") + _(r"""
Add a condition to the rule:
ipa automember-add-condition --key=fqdn --type=hostgroup --inclusive-regex=^web[1-9]+\.example\.com webservers
ipa automember-add-condition --key=manager --type=group --inclusive-regex=^uid=mscott devel
""") + _("""
""") + _(r"""
Add an exclusive condition to the rule to prevent auto assignment:
ipa automember-add-condition --key=fqdn --type=hostgroup --exclusive-regex=^web5\.example\.com webservers
""") + _("""
Expand All @@ -95,7 +95,7 @@
Description: Developers
GID: 1004200000
Member users: tuser
""") + _("""
""") + _(r"""
Remove a condition from the rule:
ipa automember-remove-condition --key=fqdn --type=hostgroup --inclusive-regex=^web[1-9]+\.example\.com webservers
""") + _("""
Expand Down
Loading

0 comments on commit c898be1

Please sign in to comment.