BlinkenArea - GitList
Repositories
Blog
Wiki
pyetherpix
Code
Commits
Branches
Tags
Search
Tree:
bc491f5
Branches
Tags
master
pyetherpix
pyetherpix
parse.py
begin of config file parsing
Stefan Schuermans
commited
bc491f5
at 2017-05-25 22:18:34
parse.py
Blame
History
Raw
def _parse_addr(addr_str): """parse an IPv4 address, e.g. \"1.2.3.4:567\", return tuple of IP and port, e.g. ("1.2.3.4", 567), None on error""" fields = addr_str.split(":") if len(fields) > 2: return None ip = fields[0] port = fields[1] if len(ip.split(".")) != 4: return None try: port = int(port) except: return None if port < 0 or port > 65535: return None return (ip, port) def _parse_two_nos(txt): """parse two comma separated decimal unsigned integers from string, e.g. \"12,34\", return tuple of two numbers, e.g. (12, 34), None on error""" fields = txt.strip().split() if len(fields) > 1: return None fields = fields[0].split(",") if len(fields) != 2: return None try: no1 = int(fields[0]) no2 = int(fields[1]) except: return None if no1 < 0 or no2 < 0: return None return (no1, no2)