(ipstr)
| 18 | |
| 19 | |
| 20 | def _ipmatch(ipstr): |
| 21 | # FIXME: IPv4 only |
| 22 | if ipstr == 'default': |
| 23 | ipstr = '0.0.0.0/0' |
| 24 | m = re.match(r'^(\d+(\.\d+(\.\d+(\.\d+)?)?)?)(?:/(\d+))?$', ipstr) |
| 25 | if m: |
| 26 | g = m.groups() |
| 27 | ips = g[0] |
| 28 | width = int(g[4] or 32) |
| 29 | if g[1] is None: |
| 30 | ips += '.0.0.0' |
| 31 | width = min(width, 8) |
| 32 | elif g[2] is None: |
| 33 | ips += '.0.0' |
| 34 | width = min(width, 16) |
| 35 | elif g[3] is None: |
| 36 | ips += '.0' |
| 37 | width = min(width, 24) |
| 38 | return (struct.unpack('!I', socket.inet_aton(ips))[0], width) |
| 39 | |
| 40 | |
| 41 | def _ipstr(ip, width): |
no outgoing calls
no test coverage detected