backrefs 5.8__py313-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.
Files changed (40) hide show
  1. backrefs/__init__.py +2 -0
  2. backrefs/__meta__.py +197 -0
  3. backrefs/_bre_parse.py +1529 -0
  4. backrefs/_bregex_parse.py +1362 -0
  5. backrefs/_bregex_typing.py +6 -0
  6. backrefs/bre.py +652 -0
  7. backrefs/bregex.py +726 -0
  8. backrefs/py.typed +0 -0
  9. backrefs/uniprops/__init__.py +592 -0
  10. backrefs/uniprops/unidata/__init__.py +26 -0
  11. backrefs/uniprops/unidata/age.py +115 -0
  12. backrefs/uniprops/unidata/alias.py +771 -0
  13. backrefs/uniprops/unidata/bidiclass.py +99 -0
  14. backrefs/uniprops/unidata/bidipairedbrackettype.py +19 -0
  15. backrefs/uniprops/unidata/binary.py +331 -0
  16. backrefs/uniprops/unidata/block.py +1323 -0
  17. backrefs/uniprops/unidata/canonicalcombiningclass.py +1031 -0
  18. backrefs/uniprops/unidata/decompositiontype.py +79 -0
  19. backrefs/uniprops/unidata/eastasianwidth.py +31 -0
  20. backrefs/uniprops/unidata/generalcategory.py +173 -0
  21. backrefs/uniprops/unidata/graphemeclusterbreak.py +79 -0
  22. backrefs/uniprops/unidata/hangulsyllabletype.py +31 -0
  23. backrefs/uniprops/unidata/indicpositionalcategory.py +71 -0
  24. backrefs/uniprops/unidata/indicsyllabiccategory.py +151 -0
  25. backrefs/uniprops/unidata/joininggroup.py +423 -0
  26. backrefs/uniprops/unidata/joiningtype.py +31 -0
  27. backrefs/uniprops/unidata/linebreak.py +199 -0
  28. backrefs/uniprops/unidata/numerictype.py +23 -0
  29. backrefs/uniprops/unidata/numericvalue.py +583 -0
  30. backrefs/uniprops/unidata/quickcheck.py +59 -0
  31. backrefs/uniprops/unidata/script.py +667 -0
  32. backrefs/uniprops/unidata/scriptextensions.py +667 -0
  33. backrefs/uniprops/unidata/sentencebreak.py +67 -0
  34. backrefs/uniprops/unidata/verticalorientation.py +23 -0
  35. backrefs/uniprops/unidata/wordbreak.py +99 -0
  36. backrefs/util.py +163 -0
  37. backrefs-5.8.dist-info/METADATA +74 -0
  38. backrefs-5.8.dist-info/RECORD +40 -0
  39. backrefs-5.8.dist-info/WHEEL +4 -0
  40. backrefs-5.8.dist-info/licenses/LICENSE.md +21 -0
backrefs/util.py ADDED
@@ -0,0 +1,163 @@
1
+ """
2
+ Utilities and compatibility abstraction.
3
+
4
+ Licensed under MIT
5
+ Copyright (c) 2015 - 2020 Isaac Muse <isaacmuse@gmail.com>
6
+ """
7
+ from __future__ import annotations
8
+ import warnings
9
+ import sys
10
+ from typing import Any, Callable, AnyStr
11
+
12
+ PY311 = (3, 11) <= sys.version_info
13
+ PY312 = (3, 12) <= sys.version_info
14
+
15
+ FMT_FIELD = 0
16
+ FMT_INDEX = 1
17
+ FMT_ATTR = 2
18
+ FMT_CONV = 3
19
+ FMT_SPEC = 4
20
+
21
+
22
+ class StringIter:
23
+ """Preprocess replace tokens."""
24
+
25
+ def __init__(self, text: str) -> None:
26
+ """Initialize."""
27
+
28
+ self._string = text
29
+ self._index = 0
30
+
31
+ def __iter__(self) -> StringIter:
32
+ """Iterate."""
33
+
34
+ return self
35
+
36
+ def __next__(self) -> str:
37
+ """Python 3 iterator compatible next."""
38
+
39
+ return self.iternext()
40
+
41
+ @property
42
+ def index(self) -> int:
43
+ """Get Index."""
44
+
45
+ return self._index
46
+
47
+ def rewind(self, count: int) -> None:
48
+ """Rewind index."""
49
+
50
+ if count > self._index: # pragma: no cover
51
+ raise ValueError("Can't rewind past beginning!")
52
+
53
+ self._index -= count
54
+
55
+ def iternext(self) -> str:
56
+ """Iterate through characters of the string."""
57
+
58
+ try:
59
+ char = self._string[self._index]
60
+ self._index += 1
61
+ except IndexError as e:
62
+ raise StopIteration from e
63
+
64
+ return char
65
+
66
+
67
+ def _to_bstr(obj: Any) -> bytes:
68
+ """Convert to byte string."""
69
+
70
+ if isinstance(obj, str):
71
+ return obj.encode('ascii', 'backslashreplace')
72
+ elif not isinstance(obj, bytes):
73
+ return str(obj).encode('ascii', 'backslashreplace')
74
+ return obj
75
+
76
+
77
+ def _to_str(obj: Any) -> str:
78
+ """Convert to string."""
79
+
80
+ if not isinstance(obj, str):
81
+ return str(obj)
82
+ return obj
83
+
84
+
85
+ def format_captures(
86
+ captures: list[AnyStr],
87
+ formatting: tuple[tuple[int, Any]],
88
+ converter: Callable[[Any], AnyStr],
89
+ default: AnyStr
90
+ ) -> AnyStr:
91
+ """Perform a string format on a set of captures."""
92
+
93
+ capture = captures # type: Any
94
+ for i, fmt in enumerate(formatting, 0):
95
+ if i == 0:
96
+ continue
97
+ fmt_type, value = fmt
98
+ if fmt_type == FMT_ATTR:
99
+ # Attribute
100
+ capture = getattr(capture, value)
101
+ elif fmt_type == FMT_INDEX:
102
+ # Index
103
+ if value is not None:
104
+ capture = capture[value]
105
+ else:
106
+ capture = default if not capture else capture[0]
107
+ elif fmt_type == FMT_CONV:
108
+ # Conversion
109
+ if value == 'a':
110
+ capture = ascii(capture)
111
+ elif value == 'r':
112
+ capture = repr(capture)
113
+ elif value == 's':
114
+ # If the object is not string or byte string already
115
+ capture = str(capture)
116
+ elif fmt_type == FMT_SPEC:
117
+ # Integers and floats don't have an explicit 's' format type.
118
+ if value[3] and value[3] == 's':
119
+ if isinstance(capture, int): # pragma: no cover
120
+ raise ValueError("Unknown format code 's' for object of type 'int'")
121
+ if isinstance(capture, float): # pragma: no cover
122
+ raise ValueError("Unknown format code 's' for object of type 'float'")
123
+
124
+ # Ensure object is a byte string
125
+ capture = converter(capture)
126
+
127
+ spec_type = value[1]
128
+ if spec_type == '^':
129
+ capture = capture.center(value[2], value[0])
130
+ elif spec_type == ">":
131
+ capture = capture.rjust(value[2], value[0])
132
+ else:
133
+ capture = capture.ljust(value[2], value[0])
134
+
135
+ # Make sure the final object is a byte string
136
+ return converter(capture)
137
+
138
+
139
+ class Immutable:
140
+ """Immutable."""
141
+
142
+ __slots__: tuple[Any, ...] = ()
143
+
144
+ def __init__(self, **kwargs: Any) -> None:
145
+ """Initialize."""
146
+
147
+ for k, v in kwargs.items():
148
+ super().__setattr__(k, v)
149
+
150
+ def __setattr__(self, name: str, value: Any) -> None:
151
+ """Prevent mutability."""
152
+
153
+ raise AttributeError('Class is immutable!')
154
+
155
+
156
+ def warn_deprecated(message: str, stacklevel: int = 2) -> None: # pragma: no cover
157
+ """Warn deprecated."""
158
+
159
+ warnings.warn(
160
+ message,
161
+ category=DeprecationWarning,
162
+ stacklevel=stacklevel
163
+ )
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: backrefs
3
+ Version: 5.8
4
+ Summary: A wrapper around re and regex that adds additional back references.
5
+ Project-URL: Homepage, https://github.com/facelessuser/backrefs
6
+ Author-email: Isaac Muse <Isaac.Muse@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE.md
9
+ Keywords: re,regex
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Provides-Extra: extras
25
+ Requires-Dist: regex; extra == 'extras'
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![Donate via PayPal][donate-image]][donate-link]
29
+ [![Discord][discord-image]][discord-link]
30
+ [![Build][github-ci-image]][github-ci-link]
31
+ [![Coverage Status][codecov-image]][codecov-link]
32
+ [![PyPI Version][pypi-image]][pypi-link]
33
+ [![PyPI Downloads][pypi-down]][pypi-link]
34
+ [![PyPI - Python Version][python-image]][pypi-link]
35
+ ![License][license-image-mit]
36
+
37
+ # Backrefs
38
+
39
+ Backrefs is a wrapper around Python's built-in [Re][re] and the 3rd party [Regex][regex] library. Backrefs adds various
40
+ additional back references (and a couple other features) that are known to some regular expression engines, but not to
41
+ Python's Re and/or Regex. The supported back references actually vary depending on the regular expression engine being
42
+ used as the engine may already have support for some.
43
+
44
+ ```python
45
+ from backrefs import bre
46
+ >>> pattern = bre.compile(r'(\p{Letter}+)')
47
+ >>> pattern.sub(r'\C\1\E', 'sometext')
48
+ 'SOMETEXT'
49
+ ```
50
+
51
+ # Documentation
52
+
53
+ https://facelessuser.github.io/backrefs/
54
+
55
+ # License
56
+
57
+ MIT
58
+
59
+ [github-ci-image]: https://github.com/facelessuser/backrefs/workflows/build/badge.svg?branch=master&event=push
60
+ [github-ci-link]: https://github.com/facelessuser/backrefs/actions?query=workflow%3Abuild+branch%3Amaster
61
+ [discord-image]: https://img.shields.io/discord/678289859768745989?logo=discord&logoColor=aaaaaa&color=mediumpurple&labelColor=333333
62
+ [discord-link]:https://discord.gg/TWs8Tgr
63
+ [codecov-image]: https://img.shields.io/codecov/c/github/facelessuser/backrefs/master.svg?logo=codecov&logoColor=aaaaaa&labelColor=333333
64
+ [codecov-link]: https://codecov.io/github/facelessuser/backrefs
65
+ [pypi-image]: https://img.shields.io/pypi/v/backrefs.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
66
+ [pypi-down]: https://img.shields.io/pypi/dm/backrefs.svg?logo=pypi&logoColor=aaaaaa&labelColor=333333
67
+ [pypi-link]: https://pypi.python.org/pypi/backrefs
68
+ [python-image]: https://img.shields.io/pypi/pyversions/backrefs?logo=python&logoColor=aaaaaa&labelColor=333333
69
+ [license-image-mit]: https://img.shields.io/badge/license-MIT-blue.svg?labelColor=333333
70
+ [donate-image]: https://img.shields.io/badge/Donate-PayPal-3fabd1?logo=paypal
71
+ [donate-link]: https://www.paypal.me/facelessuser
72
+
73
+ [re]: https://docs.python.org/3/library/re.html
74
+ [regex]: https://pypi.python.org/pypi/regex
@@ -0,0 +1,40 @@
1
+ backrefs/__init__.py,sha256=8Qt-anmlWzm-8FEjX1c9xYa47PG8-ccQgWQOAiKA4PM,90
2
+ backrefs/__meta__.py,sha256=mSYqLTsLDPFAUgIjV35jMDcez1NdX9z2ac81kYO0YT4,6766
3
+ backrefs/_bre_parse.py,sha256=w6wONmzAZRTf0sz1pIFGH3fxlpPa-rDutMjEBl8oSx0,52529
4
+ backrefs/_bregex_parse.py,sha256=VGrP76iMRPXiaYo3vKGu9Jq5PFaYOaWUDMg6537N6n4,46436
5
+ backrefs/_bregex_typing.py,sha256=THgf80whbUAJrpKWayEMJx8ixrU5oXwmVaQAa8n0DsQ,236
6
+ backrefs/bre.py,sha256=1NY-n_gcftYTkgdhDgOBGGrWgedBHwygFys1UOutufo,19815
7
+ backrefs/bregex.py,sha256=VHdyZkcoIWcfRlZ4jYfCLTdWhM872wJL7DSwKAe3WFw,20919
8
+ backrefs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ backrefs/util.py,sha256=2qnLiUsB06IKKIdrjWIxYqwUG7OFqtOhafgx23ZwBn8,4285
10
+ backrefs/uniprops/__init__.py,sha256=87ZqdAgKgULgX_SyxRlEXcUsMVOmLY2XqOYqcwYEG-0,20983
11
+ backrefs/uniprops/unidata/__init__.py,sha256=P2_J3AFJMSQLerh7imUYLRlZJFFQjo5FynhEAU3GNlA,992
12
+ backrefs/uniprops/unidata/age.py,sha256=COo7QxVKOqkKWXAEmEyDq1qpDT2OA5seIlHNjRuNGsU,72680
13
+ backrefs/uniprops/unidata/alias.py,sha256=-qkP1PRDi1sT6L2PQ6CPpJuE69k-aIwzV4qBwzCm2jw,23996
14
+ backrefs/uniprops/unidata/bidiclass.py,sha256=YB1sRZFPwSkgI7m5CcDS2dTGr0OlDSfiHeNTzsxfXko,45044
15
+ backrefs/uniprops/unidata/bidipairedbrackettype.py,sha256=iqSaRbzHhZhrx5jHfuRtqkmkb6Gv92RWYi7lvCXP-CY,3226
16
+ backrefs/uniprops/unidata/binary.py,sha256=0PQnH3FONroFTejZUCAvqJRCDV2OAkzPb22hfqr_wHA,416599
17
+ backrefs/uniprops/unidata/block.py,sha256=xYdrPqQNlZFhojRNgM6bRWsULowAf3wxA5bwydCKSX0,58868
18
+ backrefs/uniprops/unidata/canonicalcombiningclass.py,sha256=nnM92VD4NQqM-uhnCLXqdK-2xyFC0KZsJrXYH_N9GpA,37918
19
+ backrefs/uniprops/unidata/decompositiontype.py,sha256=kCOMO35nCv0U4WhEIUUdb2xQ2xJ0RfcfvkFi1WiRk9A,27340
20
+ backrefs/uniprops/unidata/eastasianwidth.py,sha256=RWV0Dpjs-Bw71qU7YWDbROKwb-qaOA28MgsSQQtJ2QY,15385
21
+ backrefs/uniprops/unidata/generalcategory.py,sha256=3Ui8c2Zbf4AKvIM29XWHGDP2FqGpCkLSetqFkdgtRUI,137221
22
+ backrefs/uniprops/unidata/graphemeclusterbreak.py,sha256=4WOJJKOwbAGV2skDB4FsrQ1JIlmKu-qqmQku8xQXTTQ,42409
23
+ backrefs/uniprops/unidata/hangulsyllabletype.py,sha256=7DIE0I2XpGo6FRZD_dMtpQ3734Mgz2vH3dRCO8705Og,16173
24
+ backrefs/uniprops/unidata/indicpositionalcategory.py,sha256=3NxmotJhdMtpENizEb-UWjmCTBRB6mfUjgG5ioBbIFQ,24481
25
+ backrefs/uniprops/unidata/indicsyllabiccategory.py,sha256=9JD-ereOAnPz88j2hugK0orAqeHgdHSSsBz4xG0oQEk,35093
26
+ backrefs/uniprops/unidata/joininggroup.py,sha256=5WnWwxmXUfdQUMJanXAFg6KfCYNVGLhgTQWdWf-92aY,17883
27
+ backrefs/uniprops/unidata/joiningtype.py,sha256=ANJ0uDz4Z1B9OQBEkxFoiyA6Fbyiydez-SQE62lFvlk,24897
28
+ backrefs/uniprops/unidata/linebreak.py,sha256=Hse42kUIocVUT4wvDIiIaSNFUzmI7mI2thQaplnJAEw,93916
29
+ backrefs/uniprops/unidata/numerictype.py,sha256=HA7pTq474mXi5jHlYPSf6Gswfj-uXXsoHtsA0OGktaM,13975
30
+ backrefs/uniprops/unidata/numericvalue.py,sha256=e80mjWWkgf7wdUadas6HFZtsJo0Z6r7McdIBG31mxuE,68897
31
+ backrefs/uniprops/unidata/quickcheck.py,sha256=L8W2OEkTsEgI6xsPJNXESYUxOD2E75-DDq6ZCi9kZFg,47702
32
+ backrefs/uniprops/unidata/script.py,sha256=9SrMpTFDLz2Mzguz5spUYCZuTO-x_fm0Id-RHZDcYGo,68216
33
+ backrefs/uniprops/unidata/scriptextensions.py,sha256=54DWwqAFZ1ELAf6tAG00ry_vAnrI0Of40cB570_TCz8,73306
34
+ backrefs/uniprops/unidata/sentencebreak.py,sha256=9yx3B1vDSiXZy9LW8894dMpxRHU7uamwc5ymXEWUo40,77366
35
+ backrefs/uniprops/unidata/verticalorientation.py,sha256=BslCuQxyLjlrYuaIAWWycbOy2bU7S62NMp27XZAx2JM,6860
36
+ backrefs/uniprops/unidata/wordbreak.py,sha256=11bI8IpBeBZNcKxV8IWo-8BI1WxR6EUWUPPVt_9yWp0,54677
37
+ backrefs-5.8.dist-info/METADATA,sha256=3QKkNWY0pTfQgRv4OEncFpGmObF-yBp7d_lPLwVdirk,3329
38
+ backrefs-5.8.dist-info/WHEEL,sha256=OS2QfsHxY8Lt2DGTbHY6dnHbm1Jjry_zcEe4ga9mbtc,89
39
+ backrefs-5.8.dist-info/licenses/LICENSE.md,sha256=p7PCxDq-7r411h71_GHWySyijC5wKgao9GiyXpQA9dg,1084
40
+ backrefs-5.8.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py313-none-any
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 - 2023 Isaac Muse
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.