Skip to content

Commit

Permalink
[mod] regex must be stored in raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Aug 25, 2019
1 parent 0849adb commit 19dbe87
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/yunohost/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def get_network_interfaces():
# Get network devices and their addresses (raw infos from 'ip addr')
devices_raw = {}
output = subprocess.check_output('ip addr show'.split())
for d in re.split('^(?:[0-9]+: )', output, flags=re.MULTILINE):
for d in re.split(r'^(?:[0-9]+: )', output, flags=re.MULTILINE):
# Extract device name (1) and its addresses (2)
m = re.match('([^\s@]+)(?:@[\S]+)?: (.*)', d, flags=re.DOTALL)
m = re.match(r'([^\s@]+)(?:@[\S]+)?: (.*)', d, flags=re.DOTALL)
if m:
devices_raw[m.group(1)] = m.group(2)

Expand All @@ -63,7 +63,7 @@ def get_network_interfaces():
def get_gateway():

output = subprocess.check_output('ip route show'.split())
m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output)
m = re.search(r'default via (.*) dev ([a-z]+[0-9]?)', output)
if not m:
return None

Expand All @@ -86,10 +86,10 @@ def _extract_inet(string, skip_netmask=False, skip_loopback=True):
A dict of {protocol: address} with protocol one of 'ipv4' or 'ipv6'
"""
ip4_pattern = '((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
ip6_pattern = '(((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)'
ip4_pattern += '/[0-9]{1,2})' if not skip_netmask else ')'
ip6_pattern += '/[0-9]{1,3})' if not skip_netmask else ')'
ip4_pattern = r'((25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
ip6_pattern = r'(((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)'
ip4_pattern += r'/[0-9]{1,2})' if not skip_netmask else ')'
ip6_pattern += r'/[0-9]{1,3})' if not skip_netmask else ')'
result = {}

for m in re.finditer(ip4_pattern, string):
Expand Down

0 comments on commit 19dbe87

Please sign in to comment.