Skip to content

Commit

Permalink
Make all Python regexps raw strings. #1441
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeit-internet2 committed Jun 27, 2024
1 parent 7f4f4da commit e008658
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 86 deletions.
2 changes: 1 addition & 1 deletion pscheduler-tool-ethr/ethr/run
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def run_client():

# Make the result and return it

matcher = re.compile('^\[([^]]+)\]\s+(TCP|UDP)\s+([^\s]+)-([^\s]+)\s+[^\s]+\s*([^\s]+)$')
matcher = re.compile(r'^\[([^]]+)\]\s+(TCP|UDP)\s+([^\s]+)-([^\s]+)\s+[^\s]+\s*([^\s]+)$')


def group_block(stream, start, end, bps):
Expand Down
2 changes: 1 addition & 1 deletion pscheduler-tool-globus/globus/run
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if True:
for line in lines:
logger.debug("searching line: {0}".format(line))
#make sure you grab the last one because each screen update its own line
test = re.search('\s*(\d+) bytes\s+(\S+) ([A-za-z])B/sec avg\s+\S+ [A-za-z]B/sec inst$', line)
test = re.search(r'\s*(\d+) bytes\s+(\S+) ([A-za-z])B/sec avg\s+\S+ [A-za-z]B/sec inst$', line)
if test:
logger.debug("looks like a performance metric line")
bytes_sent = int(test.group(1))
Expand Down
58 changes: 29 additions & 29 deletions pscheduler-tool-iperf2/iperf2/iperf2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def parse_output(lines, expect_udp=False, logger=None):

# Bogus numbers

if re.match('\(nan%\)', line):
if re.match(r'\(nan%\)', line):
return {
'succeeded': False,
'error': 'Found NaN result'
}

# Connection failures

if re.match('read failed: Connection refused', line):
if re.match(r'read failed: Connection refused', line):
return {
'succeeded': False,
'error': 'Connection refused'
Expand All @@ -91,7 +91,7 @@ def parse_output(lines, expect_udp=False, logger=None):
# Client connecting to localhost, TCP port 5001 with pid 119661 (1 flows)
# Client connecting to localhost, UDP port 5001 with pid 119686 (1 flows)

test = re.match('^Client connecting to .*, (TCP|UDP) port', line)
test = re.match(r'^Client connecting to .*, (TCP|UDP) port', line)
if test:
protocol = test.group(1)
if (protocol == 'TCP' and expect_udp) or (protocol == 'UDP' and not expect_udp):
Expand All @@ -108,7 +108,7 @@ def parse_output(lines, expect_udp=False, logger=None):
# TCP window size: 2626560 Byte (default)
# TCP window size: 425984 Byte (WARNING: requested 1000000 Byte)

test = re.match('^TCP window size:\s+(\d+) Byte (\(WARNING: requested (\d+) Byte\))?', line)
test = re.match(r'^TCP window size:\s+(\d+) Byte (\(WARNING: requested (\d+) Byte\))?', line)
if test:
assert not expect_udp
results['tcp-window-size'] = int(test.group(1))
Expand All @@ -126,15 +126,15 @@ def parse_output(lines, expect_udp=False, logger=None):
# stream. This shouldn't matter because, in theory, they
# should all be the same.

test = re.match('^\[\s*\d+\].*\(icwnd/mss/irtt=\d+/(\d+)/\d+\)', line)
test = re.match(r'^\[\s*\d+\].*\(icwnd/mss/irtt=\d+/(\d+)/\d+\)', line)
if test:
assert not expect_udp
results['mss'] = int(test.group(1))


# If we start seeing server reports, we've seen everything
# from the client side. Treat it as EOF.
if re.match('^\[\s*(\d+|SUM) Server Report:', line):
if re.match(r'^\[\s*(\d+|SUM) Server Report:', line):
break

# Interval
Expand All @@ -151,14 +151,14 @@ def parse_output(lines, expect_udp=False, logger=None):
# [ 1] 4.00-6.00 sec 263130 Bytes 1052520 bits/sec 179/0 89 pps

test = re.match(
'^\[\s*(\d+|SUM)\]' # 1 - Stream ID
'\s+(\d+\.\d+)' # 2 - Interval start
'-(\d+\.\d+) sec' # 3 - Interval end
'\s+(\d+) Bytes' # 4 - Bytes transferred
'\s+(\d+) bits/sec' # 5 - Bandwidth
'\s+(\d+)' # 6 - Writes
'/(\d+)' # 7 - Errors
'\s+(\d+) pps$' # 8 - Packets per second
r'^\[\s*(\d+|SUM)\]' # 1 - Stream ID
r'\s+(\d+\.\d+)' # 2 - Interval start
r'-(\d+\.\d+) sec' # 3 - Interval end
r'\s+(\d+) Bytes' # 4 - Bytes transferred
r'\s+(\d+) bits/sec' # 5 - Bandwidth
r'\s+(\d+)' # 6 - Writes
r'/(\d+)' # 7 - Errors
r'\s+(\d+) pps$' # 8 - Packets per second
, line)

if not test:
Expand All @@ -184,21 +184,21 @@ def parse_output(lines, expect_udp=False, logger=None):
# [ 1] 2.00-4.00 sec 11173888000 Bytes 44695552000 bits/sec 85250/0 10 1470K/33(4) us 169301333

test = re.match(
'^\[\s*(\d+|SUM)\]' # 1 - Stream ID
'\s+(\d+\.\d+)' # 2 - Interval start
'-(\d+\.\d+) sec' # 3 - Interval end
'\s+(\d+) Bytes' # 4 - Bytes transferred
'\s+(\d+) bits/sec' # 5 - Bandwidth
'\s+(\d+)' # 6 - Writes
'/(\d+)' # 7 - Errors
'\s+(\d+)' # 8 - Retransmits
'(' # 9 - Begin optional stuff
'\s+(\d+K)' # 10 - Window size in SI units
'/(\d+)' # 11 - RTT
'\((\d+)\) us' # 12 - RTT Variance(?)
'\s*(\d+)' # 13 - Net Power (Experimental)
')?'
'\s*$'
r'^\[\s*(\d+|SUM)\]' # 1 - Stream ID
r'\s+(\d+\.\d+)' # 2 - Interval start
r'-(\d+\.\d+) sec' # 3 - Interval end
r'\s+(\d+) Bytes' # 4 - Bytes transferred
r'\s+(\d+) bits/sec' # 5 - Bandwidth
r'\s+(\d+)' # 6 - Writes
r'/(\d+)' # 7 - Errors
r'\s+(\d+)' # 8 - Retransmits
r'(' # 9 - Begin optional stuff
r'\s+(\d+K)' # 10 - Window size in SI units
r'/(\d+)' # 11 - RTT
r'\((\d+)\) us' # 12 - RTT Variance(?)
r'\s*(\d+)' # 13 - Net Power (Experimental)
r')?'
r'\s*$'
, line)

if not test:
Expand Down
2 changes: 1 addition & 1 deletion pscheduler-tool-nmapreach/nmapreach/run
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ nmap_first_args = [ 'nmap', '-n', '-sP', '-oG', '-', '--host-timeout', str(timeo

# The lines we want look like this:
# Host: 192.168.1.1 () Status: Up
nmap_output_matcher = re.compile("^Host:\s*([^\s]+)\s.*Status:\s*Up")
nmap_output_matcher = re.compile(r'^Host:\s*([^\s]+)\s.*Status:\s*Up')

nmap_timeout = timeout * 1.5

Expand Down
8 changes: 4 additions & 4 deletions pscheduler-tool-nuttcp/nuttcp/nuttcp_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_output(lines):

# Example line:
# 216.8125 MB / 1.00 sec = 1817.8571 Mbps 45 retrans 206 KB-cwnd
test = re.match('^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) retrans(\s*(\d+)\s*(\S)\S\-cwnd)?', line)
test = re.match(r'^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) retrans(\s*(\d+)\s*(\S)\S\-cwnd)?', line)
if test:
spacing = int(test.group(1))
value = test.group(2)
Expand Down Expand Up @@ -52,7 +52,7 @@ def parse_output(lines):

# Example UDP line
# 25.1572 MB / 1.00 sec = 211.0065 Mbps 62 / 25823 ~drop/pkt 0.24 ~%loss 4.8672 msMaxJitter
test = re.match('^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) / (\d+) ~drop/pkt\s*(\d+\.\d+) ~%loss\s*(\d+\.\d+) msMaxJitter', line)
test = re.match(r'^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) / (\d+) ~drop/pkt\s*(\d+\.\d+) ~%loss\s*(\d+\.\d+) msMaxJitter', line)
if test:
spacing = int(test.group(1))
value = test.group(2)
Expand Down Expand Up @@ -84,7 +84,7 @@ def parse_output(lines):

# Example summary line:
# 2197.0657 MB / 10.00 sec = 1842.3790 Mbps 8 %TX 90 %RX 90 retrans 237 KB-cwnd 0.50 msRTT
test = re.match('^.* (\d+)\.\d+ sec =\s*(\d+(\.\d+)?) (\S)bps \d+ %TX \d+ %RX (\d+) retrans(\s*(\d+)\s*(\S)\S\-cwnd)?', line)
test = re.match(r'^.* (\d+)\.\d+ sec =\s*(\d+(\.\d+)?) (\S)bps \d+ %TX \d+ %RX (\d+) retrans(\s*(\d+)\s*(\S)\S\-cwnd)?', line)
if test:
duration = int(test.group(1))
value = test.group(2)
Expand All @@ -108,7 +108,7 @@ def parse_output(lines):

# Example UDP summary line
# 252.0586 MB / 10.00 sec = 211.4462 Mbps 99 %TX 50 %RX 1485 / 259593 drop/pkt 0.57 %loss 37.2012 msMaxJitter
test = re.match('^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) %TX (\d+) %RX (\d+) / (\d+) drop/pkt\s*(\d+\.\d+) %loss\s*(\d+\.\d+) msMaxJitter', line)
test = re.match(r'^.* (\d+)\.\d+ sec \=\s*(\d+(\.\d+)?) (\S)bps\s*(\d+) %TX (\d+) %RX (\d+) / (\d+) drop/pkt\s*(\d+\.\d+) %loss\s*(\d+\.\d+) msMaxJitter', line)
if test:
duration = int(test.group(1))
value = test.group(2)
Expand Down
4 changes: 2 additions & 2 deletions pscheduler-tool-owping/owping/run
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ if role == CLIENT_ROLE:
pscheduler.succeed_json(results)

#Parse output
owping_regex = re.compile('^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
owping_regex = re.compile(r'^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
results['packets-sent'] = 0
results['packets-received'] = 0
results['packets-duplicated'] = 0
Expand Down Expand Up @@ -285,7 +285,7 @@ elif role == SERVER_ROLE:
# pscheduler.fail("Control port must be an integer")
#
# #data-port-range must be in form N-M where N < M and both are integers
# range_match = re.compile("(\d+)-(\d+)").match(recv_participant_data['data-port-range'])
# range_match = re.compile(r'(\d+)-(\d+)').match(recv_participant_data['data-port-range'])
# if not range_match:
# pscheduler.fail("Data port range is not a valid range. Must be in form N-M where N < M and both are integers")
# elif range_match.group(1) >= range_match.group(2):
Expand Down
4 changes: 2 additions & 2 deletions pscheduler-tool-paris-traceroute/paris-traceroute/run
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ ips = []
last_hop = 0

for line in stdout.split('\n'):
line = re.sub('\s+', ' ', line).strip()
line = re.sub(r'\s+', ' ', line).strip()


matches = re.match('^(\d*)\s+(.*)$', line)
matches = re.match(r'^(\d*)\s+(.*)$', line)
if matches is None:
log.debug("Discarding: %s", line)
continue
Expand Down
2 changes: 1 addition & 1 deletion pscheduler-tool-powstream/powstream/powstream_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def parse_raw_owamp_output(file, raw_output=False, bucket_width=TIME_SCALE):
'schema': LATENCY_SCHEMA_VERSION,
'succeeded': False
}
powstream_regex = re.compile('^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
powstream_regex = re.compile(r'^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
results['packets-sent'] = 0
results['packets-received'] = 0
results['packets-duplicated'] = 0
Expand Down
16 changes: 8 additions & 8 deletions pscheduler-tool-tcpping/tcpping/run
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ result = {


# TCP Ping Results: Connections (Total/Pass/Fail): [3/3/0] (Failed: 0%)
CONNECTED = re.compile('^Connected to\\s*[^\\s]+'
'\\s+\\(([^)]+)\)'
'\\s+.*:'
'\\s+tcp_seq=([0-9]+)'
'\\s+time=([0-9.]+) ms$')
CONNECTED = re.compile(r'^Connected to\\s*[^\\s]+'
r'\\s+\\(([^)]+)\)'
r'\\s+.*:'
r'\\s+tcp_seq=([0-9]+)'
r'\\s+time=([0-9.]+) ms$')

# TCP Ping Results: Connections (Total/Pass/Fail): [3/3/0] (Failed: 0%)
COUNTED = re.compile('^TCP Ping Results: Connections \\(Total/Pass/Fail\\): \\[([0-9]+)/([0-9]+)/([0-9]+)\\]')
COUNTED = re.compile(r'^TCP Ping Results: Connections \\(Total/Pass/Fail\\): \\[([0-9]+)/([0-9]+)/([0-9]+)\\]')

# rtt min/avg/max/mdev = 32.660/32.827/33.150/0.280 ms
STATS = re.compile('^rtt min/avg/max/mdev\\s+=\\s+'
'([0-9.]+)/([0-9.]+)/([0-9.]+)/([0-9.]+)\\s+ms')
STATS = re.compile(r'^rtt min/avg/max/mdev\\s+=\\s+'
r'([0-9.]+)/([0-9.]+)/([0-9.]+)/([0-9.]+)\\s+ms')



Expand Down
14 changes: 7 additions & 7 deletions pscheduler-tool-tracepath/tracepath/run
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ traced_hops = []
ips = []
last_hop = 0

ttl_re = re.compile('^(\d*)\??:');
no_reply_re = re.compile('no reply');
reached_re = re.compile('reached');
rtt_re = re.compile('([0-9]+\.[0-9]+)ms');
mtu_re = re.compile('pmtu ([0-9]+)');
error_re = re.compile('!(\w+)$');
ttl_re = re.compile(r'^(\d*)\??:');
no_reply_re = re.compile(r'no reply');
reached_re = re.compile(r'reached');
rtt_re = re.compile(r'([0-9]+\.[0-9]+)ms');
mtu_re = re.compile(r'pmtu ([0-9]+)');
error_re = re.compile(r'!(\w+)$');
path_mtu = None
for line in stdout.split('\n'):
line = re.sub('\s+', ' ', line).strip()
line = re.sub(r'\s+', ' ', line).strip()
matches = ttl_re.match(line)
if matches is None:
continue
Expand Down
4 changes: 2 additions & 2 deletions pscheduler-tool-traceroute/traceroute/run
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ ips = []
last_hop = 0

for line in stdout.split('\n'):
line = re.sub('\s+', ' ', line).strip()
line = re.sub(r'\s+', ' ', line).strip()


matches = re.match('^(\d*)\s+(.*)$', line)
matches = re.match(r'^(\d*)\s+(.*)$', line)
if matches is None:
log.debug("Discarding: %s", line)
continue
Expand Down
4 changes: 2 additions & 2 deletions pscheduler-tool-twping/twping/run
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ if role == CLIENT_ROLE:
# RS recv synchronized boolean unsigned
# RERR recv err estimate float (%g)
# RTTL reflected ttl unsigned short
twping_regex = re.compile('^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
twping_regex = re.compile(r'^(\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d+) (\d+) (\d) ([-.0-9e+]*) (\d+) (\d) ([-.0-9e+]*) (\d+)$')
results['packets-sent'] = 0
results['packets-received'] = 0
results['packets-duplicated'] = 0
Expand Down Expand Up @@ -416,7 +416,7 @@ elif role == SERVER_ROLE:
# pscheduler.fail("Control port must be an integer")
#
# #data-port-range must be in form N-M where N < M and both are integers
# range_match = re.compile("(\d+)-(\d+)").match(recv_participant_data['data-port-range'])
# range_match = re.compile(r'(\d+)-(\d+)').match(recv_participant_data['data-port-range'])
# if not range_match:
# pscheduler.fail("Data port range is not a valid range. Must be in form N-M where N < M and both are integers")
# elif range_match.group(1) >= range_match.group(2):
Expand Down
2 changes: 1 addition & 1 deletion python-pscheduler/pscheduler/pscheduler/jsonval.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
"oneOf": [
{
"type": "string",
"pattern": "^[0-9]+(\\.[0-9]+)?(\\s*[KkMmGgTtPpEeZzYy][Ii]?)?$"
"pattern": r'^[0-9]+(\\.[0-9]+)?(\\s*[KkMmGgTtPpEeZzYy][Ii]?)?$'
},
{
"type": "integer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def data_is_valid(data):

# These are for ue by ipv6_netmask_size()

ipv6_netmask_re = re.compile("^([f]*)([ec80]?)0*$")
ipv6_netmask_re = re.compile(r'^([f]*)([ec80]?)0*$')

ipv6_digit_bits = {
"e": 3,
Expand Down
4 changes: 2 additions & 2 deletions python-pscheduler/pscheduler/pscheduler/mtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from .ipaddr import ip_addr_version
from .program import run_program

mtu_match = re.compile("^.*pmtu ([0-9]+)")
hop_match = re.compile("^\s*[0-9]+\??:")
mtu_match = re.compile(r'^.*pmtu ([0-9]+)')
hop_match = re.compile(r'^\s*[0-9]+\??:')


def mtu_path_is_safe(host, ipversion=None):
Expand Down
48 changes: 27 additions & 21 deletions python-pscheduler/pscheduler/pscheduler/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ def parse_ping(output, count):
# Matchers for output lines we care about
#

PACKET_RETURNED = re.compile("^([0-9]+) bytes"
"\s+from (.*):"
"\s+icmp_[rs]eq=([0-9]+)"
"\s+ttl=([0-9]+)"
"\s+time=([0-9.]+) ms"
"$")
PACKET_RETURNED = re.compile(
r'^([0-9]+) bytes'
r'\s+from (.*):'
r'\s+icmp_[rs]eq=([0-9]+)'
r'\s+ttl=([0-9]+)'
r'\s+time=([0-9.]+) ms'
r'$'
)

# Error: From 5.6.7.8 icmp_seq=7 Destination Net Unreachable

ERROR_RETURNED = re.compile("^From"
"\s+([^\s]+)"
"\s+icmp_seq=([0-9]+)"
"\s+(.*)"
"$")
ERROR_RETURNED = re.compile(
r'^From'
r'\s+([^\s]+)'
r'\s+icmp_seq=([0-9]+)'
r'\s+(.*)'
r'$'
)

# Error messages known to be output by ping
ERROR_STRINGS = {
Expand All @@ -47,24 +51,26 @@ def parse_ping(output, count):

# Same, but require regexps to match
ERROR_MATCHES = [
( re.compile("^Frag needed and DF set"), 'fragmentation-needed-and-df-set' )
( re.compile(r'^Frag needed and DF set'), 'fragmentation-needed-and-df-set' )
]


# Sent/received/loss statistics:
# 5 packets transmitted, 5 received, 0% packet loss, time 4131ms
LOSS_STATS = re.compile(
'^([0-9]+) packets transmitted,'
' ([0-9]+) received,'
' ([0-9.]+)% packet loss')
r'^([0-9]+) packets transmitted,'
r' ([0-9]+) received,'
r' ([0-9.]+)% packet loss')

# Times: rtt min/avg/max/mdev = 19.631/24.191/29.874/4.262 ms
TIMES_RETURNED = re.compile("^rtt min/avg/max/mdev\s*=\s*"
"([0-9.]+)"
"/([0-9.]+)"
"/([0-9.]+)"
"/([0-9.]+)"
"\s+ms$")
TIMES_RETURNED = re.compile(
r'^rtt min/avg/max/mdev\s*=\s*'
r'([0-9.]+)'
r'/([0-9.]+)'
r'/([0-9.]+)'
r'/([0-9.]+)'
r'\s+ms$'
)

roundtrips = []
ips = []
Expand Down
Loading

0 comments on commit e008658

Please sign in to comment.