diff --git a/lib/ansible/modules/cloud/amazon/_ec2_ami_find.py b/lib/ansible/modules/cloud/amazon/_ec2_ami_find.py index 6696ec77530..fa67add8098 100644 --- a/lib/ansible/modules/cloud/amazon/_ec2_ami_find.py +++ b/lib/ansible/modules/cloud/amazon/_ec2_ami_find.py @@ -11,7 +11,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: ec2_ami_find version_added: '2.0' diff --git a/lib/ansible/modules/cloud/amazon/cloudwatchevent_rule.py b/lib/ansible/modules/cloud/amazon/cloudwatchevent_rule.py index 05b9784be79..03f2ce68769 100644 --- a/lib/ansible/modules/cloud/amazon/cloudwatchevent_rule.py +++ b/lib/ansible/modules/cloud/amazon/cloudwatchevent_rule.py @@ -11,7 +11,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: cloudwatchevent_rule short_description: Manage CloudWatch Event rules and targets diff --git a/lib/ansible/modules/cloud/amazon/ec2_group.py b/lib/ansible/modules/cloud/amazon/ec2_group.py index a7068aa65f0..281db4ea84b 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_group.py +++ b/lib/ansible/modules/cloud/amazon/ec2_group.py @@ -368,7 +368,7 @@ def get_target_from_rule(module, client, rule, name, group, groups, vpc_id): group_id or a non-None ip range. """ - FOREIGN_SECURITY_GROUP_REGEX = '^(\S+)/(sg-\S+)/(\S+)' + FOREIGN_SECURITY_GROUP_REGEX = r'^(\S+)/(sg-\S+)/(\S+)' group_id = None group_name = None ip = None diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py index fc1a357534c..8fa3d875a4f 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py @@ -169,9 +169,9 @@ class AnsibleSubnetSearchException(AnsibleRouteTableException): pass -CIDR_RE = re.compile('^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$') -SUBNET_RE = re.compile('^subnet-[A-z0-9]+$') -ROUTE_TABLE_RE = re.compile('^rtb-[A-z0-9]+$') +CIDR_RE = re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$') +SUBNET_RE = re.compile(r'^subnet-[A-z0-9]+$') +ROUTE_TABLE_RE = re.compile(r'^rtb-[A-z0-9]+$') def find_subnets(vpc_conn, vpc_id, identified_subnets): diff --git a/lib/ansible/modules/cloud/amazon/lambda.py b/lib/ansible/modules/cloud/amazon/lambda.py index edf1d1525f4..b3829dc664b 100644 --- a/lib/ansible/modules/cloud/amazon/lambda.py +++ b/lib/ansible/modules/cloud/amazon/lambda.py @@ -238,7 +238,7 @@ def get_account_id(module, region=None, endpoint=None, **aws_connect_kwargs): except ClientError as e: if (e.response['Error']['Code'] == 'AccessDenied'): except_msg = to_native(e.message) - account_id = except_msg.search("arn:aws:iam::([0-9]{12,32}):\w+/").group(1) + account_id = except_msg.search(r"arn:aws:iam::([0-9]{12,32}):\w+/").group(1) if account_id is None: module.fail_json_aws(e, msg="getting account information") except Exception as e: diff --git a/lib/ansible/modules/cloud/amazon/lambda_alias.py b/lib/ansible/modules/cloud/amazon/lambda_alias.py index 78aae3cdb05..01b160b40c7 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_alias.py +++ b/lib/ansible/modules/cloud/amazon/lambda_alias.py @@ -235,7 +235,7 @@ def validate_params(module, aws): function_name = module.params['function_name'] # validate function name - if not re.search('^[\w\-:]+$', function_name): + if not re.search(r'^[\w\-:]+$', function_name): module.fail_json( msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format(function_name) ) diff --git a/lib/ansible/modules/cloud/amazon/lambda_event.py b/lib/ansible/modules/cloud/amazon/lambda_event.py index f7298cb548f..6484c0993aa 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_event.py +++ b/lib/ansible/modules/cloud/amazon/lambda_event.py @@ -222,7 +222,7 @@ def validate_params(module, aws): function_name = module.params['lambda_function_arn'] # validate function name - if not re.search('^[\w\-:]+$', function_name): + if not re.search(r'^[\w\-:]+$', function_name): module.fail_json( msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format(function_name) ) diff --git a/lib/ansible/modules/cloud/amazon/lambda_facts.py b/lib/ansible/modules/cloud/amazon/lambda_facts.py index 868b12ab019..21ccf29fc50 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_facts.py +++ b/lib/ansible/modules/cloud/amazon/lambda_facts.py @@ -361,7 +361,7 @@ def main(): # validate function_name if present function_name = module.params['function_name'] if function_name: - if not re.search("^[\w\-:]+$", function_name): + if not re.search(r"^[\w\-:]+$", function_name): module.fail_json( msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format(function_name) ) diff --git a/lib/ansible/modules/cloud/amazon/lambda_policy.py b/lib/ansible/modules/cloud/amazon/lambda_policy.py index 9163889fcde..c9b6057aeec 100644 --- a/lib/ansible/modules/cloud/amazon/lambda_policy.py +++ b/lib/ansible/modules/cloud/amazon/lambda_policy.py @@ -188,7 +188,7 @@ def validate_params(module): # validate function name if function_name.startswith('arn:'): - if not re.search('^[\w\-]+$', function_name): + if not re.search(r'^[\w\-]+$', function_name): module.fail_json( msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format( function_name) @@ -197,7 +197,7 @@ def validate_params(module): module.fail_json( msg='Function name "{0}" exceeds 64 character limit'.format(function_name)) else: - if not re.search('^[\w\-:]+$', function_name): + if not re.search(r'^[\w\-:]+$', function_name): module.fail_json( msg='ARN {0} is invalid. ARNs must contain only alphanumeric characters, hyphens and colons.'.format(function_name) ) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index fdf95c97be8..97a86789d26 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -613,8 +613,8 @@ AZURE_ENUM_MODULES = ['azure.mgmt.compute.models'] def extract_names_from_blob_uri(blob_uri, storage_suffix): # HACK: ditch this once python SDK supports get by URI - m = re.match('^https://(?P[^\.]+)\.blob\.{0}/' - '(?P[^/]+)/(?P.+)$'.format(storage_suffix), blob_uri) + m = re.match(r'^https://(?P[^.]+)\.blob\.{0}/' + r'(?P[^/]+)/(?P.+)$'.format(storage_suffix), blob_uri) if not m: raise Exception("unable to parse blob uri '%s'" % blob_uri) extracted_names = m.groupdict() diff --git a/lib/ansible/modules/cloud/misc/proxmox_kvm.py b/lib/ansible/modules/cloud/misc/proxmox_kvm.py index 53c125d7e45..bb72d057b2e 100644 --- a/lib/ansible/modules/cloud/misc/proxmox_kvm.py +++ b/lib/ansible/modules/cloud/misc/proxmox_kvm.py @@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: proxmox_kvm short_description: Management of Qemu(KVM) Virtual Machines in Proxmox VE cluster. diff --git a/lib/ansible/modules/cloud/packet/packet_device.py b/lib/ansible/modules/cloud/packet/packet_device.py index b2879cb04a2..0406f9ea884 100644 --- a/lib/ansible/modules/cloud/packet/packet_device.py +++ b/lib/ansible/modules/cloud/packet/packet_device.py @@ -271,8 +271,8 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule -NAME_RE = '({0}|{0}{1}*{0})'.format('[a-zA-Z0-9]', '[a-zA-Z0-9\-]') -HOSTNAME_RE = '({0}\.)*{0}$'.format(NAME_RE) +NAME_RE = r'({0}|{0}{1}*{0})'.format(r'[a-zA-Z0-9]', r'[a-zA-Z0-9\-]') +HOSTNAME_RE = r'({0}\.)*{0}$'.format(NAME_RE) MAX_DEVICES = 100 PACKET_DEVICE_STATES = ( @@ -403,7 +403,7 @@ def get_hostname_list(module): if (len(hostnames) == 1) and (count > 0): hostname_spec = hostnames[0] count_range = range(count_offset, count_offset + count) - if re.search("%\d{0,2}d", hostname_spec): + if re.search(r"%\d{0,2}d", hostname_spec): hostnames = [hostname_spec % i for i in count_range] elif count > 1: hostname_spec = '%s%%02d' % hostname_spec diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks.py b/lib/ansible/modules/cloud/profitbricks/profitbricks.py index 33045bfacd7..d965167d4b1 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks.py @@ -215,7 +215,7 @@ LOCATIONS = ['us/las', 'de/fkb'] uuid_match = re.compile( - '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) + r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py index 905e32637a6..bebff23c8c5 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py @@ -95,7 +95,7 @@ LOCATIONS = ['us/las', 'de/fkb'] uuid_match = re.compile( - '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) + r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py index 5448a054f85..ccf863a6591 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py @@ -98,7 +98,7 @@ from ansible.module_utils.basic import AnsibleModule uuid_match = re.compile( - '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) + r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py index 1bc16354615..1d1980e0780 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py @@ -147,7 +147,7 @@ from ansible.module_utils._text import to_native uuid_match = re.compile( - '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) + r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py index 3deff0578ab..9a7bfec3bfa 100644 --- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py +++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py @@ -95,7 +95,7 @@ from ansible.module_utils.basic import AnsibleModule uuid_match = re.compile( - '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) + r'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) def _wait_for_completion(profitbricks, promise, wait_timeout, msg): diff --git a/lib/ansible/modules/cloud/smartos/imgadm.py b/lib/ansible/modules/cloud/smartos/imgadm.py index a9012b31133..7d7b04f964c 100644 --- a/lib/ansible/modules/cloud/smartos/imgadm.py +++ b/lib/ansible/modules/cloud/smartos/imgadm.py @@ -145,7 +145,7 @@ class Imgadm(object): # Helper method to massage stderr def errmsg(self, stderr): - match = re.match('^imgadm .*?: error \(\w+\): (.*): .*', stderr) + match = re.match(r'^imgadm .*?: error \(\w+\): (.*): .*', stderr) if match: return match.groups()[0] else: @@ -236,7 +236,7 @@ class Imgadm(object): if rc != 0: self.module.fail_json(msg='Failed to import image: {0}'.format(self.errmsg(stderr))) - regex = 'Image {0} \(.*\) is already installed, skipping'.format(self.uuid) + regex = r'Image {0} \(.*\) is already installed, skipping'.format(self.uuid) if re.match(regex, stdout): self.changed = False diff --git a/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py b/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py index 2c2581356a6..e071b1b9c3b 100644 --- a/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py +++ b/lib/ansible/modules/database/influxdb/influxdb_retention_policy.py @@ -181,7 +181,7 @@ def alter_retention_policy(module, client, retention_policy): duration = module.params['duration'] replication = module.params['replication'] default = module.params['default'] - duration_regexp = re.compile('(\d+)([hdw]{1})|(^INF$){1}') + duration_regexp = re.compile(r'(\d+)([hdw]{1})|(^INF$){1}') changed = False duration_lookup = duration_regexp.search(duration) diff --git a/lib/ansible/modules/database/mysql/mysql_db.py b/lib/ansible/modules/database/mysql/mysql_db.py index 5f69d96cea6..a844befcf29 100644 --- a/lib/ansible/modules/database/mysql/mysql_db.py +++ b/lib/ansible/modules/database/mysql/mysql_db.py @@ -126,7 +126,7 @@ from ansible.module_utils._text import to_native def db_exists(cursor, db): - res = cursor.execute("SHOW DATABASES LIKE %s", (db.replace("_", "\_"),)) + res = cursor.execute("SHOW DATABASES LIKE %s", (db.replace("_", r"\_"),)) return bool(res) diff --git a/lib/ansible/modules/database/postgresql/postgresql_user.py b/lib/ansible/modules/database/postgresql/postgresql_user.py index fa049ef7bfc..4745dd76a7f 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_user.py +++ b/lib/ansible/modules/database/postgresql/postgresql_user.py @@ -503,7 +503,7 @@ def get_database_privileges(cursor, user, db): datacl = cursor.fetchone()[0] if datacl is None: return set() - r = re.search('%s\\\\?\"?=(C?T?c?)/[^,]+\,?' % user, datacl) + r = re.search(r'%s\\?"?=(C?T?c?)/[^,]+,?' % user, datacl) if r is None: return set() o = set() diff --git a/lib/ansible/modules/files/find.py b/lib/ansible/modules/files/find.py index def9480154a..e429df6fa68 100644 --- a/lib/ansible/modules/files/find.py +++ b/lib/ansible/modules/files/find.py @@ -287,7 +287,7 @@ def main(): age = None else: # convert age to seconds: - m = re.match("^(-?\d+)(s|m|h|d|w)?$", params['age'].lower()) + m = re.match(r"^(-?\d+)(s|m|h|d|w)?$", params['age'].lower()) seconds_per_unit = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800} if m: age = int(m.group(1)) * seconds_per_unit.get(m.group(2), 1) @@ -298,7 +298,7 @@ def main(): size = None else: # convert size to bytes: - m = re.match("^(-?\d+)(b|k|m|g|t)?$", params['size'].lower()) + m = re.match(r"^(-?\d+)(b|k|m|g|t)?$", params['size'].lower()) bytes_per_unit = {"b": 1, "k": 1024, "m": 1024**2, "g": 1024**3, "t": 1024**4} if m: size = int(m.group(1)) * bytes_per_unit.get(m.group(2), 1) diff --git a/lib/ansible/modules/files/xattr.py b/lib/ansible/modules/files/xattr.py index f8973901794..1c0f8aef316 100644 --- a/lib/ansible/modules/files/xattr.py +++ b/lib/ansible/modules/files/xattr.py @@ -179,7 +179,7 @@ def main(): module.fail_json(msg="%s needs a key parameter" % state) # All xattr must begin in user namespace - if key is not None and not re.match('^user\.', key): + if key is not None and not re.match(r'^user\.', key): key = 'user.%s' % key if (state == 'present' or value is not None): diff --git a/lib/ansible/modules/files/xml.py b/lib/ansible/modules/files/xml.py index 0548ecab8f4..58ef067f2cf 100644 --- a/lib/ansible/modules/files/xml.py +++ b/lib/ansible/modules/files/xml.py @@ -274,7 +274,7 @@ from ansible.module_utils.basic import AnsibleModule, json_dict_bytes_to_unicode from ansible.module_utils.six import iteritems, string_types from ansible.module_utils._text import to_bytes, to_native -_IDENT = "[a-zA-Z-][a-zA-Z0-9_\-\.]*" +_IDENT = r"[a-zA-Z-][a-zA-Z0-9_\-\.]*" _NSIDENT = _IDENT + "|" + _IDENT + ":" + _IDENT # Note: we can't reasonably support the 'if you need to put both ' and " in a string, concatenate # strings wrapped by the other delimiter' XPath trick, especially as simple XPath. diff --git a/lib/ansible/modules/inventory/add_host.py b/lib/ansible/modules/inventory/add_host.py index 35905ccf00d..c6daeff1dc7 100644 --- a/lib/ansible/modules/inventory/add_host.py +++ b/lib/ansible/modules/inventory/add_host.py @@ -12,7 +12,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'core'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: add_host short_description: add a host (and alternatively a group) to the ansible-playbook in-memory inventory diff --git a/lib/ansible/modules/monitoring/monit.py b/lib/ansible/modules/monitoring/monit.py index 9c9edd63268..53f7080c84b 100644 --- a/lib/ansible/modules/monitoring/monit.py +++ b/lib/ansible/modules/monitoring/monit.py @@ -75,7 +75,7 @@ def main(): def monit_version(): rc, out, err = module.run_command('%s -V' % MONIT, check_rc=True) version_line = out.split('\n')[0] - version = re.search("[0-9]+\.[0-9]+", version_line).group().split('.') + version = re.search(r"[0-9]+\.[0-9]+", version_line).group().split('.') # Use only major and minor even if there are more these should be enough return int(version[0]), int(version[1]) diff --git a/lib/ansible/modules/notification/irc.py b/lib/ansible/modules/notification/irc.py index a3313450f34..1bee674bfd1 100644 --- a/lib/ansible/modules/notification/irc.py +++ b/lib/ansible/modules/notification/irc.py @@ -206,7 +206,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k motd += irc.recv(1024) # The server might send back a shorter nick than we specified (due to NICKLEN), # so grab that and use it from now on (assuming we find the 00[1-4] response). - match = re.search('^:\S+ 00[1-4] (?P\S+) :', motd, flags=re.M) + match = re.search(r'^:\S+ 00[1-4] (?P\S+) :', motd, flags=re.M) if match: nick = match.group('nick') break @@ -223,7 +223,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k start = time.time() while 1: join += irc.recv(1024) - if re.search('^:\S+ 366 %s %s :' % (nick, channel), join, flags=re.M): + if re.search(r'^:\S+ 366 %s %s :' % (nick, channel), join, flags=re.M): break elif time.time() - start > timeout: raise Exception('Timeout waiting for IRC JOIN response') diff --git a/lib/ansible/modules/packaging/language/composer.py b/lib/ansible/modules/packaging/language/composer.py index 0a434cf7564..4908136a3c2 100644 --- a/lib/ansible/modules/packaging/language/composer.py +++ b/lib/ansible/modules/packaging/language/composer.py @@ -137,7 +137,7 @@ from ansible.module_utils.basic import AnsibleModule def parse_out(string): - return re.sub("\s+", " ", string).strip() + return re.sub(r"\s+", " ", string).strip() def has_changed(string): diff --git a/lib/ansible/modules/packaging/language/npm.py b/lib/ansible/modules/packaging/language/npm.py index f2a48deb03c..fed13921d00 100644 --- a/lib/ansible/modules/packaging/language/npm.py +++ b/lib/ansible/modules/packaging/language/npm.py @@ -220,7 +220,7 @@ class Npm(object): if dep: # node.js v0.10.22 changed the `npm outdated` module separator # from "@" to " ". Split on both for backwards compatibility. - pkg, other = re.split('\s|@', dep, 1) + pkg, other = re.split(r'\s|@', dep, 1) outdated.append(pkg) return outdated diff --git a/lib/ansible/modules/packaging/os/apk.py b/lib/ansible/modules/packaging/os/apk.py index 6cbe54372ca..0d1e1f73f25 100644 --- a/lib/ansible/modules/packaging/os/apk.py +++ b/lib/ansible/modules/packaging/os/apk.py @@ -150,7 +150,7 @@ from ansible.module_utils.basic import AnsibleModule def parse_for_packages(stdout): packages = [] data = stdout.split('\n') - regex = re.compile('^\(\d+/\d+\)\s+\S+\s+(\S+)') + regex = re.compile(r'^\(\d+/\d+\)\s+\S+\s+(\S+)') for l in data: p = regex.search(l) if p: diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index f6c3af5169f..1322f0b4813 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -208,8 +208,8 @@ class SourcesList(object): return s # Drop options and protocols. - line = re.sub('\[[^\]]+\]', '', line) - line = re.sub('\w+://', '', line) + line = re.sub(r'\[[^\]]+\]', '', line) + line = re.sub(r'\w+://', '', line) # split line into valid keywords parts = [part for part in line.split() if part not in VALID_SOURCE_TYPES] diff --git a/lib/ansible/modules/packaging/os/openbsd_pkg.py b/lib/ansible/modules/packaging/os/openbsd_pkg.py index f3b04436644..feeed07614e 100644 --- a/lib/ansible/modules/packaging/os/openbsd_pkg.py +++ b/lib/ansible/modules/packaging/os/openbsd_pkg.py @@ -235,7 +235,7 @@ def package_present(names, pkg_spec, module): # "file:/local/package/directory/ is empty" message on stderr # while still installing the package, so we need to look for # for a message like "packagename-1.0: ok" just in case. - match = re.search("\W%s-[^:]+: ok\W" % pkg_spec[name]['stem'], pkg_spec[name]['stdout']) + match = re.search(r"\W%s-[^:]+: ok\W" % pkg_spec[name]['stem'], pkg_spec[name]['stdout']) if match: # It turns out we were able to install the package. @@ -286,7 +286,7 @@ def package_latest(names, pkg_spec, module): pkg_spec[name]['changed'] = False for installed_name in pkg_spec[name]['installed_names']: module.debug("package_latest(): checking for pre-upgrade package name: %s" % installed_name) - match = re.search("\W%s->.+: ok\W" % installed_name, pkg_spec[name]['stdout']) + match = re.search(r"\W%s->.+: ok\W" % installed_name, pkg_spec[name]['stdout']) if match: module.debug("package_latest(): pre-upgrade package name match: %s" % installed_name) @@ -502,7 +502,7 @@ def upgrade_packages(pkg_spec, module): # Try to find any occurrence of a package changing version like: # "bzip2-1.0.6->1.0.6p0: ok". - match = re.search("\W\w.+->.+: ok\W", pkg_spec['*']['stdout']) + match = re.search(r"\W\w.+->.+: ok\W", pkg_spec['*']['stdout']) if match: pkg_spec['*']['changed'] = True diff --git a/lib/ansible/modules/packaging/os/pacman.py b/lib/ansible/modules/packaging/os/pacman.py index 8cacba5e9a9..0b2e0d17175 100644 --- a/lib/ansible/modules/packaging/os/pacman.py +++ b/lib/ansible/modules/packaging/os/pacman.py @@ -194,7 +194,7 @@ def upgrade(module, pacman_path): } if rc == 0: - regex = re.compile('([\w-]+) ((?:\S+)-(?:\S+)) -> ((?:\S+)-(?:\S+))') + regex = re.compile(r'([\w-]+) ((?:\S+)-(?:\S+)) -> ((?:\S+)-(?:\S+))') for p in data: m = regex.search(p) packages.append(m.group(1)) @@ -419,11 +419,11 @@ def main(): for i, pkg in enumerate(pkgs): if not pkg: # avoid empty strings continue - elif re.match(".*\.pkg\.tar(\.(gz|bz2|xz|lrz|lzo|Z))?$", pkg): + elif re.match(r".*\.pkg\.tar(\.(gz|bz2|xz|lrz|lzo|Z))?$", pkg): # The package given is a filename, extract the raw pkg name from # it and store the filename pkg_files.append(pkg) - pkgs[i] = re.sub('-[0-9].*$', '', pkgs[i].split('/')[-1]) + pkgs[i] = re.sub(r'-[0-9].*$', '', pkgs[i].split('/')[-1]) else: pkg_files.append(None) diff --git a/lib/ansible/modules/packaging/os/pkg5.py b/lib/ansible/modules/packaging/os/pkg5.py index ff14cb8f7e8..33364ecf98a 100644 --- a/lib/ansible/modules/packaging/os/pkg5.py +++ b/lib/ansible/modules/packaging/os/pkg5.py @@ -95,8 +95,8 @@ def main(): # Try to spot where this has happened and fix it. for fragment in params['name']: if ( - re.search('^\d+(?:\.\d+)*', fragment) - and packages and re.search('@[^,]*$', packages[-1]) + re.search(r'^\d+(?:\.\d+)*', fragment) + and packages and re.search(r'@[^,]*$', packages[-1]) ): packages[-1] += ',' + fragment else: diff --git a/lib/ansible/modules/packaging/os/sorcery.py b/lib/ansible/modules/packaging/os/sorcery.py index afbff4debbe..a1486121239 100644 --- a/lib/ansible/modules/packaging/os/sorcery.py +++ b/lib/ansible/modules/packaging/os/sorcery.py @@ -231,7 +231,7 @@ def codex_list(module): if rc != 0: module.fail_json(msg="unable to list grimoire collection, fix your Codex") - rex = re.compile("^\s*\[\d+\] : (?P[\w\-\+\.]+) : [\w\-\+\./]+(?: : (?P[\w\-\+\.]+))?\s*$") + rex = re.compile(r"^\s*\[\d+\] : (?P[\w\-+.]+) : [\w\-+./]+(?: : (?P[\w\-+.]+))?\s*$") # drop 4-line header and empty trailing line for line in stdout.splitlines()[4:-1]: diff --git a/lib/ansible/modules/packaging/os/swdepot.py b/lib/ansible/modules/packaging/os/swdepot.py index 3572c96fbd6..8b9785202a0 100644 --- a/lib/ansible/modules/packaging/os/swdepot.py +++ b/lib/ansible/modules/packaging/os/swdepot.py @@ -102,7 +102,7 @@ def query_package(module, name, depot=None): else: rc, stdout, stderr = module.run_command("%s %s | grep %s" % (cmd_list, pipes.quote(name), pipes.quote(name)), use_unsafe_shell=True) if rc == 0: - version = re.sub("\s\s+|\t" , " ", stdout).strip().split()[1] + version = re.sub(r"\s\s+|\t", " ", stdout).strip().split()[1] else: version = None diff --git a/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py b/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py index 2f01187c340..1c8b7a890bf 100755 --- a/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py +++ b/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py @@ -231,7 +231,7 @@ def main(): for cpu, details in memory_details_summary.items(): cpu_total_memory_size = details.get('total_memory_size') if cpu_total_memory_size: - ram = re.search('(\d+)\s+(\w+)', cpu_total_memory_size) + ram = re.search(r'(\d+)\s+(\w+)', cpu_total_memory_size) if ram: if ram.group(2) == 'GB': facts['hw_memory_total'] = facts['hw_memory_total'] + int(ram.group(1)) diff --git a/lib/ansible/modules/system/aix_lvol.py b/lib/ansible/modules/system/aix_lvol.py index dde908e443f..ebadd816654 100644 --- a/lib/ansible/modules/system/aix_lvol.py +++ b/lib/ansible/modules/system/aix_lvol.py @@ -144,20 +144,20 @@ def parse_lv(data): name = None for line in data.splitlines(): - match = re.search("LOGICAL VOLUME:\s+(\w+)\s+VOLUME GROUP:\s+(\w+)", line) + match = re.search(r"LOGICAL VOLUME:\s+(\w+)\s+VOLUME GROUP:\s+(\w+)", line) if match is not None: name = match.group(1) vg = match.group(2) continue - match = re.search("LPs:\s+(\d+).*PPs", line) + match = re.search(r"LPs:\s+(\d+).*PPs", line) if match is not None: lps = int(match.group(1)) continue - match = re.search("PP SIZE:\s+(\d+)", line) + match = re.search(r"PP SIZE:\s+(\d+)", line) if match is not None: pp_size = int(match.group(1)) continue - match = re.search("INTER-POLICY:\s+(\w+)", line) + match = re.search(r"INTER-POLICY:\s+(\w+)", line) if match is not None: policy = match.group(1) continue @@ -174,22 +174,22 @@ def parse_vg(data): for line in data.splitlines(): - match = re.search("VOLUME GROUP:\s+(\w+)", line) + match = re.search(r"VOLUME GROUP:\s+(\w+)", line) if match is not None: name = match.group(1) continue - match = re.search("TOTAL PP.*\((\d+)", line) + match = re.search(r"TOTAL PP.*\((\d+)", line) if match is not None: size = int(match.group(1)) continue - match = re.search("PP SIZE:\s+(\d+)", line) + match = re.search(r"PP SIZE:\s+(\d+)", line) if match is not None: pp_size = int(match.group(1)) continue - match = re.search("FREE PP.*\((\d+)", line) + match = re.search(r"FREE PP.*\((\d+)", line) if match is not None: free = int(match.group(1)) continue diff --git a/lib/ansible/modules/system/authorized_key.py b/lib/ansible/modules/system/authorized_key.py index 3af2686d7b1..a0c23ab2968 100644 --- a/lib/ansible/modules/system/authorized_key.py +++ b/lib/ansible/modules/system/authorized_key.py @@ -404,7 +404,7 @@ def parsekey(module, raw_key, rank=None): type_index = None # index of keytype in key string|list # remove comment yaml escapes - raw_key = raw_key.replace('\#', '#') + raw_key = raw_key.replace(r'\#', '#') # split key safely lex = shlex.shlex(raw_key) diff --git a/lib/ansible/modules/system/awall.py b/lib/ansible/modules/system/awall.py index 2e9b5a4b971..b943c64dd44 100644 --- a/lib/ansible/modules/system/awall.py +++ b/lib/ansible/modules/system/awall.py @@ -74,7 +74,7 @@ def activate(module): def is_policy_enabled(module, name): cmd = "%s list" % (AWALL_PATH) rc, stdout, stderr = module.run_command(cmd) - if re.search("^%s\s+enabled" % name, stdout, re.MULTILINE): + if re.search(r"^%s\s+enabled" % name, stdout, re.MULTILINE): return True return False diff --git a/lib/ansible/modules/system/gluster_volume.py b/lib/ansible/modules/system/gluster_volume.py index 3577a6e9f48..3ede8a9023b 100644 --- a/lib/ansible/modules/system/gluster_volume.py +++ b/lib/ansible/modules/system/gluster_volume.py @@ -261,7 +261,7 @@ def get_quotas(name, nofail): out = run_gluster(['volume', 'quota', name, 'list']) for row in out.split('\n'): if row[:1] == '/': - q = re.split('\s+', row) + q = re.split(r'\s+', row) quotas[q[0]] = q[1] return quotas diff --git a/lib/ansible/modules/system/interfaces_file.py b/lib/ansible/modules/system/interfaces_file.py index bf560e35b87..215e3fc3a03 100755 --- a/lib/ansible/modules/system/interfaces_file.py +++ b/lib/ansible/modules/system/interfaces_file.py @@ -161,14 +161,14 @@ def optionDict(line, iface, option, value): def getValueFromLine(s): - spaceRe = re.compile('\s+') + spaceRe = re.compile(r'\s+') for m in spaceRe.finditer(s): pass valueEnd = m.start() option = s.split()[0] optionStart = s.find(option) optionLen = len(option) - valueStart = re.search('\s', s[optionLen + optionStart:]).end() + optionLen + optionStart + valueStart = re.search(r'\s', s[optionLen + optionStart:]).end() + optionLen + optionStart return s[valueStart:valueEnd] @@ -286,7 +286,7 @@ def setInterfaceOption(module, lines, iface, option, raw_value, state): old_value = target_option['value'] prefix_start = old_line.find(option) optionLen = len(option) - old_value_position = re.search("\s+".join(old_value.split()), old_line[prefix_start + optionLen:]) + old_value_position = re.search(r"\s+".join(old_value.split()), old_line[prefix_start + optionLen:]) start = old_value_position.start() + prefix_start + optionLen end = old_value_position.end() + prefix_start + optionLen line = old_line[:start] + value + old_line[end:] diff --git a/lib/ansible/modules/system/kernel_blacklist.py b/lib/ansible/modules/system/kernel_blacklist.py index 5844bf51c52..9d323d1cbc9 100644 --- a/lib/ansible/modules/system/kernel_blacklist.py +++ b/lib/ansible/modules/system/kernel_blacklist.py @@ -66,7 +66,7 @@ class Blacklist(object): return False def get_pattern(self): - return '^blacklist\s*' + self.module + '$' + return r'^blacklist\s*' + self.module + '$' def readlines(self): f = open(self.filename, 'r') diff --git a/lib/ansible/modules/system/locale_gen.py b/lib/ansible/modules/system/locale_gen.py index 90f4e5a147d..649de5e02f4 100644 --- a/lib/ansible/modules/system/locale_gen.py +++ b/lib/ansible/modules/system/locale_gen.py @@ -70,10 +70,10 @@ def is_available(name, ubuntuMode): * if the locale is present in /etc/locales.gen * or if the locale is present in /usr/share/i18n/SUPPORTED""" if ubuntuMode: - __regexp = '^(?P\S+_\S+) (?P\S+)\s*$' + __regexp = r'^(?P\S+_\S+) (?P\S+)\s*$' __locales_available = '/usr/share/i18n/SUPPORTED' else: - __regexp = '^#{0,1}\s*(?P\S+_\S+) (?P\S+)\s*$' + __regexp = r'^#{0,1}\s*(?P\S+_\S+) (?P\S+)\s*$' __locales_available = '/etc/locale.gen' re_compiled = re.compile(__regexp) @@ -117,11 +117,11 @@ def replace_line(existing_line, new_line): def set_locale(name, enabled=True): """ Sets the state of the locale. Defaults to enabled. """ - search_string = '#{0,1}\s*%s (?P.+)' % name + search_string = r'#{0,1}\s*%s (?P.+)' % name if enabled: - new_string = '%s \g' % (name) + new_string = r'%s \g' % (name) else: - new_string = '# %s \g' % (name) + new_string = r'# %s \g' % (name) try: f = open("/etc/locale.gen", "r") lines = [re.sub(search_string, new_string, line) for line in f] diff --git a/lib/ansible/modules/system/lvol.py b/lib/ansible/modules/system/lvol.py index d912e77bd59..d994d87bff1 100644 --- a/lib/ansible/modules/system/lvol.py +++ b/lib/ansible/modules/system/lvol.py @@ -226,7 +226,7 @@ def get_lvm_version(module): rc, out, err = module.run_command("%s version" % (ver_cmd)) if rc != 0: return None - m = re.search("LVM version:\s+(\d+)\.(\d+)\.(\d+).*(\d{4}-\d{2}-\d{2})", out) + m = re.search(r"LVM version:\s+(\d+)\.(\d+)\.(\d+).*(\d{4}-\d{2}-\d{2})", out) if not m: return None return mkversion(m.group(1), m.group(2), m.group(3)) diff --git a/lib/ansible/modules/system/runit.py b/lib/ansible/modules/system/runit.py index 4fcecf1f38c..0c86ba46f3f 100644 --- a/lib/ansible/modules/system/runit.py +++ b/lib/ansible/modules/system/runit.py @@ -169,11 +169,11 @@ class Sv(object): else: self.full_state = out - m = re.search('\(pid (\d+)\)', out) + m = re.search(r'\(pid (\d+)\)', out) if m: self.pid = m.group(1) - m = re.search(' (\d+)s', out) + m = re.search(r' (\d+)s', out) if m: self.duration = m.group(1) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index 0fe20e3c499..1f48ba948a0 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -672,10 +672,10 @@ class LinuxService(Service): initpath = '/etc/init' if self.upstart_version >= LooseVersion('0.6.7'): - manreg = re.compile('^manual\s*$', re.M | re.I) + manreg = re.compile(r'^manual\s*$', re.M | re.I) config_line = 'manual\n' else: - manreg = re.compile('^start on manual\s*$', re.M | re.I) + manreg = re.compile(r'^start on manual\s*$', re.M | re.I) config_line = 'start on manual\n' conf_file_name = "%s/%s.conf" % (initpath, self.name) override_file_name = "%s/%s.override" % (initpath, self.name) @@ -1308,7 +1308,7 @@ class SunOSService(Service): # Support for synchronous restart/refresh is only supported on # Oracle Solaris >= 11.2 for line in open('/etc/release', 'r').readlines(): - m = re.match('\s+Oracle Solaris (\d+\.\d+).*', line.rstrip()) + m = re.match(r'\s+Oracle Solaris (\d+\.\d+).*', line.rstrip()) if m and m.groups()[0] >= 11.2: return True diff --git a/lib/ansible/modules/system/svc.py b/lib/ansible/modules/system/svc.py index 691315b23f0..120c334b51b 100644 --- a/lib/ansible/modules/system/svc.py +++ b/lib/ansible/modules/system/svc.py @@ -180,11 +180,11 @@ class Svc(object): else: self.full_state = out - m = re.search('\(pid (\d+)\)', out) + m = re.search(r'\(pid (\d+)\)', out) if m: self.pid = m.group(1) - m = re.search('(\d+) seconds', out) + m = re.search(r'(\d+) seconds', out) if m: self.duration = m.group(1) diff --git a/lib/ansible/modules/system/timezone.py b/lib/ansible/modules/system/timezone.py index eabdca54849..283a7c98f3f 100644 --- a/lib/ansible/modules/system/timezone.py +++ b/lib/ansible/modules/system/timezone.py @@ -517,7 +517,7 @@ class SmartOSTimezone(Timezone): # sm-set-timezone knows no state and will always set the timezone. # XXX: https://github.com/joyent/smtools/pull/2 - m = re.match('^\* Changed (to)? timezone (to)? (%s).*' % value, stdout.splitlines()[1]) + m = re.match(r'^\* Changed (to)? timezone (to)? (%s).*' % value, stdout.splitlines()[1]) if not (m and m.groups()[-1] == value): self.module.fail_json(msg='Failed to set timezone') else: