diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2018-02-23 11:02:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-23 11:02:41 (GMT) |
commit | 58a10967619d0281adf346f227c254f1c3b3f32e (patch) | |
tree | e0cb790c62e7a85987ad86b13afd94e42337d52f | |
parent | 33dddac00ba8d9b72cf21b8698504077eb3c23ad (diff) | |
download | cpython-58a10967619d0281adf346f227c254f1c3b3f32e.zip cpython-58a10967619d0281adf346f227c254f1c3b3f32e.tar.gz cpython-58a10967619d0281adf346f227c254f1c3b3f32e.tar.bz2 |
ipaddress: Use str.isascii() instead of frozenset (GH-5811)
-rw-r--r-- | Lib/ipaddress.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index e8ce4ce..77df051 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -488,7 +488,7 @@ class _IPAddressBase: """ # int allows a leading +/- as well as surrounding whitespace, # so we ensure that isn't the case - if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str): + if not (prefixlen_str.isascii() and prefixlen_str.isdigit()): cls._report_invalid_netmask(prefixlen_str) try: prefixlen = int(prefixlen_str) @@ -1076,7 +1076,6 @@ class _BaseV4: _version = 4 # Equivalent to 255.255.255.255 or 32 bits of 1's. _ALL_ONES = (2**IPV4LENGTH) - 1 - _DECIMAL_DIGITS = frozenset('0123456789') # the valid octets for host and netmasks. only useful for IPv4. _valid_mask_octets = frozenset({255, 254, 252, 248, 240, 224, 192, 128, 0}) @@ -1156,7 +1155,7 @@ class _BaseV4: if not octet_str: raise ValueError("Empty octet not permitted") # Whitelist the characters, since int() allows a lot of bizarre stuff. - if not cls._DECIMAL_DIGITS.issuperset(octet_str): + if not (octet_str.isascii() and octet_str.isdigit()): msg = "Only decimal digits permitted in %r" raise ValueError(msg % octet_str) # We do the length check second, since the invalid character error |