pyap2 0.2.19__tar.gz → 0.3.0__tar.gz
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.
- pyap2-0.3.0/.gitignore +26 -0
- pyap2-0.3.0/AUTHORS.rst +10 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/PKG-INFO +39 -19
- {pyap2-0.2.19 → pyap2-0.3.0}/README.rst +26 -2
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/__init__.py +1 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/address.py +6 -6
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/api.py +5 -5
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/exceptions.py +5 -5
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/parser.py +9 -9
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_CA/data.py +19 -23
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_GB/data.py +8 -9
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_US/data.py +21 -34
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/utils.py +5 -5
- pyap2-0.3.0/pyproject.toml +105 -0
- pyap2-0.3.0/tests/__init__.py +0 -0
- pyap2-0.3.0/tests/test_parser.py +500 -0
- pyap2-0.3.0/tests/test_parser_ca.py +516 -0
- pyap2-0.3.0/tests/test_parser_gb.py +586 -0
- pyap2-0.3.0/tests/test_parser_us.py +780 -0
- pyap2-0.3.0/uv.lock +332 -0
- pyap2-0.2.19/pyproject.toml +0 -75
- {pyap2-0.2.19 → pyap2-0.3.0}/LICENSE +0 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/py.typed +0 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_CA/__init__.py +0 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_GB/__init__.py +0 -0
- {pyap2-0.2.19 → pyap2-0.3.0}/pyap/source_US/__init__.py +0 -0
pyap2-0.3.0/.gitignore
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Compiled python modules.
|
|
2
|
+
*.pyc
|
|
3
|
+
|
|
4
|
+
# Setuptools distribution folder.
|
|
5
|
+
/dist/
|
|
6
|
+
/build/
|
|
7
|
+
|
|
8
|
+
# Python egg metadata, regenerated from source files by setuptools.
|
|
9
|
+
/*.egg-info
|
|
10
|
+
|
|
11
|
+
# Coverage reports
|
|
12
|
+
/htmlcov
|
|
13
|
+
/__pycache__
|
|
14
|
+
.coverage
|
|
15
|
+
|
|
16
|
+
# Venvs
|
|
17
|
+
/venv*
|
|
18
|
+
/.venv
|
|
19
|
+
|
|
20
|
+
# Misc
|
|
21
|
+
run.py
|
|
22
|
+
todo.txt
|
|
23
|
+
.DS_Store
|
|
24
|
+
.tox
|
|
25
|
+
files.txt
|
|
26
|
+
.vscode
|
pyap2-0.3.0/AUTHORS.rst
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Argyle's Pyap fork is developed by
|
|
2
|
+
- `<https://github.com/DeviousStoat>`_
|
|
3
|
+
- `<https://github.com/lmelninkas>`_
|
|
4
|
+
|
|
5
|
+
Initial Authors of Pyap
|
|
6
|
+
```````````````````````
|
|
7
|
+
- `Vladimir Goncharov <https://github.com/vladimarius>`_
|
|
8
|
+
- `Thomas Bird <https://github.com/thomasbird>`_ (British parsing rules)
|
|
9
|
+
- `Thomas Funk <https://github.com/tomfunk>`_ (thomasfunk10@gmail.com)
|
|
10
|
+
- `KCzar <https://github.com/KCzar>`_
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: pyap2
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: A maintained, typed fork of pyap for parsing US, CA, and UK addresses
|
|
5
|
+
Project-URL: Documentation, https://github.com/argyle-engineering/pyap
|
|
6
|
+
Project-URL: Homepage, https://github.com/argyle-engineering/pyap
|
|
7
|
+
Project-URL: Repository, https://github.com/argyle-engineering/pyap
|
|
8
|
+
Author-email: Argyle Developers <developers@argyle.io>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
7
11
|
Keywords: address,parser,regex
|
|
8
|
-
Author: Argyle Developers
|
|
9
|
-
Author-email: developers@argyle.io
|
|
10
|
-
Requires-Python: >=3.9,<4.0
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
17
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
21
18
|
Classifier: Topic :: Software Development :: Libraries
|
|
22
19
|
Classifier: Topic :: Utilities
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
25
22
|
Description-Content-Type: text/x-rst
|
|
26
23
|
|
|
27
24
|
Pyap2: Python address parser
|
|
@@ -55,17 +52,41 @@ detecting and parsing addresses. Currently it supports US 🇺🇸, Canadian
|
|
|
55
52
|
Installation
|
|
56
53
|
------------
|
|
57
54
|
|
|
58
|
-
To install
|
|
55
|
+
Pyap2 requires Python 3.11 or newer. To install it:
|
|
59
56
|
|
|
60
57
|
.. code-block:: bash
|
|
61
58
|
|
|
62
59
|
$ pip install pyap2
|
|
63
60
|
|
|
64
61
|
|
|
62
|
+
Development
|
|
63
|
+
-----------
|
|
64
|
+
|
|
65
|
+
Install the project and its development tools from the lock file:
|
|
66
|
+
|
|
67
|
+
.. code-block:: bash
|
|
68
|
+
|
|
69
|
+
$ uv sync --locked --all-groups
|
|
70
|
+
|
|
71
|
+
Run the same checks used by CI:
|
|
72
|
+
|
|
73
|
+
.. code-block:: bash
|
|
74
|
+
|
|
75
|
+
$ uv run task check
|
|
76
|
+
|
|
77
|
+
Individual tasks include ``lint``, ``check_fmt``, ``check_types``, ``fmt``, and
|
|
78
|
+
``test``. For example:
|
|
79
|
+
|
|
80
|
+
.. code-block:: bash
|
|
81
|
+
|
|
82
|
+
$ uv run task fmt
|
|
83
|
+
$ uv run task test
|
|
84
|
+
|
|
85
|
+
|
|
65
86
|
|
|
66
87
|
About
|
|
67
88
|
-----
|
|
68
|
-
We started improving the original `pyap` by adopting
|
|
89
|
+
We started improving the original `pyap` by adopting modern packaging and adding typing support.
|
|
69
90
|
It was extensively tested in web-scraping operations on thousands of US addresses.
|
|
70
91
|
Gradually, we added support for many rarer address formats and edge cases, as well
|
|
71
92
|
as the ability to parse a partial address where only street info is available.
|
|
@@ -99,4 +120,3 @@ and a state name abbreviation "IN" (Indiana).
|
|
|
99
120
|
The good news is that the above mentioned errors are **quite rare**.
|
|
100
121
|
|
|
101
122
|
|
|
102
|
-
|
|
@@ -29,17 +29,41 @@ detecting and parsing addresses. Currently it supports US 🇺🇸, Canadian
|
|
|
29
29
|
Installation
|
|
30
30
|
------------
|
|
31
31
|
|
|
32
|
-
To install
|
|
32
|
+
Pyap2 requires Python 3.11 or newer. To install it:
|
|
33
33
|
|
|
34
34
|
.. code-block:: bash
|
|
35
35
|
|
|
36
36
|
$ pip install pyap2
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
Development
|
|
40
|
+
-----------
|
|
41
|
+
|
|
42
|
+
Install the project and its development tools from the lock file:
|
|
43
|
+
|
|
44
|
+
.. code-block:: bash
|
|
45
|
+
|
|
46
|
+
$ uv sync --locked --all-groups
|
|
47
|
+
|
|
48
|
+
Run the same checks used by CI:
|
|
49
|
+
|
|
50
|
+
.. code-block:: bash
|
|
51
|
+
|
|
52
|
+
$ uv run task check
|
|
53
|
+
|
|
54
|
+
Individual tasks include ``lint``, ``check_fmt``, ``check_types``, ``fmt``, and
|
|
55
|
+
``test``. For example:
|
|
56
|
+
|
|
57
|
+
.. code-block:: bash
|
|
58
|
+
|
|
59
|
+
$ uv run task fmt
|
|
60
|
+
$ uv run task test
|
|
61
|
+
|
|
62
|
+
|
|
39
63
|
|
|
40
64
|
About
|
|
41
65
|
-----
|
|
42
|
-
We started improving the original `pyap` by adopting
|
|
66
|
+
We started improving the original `pyap` by adopting modern packaging and adding typing support.
|
|
43
67
|
It was extensively tested in web-scraping operations on thousands of US addresses.
|
|
44
68
|
Gradually, we added support for many rarer address formats and edge cases, as well
|
|
45
69
|
as the ability to parse a partial address where only street info is available.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.address
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Contains class for constructing Address object which holds information
|
|
8
|
+
about address and its components.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
11
|
+
:license: MIT, see LICENSE for more details.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
from dataclasses import dataclass, asdict
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.api
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This module contains address parser API functions.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
10
|
+
:license: MIT, see LICENSE for more details.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
from typing import Literal, List
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.exceptions
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This module contains address parser exceptions.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
10
|
+
:license: MIT, see LICENSE for more details.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.parser
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
This module contains AddressParser class which connects all the
|
|
8
|
+
functionality of the package in one place.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
11
|
+
:license: MIT, see LICENSE for more details.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
import re
|
|
@@ -32,13 +32,13 @@ class AddressParser:
|
|
|
32
32
|
self.rules = data.full_address
|
|
33
33
|
self.single_street_rules = data.full_street
|
|
34
34
|
|
|
35
|
-
except ImportError:
|
|
35
|
+
except ImportError as exc:
|
|
36
36
|
raise e.CountryDetectionMissing(
|
|
37
37
|
'Detection rules for country "{country}" not found.'.format(
|
|
38
38
|
country=self.country
|
|
39
39
|
),
|
|
40
40
|
"Error 2",
|
|
41
|
-
)
|
|
41
|
+
) from exc
|
|
42
42
|
|
|
43
43
|
def parse(self, text: str) -> List[address.Address]:
|
|
44
44
|
"""Returns a list of addresses found in text
|
|
@@ -100,7 +100,7 @@ class AddressParser:
|
|
|
100
100
|
if k not in keys:
|
|
101
101
|
keys.append(k)
|
|
102
102
|
vals.append(v)
|
|
103
|
-
return dict(zip(keys, vals))
|
|
103
|
+
return dict(zip(keys, vals, strict=True))
|
|
104
104
|
|
|
105
105
|
@staticmethod
|
|
106
106
|
def _normalize_string(text: str) -> str:
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.source_US.data
|
|
5
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
This module provides regular expression definitions required for
|
|
8
|
+
detecting Canada addresses.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
The module is expected to always contain 'full_address' variable containing
|
|
11
|
+
all address parsing definitions.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
14
|
+
:license: MIT, see LICENSE for more details.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
17
|
import re
|
|
@@ -149,9 +149,7 @@ post_direction = r"""
|
|
|
149
149
|
O[\.\ ]
|
|
150
150
|
)
|
|
151
151
|
)
|
|
152
|
-
""".format(
|
|
153
|
-
d="[\ ,]"
|
|
154
|
-
)
|
|
152
|
+
""".format(d=r"[\ ,]")
|
|
155
153
|
|
|
156
154
|
# Regexp for matching street type
|
|
157
155
|
# According to
|
|
@@ -308,9 +306,7 @@ street_type = r"""
|
|
|
308
306
|
[\(\ \,]{route_symbols}
|
|
309
307
|
[Rr][Oo][Uu][Tt][Ee]\ [A-Za-z0-9]+[\)\ \,]{route_symbols}
|
|
310
308
|
)?
|
|
311
|
-
""".format(
|
|
312
|
-
div="[\.\ ,]{0,2}", route_symbols="{0,3}"
|
|
313
|
-
)
|
|
309
|
+
""".format(div=r"[\.\ ,]{0,2}", route_symbols="{0,3}")
|
|
314
310
|
|
|
315
311
|
floor = r"""
|
|
316
312
|
(?P<floor>
|
|
@@ -399,11 +395,11 @@ po_box = r"""
|
|
|
399
395
|
"""Define detection rules for a second type of address format
|
|
400
396
|
(the French one)
|
|
401
397
|
"""
|
|
402
|
-
street_number_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_number)
|
|
403
|
-
street_name_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_name)
|
|
404
|
-
street_type_b = re.sub("<([a-z\_]+)>", r"<\1_b>", street_type)
|
|
405
|
-
po_box_b = re.sub("<([a-z\_]+)>", r"<\1_b>", po_box)
|
|
406
|
-
post_direction_b = re.sub("<([a-z\_]+)>", r"<\1_b>", post_direction)
|
|
398
|
+
street_number_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_number)
|
|
399
|
+
street_name_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_name)
|
|
400
|
+
street_type_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", street_type)
|
|
401
|
+
po_box_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", po_box)
|
|
402
|
+
post_direction_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", post_direction)
|
|
407
403
|
|
|
408
404
|
po_box_positive_lookahead = r"""
|
|
409
405
|
(?=
|
|
@@ -479,7 +475,7 @@ full_street = r"""
|
|
|
479
475
|
po_box=po_box,
|
|
480
476
|
po_box_b=po_box_b,
|
|
481
477
|
po_box_positive_lookahead=po_box_positive_lookahead,
|
|
482
|
-
div="[\ ,]{1,2}",
|
|
478
|
+
div=r"[\ ,]{1,2}",
|
|
483
479
|
)
|
|
484
480
|
|
|
485
481
|
# region1 here is actually a "province"
|
|
@@ -551,8 +547,8 @@ country = r"""
|
|
|
551
547
|
"""
|
|
552
548
|
|
|
553
549
|
# define detection rules for postal code placed in different parts of address
|
|
554
|
-
postal_code_b = re.sub("<([a-z\_]+)>", r"<\1_b>", postal_code)
|
|
555
|
-
postal_code_c = re.sub("<([a-z\_]+)>", r"<\1_c>", postal_code)
|
|
550
|
+
postal_code_b = re.sub(r"<([a-z\_]+)>", r"<\1_b>", postal_code)
|
|
551
|
+
postal_code_c = re.sub(r"<([a-z\_]+)>", r"<\1_c>", postal_code)
|
|
556
552
|
|
|
557
553
|
full_address = r"""
|
|
558
554
|
(?P<full_address>
|
|
@@ -569,7 +565,7 @@ full_address = r"""
|
|
|
569
565
|
)
|
|
570
566
|
""".format(
|
|
571
567
|
full_street=full_street,
|
|
572
|
-
div="[\, ]{,2}",
|
|
568
|
+
div=r"[\, ]{,2}",
|
|
573
569
|
city=city,
|
|
574
570
|
region1=region1,
|
|
575
571
|
country=country,
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.source_GB.data
|
|
5
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
This module provides regular expression definitions required for
|
|
8
|
+
detecting British/GB/UK addresses.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
The module is expected to always contain 'full_address' variable containing
|
|
11
|
+
all address parsing definitions.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
14
|
+
:license: MIT, see LICENSE for more details.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
"""Numerals from one to nine
|
|
19
18
|
Note: here and below we use syntax like '[Oo][Nn][Ee]'
|
|
20
19
|
instead of '(one)(?i)' to match 'One' or 'oNe' because
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.source_US.data
|
|
5
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
This module provides regular expression definitions required for
|
|
8
|
+
detecting US addresses.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
The module is expected to always contain 'full_address' variable containing
|
|
11
|
+
all address parsing definitions.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
14
|
+
:license: MIT, see LICENSE for more details.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
17
|
import string
|
|
@@ -259,9 +259,7 @@ post_direction_re = r"""
|
|
|
259
259
|
|
|
260
260
|
numbered_avenue_re = r"""
|
|
261
261
|
(?:{post_direction_re}\ [Aa][Vv][Ee](?:\.|[Nn][Uu][Ee])?\ \d{{1,2}})
|
|
262
|
-
""".format(
|
|
263
|
-
post_direction_re=post_direction_re
|
|
264
|
-
)
|
|
262
|
+
""".format(post_direction_re=post_direction_re)
|
|
265
263
|
|
|
266
264
|
|
|
267
265
|
single_street_name_list = [
|
|
@@ -286,9 +284,7 @@ numbered_state_highway = r"""
|
|
|
286
284
|
(?:{states}\ \d{{1,4}}(?!\d))
|
|
287
285
|
|
|
|
288
286
|
(?:[Ss][Tt][Aa][Tt][Ee]\s[Hh][Ww][Yy]\s\d{{1,4}}(?!\d))
|
|
289
|
-
""".format(
|
|
290
|
-
states=state_highway_abbrvs_regex()
|
|
291
|
-
)
|
|
287
|
+
""".format(states=state_highway_abbrvs_regex())
|
|
292
288
|
|
|
293
289
|
|
|
294
290
|
# Used to handle edge cases where streets don't have a street type:
|
|
@@ -334,9 +330,7 @@ post_direction = r"""
|
|
|
334
330
|
(?P<post_direction>
|
|
335
331
|
{post_direction_re}
|
|
336
332
|
)
|
|
337
|
-
""".format(
|
|
338
|
-
post_direction_re=post_direction_re
|
|
339
|
-
)
|
|
333
|
+
""".format(post_direction_re=post_direction_re)
|
|
340
334
|
|
|
341
335
|
# This list was taken from: https://pe.usps.com/text/pub28/28apc_002.htm
|
|
342
336
|
# Bay, Broadway and Lp (abbreviation for Loop) were added to the list
|
|
@@ -358,7 +352,7 @@ street_type_list = [
|
|
|
358
352
|
"Avenue",
|
|
359
353
|
"Avn",
|
|
360
354
|
"Avnue",
|
|
361
|
-
"Bay(?!\ [1-9])",
|
|
355
|
+
r"Bay(?!\ [1-9])",
|
|
362
356
|
"Bayoo",
|
|
363
357
|
"Bayou",
|
|
364
358
|
"Bch",
|
|
@@ -573,6 +567,7 @@ street_type_list = [
|
|
|
573
567
|
"Hbr",
|
|
574
568
|
"Hbrs",
|
|
575
569
|
"Heights",
|
|
570
|
+
"Hgts",
|
|
576
571
|
"Highway",
|
|
577
572
|
"Highwy",
|
|
578
573
|
"Hill",
|
|
@@ -906,12 +901,12 @@ street_type_list = [
|
|
|
906
901
|
|
|
907
902
|
street_type_leading_list = [
|
|
908
903
|
"Camino",
|
|
909
|
-
"El\ Camino",
|
|
904
|
+
r"El\ Camino",
|
|
910
905
|
"Via",
|
|
911
906
|
"Avenue",
|
|
912
907
|
"Blvd",
|
|
913
908
|
"Ave",
|
|
914
|
-
"La\ Rue",
|
|
909
|
+
r"La\ Rue",
|
|
915
910
|
"Rue",
|
|
916
911
|
]
|
|
917
912
|
|
|
@@ -1082,9 +1077,7 @@ floor = r"""
|
|
|
1082
1077
|
{floor_indic}\ ?\#?\d+[A-Za-z]{{0,2}}
|
|
1083
1078
|
)
|
|
1084
1079
|
)
|
|
1085
|
-
""".format(
|
|
1086
|
-
floor_indic=floor_indic
|
|
1087
|
-
)
|
|
1080
|
+
""".format(floor_indic=floor_indic)
|
|
1088
1081
|
|
|
1089
1082
|
tower = r"(?:{re_post_direction}\ [Tt][Oo][Ww][Ee][Rr])".format(
|
|
1090
1083
|
re_post_direction=post_direction_re
|
|
@@ -1203,9 +1196,7 @@ occupancy = r"""
|
|
|
1203
1196
|
)
|
|
1204
1197
|
)
|
|
1205
1198
|
)
|
|
1206
|
-
""".format(
|
|
1207
|
-
occupancy_details=occupancy_details
|
|
1208
|
-
)
|
|
1199
|
+
""".format(occupancy_details=occupancy_details)
|
|
1209
1200
|
|
|
1210
1201
|
mail_stop = r"""
|
|
1211
1202
|
(?P<mail_stop>
|
|
@@ -1227,7 +1218,7 @@ po_box = r"""
|
|
|
1227
1218
|
(?:
|
|
1228
1219
|
(?:
|
|
1229
1220
|
(?:
|
|
1230
|
-
[Bb][Oo][Xx]
|
|
1221
|
+
[Bb][Oo]?[Xx]
|
|
1231
1222
|
|
|
|
1232
1223
|
[Pp][Mm][Bb]
|
|
1233
1224
|
|
|
|
@@ -1238,9 +1229,7 @@ po_box = r"""
|
|
|
1238
1229
|
|
|
|
1239
1230
|
(?:[Dd][Rr][Aa][Ww][Ee][Rr]\ +[A-Z]\b)
|
|
1240
1231
|
)
|
|
1241
|
-
""".format(
|
|
1242
|
-
po_marker=po_marker
|
|
1243
|
-
)
|
|
1232
|
+
""".format(po_marker=po_marker)
|
|
1244
1233
|
|
|
1245
1234
|
phone_number = r"""
|
|
1246
1235
|
(?:
|
|
@@ -1383,9 +1372,7 @@ def make_region1(idx: Optional[str] = None):
|
|
|
1383
1372
|
{state_abbrvs}
|
|
1384
1373
|
)
|
|
1385
1374
|
)
|
|
1386
|
-
""".format(
|
|
1387
|
-
state_abbrvs=states_abbrvs_regex(), maybe_idx=maybe_idx
|
|
1388
|
-
)
|
|
1375
|
+
""".format(state_abbrvs=states_abbrvs_regex(), maybe_idx=maybe_idx)
|
|
1389
1376
|
|
|
1390
1377
|
|
|
1391
1378
|
# TODO: doesn't catch cities containing French characters
|
|
@@ -1427,7 +1414,7 @@ def make_region1_postal_code(
|
|
|
1427
1414
|
def _indexed_region1(idx: Optional[str] = None):
|
|
1428
1415
|
return rf"""(?:{part_div} {make_region1(idx)})"""
|
|
1429
1416
|
|
|
1430
|
-
_postal_code =
|
|
1417
|
+
_postal_code = rf"""(?:{part_div}|\-)? {postal_code}"""
|
|
1431
1418
|
return rf"""
|
|
1432
1419
|
(?:{_indexed_region1("a")}?(?:{part_div}{make_country("b")})?{_postal_code}{_indexed_region1("b")}?
|
|
1433
1420
|
|{_indexed_region1("c")}(?![-,.\sA-Za-z]{{0,10}}{postal_code_re}))
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
pyap.utils
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This module provides some utility functions.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
:copyright: (c) 2015 by Vladimir Goncharov.
|
|
10
|
+
:license: MIT, see LICENSE for more details.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import re
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.33.0", "hatch-vcs>=0.5.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyap2"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A maintained, typed fork of pyap for parsing US, CA, and UK addresses"
|
|
9
|
+
readme = "README.rst"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Argyle Developers", email = "developers@argyle.io" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["address", "parser", "regex"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
24
|
+
"Topic :: Software Development :: Libraries",
|
|
25
|
+
"Topic :: Utilities",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Documentation = "https://github.com/argyle-engineering/pyap"
|
|
32
|
+
Homepage = "https://github.com/argyle-engineering/pyap"
|
|
33
|
+
Repository = "https://github.com/argyle-engineering/pyap"
|
|
34
|
+
|
|
35
|
+
[dependency-groups]
|
|
36
|
+
dev = [
|
|
37
|
+
"pyright>=1.1.414",
|
|
38
|
+
"pytest>=9.2.0",
|
|
39
|
+
"ruff>=0.17.5",
|
|
40
|
+
"taskipy>=1.14.1",
|
|
41
|
+
"yamllint>=1.38.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.uv]
|
|
45
|
+
required-version = ">=0.13.7"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.version]
|
|
48
|
+
source = "vcs"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.version.raw-options]
|
|
51
|
+
version_scheme = "no-guess-dev"
|
|
52
|
+
local_scheme = "no-local-version"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["pyap"]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
include = [
|
|
59
|
+
"/AUTHORS.rst",
|
|
60
|
+
"/LICENSE",
|
|
61
|
+
"/README.rst",
|
|
62
|
+
"/pyap",
|
|
63
|
+
"/pyproject.toml",
|
|
64
|
+
"/tests",
|
|
65
|
+
"/uv.lock",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.taskipy.tasks]
|
|
69
|
+
lint = "ruff check . && yamllint ."
|
|
70
|
+
check_types = "pyright"
|
|
71
|
+
check_fmt = "ruff format --check ."
|
|
72
|
+
fmt = "ruff format . && ruff check . --fix"
|
|
73
|
+
test = "pytest tests -vvv"
|
|
74
|
+
check = "task lint && task check_fmt && task check_types && task test"
|
|
75
|
+
|
|
76
|
+
[tool.pyright]
|
|
77
|
+
pythonVersion = "3.11"
|
|
78
|
+
reportIncompatibleVariableOverride = true
|
|
79
|
+
strictListInference = true
|
|
80
|
+
strictDictionaryInference = true
|
|
81
|
+
strictSetInference = true
|
|
82
|
+
reportUnusedImport = true
|
|
83
|
+
reportDuplicateImport = true
|
|
84
|
+
reportWildcardImportFromLibrary = true
|
|
85
|
+
reportOptionalMemberAccess = true
|
|
86
|
+
reportUntypedBaseClass = true
|
|
87
|
+
reportPrivateUsage = true
|
|
88
|
+
reportUntypedClassDecorator = true
|
|
89
|
+
reportConstantRedefinition = true
|
|
90
|
+
reportInvalidTypeVarUse = true
|
|
91
|
+
reportUnnecessaryIsInstance = true
|
|
92
|
+
reportUnnecessaryCast = true
|
|
93
|
+
reportUnnecessaryComparison = true
|
|
94
|
+
reportAssertAlwaysTrue = true
|
|
95
|
+
reportUnusedCoroutine = true
|
|
96
|
+
|
|
97
|
+
[tool.ruff]
|
|
98
|
+
line-length = 88
|
|
99
|
+
target-version = "py311"
|
|
100
|
+
|
|
101
|
+
[tool.ruff.lint]
|
|
102
|
+
select = ["B", "E", "F"]
|
|
103
|
+
|
|
104
|
+
[tool.ruff.lint.per-file-ignores]
|
|
105
|
+
"pyap/source_*/*" = ["E501", "F522", "W291", "W293"]
|