-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
ipaddress: Use str.isascii() instead of frozenset. #5811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lib/ipaddress.py
Outdated
| raise ValueError("Only hex digits permitted in %r" % hextet_str) | ||
| # Reject non-ASCII characters, '+' and '-', since int() accepts them. | ||
| msg = "Only hex digits permitted in %r" | ||
| if not hextet_str.isascii() or not hextet_str.isalnum(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'z' and '_' shouldn't be permitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are rejected by int()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'0x12' is accepted by int().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I'll revert it.
Lib/ipaddress.py
Outdated
| # 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() or not prefixlen_str.isdigit(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is _DECIMAL_DIGITS still used?
|
What is the benefit of rewriting the code? |
I found these code and I felt "Python should have str.isascii()". I proposed it and it's implemented. There are a little performance gain too. |
|
BTW, which is readable? |
|
I would prefer the second form. Both are compiled to the same bytecode. |
No description provided.