Skip to content

Commit

Permalink
Fix invalid string escape sequences.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed Nov 21, 2017
1 parent f9cd504 commit e45c763
Show file tree
Hide file tree
Showing 48 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion contrib/inventory/apache-libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def to_safe(self, word):
used as Ansible groups
'''

return re.sub("[^A-Za-z0-9\-]", "_", word)
return re.sub(r"[^A-Za-z0-9\-]", "_", word)

def json_format_dict(self, data, pretty=False):
'''
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/apstra_aos.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def cleanup_group_name(self, group_name):
- Converting to lowercase
"""

rx = re.compile('\W+')
rx = re.compile(r'\W+')
clean_group = rx.sub('_', group_name).lower()

return clean_group
Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/azure_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ def _tags_match(self, tag_obj, tag_args):

def _to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
regex = "[^A-Za-z0-9\_"
regex = r"[^A-Za-z0-9\_"
if not self.replace_dash_in_groups:
regex += "\-"
regex += r"\-"
return re.sub(regex + "]", "_", word)


Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/cloudforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def to_safe(self, word):
Converts 'bad' characters in a string to underscores so they can be used as Ansible groups
"""
if self.cloudforms_clean_group_keys:
regex = "[^A-Za-z0-9\_]"
regex = r"[^A-Za-z0-9\_]"
return re.sub(regex, "_", word.replace(" ", ""))
else:
return word
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/cobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def write_to_cache(self, data, filename):
def to_safe(self, word):
""" Converts 'bad' characters in a string to underscores so they can be used as Ansible groups """

return re.sub("[^A-Za-z0-9\-]", "_", word)
return re.sub(r"[^A-Za-z0-9\-]", "_", word)

def json_format_dict(self, data, pretty=False):
""" Converts a dict to a JSON object and dumps it as a formatted string """
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/collins.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def to_safe(self, word):
""" Converts 'bad' characters in a string to underscores so they
can be used as Ansible groups """

return re.sub("[^A-Za-z0-9\-]", "_", word)
return re.sub(r"[^A-Za-z0-9\-]", "_", word)

def json_format_dict(self, data, pretty=False):
""" Converts a dict to a JSON object and dumps it as a formatted string """
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/consul_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def push(self, my_dict, key, element):
def to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be used
as Ansible groups '''
return re.sub('[^A-Za-z0-9\-\.]', '_', word)
return re.sub(r'[^A-Za-z0-9\-\.]', '_', word)

def sanitize_dict(self, d):

Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/digital_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def push(self, my_dict, key, element):

def to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
return re.sub("[^A-Za-z0-9\-\.]", "_", word)
return re.sub(r"[^A-Za-z0-9\-\.]", "_", word)

def do_namespace(self, data):
''' Returns a copy of the dictionary with all the keys put in a 'do_' namespace '''
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def get_inventory(self, client, host):
self.hostvars[name].update(facts)

def _slugify(self, value):
return 'docker_%s' % (re.sub('[^\w-]', '_', value).lower().lstrip('_'))
return 'docker_%s' % (re.sub(r'[^\w-]', '_', value).lower().lstrip('_'))

def get_hosts(self, config):
'''
Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1680,9 +1680,9 @@ def uncammelize(self, key):

def to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
regex = "[^A-Za-z0-9\_"
regex = r"[^A-Za-z0-9\_"
if not self.replace_dash_in_groups:
regex += "\-"
regex += r"\-"
return re.sub(regex + "]", "_", word)

def json_format_dict(self, data, pretty=False):
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/fleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_ssh_config():
def list_running_boxes():
boxes = []
for line in subprocess.check_output(["fleetctl", "list-machines"]).split('\n'):
matcher = re.search("[^\s]+[\s]+([^\s]+).+", line)
matcher = re.search(r"[^\s]+[\s]+([^\s]+).+", line)
if matcher and matcher.group(1) != "IP":
boxes.append(matcher.group(1))

Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/foreman.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def to_safe(self, word):
>>> ForemanInventory.to_safe("foo-bar baz")
'foo_barbaz'
'''
regex = "[^A-Za-z0-9\_]"
regex = r"[^A-Za-z0-9\_]"
return re.sub(regex, "_", word.replace(" ", ""))

def update_cache(self):
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def write_to_cache(self, data, filename):

def to_safe(self, word):
"""Escapes any characters that would be invalid in an ansible group name."""
return re.sub("[^A-Za-z0-9\-]", "_", word)
return re.sub(r"[^A-Za-z0-9\-]", "_", word)

def json_format_dict(self, data, pretty=False):
"""Converts a dict to a JSON object and dumps it as a formatted string."""
Expand Down
4 changes: 2 additions & 2 deletions contrib/inventory/packet_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ def uncammelize(self, key):

def to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
regex = "[^A-Za-z0-9\_"
regex = r"[^A-Za-z0-9\_"
if not self.replace_dash_in_groups:
regex += "\-"
regex += r"\-"
return re.sub(regex + "]", "_", word)

def json_format_dict(self, data, pretty=False):
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/rax.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def load_config_file():


def rax_slugify(value):
return 'rax_%s' % (re.sub('[^\w-]', '_', value).lower().lstrip('_'))
return 'rax_%s' % (re.sub(r'[^\w-]', '_', value).lower().lstrip('_'))


def to_dict(obj):
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/rudder.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def to_safe(self, word):
''' Converts 'bad' characters in a string to underscores so they can be
used as Ansible variable names '''

return re.sub('[^A-Za-z0-9\_]', '_', word)
return re.sub(r'[^A-Za-z0-9\_]', '_', word)

# Run the script
RudderInventory()
2 changes: 1 addition & 1 deletion contrib/inventory/softlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self):
def to_safe(self, word):
'''Converts 'bad' characters in a string to underscores so they can be used as Ansible groups'''

return re.sub("[^A-Za-z0-9\-\.]", "_", word)
return re.sub(r"[^A-Za-z0-9\-\.]", "_", word)

def push(self, my_dict, key, element):
'''Push an element onto an array that may not have been defined in the dict'''
Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def list_running_boxes():
boxes = []

for line in output:
matcher = re.search("([^\s]+)[\s]+running \(.+", line)
matcher = re.search(r"([^\s]+)[\s]+running \(.+", line)
if matcher:
boxes.append(matcher.group(1))

Expand Down
2 changes: 1 addition & 1 deletion contrib/inventory/windows_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def write_to_cache(self, data, filename):

def to_safe(self, word):
"""Escapes any characters that would be invalid in an ansible group name."""
return re.sub("[^A-Za-z0-9\-]", "_", word)
return re.sub(r"[^A-Za-z0-9\-]", "_", word)

def json_format_dict(self, data, pretty=False):
"""Converts a dict to a JSON object and dumps it as a formatted string."""
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/executor/module_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,9 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas
module_style = 'new'
module_substyle = 'powershell'
b_module_data = b_module_data.replace(REPLACER_WINDOWS, b'#Requires -Module Ansible.ModuleUtils.Legacy')
elif re.search(b'#Requires \-Module', b_module_data, re.IGNORECASE) \
or re.search(b'#Requires \-Version', b_module_data, re.IGNORECASE)\
or re.search(b'#AnsibleRequires \-OSVersion', b_module_data, re.IGNORECASE):
elif re.search(b'#Requires -Module', b_module_data, re.IGNORECASE) \
or re.search(b'#Requires -Version', b_module_data, re.IGNORECASE)\
or re.search(b'#AnsibleRequires -OSVersion', b_module_data, re.IGNORECASE):
module_style = 'new'
module_substyle = 'powershell'
elif REPLACER_JSONARGS in b_module_data:
Expand Down Expand Up @@ -796,9 +796,9 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas
min_ps_version = None

requires_module_list = re.compile(to_bytes(r'(?i)^#\s*requires\s+\-module(?:s?)\s*(Ansible\.ModuleUtils\..+)'))
requires_ps_version = re.compile(to_bytes('(?i)^#requires\s+\-version\s+([0-9]+(\.[0-9]+){0,3})$'))
requires_os_version = re.compile(to_bytes('(?i)^#ansiblerequires\s+\-osversion\s+([0-9]+(\.[0-9]+){0,3})$'))
requires_become = re.compile(to_bytes('(?i)^#ansiblerequires\s+\-become$'))
requires_ps_version = re.compile(to_bytes(r'(?i)^#requires\s+\-version\s+([0-9]+(\.[0-9]+){0,3})$'))
requires_os_version = re.compile(to_bytes(r'(?i)^#ansiblerequires\s+\-osversion\s+([0-9]+(\.[0-9]+){0,3})$'))
requires_become = re.compile(to_bytes(r'(?i)^#ansiblerequires\s+\-become$'))

for line in lines:
module_util_line_match = requires_module_list.match(line)
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/inventory/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from ansible.utils.display import Display
display = Display()

IGNORED_ALWAYS = [b"^\.", b"^host_vars$", b"^group_vars$", b"^vars_plugins$"]
IGNORED_ALWAYS = [br"^\.", b"^host_vars$", b"^group_vars$", b"^vars_plugins$"]
IGNORED_PATTERNS = [to_bytes(x) for x in C.INVENTORY_IGNORE_PATTERNS]
IGNORED_EXTS = [b'%s$' % to_bytes(re.escape(x)) for x in C.INVENTORY_IGNORE_EXTS]

Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
ANSIBLE_USER_AGENT = 'Ansible/{0}'.format(ANSIBLE_VERSION)
CLOUDSHELL_USER_AGENT_KEY = 'AZURE_HTTP_USER_AGENT'

CIDR_PATTERN = re.compile("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1"
"[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))")
CIDR_PATTERN = re.compile(r"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1"
r"[0-9]{2}|2[0-4][0-9]|25[0-5])(/([0-9]|[1-2][0-9]|3[0-2]))")

AZURE_SUCCESS_STATE = "Succeeded"
AZURE_FAILED_STATE = "Failed"
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def human_to_bytes(number, default_unit=None, isbits=False):
ex:
human_to_bytes('10M') <=> human_to_bytes(10, 'M')
'''
m = re.search('^\s*(\d*\.?\d*)\s*([A-Za-z]+)?', str(number), flags=re.IGNORECASE)
m = re.search(r'^\s*(\d*\.?\d*)\s*([A-Za-z]+)?', str(number), flags=re.IGNORECASE)
if m is None:
raise ValueError("human_to_bytes() can't interpret following string: %s" % str(number))
try:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/docker_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
]

DEFAULT_DOCKER_REGISTRY = 'https://index.docker.io/v1/'
EMAIL_REGEX = '[^@]+@[^@]+\.[^@]+'
EMAIL_REGEX = r'[^@]+@[^@]+\.[^@]+'
BYTE_SUFFIXES = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']


Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/module_utils/facts/hardware/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def get_device_facts(self):

sysdir = '/dev'
device_facts['devices'] = {}
drives = re.compile('(ada?\d+|da\d+|a?cd\d+)') # TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks")
slices = re.compile('(ada?\d+s\d+\w*|da\d+s\d+\w*)')
drives = re.compile(r'(ada?\d+|da\d+|a?cd\d+)') # TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks")
slices = re.compile(r'(ada?\d+s\d+\w*|da\d+s\d+\w*)')
if os.path.isdir(sysdir):
dirlist = sorted(os.listdir(sysdir))
for device in dirlist:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/hardware/hpux.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_memory_facts(self, collected_facts=None):
memory_facts['memtotal_mb'] = int(data) / 256
else:
rc, out, err = self.module.run_command("/usr/contrib/bin/machinfo | grep Memory", use_unsafe_shell=True)
data = re.search('Memory[\ :=]*([0-9]*).*MB.*', out).groups()[0].strip()
data = re.search(r'Memory[\ :=]*([0-9]*).*MB.*', out).groups()[0].strip()
memory_facts['memtotal_mb'] = int(data)
rc, out, err = self.module.run_command("/usr/sbin/swapinfo -m -d -f -q")
memory_facts['swaptotal_mb'] = int(out.strip())
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/module_utils/facts/hardware/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def get_device_facts(self):
device = "/dev/%s" % (block)
rc, drivedata, err = self.module.run_command([sg_inq, device])
if rc == 0:
serial = re.search("Unit serial number:\s+(\w+)", drivedata)
serial = re.search(r"Unit serial number:\s+(\w+)", drivedata)
if serial:
d['serial'] = serial.group(1)

Expand All @@ -585,7 +585,7 @@ def get_device_facts(self):

d['partitions'] = {}
for folder in os.listdir(sysdir):
m = re.search("(" + diskname + "\d+)", folder)
m = re.search("(" + diskname + r"\d+)", folder)
if m:
part = {}
partname = m.group(1)
Expand All @@ -611,7 +611,7 @@ def get_device_facts(self):
d['scheduler_mode'] = ""
scheduler = get_file_content(sysdir + "/queue/scheduler")
if scheduler is not None:
m = re.match(".*?(\[(.*)\])", scheduler)
m = re.match(r".*?(\[(.*)\])", scheduler)
if m:
d['scheduler_mode'] = m.group(2)

Expand All @@ -626,11 +626,11 @@ def get_device_facts(self):
d['host'] = ""

# domains are numbered (0 to ffff), bus (0 to ff), slot (0 to 1f), and function (0 to 7).
m = re.match(".+/([a-f0-9]{4}:[a-f0-9]{2}:[0|1][a-f0-9]\.[0-7])/", sysdir)
m = re.match(r".+/([a-f0-9]{4}:[a-f0-9]{2}:[0|1][a-f0-9]\.[0-7])/", sysdir)
if m and pcidata:
pciid = m.group(1)
did = re.escape(pciid)
m = re.search("^" + did + "\s(.*)$", pcidata, re.MULTILINE)
m = re.search("^" + did + r"\s(.*)$", pcidata, re.MULTILINE)
if m:
d['host'] = m.group(1)

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/network/aix.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_interfaces_info(self, ifconfig_path, ifconfig_options='-a'):
words = line.split()

# only this condition differs from GenericBsdIfconfigNetwork
if re.match('^\w*\d*:', line):
if re.match(r'^\w*\d*:', line):
current_if = self.parse_interface_line(words)
interfaces[current_if['device']] = current_if
elif words[0].startswith('options='):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/network/generic_bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_interfaces_info(self, ifconfig_path, ifconfig_options='-a'):

if words[0] == 'pass':
continue
elif re.match('^\S', line) and len(words) > 3:
elif re.match(r'^\S', line) and len(words) > 3:
current_if = self.parse_interface_line(words)
interfaces[current_if['device']] = current_if
elif words[0].startswith('options='):
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/module_utils/facts/network/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def get_ethtool_data(self, device):
args = [ethtool_path, '-T', device]
rc, stdout, stderr = self.module.run_command(args, errors='surrogate_then_replace')
if rc == 0:
data['timestamping'] = [m.lower() for m in re.findall('SOF_TIMESTAMPING_(\w+)', stdout)]
data['hw_timestamp_filters'] = [m.lower() for m in re.findall('HWTSTAMP_FILTER_(\w+)', stdout)]
m = re.search('PTP Hardware Clock: (\d+)', stdout)
data['timestamping'] = [m.lower() for m in re.findall(r'SOF_TIMESTAMPING_(\w+)', stdout)]
data['hw_timestamp_filters'] = [m.lower() for m in re.findall(r'HWTSTAMP_FILTER_(\w+)', stdout)]
m = re.search(r'PTP Hardware Clock: (\d+)', stdout)
if m:
data['phc_index'] = int(m.groups()[0])

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/network/sunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_interfaces_info(self, ifconfig_path):
if line:
words = line.split()

if re.match('^\S', line) and len(words) > 3:
if re.match(r'^\S', line) and len(words) > 3:
current_if = self.parse_interface_line(words, current_if, interfaces)
interfaces[current_if['device']] = current_if
elif words[0].startswith('options='):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/facts/sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_sysctl(module, prefixes):
for line in out.splitlines():
if not line:
continue
(key, value) = re.split('\s?=\s?|: ', line, maxsplit=1)
(key, value) = re.split(r'\s?=\s?|: ', line, maxsplit=1)
sysctl[key] = value.strip()

return sysctl
Loading

0 comments on commit e45c763

Please sign in to comment.