valid8r 0.5.7__py3-none-any.whl → 0.5.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of valid8r might be problematic. Click here for more details.
- valid8r/__init__.py +1 -1
- valid8r/core/parsers.py +40 -4
- {valid8r-0.5.7.dist-info → valid8r-0.5.9.dist-info}/METADATA +1 -1
- {valid8r-0.5.7.dist-info → valid8r-0.5.9.dist-info}/RECORD +7 -7
- {valid8r-0.5.7.dist-info → valid8r-0.5.9.dist-info}/WHEEL +0 -0
- {valid8r-0.5.7.dist-info → valid8r-0.5.9.dist-info}/entry_points.txt +0 -0
- {valid8r-0.5.7.dist-info → valid8r-0.5.9.dist-info}/licenses/LICENSE +0 -0
valid8r/__init__.py
CHANGED
valid8r/core/parsers.py
CHANGED
|
@@ -70,6 +70,11 @@ E = TypeVar('E', bound=Enum)
|
|
|
70
70
|
|
|
71
71
|
ISO_DATE_LENGTH = 10
|
|
72
72
|
|
|
73
|
+
# Compiled regex patterns for phone parsing (cached for performance)
|
|
74
|
+
_PHONE_EXTENSION_PATTERN = re.compile(r'\s*[,;]\s*(\d+)$|\s+(?:x|ext\.?|extension)\s*(\d+)$', re.IGNORECASE)
|
|
75
|
+
_PHONE_VALID_CHARS_PATTERN = re.compile(r'^[\d\s()\-+.]+$', re.MULTILINE)
|
|
76
|
+
_PHONE_DIGIT_EXTRACTION_PATTERN = re.compile(r'\D')
|
|
77
|
+
|
|
73
78
|
|
|
74
79
|
def parse_int(input_value: str, error_message: str | None = None) -> Maybe[int]:
|
|
75
80
|
"""Parse a string to an integer."""
|
|
@@ -1329,8 +1334,7 @@ def parse_phone(text: str | None, *, region: str = 'US', strict: bool = False) -
|
|
|
1329
1334
|
|
|
1330
1335
|
# Extract extension if present
|
|
1331
1336
|
extension = None
|
|
1332
|
-
|
|
1333
|
-
extension_match = re.search(extension_pattern, s, re.IGNORECASE)
|
|
1337
|
+
extension_match = _PHONE_EXTENSION_PATTERN.search(s)
|
|
1334
1338
|
if extension_match:
|
|
1335
1339
|
# Get the captured group (either group 1 or 2)
|
|
1336
1340
|
extension = extension_match.group(1) or extension_match.group(2)
|
|
@@ -1342,11 +1346,11 @@ def parse_phone(text: str | None, *, region: str = 'US', strict: bool = False) -
|
|
|
1342
1346
|
|
|
1343
1347
|
# Check for invalid characters before extracting digits
|
|
1344
1348
|
# Allow only: digits, whitespace (including tabs/newlines), ()-.+ and common separators
|
|
1345
|
-
if not
|
|
1349
|
+
if not _PHONE_VALID_CHARS_PATTERN.match(s):
|
|
1346
1350
|
return Maybe.failure('Invalid format: phone number contains invalid characters')
|
|
1347
1351
|
|
|
1348
1352
|
# Extract only digits
|
|
1349
|
-
digits =
|
|
1353
|
+
digits = _PHONE_DIGIT_EXTRACTION_PATTERN.sub('', s)
|
|
1350
1354
|
|
|
1351
1355
|
# Check for strict mode - original must have formatting
|
|
1352
1356
|
if strict and text.strip() == digits:
|
|
@@ -1404,3 +1408,35 @@ def parse_phone(text: str | None, *, region: str = 'US', strict: bool = False) -
|
|
|
1404
1408
|
extension=extension,
|
|
1405
1409
|
)
|
|
1406
1410
|
)
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
# Public API exports
|
|
1414
|
+
__all__ = [
|
|
1415
|
+
'EmailAddress',
|
|
1416
|
+
'PhoneNumber',
|
|
1417
|
+
'UrlParts',
|
|
1418
|
+
'create_parser',
|
|
1419
|
+
'make_parser',
|
|
1420
|
+
'parse_bool',
|
|
1421
|
+
'parse_cidr',
|
|
1422
|
+
'parse_complex',
|
|
1423
|
+
'parse_date',
|
|
1424
|
+
'parse_decimal',
|
|
1425
|
+
'parse_dict',
|
|
1426
|
+
'parse_dict_with_validation',
|
|
1427
|
+
'parse_email',
|
|
1428
|
+
'parse_enum',
|
|
1429
|
+
'parse_float',
|
|
1430
|
+
'parse_int',
|
|
1431
|
+
'parse_int_with_validation',
|
|
1432
|
+
'parse_ip',
|
|
1433
|
+
'parse_ipv4',
|
|
1434
|
+
'parse_ipv6',
|
|
1435
|
+
'parse_list',
|
|
1436
|
+
'parse_list_with_validation',
|
|
1437
|
+
'parse_phone',
|
|
1438
|
+
'parse_set',
|
|
1439
|
+
'parse_url',
|
|
1440
|
+
'parse_uuid',
|
|
1441
|
+
'validated_parser',
|
|
1442
|
+
]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
valid8r/__init__.py,sha256=
|
|
1
|
+
valid8r/__init__.py,sha256=2fzSl6XtKX44sdqzf0GBTn4oEaCvhmyGkdsPDMJjZz8,447
|
|
2
2
|
valid8r/core/__init__.py,sha256=ASOdzqCtpZHbHjjYMZkb78Z-nKxtD26ruTY0bd43ImA,520
|
|
3
3
|
valid8r/core/combinators.py,sha256=KvRiDEqoZgH58cBYPO6SW9pdtkyijk0lS8aGSB5DbO4,2349
|
|
4
4
|
valid8r/core/maybe.py,sha256=xT1xbiLVKohZ2aeaDZoKjT0W6Vk_PPwKbZXpIfsP7hc,4359
|
|
5
|
-
valid8r/core/parsers.py,sha256=
|
|
5
|
+
valid8r/core/parsers.py,sha256=Cr-hzeb4txSiBBhWcP36aXAXizqqcFjcvR8BVe-Kz1Q,46130
|
|
6
6
|
valid8r/core/validators.py,sha256=oCrRQ2wIPNkqQXy-hJ7sQ9mJAvxtEtGhoy7WvehWqTc,5756
|
|
7
7
|
valid8r/prompt/__init__.py,sha256=XYB3NEp-tmqT6fGmETVEeXd7Urj0M4ijlwdRAjj-rG8,175
|
|
8
8
|
valid8r/prompt/basic.py,sha256=fLWuN-oiVZyaLdbcW5GHWpoGQ82RG0j-1n7uMYDfOb8,6008
|
|
@@ -11,8 +11,8 @@ valid8r/testing/__init__.py,sha256=8mk54zt0Ai2dK0a3GMOTfDPsVQWXaS6uvQJDrkRV9hs,7
|
|
|
11
11
|
valid8r/testing/assertions.py,sha256=9KGz1JooCoyikyxMX7VuXB9VYAtj-4H_LPYFGdvS-ps,1820
|
|
12
12
|
valid8r/testing/generators.py,sha256=kAV6NRO9x1gPy0BfGs07ETVxjpTIxOZyV9wH2BA1nHA,8791
|
|
13
13
|
valid8r/testing/mock_input.py,sha256=9GRT7h0PCh9Dea-OcQ5Uls7YqhsTdqMWuX6I6ZlW1aw,2334
|
|
14
|
-
valid8r-0.5.
|
|
15
|
-
valid8r-0.5.
|
|
16
|
-
valid8r-0.5.
|
|
17
|
-
valid8r-0.5.
|
|
18
|
-
valid8r-0.5.
|
|
14
|
+
valid8r-0.5.9.dist-info/METADATA,sha256=AOxnN8cpmPpKBvQvac-MrAjc_86wYbdiEcsrH_7KQlw,9096
|
|
15
|
+
valid8r-0.5.9.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
16
|
+
valid8r-0.5.9.dist-info/entry_points.txt,sha256=H_24A4zUgnKIXAIRosJliIcntyqMfmcgKh5_Prl7W18,79
|
|
17
|
+
valid8r-0.5.9.dist-info/licenses/LICENSE,sha256=JpEmJvRYOTIUt0UjgvpDrd3U94Wnbt_Grr5z-xU2jtk,1066
|
|
18
|
+
valid8r-0.5.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|