Skip to content

Commit

Permalink
Fix anomalous backslashes and enable pylint test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed Nov 22, 2017
1 parent 9735a70 commit c6bb6c7
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/cumulus/_cl_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'supported_by': 'community'}


DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_bond
version_added: "2.1"
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/cumulus/_cl_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'supported_by': 'community'}


DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_bridge
version_added: "2.1"
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/network/cumulus/_cl_img_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def check_fw_print_env(module, slot_num):
cmd = "/usr/bin/grub-editenv list"
grub_output = run_cl_cmd(module, cmd)
for _line in grub_output:
_regex_str = re.compile('cl.ver' + slot_num + '=([\w.]+)-')
_regex_str = re.compile('cl.ver' + slot_num + r'=([\w.]+)-')
m0 = re.match(_regex_str, _line)
if m0:
return m0.group(1)
Expand All @@ -197,7 +197,7 @@ def get_primary_slot_num(module):
cmd = "/usr/bin/grub-editenv list"
grub_output = run_cl_cmd(module, cmd)
for _line in grub_output:
_regex_str = re.compile('cl.active=(\d)')
_regex_str = re.compile(r'cl.active=(\d)')
m0 = re.match(_regex_str, _line)
if m0:
return m0.group(1)
Expand All @@ -210,7 +210,7 @@ def get_active_slot(module):
module.fail_json(msg='Failed to open /proc/cmdline. ' +
'Unable to determine active slot')

_match = re.search('active=(\d+)', cmdline)
_match = re.search(r'active=(\d+)', cmdline)
if _match:
return _match.group(1)
return None
Expand Down Expand Up @@ -247,9 +247,9 @@ def determine_sw_version(module):
return
else:
_filename = module.params.get('src').split('/')[-1]
_match = re.search('\d+\W\d+\W\w+', _filename)
_match = re.search(r'\d+\W\d+\W\w+', _filename)
if _match:
module.sw_version = re.sub('\W', '.', _match.group())
module.sw_version = re.sub(r'\W', '.', _match.group())
return
_msg = 'Unable to determine version from file %s' % (_filename)
module.exit_json(changed=False, msg=_msg)
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/cumulus/_cl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'supported_by': 'community'}


DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_interface
version_added: "2.1"
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/modules/network/dellos6/dellos6_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Hardware(FactsBase):
def populate(self):
super(Hardware, self).populate()
data = self.responses[0]
match = re.findall('\s(\d+)\s', data)
match = re.findall(r'\s(\d+)\s', data)
if match:
self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[1]) // 1024
Expand Down Expand Up @@ -231,12 +231,12 @@ def parse_vlan(self, vlan):
for en in vlan_info_next.splitlines():
if en == '':
continue
match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en)
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
intf = match.group(1)
if intf not in facts:
facts[intf] = list()
fact = dict()
matc = re.search('^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
fact['address'] = matc.group(2)
fact['masklen'] = matc.group(3)
facts[intf].append(fact)
Expand Down Expand Up @@ -299,7 +299,7 @@ def parse_description(self, key, desc):
desc_val, desc_info = desc_next.split('Port')
for en in desc_val.splitlines():
if key in en:
match = re.search('^(\S+)\s+(\S+)', en)
match = re.search(r'^(\S+)\s+(\S+)', en)
if match.group(2) in ['Full', 'N/A']:
return "Null"
else:
Expand Down Expand Up @@ -331,7 +331,7 @@ def parse_mediatype(self, key, properties):
for en in mediatype_next.splitlines():
if key in en:
flag = 0
match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en)
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
if match:
strval = match.group(3)
return strval
Expand All @@ -344,7 +344,7 @@ def parse_type(self, key, properties):
for en in type_val_next.splitlines():
if key in en:
flag = 0
match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en)
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
if match:
strval = match.group(2)
return strval
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/dellos9/dellos9_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def populate(self):
self.facts['filesystems'] = self.parse_filesystems(data)

data = self.responses[1]
match = re.findall('\s(\d+)\s', data)
match = re.findall(r'\s(\d+)\s', data)
if match:
self.facts['memtotal_mb'] = int(match[0]) // 1024
self.facts['memfree_mb'] = int(match[2]) // 1024
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/eos/eos_eapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def validate_local_http_port(value, module):

def validate_vrf(value, module):
out = run_commands(module, ['show vrf'])
configured_vrfs = re.findall('^\s+(\w+)(?=\s)', out[0], re.M)
configured_vrfs = re.findall(r'^\s+(\w+)(?=\s)', out[0], re.M)
configured_vrfs.append('default')
if value not in configured_vrfs:
module.fail_json(msg='vrf `%s` is not configured on the system' % value)
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/modules/network/eos/eos_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def has_vrf(module, vrf):
if _CONFIGURED_VRFS is not None:
return vrf in _CONFIGURED_VRFS
config = get_config(module)
_CONFIGURED_VRFS = re.findall('vrf definition (\S+)', config)
_CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config)
_CONFIGURED_VRFS.append('default')
return vrf in _CONFIGURED_VRFS

Expand Down Expand Up @@ -223,18 +223,18 @@ def map_obj_to_commands(want, have, module):
return commands

def parse_hostname(config):
match = re.search('^hostname (\S+)', config, re.M)
match = re.search(r'^hostname (\S+)', config, re.M)
if match:
return match.group(1)

def parse_domain_name(config):
match = re.search('^ip domain-name (\S+)', config, re.M)
match = re.search(r'^ip domain-name (\S+)', config, re.M)
if match:
return match.group(1)

def parse_lookup_source(config):
objects = list()
regex = 'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)'
regex = r'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)'
for vrf, intf in re.findall(regex, config, re.M):
if len(vrf) == 0:
vrf= None
Expand All @@ -243,7 +243,7 @@ def parse_lookup_source(config):

def parse_name_servers(config):
objects = list()
for vrf, addr in re.findall('ip name-server vrf (\S+) (\S+)', config, re.M):
for vrf, addr in re.findall(r'ip name-server vrf (\S+) (\S+)', config, re.M):
objects.append({'server': addr, 'vrf': vrf})
return objects

Expand All @@ -252,7 +252,7 @@ def map_config_to_obj(module):
return {
'hostname': parse_hostname(config),
'domain_name': parse_domain_name(config),
'domain_list': re.findall('^ip domain-list (\S+)', config, re.M),
'domain_list': re.findall(r'^ip domain-list (\S+)', config, re.M),
'lookup_source': parse_lookup_source(config),
'name_servers': parse_name_servers(config)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/f5/bigip_selfip.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def address(self):

@address.setter
def address(self, value):
pattern = '^(?P<ip>[0-9A-Fa-f:.]+)%?(?P<rd>\d+)?\/(?P<nm>\d+)$'
pattern = r'^(?P<ip>[0-9A-Fa-f:.]+)%?(?P<rd>\d+)?\/(?P<nm>\d+)$'
matches = re.match(pattern, value)
if not matches:
raise F5ModuleError(
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/ios/ios_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def map_config_to_obj(module):
'show running-config | begin banner %s'
% module.params['banner'])
if out:
output = re.search('\^C(.*)\^C', out, re.S).group(1).strip()
output = re.search(r'\^C(.*)\^C', out, re.S).group(1).strip()
else:
output = None
obj = {'banner': module.params['banner'], 'state': 'absent'}
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/network/ios/ios_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def parse_ping(ping_stats):
Example: "Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/8 ms"
Returns the percent of packet loss, recieved packets, transmitted packets, and RTT dict.
"""
rate_re = re.compile("^\w+\s+\w+\s+\w+\s+(?P<pct>\d+)\s+\w+\s+\((?P<rx>\d+)\/(?P<tx>\d+)\)")
rtt_re = re.compile(".*,\s+\S+\s+\S+\s+=\s+(?P<min>\d+)\/(?P<avg>\d+)\/(?P<max>\d+)\s+\w+\s*$|.*\s*$")
rate_re = re.compile(r"^\w+\s+\w+\s+\w+\s+(?P<pct>\d+)\s+\w+\s+\((?P<rx>\d+)/(?P<tx>\d+)\)")
rtt_re = re.compile(r".*,\s+\S+\s+\S+\s+=\s+(?P<min>\d+)/(?P<avg>\d+)/(?P<max>\d+)\s+\w+\s*$|.*\s*$")

rate = rate_re.match(ping_stats)
rtt = rtt_re.match(ping_stats)
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/modules/network/ios/ios_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def has_vrf(module, vrf):
if _CONFIGURED_VRFS is not None:
return vrf in _CONFIGURED_VRFS
config = get_config(module)
_CONFIGURED_VRFS = re.findall('vrf definition (\S+)', config)
_CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config)
return vrf in _CONFIGURED_VRFS

def requires_vrf(module, vrf):
Expand Down Expand Up @@ -244,11 +244,11 @@ def map_obj_to_commands(want, have, module):
return commands

def parse_hostname(config):
match = re.search('^hostname (\S+)', config, re.M)
match = re.search(r'^hostname (\S+)', config, re.M)
return match.group(1)

def parse_domain_name(config):
match = re.findall('^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M)
match = re.findall(r'^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M)
matches = list()
for vrf, name in match:
if not vrf:
Expand All @@ -257,7 +257,7 @@ def parse_domain_name(config):
return matches

def parse_domain_search(config):
match = re.findall('^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M)
match = re.findall(r'^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M)
matches = list()
for vrf, name in match:
if not vrf:
Expand All @@ -266,7 +266,7 @@ def parse_domain_search(config):
return matches

def parse_name_servers(config):
match = re.findall('^ip name-server (?:vrf (\S+) )*(.*)', config, re.M)
match = re.findall(r'^ip name-server (?:vrf (\S+) )*(.*)', config, re.M)
matches = list()
for vrf, servers in match:
if not vrf:
Expand All @@ -276,7 +276,7 @@ def parse_name_servers(config):
return matches

def parse_lookup_source(config):
match = re.search('ip domain lookup source-interface (\S+)', config, re.M)
match = re.search(r'ip domain lookup source-interface (\S+)', config, re.M)
if match:
return match.group(1)

Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/network/iosxr/iosxr_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ def map_obj_to_commands(want, have, module):
return commands

def parse_hostname(config):
match = re.search('^hostname (\S+)', config, re.M)
match = re.search(r'^hostname (\S+)', config, re.M)
return match.group(1)

def parse_domain_name(config):
match = re.search('^domain name (\S+)', config, re.M)
match = re.search(r'^domain name (\S+)', config, re.M)
if match:
return match.group(1)

def parse_lookup_source(config):
match = re.search('^domain lookup source-interface (\S+)', config, re.M)
match = re.search(r'^domain lookup source-interface (\S+)', config, re.M)
if match:
return match.group(1)

Expand All @@ -186,10 +186,10 @@ def map_config_to_obj(module):
return {
'hostname': parse_hostname(config),
'domain_name': parse_domain_name(config),
'domain_search': re.findall('^domain list (\S+)', config, re.M),
'domain_search': re.findall(r'^domain list (\S+)', config, re.M),
'lookup_source': parse_lookup_source(config),
'lookup_enabled': 'domain lookup disable' not in config,
'name_servers': re.findall('^domain name-server (\S+)', config, re.M)
'name_servers': re.findall(r'^domain name-server (\S+)', config, re.M)
}

def map_params_to_obj(module):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/ironware/ironware_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def parse_lsp_frr(self, data):
path['up'] = True if match.group(1) == 'UP' else False
path['name'] = None
if path['up']:
match = re.search('bypass_lsp: (\S)', data, re.M)
match = re.search(r'bypass_lsp: (\S)', data, re.M)
path['name'] = match.group(1) if match else None
return path

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/nxos/nxos_aaa_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_aaa_server_info(server_type, module):
server_command = 'show {0}-server'.format(server_type)
request_command = 'show {0}-server directed-request'.format(server_type)
global_key_command = 'show run | sec {0}'.format(server_type)
aaa_regex = '.*{0}-server\skey\s\d\s+(?P<key>\S+).*'.format(server_type)
aaa_regex = r'.*{0}-server\skey\s\d\s+(?P<key>\S+).*'.format(server_type)

server_body = execute_show_command(
server_command, module, command_type='cli_show_ascii')[0]
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def get_aaa_host_info(module, server_type, address):

if body[0]:
try:
pattern = ('(acct-port \d+)|(timeout \d+)|(auth-port \d+)|'
'(key 7 "\w+")|( port \d+)')
pattern = (r'(acct-port \d+)|(timeout \d+)|(auth-port \d+)|'
r'(key 7 "\w+")|( port \d+)')
raw_match = re.findall(pattern, body[0])
aaa_host_info = _match_dict(raw_match, {'acct-port': 'acct_port',
'auth-port': 'auth_port',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/nxos/nxos_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def check_args(module, warnings):

def get_available_features(feature, module):
available_features = {}
feature_regex = '(?P<feature>\S+)\s+\d+\s+(?P<state>.*)'
feature_regex = r'(?P<feature>\S+)\s+\d+\s+(?P<state>.*)'
command = {'command': 'show feature', 'output': 'text'}

try:
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/network/nxos/nxos_igmp_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ def get_igmp_interface(module, interface):
staticoif = []
if body:
split_body = body.split('\n')
route_map_regex = ('.*ip igmp static-oif route-map\s+'
'(?P<route_map>\S+).*')
prefix_source_regex = ('.*ip igmp static-oif\s+(?P<prefix>'
'((\d+.){3}\d+))(\ssource\s'
'(?P<source>\S+))?.*')
route_map_regex = (r'.*ip igmp static-oif route-map\s+'
r'(?P<route_map>\S+).*')
prefix_source_regex = (r'.*ip igmp static-oif\s+(?P<prefix>'
r'((\d+.){3}\d+))(\ssource\s'
r'(?P<source>\S+))?.*')

for line in split_body:
temp = {}
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/network/nxos/nxos_ip_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def parse_unstructured_data(body, interface_name, version, module):
else:
for index in range(0, len(splitted_body) - 1):
if "IP address" in splitted_body[index]:
regex = '.*IP\saddress:\s(?P<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
'(.+?tag:\s(?P<tag>\d+).*)?'
regex = r'.*IP\saddress:\s(?P<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
r'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
r'(.+?tag:\s(?P<tag>\d+).*)?'
match = re.match(regex, splitted_body[index])
if match:
match_dict = match.groupdict()
Expand All @@ -325,7 +325,7 @@ def parse_unstructured_data(body, interface_name, version, module):
interface['prefixes'].append(prefix)

try:
vrf_regex = '.+?VRF\s+(?P<vrf>\S+?)\s'
vrf_regex = r'.+?VRF\s+(?P<vrf>\S+?)\s'
match_vrf = re.match(vrf_regex, body, re.DOTALL)
vrf = match_vrf.groupdict()['vrf']
except AttributeError:
Expand All @@ -344,7 +344,7 @@ def parse_interface_data(body):

for index in range(0, len(splitted_body) - 1):
if "Encapsulation 802.1Q" in splitted_body[index]:
regex = '(.+?ID\s(?P<dot1q>\d+).*)?'
regex = r'(.+?ID\s(?P<dot1q>\d+).*)?'
match = re.match(regex, splitted_body[index])
if match:
match_dict = match.groupdict()
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/network/nxos/nxos_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def get_ntp_peer(module):
ntp = response
if ntp:
ntp_regex = (
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
"(key\s(?P<key_id>\d+))?.*"
r".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
r"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
r"(key\s(?P<key_id>\d+))?.*"
)

split_ntp = ntp.splitlines()
Expand Down
Loading

0 comments on commit c6bb6c7

Please sign in to comment.