python-debian 0.1.48__tar.gz → 1.0.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.
- python-debian-1.0.0/PKG-INFO +57 -0
- {python-debian-0.1.48 → python-debian-1.0.0}/README.rst +6 -6
- python-debian-1.0.0/pyproject.toml +168 -0
- python-debian-1.0.0/src/debian/__init__.py +23 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_arch_table.py +6 -11
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/__init__.py +4 -4
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/_util.py +10 -15
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/formatter.py +17 -20
- python-debian-1.0.0/src/debian/_deb822_repro/locatable.py +349 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/parsing.py +216 -147
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/tokens.py +65 -35
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_util.py +28 -52
- python-debian-1.0.0/src/debian/_version.py +4 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/arfile.py +22 -38
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/changelog.py +57 -86
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/copyright.py +35 -46
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/deb822.py +221 -195
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/debfile.py +97 -56
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/debian_support.py +37 -96
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/debtags.py +29 -106
- python-debian-1.0.0/src/debian/doc-debtags +117 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/substvars.py +13 -16
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/watch.py +13 -22
- python-debian-1.0.0/src/python_debian.egg-info/PKG-INFO +57 -0
- python-debian-1.0.0/src/python_debian.egg-info/SOURCES.txt +29 -0
- python-debian-1.0.0/src/python_debian.egg-info/requires.txt +5 -0
- python-debian-1.0.0/src/python_debian.egg-info/top_level.txt +1 -0
- python-debian-0.1.48/PKG-INFO +0 -28
- python-debian-0.1.48/lib/deb822.py +0 -8
- python-debian-0.1.48/lib/debian/__init__.py +0 -29
- python-debian-0.1.48/lib/debian/_version.py +0 -3
- python-debian-0.1.48/lib/debian/deprecation.py +0 -51
- python-debian-0.1.48/lib/debian_bundle/__init__.py +0 -11
- python-debian-0.1.48/lib/python_debian.egg-info/PKG-INFO +0 -28
- python-debian-0.1.48/lib/python_debian.egg-info/SOURCES.txt +0 -30
- python-debian-0.1.48/lib/python_debian.egg-info/requires.txt +0 -1
- python-debian-0.1.48/lib/python_debian.egg-info/top_level.txt +0 -3
- python-debian-0.1.48/setup.py +0 -68
- {python-debian-0.1.48 → python-debian-1.0.0}/setup.cfg +0 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/_deb822_repro/types.py +0 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/debian/py.typed +0 -0
- {python-debian-0.1.48/lib → python-debian-1.0.0/src}/python_debian.egg-info/dependency_links.txt +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: python-debian
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Modules to read and manipulate many file formats related to Debian packages and repositories
|
|
5
|
+
Author-email: Debian python-debian Maintainers <pkg-python-debian-maint@lists.alioth.debian.org>
|
|
6
|
+
License: GPL-2.0-or-later
|
|
7
|
+
Project-URL: homepage, https://salsa.debian.org/python-debian-team/python-debian
|
|
8
|
+
Keywords: debian,linux,metadata,packages,packaging
|
|
9
|
+
Platform: any
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: DFSG approved
|
|
14
|
+
Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
|
|
15
|
+
Classifier: Operating System :: POSIX
|
|
16
|
+
Requires-Python: >=3.7
|
|
17
|
+
Description-Content-Type: text/x-rst
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
|
|
20
|
+
The `debian` Python modules work with Debian-related data formats,
|
|
21
|
+
providing a means to read data from files involved in Debian packaging,
|
|
22
|
+
and the distribution of Debian packages. The ability to create or edit
|
|
23
|
+
the files is also available for some formats.
|
|
24
|
+
|
|
25
|
+
Currently supported are:
|
|
26
|
+
|
|
27
|
+
* Debtags information (`debian.debtags` module)
|
|
28
|
+
* debian/changelog (`debian.changelog` module)
|
|
29
|
+
* Packages files, pdiffs (`debian.debian_support` module)
|
|
30
|
+
* Control files of single or multiple RFC822-style paragraphs, e.g.
|
|
31
|
+
debian/control, .changes, .dsc, Packages, Sources, Release, etc.
|
|
32
|
+
(`debian.deb822` module)
|
|
33
|
+
* Raw .deb and .ar files, with (read-only) access to contained
|
|
34
|
+
files and meta-information (`debian.debfile` module)
|
|
35
|
+
|
|
36
|
+
`API documentation`_, can be found online and throughout the code. There
|
|
37
|
+
are examples both within the code and in the examples_ directory.
|
|
38
|
+
|
|
39
|
+
.. _API documentation: https://python-debian-team.pages.debian.net/python-debian/html/
|
|
40
|
+
|
|
41
|
+
.. _examples: https://salsa.debian.org/python-debian-team/python-debian/tree/master/examples
|
|
42
|
+
|
|
43
|
+
Note that some modules can use `python-apt`_ to speed up processing.
|
|
44
|
+
|
|
45
|
+
.. _python-apt: https://packages.debian.org/unstable/python3-apt
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Contributions to `python-debian` are most welcome, including expansion of the
|
|
49
|
+
module's capabilities. If you have a module that is for manipulation or
|
|
50
|
+
interrogation of Debian specific data then consider adding it to this package.
|
|
51
|
+
Please discuss your ideas on the `mailing list`_,
|
|
52
|
+
make merge requests via the `salsa repository`_,
|
|
53
|
+
and see the Contributing section of the documentation.
|
|
54
|
+
|
|
55
|
+
.. _mailing list: mailto:pkg-python-debian-maint@lists.alioth.debian.org
|
|
56
|
+
|
|
57
|
+
.. _salsa repository: https://salsa.debian.org/python-debian-team/python-debian
|
|
@@ -5,14 +5,14 @@ the files is also available for some formats.
|
|
|
5
5
|
|
|
6
6
|
Currently supported are:
|
|
7
7
|
|
|
8
|
-
* Debtags information (
|
|
9
|
-
* debian/changelog (
|
|
10
|
-
* Packages files, pdiffs (
|
|
8
|
+
* Debtags information (`debian.debtags` module)
|
|
9
|
+
* debian/changelog (`debian.changelog` module)
|
|
10
|
+
* Packages files, pdiffs (`debian.debian_support` module)
|
|
11
11
|
* Control files of single or multiple RFC822-style paragraphs, e.g.
|
|
12
12
|
debian/control, .changes, .dsc, Packages, Sources, Release, etc.
|
|
13
|
-
(
|
|
13
|
+
(`debian.deb822` module)
|
|
14
14
|
* Raw .deb and .ar files, with (read-only) access to contained
|
|
15
|
-
files and meta-information (
|
|
15
|
+
files and meta-information (`debian.debfile` module)
|
|
16
16
|
|
|
17
17
|
`API documentation`_, can be found online and throughout the code. There
|
|
18
18
|
are examples both within the code and in the examples_ directory.
|
|
@@ -31,7 +31,7 @@ module's capabilities. If you have a module that is for manipulation or
|
|
|
31
31
|
interrogation of Debian specific data then consider adding it to this package.
|
|
32
32
|
Please discuss your ideas on the `mailing list`_,
|
|
33
33
|
make merge requests via the `salsa repository`_,
|
|
34
|
-
and see the
|
|
34
|
+
and see the Contributing section of the documentation.
|
|
35
35
|
|
|
36
36
|
.. _mailing list: mailto:pkg-python-debian-maint@lists.alioth.debian.org
|
|
37
37
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# https://peps.python.org/pep-0517/
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = [
|
|
4
|
+
"setuptools>=61",
|
|
5
|
+
"setuptools_scm[toml]>=6.2",
|
|
6
|
+
"wheel",
|
|
7
|
+
]
|
|
8
|
+
build-backend = "setuptools.build_meta"
|
|
9
|
+
|
|
10
|
+
# https://peps.python.org/pep-0621/
|
|
11
|
+
[project]
|
|
12
|
+
name = "python-debian"
|
|
13
|
+
dynamic = [
|
|
14
|
+
"version",
|
|
15
|
+
]
|
|
16
|
+
description = "Modules to read and manipulate many file formats related to Debian packages and repositories"
|
|
17
|
+
readme = "README.rst"
|
|
18
|
+
requires-python = ">=3.7"
|
|
19
|
+
license = { text = "GPL-2.0-or-later" }
|
|
20
|
+
authors = [
|
|
21
|
+
{name = "Debian python-debian Maintainers", email = "pkg-python-debian-maint@lists.alioth.debian.org"},
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 5 - Production/Stable",
|
|
25
|
+
"Programming Language :: Python",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: DFSG approved",
|
|
28
|
+
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
|
|
29
|
+
"Operating System :: POSIX",
|
|
30
|
+
]
|
|
31
|
+
keywords = ["debian", "linux", "metadata", "packages", "packaging"]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"charset-normalizer",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
homepage = "https://salsa.debian.org/python-debian-team/python-debian"
|
|
38
|
+
|
|
39
|
+
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
test = [
|
|
42
|
+
"pytest",
|
|
43
|
+
"pytest-cov",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
|
|
47
|
+
[tool.setuptools]
|
|
48
|
+
include-package-data = true
|
|
49
|
+
platforms = [ "any" ]
|
|
50
|
+
# packages = [
|
|
51
|
+
# "debian",
|
|
52
|
+
# "debian.tests",
|
|
53
|
+
# "debian._deb822_repro",
|
|
54
|
+
# ]
|
|
55
|
+
|
|
56
|
+
[tool.setuptools.packages.find]
|
|
57
|
+
where = ["src"]
|
|
58
|
+
include = [
|
|
59
|
+
"debian*",
|
|
60
|
+
]
|
|
61
|
+
exclude = [
|
|
62
|
+
"debian/tests",
|
|
63
|
+
]
|
|
64
|
+
namespaces = false
|
|
65
|
+
|
|
66
|
+
[tool.setuptools.package-data]
|
|
67
|
+
"*" = [
|
|
68
|
+
"py.typed",
|
|
69
|
+
"*.pyi",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.setuptools_scm]
|
|
73
|
+
write_to = "src/debian/_version.py"
|
|
74
|
+
# needs setuptools_scm > 8
|
|
75
|
+
# version_file = "debian/_version.py"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# https://docs.pytest.org/en/6.2.x/customize.html
|
|
79
|
+
[tool.pytest.ini_options]
|
|
80
|
+
minversion = "6.0"
|
|
81
|
+
addopts = [
|
|
82
|
+
"--import-mode=prepend",
|
|
83
|
+
# "--cov-report=term-missing",
|
|
84
|
+
# "--cov=src/debian",
|
|
85
|
+
# "--cov=tests",
|
|
86
|
+
"--doctest-modules",
|
|
87
|
+
"-v",
|
|
88
|
+
"-rsx",
|
|
89
|
+
]
|
|
90
|
+
log_level = "DEBUG"
|
|
91
|
+
filterwarnings = [
|
|
92
|
+
]
|
|
93
|
+
testpaths = [
|
|
94
|
+
"src",
|
|
95
|
+
"tests",
|
|
96
|
+
]
|
|
97
|
+
pythonpath = "src"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# https://coverage.readthedocs.io/en/6.4/config.html
|
|
101
|
+
[tool.coverage.run]
|
|
102
|
+
branch = true
|
|
103
|
+
source = [
|
|
104
|
+
"src",
|
|
105
|
+
"tests",
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
[tool.coverage.report]
|
|
109
|
+
exclude_lines = [
|
|
110
|
+
"pragma: no cover",
|
|
111
|
+
"if TYPE_CHECKING:",
|
|
112
|
+
"@overload",
|
|
113
|
+
"except ImportError",
|
|
114
|
+
"if __name__ == .__main__.:",
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# https://mypy.readthedocs.io/en/stable/config_file.html
|
|
120
|
+
[tool.mypy]
|
|
121
|
+
files = [
|
|
122
|
+
"src",
|
|
123
|
+
"tests",
|
|
124
|
+
]
|
|
125
|
+
strict = true
|
|
126
|
+
show_error_codes = true
|
|
127
|
+
pretty = true
|
|
128
|
+
ignore_missing_imports = true
|
|
129
|
+
warn_unused_ignores = false
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
[tool.pylint.main]
|
|
134
|
+
extension-pkg-whitelist = ["apt_pkg"]
|
|
135
|
+
# ignore = ["tests"]
|
|
136
|
+
persistent = false
|
|
137
|
+
|
|
138
|
+
[tool.pylint."messages control"]
|
|
139
|
+
disable = [
|
|
140
|
+
"consider-using-f-string",
|
|
141
|
+
"fixme",
|
|
142
|
+
"invalid-name",
|
|
143
|
+
"locally-disabled",
|
|
144
|
+
"missing-docstring",
|
|
145
|
+
"protected-access",
|
|
146
|
+
"raise-missing-from",
|
|
147
|
+
"super-with-arguments",
|
|
148
|
+
"too-few-public-methods",
|
|
149
|
+
"too-many-ancestors",
|
|
150
|
+
"too-many-boolean-expressions",
|
|
151
|
+
"too-many-branches",
|
|
152
|
+
"too-many-instance-attributes",
|
|
153
|
+
"too-many-arguments",
|
|
154
|
+
"too-many-lines",
|
|
155
|
+
"too-many-locals",
|
|
156
|
+
"too-many-nested-blocks",
|
|
157
|
+
"too-many-positional-arguments",
|
|
158
|
+
"too-many-public-methods",
|
|
159
|
+
"too-many-statements",
|
|
160
|
+
"unsubscriptable-object",
|
|
161
|
+
"useless-object-inheritance",
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
[tool.pylint.reports]
|
|
165
|
+
reports = false
|
|
166
|
+
|
|
167
|
+
[tool.pylint.similarities]
|
|
168
|
+
min-similarity-lines = 999
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
""" Tools for working with Debian-related file formats """
|
|
2
|
+
|
|
3
|
+
__version__ = ""
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
# pylint: disable=no-member
|
|
7
|
+
import debian._version
|
|
8
|
+
__version__ = debian._version.__version__
|
|
9
|
+
|
|
10
|
+
except ImportError:
|
|
11
|
+
try:
|
|
12
|
+
from setuptools_scm import get_version
|
|
13
|
+
__version__ = get_version(root="..")
|
|
14
|
+
except ImportError:
|
|
15
|
+
import warnings
|
|
16
|
+
warnings.warn("_version.py not found and setuptools_scm not installed.")
|
|
17
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
18
|
+
import warnings
|
|
19
|
+
warnings.warn("_version.py not found and setuptools_scm couldn't make a version.\n%s" % e)
|
|
20
|
+
finally:
|
|
21
|
+
# Fake a version string in desperation
|
|
22
|
+
if not __version__:
|
|
23
|
+
__version__ = '0.0.0-unknown'
|
|
@@ -24,12 +24,8 @@ other people. Copyright years imported from the sources.
|
|
|
24
24
|
# along with this program; if not, write to the Free Software
|
|
25
25
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
26
26
|
import os
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
from typing import Iterable, Optional, IO, List, Dict, Union
|
|
30
|
-
from os import PathLike
|
|
31
|
-
except ImportError:
|
|
32
|
-
pass
|
|
27
|
+
from os import PathLike
|
|
28
|
+
from typing import Iterable, Optional, IO, List, Dict, Union
|
|
33
29
|
|
|
34
30
|
import collections.abc
|
|
35
31
|
|
|
@@ -60,8 +56,7 @@ class QuadTupleDpkgArchitecture(_QuadTuple):
|
|
|
60
56
|
return super().__contains__(item)
|
|
61
57
|
|
|
62
58
|
@property
|
|
63
|
-
def is_wildcard(self):
|
|
64
|
-
# type: () -> bool
|
|
59
|
+
def is_wildcard(self) -> bool:
|
|
65
60
|
return any(x == 'any' for x in self)
|
|
66
61
|
|
|
67
62
|
|
|
@@ -400,6 +395,6 @@ class DpkgArchTable:
|
|
|
400
395
|
dpkg_arch = self._dpkg_wildcard_to_tuple(wildcard)
|
|
401
396
|
except KeyError:
|
|
402
397
|
return False
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
398
|
+
|
|
399
|
+
# _dpkg_wildcard_to_tuple falls back to concrete architectures so this can be False
|
|
400
|
+
return dpkg_arch.is_wildcard
|
|
@@ -53,7 +53,7 @@ Compared to debian.deb822
|
|
|
53
53
|
-------------------------
|
|
54
54
|
|
|
55
55
|
The round-trip safe API is primarily useful when your program is editing files
|
|
56
|
-
and the file in question is (likely) to be hand-edited or
|
|
56
|
+
and the file in question is (likely) to be hand-edited or formatted directly by
|
|
57
57
|
human maintainers. This includes files like debian/control and the
|
|
58
58
|
debian/copyright using the "DEP-5" format.
|
|
59
59
|
|
|
@@ -93,14 +93,14 @@ the round-trip safe API. Given the following source text::
|
|
|
93
93
|
... more deskription with a misspelling
|
|
94
94
|
... '''.lstrip() # To remove the leading newline
|
|
95
95
|
>>> # A few definitions to emulate file I/O (would be different in the program)
|
|
96
|
-
>>> import contextlib
|
|
96
|
+
>>> import contextlib, os
|
|
97
97
|
>>> @contextlib.contextmanager
|
|
98
98
|
... def open_input():
|
|
99
99
|
... # Works with and without keepends=True.
|
|
100
100
|
... # Keep the ends here to truly emulate an open file.
|
|
101
101
|
... yield dctrl_input.splitlines(keepends=True)
|
|
102
102
|
>>> def open_output():
|
|
103
|
-
... return open(
|
|
103
|
+
... return open(os.devnull, 'wb')
|
|
104
104
|
|
|
105
105
|
With debian.deb822, your code might look like this::
|
|
106
106
|
|
|
@@ -150,7 +150,7 @@ Deb822ParagraphElement.as_interpreted_dict_view method.
|
|
|
150
150
|
Stability of this API
|
|
151
151
|
---------------------
|
|
152
152
|
|
|
153
|
-
The API is subject to change based on feedback from early
|
|
153
|
+
The API is subject to change based on feedback from early adopters and beta
|
|
154
154
|
testers. That said, the code for valid files is unlikely to change in
|
|
155
155
|
a backwards incompatible way.
|
|
156
156
|
|
|
@@ -5,22 +5,17 @@ import sys
|
|
|
5
5
|
import textwrap
|
|
6
6
|
from abc import ABC
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Type, cast, List, Generic,
|
|
8
|
+
from typing import (
|
|
9
|
+
Optional, Union, Iterable, Callable, TYPE_CHECKING, Iterator,
|
|
10
|
+
Type, cast, List, Generic,
|
|
12
11
|
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_combine_parts_ret_type = Callable[
|
|
17
|
-
[Iterable[Union[TokenOrElement, TE]]],
|
|
18
|
-
Iterable[Union[TokenOrElement, R]]
|
|
19
|
-
]
|
|
20
|
-
except ImportError:
|
|
21
|
-
TYPE_CHECKING = False
|
|
22
|
-
cast = lambda t, v: v
|
|
12
|
+
from debian._util import T
|
|
13
|
+
from debian._deb822_repro.types import TE, R, TokenOrElement
|
|
23
14
|
|
|
15
|
+
_combine_parts_ret_type = Callable[
|
|
16
|
+
[Iterable[Union[TokenOrElement, TE]]],
|
|
17
|
+
Iterable[Union[TokenOrElement, R]]
|
|
18
|
+
]
|
|
24
19
|
|
|
25
20
|
if TYPE_CHECKING:
|
|
26
21
|
from debian._deb822_repro.parsing import Deb822Element
|
|
@@ -254,7 +249,7 @@ def len_check_iterator(content, # type: str
|
|
|
254
249
|
msg = textwrap.dedent("""\
|
|
255
250
|
Value parser did not fully cover the entire line with tokens (
|
|
256
251
|
missing range {covered}..{content_len}). Occurred when parsing "{content}"
|
|
257
|
-
""").format(covered=covered, content_len=content_len,
|
|
252
|
+
""").format(covered=covered, content_len=content_len, content=content)
|
|
258
253
|
raise ValueError(msg)
|
|
259
254
|
msg = textwrap.dedent("""\
|
|
260
255
|
Value parser emitted tokens for more text than was present? Should have
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import operator
|
|
2
|
+
from typing import Iterator, Union
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from typing_extensions import (
|
|
6
|
+
Literal,
|
|
7
|
+
)
|
|
8
|
+
except ImportError:
|
|
9
|
+
pass
|
|
2
10
|
|
|
3
11
|
from debian._deb822_repro._util import BufferingIterator
|
|
4
12
|
from debian._deb822_repro.tokens import Deb822Token
|
|
13
|
+
from debian._deb822_repro.types import TokenOrElement, FormatterCallback
|
|
14
|
+
|
|
5
15
|
|
|
6
16
|
# Consider these "opaque" enum-like values. The actual value was chosen to
|
|
7
17
|
# make repr easier to implement, but they are subject to change.
|
|
@@ -9,12 +19,6 @@ _CONTENT_TYPE_VALUE = "is_value"
|
|
|
9
19
|
_CONTENT_TYPE_COMMENT = "is_comment"
|
|
10
20
|
_CONTENT_TYPE_SEPARATOR = "is_separator"
|
|
11
21
|
|
|
12
|
-
try:
|
|
13
|
-
from typing import Iterator, Union, Literal
|
|
14
|
-
from debian._deb822_repro.types import TokenOrElement, FormatterCallback
|
|
15
|
-
except ImportError:
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
22
|
|
|
19
23
|
class FormatterContentToken(object):
|
|
20
24
|
"""Typed, tagged text for use with the formatting API
|
|
@@ -73,8 +77,7 @@ class FormatterContentToken(object):
|
|
|
73
77
|
return cls(text, _CONTENT_TYPE_VALUE)
|
|
74
78
|
|
|
75
79
|
@property
|
|
76
|
-
def is_comment(self):
|
|
77
|
-
# type: () -> bool
|
|
80
|
+
def is_comment(self) -> bool:
|
|
78
81
|
"""True if this formatter token represent a comment
|
|
79
82
|
|
|
80
83
|
This should be used for determining whether the token is a comment
|
|
@@ -104,8 +107,7 @@ class FormatterContentToken(object):
|
|
|
104
107
|
return self._content_type is _CONTENT_TYPE_COMMENT
|
|
105
108
|
|
|
106
109
|
@property
|
|
107
|
-
def is_value(self):
|
|
108
|
-
# type: () -> bool
|
|
110
|
+
def is_value(self) -> bool:
|
|
109
111
|
"""True if this formatter token represents a semantic value
|
|
110
112
|
|
|
111
113
|
The formatter *MUST* preserve values as-in in its output. It may
|
|
@@ -116,8 +118,7 @@ class FormatterContentToken(object):
|
|
|
116
118
|
return self._content_type is _CONTENT_TYPE_VALUE
|
|
117
119
|
|
|
118
120
|
@property
|
|
119
|
-
def is_separator(self):
|
|
120
|
-
# type: () -> bool
|
|
121
|
+
def is_separator(self) -> bool:
|
|
121
122
|
"""True if this formatter token represents a separator token
|
|
122
123
|
|
|
123
124
|
The formatter is not required to preserve the provided separators but it
|
|
@@ -133,14 +134,12 @@ class FormatterContentToken(object):
|
|
|
133
134
|
return self._content_type is _CONTENT_TYPE_SEPARATOR
|
|
134
135
|
|
|
135
136
|
@property
|
|
136
|
-
def is_whitespace(self):
|
|
137
|
-
# type: () -> bool
|
|
137
|
+
def is_whitespace(self) -> bool:
|
|
138
138
|
"""True if this formatter token represents a whitespace token"""
|
|
139
139
|
return self._content_type is _CONTENT_TYPE_SEPARATOR and self._text.isspace()
|
|
140
140
|
|
|
141
141
|
@property
|
|
142
|
-
def text(self):
|
|
143
|
-
# type: () -> str
|
|
142
|
+
def text(self) -> str:
|
|
144
143
|
"""The actual context of the token
|
|
145
144
|
|
|
146
145
|
This field *must not* be used to determine the type of token. The
|
|
@@ -156,12 +155,10 @@ class FormatterContentToken(object):
|
|
|
156
155
|
"""
|
|
157
156
|
return self._text
|
|
158
157
|
|
|
159
|
-
def __str__(self):
|
|
160
|
-
# type: () -> str
|
|
158
|
+
def __str__(self) -> str:
|
|
161
159
|
return self._text
|
|
162
160
|
|
|
163
|
-
def __repr__(self):
|
|
164
|
-
# type: () -> str
|
|
161
|
+
def __repr__(self) -> str:
|
|
165
162
|
return "{}({!r}, {}=True)".format(self.__class__.__name__, self._text, self._content_type)
|
|
166
163
|
|
|
167
164
|
|