Ensure IP addresses are URI-compatible - specifically, add brackets around IPv6 literals if they are not already present.
(addr, strip=False)
| 2369 | |
| 2370 | |
| 2371 | def ip_bracket(addr, strip=False): |
| 2372 | """ |
| 2373 | Ensure IP addresses are URI-compatible - specifically, add brackets |
| 2374 | around IPv6 literals if they are not already present. |
| 2375 | """ |
| 2376 | addr = str(addr) |
| 2377 | addr = addr.lstrip("[") |
| 2378 | addr = addr.rstrip("]") |
| 2379 | addr = ipaddress.ip_address(addr) |
| 2380 | return ("[{}]" if addr.version == 6 and not strip else "{}").format(addr) |
no test coverage detected