preparse 1.1.5__tar.gz → 1.1.7__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.
- {preparse-1.1.5 → preparse-1.1.7}/PKG-INFO +2 -2
- {preparse-1.1.5 → preparse-1.1.7}/docs/v1.1.rst +1 -1
- {preparse-1.1.5 → preparse-1.1.7}/pyproject.toml +3 -3
- preparse-1.1.7/src/preparse/__init__.py +16 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Bundle.py +2 -3
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Item.py +3 -5
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Long.py +1 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Option.py +12 -15
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Positional.py +3 -4
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/Special.py +1 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_processing/__init__.py +8 -9
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_processing/deparsing.py +0 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_processing/digesting.py +2 -3
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_processing/parsing.py +13 -8
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_tests/expit.py +1 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/core/Click.py +1 -1
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/core/Optdict.py +11 -6
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/core/PreParser.py +97 -45
- preparse-1.1.7/src/preparse/enums/BaseEnum.py +10 -0
- preparse-1.1.7/src/preparse/enums/Nargs.py +9 -0
- preparse-1.1.7/src/preparse/enums/Tuning.py +9 -0
- preparse-1.1.7/src/preparse/enums/__init__.py +4 -0
- preparse-1.1.7/src/preparse/py.typed +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/test_data_toml.py +2 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/test_enums.py +1 -1
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/test_expit_toml.py +0 -1
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/test_optdict.py +0 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/test_preparser.py +0 -2
- preparse-1.1.7/src/preparse/warnings/PreparseAmbiguousOptionWarning.py +40 -0
- preparse-1.1.7/src/preparse/warnings/PreparseDualWarning.py +42 -0
- preparse-1.1.7/src/preparse/warnings/PreparseInvalidOptionWarning.py +16 -0
- preparse-1.1.7/src/preparse/warnings/PreparseLongonlyWarning.py +7 -0
- preparse-1.1.7/src/preparse/warnings/PreparseRequiredArgumentWarning.py +16 -0
- preparse-1.1.7/src/preparse/warnings/PreparseUnallowedArgumentWarning.py +21 -0
- preparse-1.1.7/src/preparse/warnings/PreparseWarning.py +65 -0
- preparse-1.1.7/src/preparse/warnings/__init__.py +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse.egg-info/PKG-INFO +2 -2
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse.egg-info/SOURCES.txt +13 -5
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse.egg-info/requires.txt +1 -1
- preparse-1.1.5/src/preparse/__init__.py +0 -2
- preparse-1.1.5/src/preparse/_utils/__init__.py +0 -1
- preparse-1.1.5/src/preparse/_utils/dataprop.py +0 -21
- preparse-1.1.5/src/preparse/core/__init__.py +0 -5
- preparse-1.1.5/src/preparse/core/enums.py +0 -31
- preparse-1.1.5/src/preparse/core/warnings.py +0 -148
- {preparse-1.1.5 → preparse-1.1.7}/LICENSE.txt +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/MANIFEST.in +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/README.rst +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/docs/v1.0.rst +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/setup.cfg +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_items/__init__.py +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_processing/pulling.py +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/_tests/__init__.py +0 -0
- /preparse-1.1.5/src/preparse/py.typed → /preparse-1.1.7/src/preparse/core/__init__.py +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/__init__.py +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/data.toml +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse/tests/expit.toml +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-1.1.5 → preparse-1.1.7}/src/preparse.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: preparse
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.7
|
|
4
4
|
Summary: This project preparses args for further parsing later on.
|
|
5
5
|
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -24,7 +24,7 @@ Requires-Dist: copyable<2,>=1.1
|
|
|
24
24
|
Requires-Dist: datahold<4,>=3.0
|
|
25
25
|
Requires-Dist: datarepr<2,>=1.2
|
|
26
26
|
Requires-Dist: frozendict<3,>=2.4.7
|
|
27
|
-
Requires-Dist: setdoc<2,>=1.3
|
|
27
|
+
Requires-Dist: setdoc<2,>=1.3.11
|
|
28
28
|
Requires-Dist: tofunc<2,>=1.1
|
|
29
29
|
Dynamic: license-file
|
|
30
30
|
|
|
@@ -24,7 +24,7 @@ dependencies = [
|
|
|
24
24
|
"datahold>=3.0,<4",
|
|
25
25
|
"datarepr>=1.2,<2",
|
|
26
26
|
"frozendict>=2.4.7,<3",
|
|
27
|
-
"setdoc>=1.3,<2",
|
|
27
|
+
"setdoc>=1.3.11,<2",
|
|
28
28
|
"tofunc>=1.1,<2",
|
|
29
29
|
]
|
|
30
30
|
description = "This project preparses args for further parsing later on."
|
|
@@ -36,7 +36,7 @@ license-files = [
|
|
|
36
36
|
name = "preparse"
|
|
37
37
|
readme = "README.rst"
|
|
38
38
|
requires-python = ">=3.11"
|
|
39
|
-
version = "1.1.
|
|
39
|
+
version = "1.1.7"
|
|
40
40
|
|
|
41
41
|
[project.urls]
|
|
42
42
|
Download = "https://pypi.org/project/preparse/#files"
|
|
@@ -49,4 +49,4 @@ files = [
|
|
|
49
49
|
".",
|
|
50
50
|
]
|
|
51
51
|
python_version = "3.11"
|
|
52
|
-
strict =
|
|
52
|
+
strict = true
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from preparse.core.PreParser import PreParser
|
|
2
|
+
from preparse.enums.Nargs import Nargs
|
|
3
|
+
from preparse.enums.Tuning import Tuning
|
|
4
|
+
from preparse.warnings.PreparseAmbiguousOptionWarning import (
|
|
5
|
+
PreparseAmbiguousOptionWarning,
|
|
6
|
+
)
|
|
7
|
+
from preparse.warnings.PreparseInvalidOptionWarning import (
|
|
8
|
+
PreparseInvalidOptionWarning,
|
|
9
|
+
)
|
|
10
|
+
from preparse.warnings.PreparseRequiredArgumentWarning import (
|
|
11
|
+
PreparseRequiredArgumentWarning,
|
|
12
|
+
)
|
|
13
|
+
from preparse.warnings.PreparseUnallowedArgumentWarning import (
|
|
14
|
+
PreparseUnallowedArgumentWarning,
|
|
15
|
+
)
|
|
16
|
+
from preparse.warnings.PreparseWarning import PreparseWarning
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any, Optional, Self
|
|
2
2
|
|
|
3
3
|
import setdoc
|
|
4
4
|
|
|
5
|
-
from preparse._items.Item import Item
|
|
6
5
|
from preparse._items.Option import Option
|
|
7
|
-
from preparse.
|
|
6
|
+
from preparse.enums.Nargs import Nargs
|
|
8
7
|
|
|
9
8
|
__all__ = ["Bundle"]
|
|
10
9
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import abc
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Any, Self
|
|
3
3
|
|
|
4
4
|
import setdoc
|
|
5
5
|
from copyable import Copyable
|
|
6
6
|
|
|
7
|
-
from preparse.core.enums import *
|
|
8
|
-
|
|
9
7
|
__all__ = ["Item"]
|
|
10
8
|
|
|
11
9
|
|
|
@@ -29,9 +27,9 @@ class Item(Copyable):
|
|
|
29
27
|
|
|
30
28
|
@classmethod
|
|
31
29
|
@abc.abstractmethod
|
|
32
|
-
def sortkey(cls: type) -> int: ...
|
|
30
|
+
def sortkey(cls: type[Self]) -> int: ...
|
|
33
31
|
|
|
34
|
-
def todict(self: Self) -> dict:
|
|
32
|
+
def todict(self: Self) -> dict[str, Any]:
|
|
35
33
|
"This method returns a dict representing the current instance."
|
|
36
34
|
ans: dict[str, Any]
|
|
37
35
|
x: str
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import operator
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Optional, Self, SupportsIndex
|
|
3
3
|
|
|
4
4
|
from preparse._items.Item import Item
|
|
5
|
-
from preparse.
|
|
5
|
+
from preparse.enums.Nargs import Nargs
|
|
6
6
|
|
|
7
7
|
__all__ = ["Option"]
|
|
8
8
|
|
|
@@ -11,9 +11,9 @@ class Option(Item):
|
|
|
11
11
|
|
|
12
12
|
__slots__ = ()
|
|
13
13
|
|
|
14
|
-
_joined:
|
|
15
|
-
_nargs:
|
|
16
|
-
_right:
|
|
14
|
+
_joined: bool
|
|
15
|
+
_nargs: Nargs
|
|
16
|
+
_right: Optional[str]
|
|
17
17
|
|
|
18
18
|
def ishungry(self: Self) -> bool:
|
|
19
19
|
return (self.right is None) and (self.nargs == Nargs.REQUIRED_ARGUMENT)
|
|
@@ -23,28 +23,25 @@ class Option(Item):
|
|
|
23
23
|
return self._joined
|
|
24
24
|
|
|
25
25
|
@joined.setter
|
|
26
|
-
def joined(self: Self, x: SupportsIndex) -> None:
|
|
27
|
-
self._joined = bool(operator.index(x))
|
|
26
|
+
def joined(self: Self, x: SupportsIndex, /) -> None:
|
|
27
|
+
self._joined = bool(operator.index(x)) # type: ignore[misc]
|
|
28
28
|
|
|
29
29
|
@property
|
|
30
30
|
def nargs(self: Self) -> Nargs:
|
|
31
31
|
return self._nargs
|
|
32
32
|
|
|
33
33
|
@nargs.setter
|
|
34
|
-
def nargs(self: Self, x:
|
|
35
|
-
self._nargs = Nargs(x)
|
|
34
|
+
def nargs(self: Self, x: int, /) -> None:
|
|
35
|
+
self._nargs = Nargs(x) # type: ignore[misc]
|
|
36
36
|
|
|
37
37
|
@property
|
|
38
38
|
def right(self: Self) -> Optional[str]:
|
|
39
39
|
return self._right
|
|
40
40
|
|
|
41
41
|
@right.setter
|
|
42
|
-
def right(self: Self, x:
|
|
43
|
-
if x is None:
|
|
44
|
-
self._right = None
|
|
45
|
-
else:
|
|
46
|
-
self._right = str(x)
|
|
42
|
+
def right(self: Self, x: object, /) -> None:
|
|
43
|
+
self._right = None if x is None else str(x) # type: ignore[misc]
|
|
47
44
|
|
|
48
45
|
@classmethod
|
|
49
|
-
def sortkey(cls: type) -> int:
|
|
46
|
+
def sortkey(cls: type[Self]) -> int:
|
|
50
47
|
return 0
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any, Self
|
|
2
2
|
|
|
3
3
|
import setdoc
|
|
4
4
|
|
|
5
5
|
from preparse._items.Item import Item
|
|
6
|
-
from preparse.core.enums import *
|
|
7
6
|
|
|
8
7
|
__all__ = ["Positional"]
|
|
9
8
|
|
|
@@ -27,7 +26,7 @@ class Positional(Item):
|
|
|
27
26
|
return self.value == "-" or not self.value.startswith("-")
|
|
28
27
|
|
|
29
28
|
@classmethod
|
|
30
|
-
def sortkey(cls: type) -> int:
|
|
29
|
+
def sortkey(cls: type[Self]) -> int:
|
|
31
30
|
return 2
|
|
32
31
|
|
|
33
32
|
@property
|
|
@@ -35,5 +34,5 @@ class Positional(Item):
|
|
|
35
34
|
return self._value
|
|
36
35
|
|
|
37
36
|
@value.setter
|
|
38
|
-
def value(self: Self, x:
|
|
37
|
+
def value(self: Self, x: object) -> None:
|
|
39
38
|
self._value = str(x)
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from collections.abc import Iterable
|
|
2
2
|
from types import FunctionType
|
|
3
|
-
from typing import Optional
|
|
3
|
+
from typing import Any, Optional
|
|
4
4
|
|
|
5
|
-
from preparse._items import
|
|
6
|
-
from preparse._processing.deparsing import
|
|
7
|
-
from preparse._processing.digesting import
|
|
8
|
-
from preparse._processing.parsing import
|
|
9
|
-
from preparse._processing.pulling import
|
|
10
|
-
from preparse.
|
|
11
|
-
from preparse.core.enums import *
|
|
5
|
+
from preparse._items.Item import Item
|
|
6
|
+
from preparse._processing.deparsing import deparse
|
|
7
|
+
from preparse._processing.digesting import digest
|
|
8
|
+
from preparse._processing.parsing import parse
|
|
9
|
+
from preparse._processing.pulling import pull
|
|
10
|
+
from preparse.enums.Tuning import Tuning
|
|
12
11
|
|
|
13
12
|
__all__ = ["process"]
|
|
14
13
|
|
|
@@ -22,7 +21,7 @@ def process(
|
|
|
22
21
|
expandsabbr: bool,
|
|
23
22
|
expectsabbr: bool,
|
|
24
23
|
expectsposix: bool,
|
|
25
|
-
optdict: dict,
|
|
24
|
+
optdict: dict[Any, Any],
|
|
26
25
|
prog: str,
|
|
27
26
|
reconcilesorders: bool,
|
|
28
27
|
special: Tuning,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
from preparse._items.Bundle import Bundle
|
|
4
4
|
from preparse._items.Item import Item
|
|
@@ -6,8 +6,7 @@ from preparse._items.Long import Long
|
|
|
6
6
|
from preparse._items.Option import Option
|
|
7
7
|
from preparse._items.Positional import Positional
|
|
8
8
|
from preparse._items.Special import Special
|
|
9
|
-
from preparse.
|
|
10
|
-
from preparse.core.warnings import *
|
|
9
|
+
from preparse.enums.Tuning import Tuning
|
|
11
10
|
|
|
12
11
|
__all__ = ["digest"]
|
|
13
12
|
|
|
@@ -6,18 +6,23 @@ from preparse._items.Bundle import Bundle
|
|
|
6
6
|
from preparse._items.Item import Item
|
|
7
7
|
from preparse._items.Long import Long
|
|
8
8
|
from preparse._items.Option import Option
|
|
9
|
-
from preparse._items.Positional import Positional
|
|
10
9
|
from preparse._items.Special import Special
|
|
11
|
-
from preparse.
|
|
12
|
-
from preparse.
|
|
10
|
+
from preparse.enums.Nargs import Nargs
|
|
11
|
+
from preparse.warnings.PreparseAmbiguousOptionWarning import (
|
|
12
|
+
PreparseAmbiguousOptionWarning as PAOW,
|
|
13
|
+
)
|
|
14
|
+
from preparse.warnings.PreparseInvalidOptionWarning import (
|
|
15
|
+
PreparseInvalidOptionWarning as PIOW,
|
|
16
|
+
)
|
|
17
|
+
from preparse.warnings.PreparseRequiredArgumentWarning import (
|
|
18
|
+
PreparseRequiredArgumentWarning as PRAW,
|
|
19
|
+
)
|
|
20
|
+
from preparse.warnings.PreparseUnallowedArgumentWarning import (
|
|
21
|
+
PreparseUnallowedArgumentWarning as PUAW,
|
|
22
|
+
)
|
|
13
23
|
|
|
14
24
|
__all__ = ["parse"]
|
|
15
25
|
|
|
16
|
-
PAOW = warnings.PreparseAmbiguousOptionWarning
|
|
17
|
-
PIOW = warnings.PreparseInvalidOptionWarning
|
|
18
|
-
PUAW = warnings.PreparseUnallowedArgumentWarning
|
|
19
|
-
PRAW = warnings.PreparseRequiredArgumentWarning
|
|
20
|
-
|
|
21
26
|
|
|
22
27
|
def parse(args: list[Item], **kwargs: Any) -> list[Item]:
|
|
23
28
|
return list(parse_generator(args, **kwargs))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Hashable
|
|
2
|
-
from typing import Any, Optional, Self
|
|
2
|
+
from typing import Any, Optional, Self, cast
|
|
3
3
|
|
|
4
4
|
import cmp3
|
|
5
5
|
import datahold
|
|
@@ -7,7 +7,7 @@ import setdoc
|
|
|
7
7
|
from datarepr import datarepr
|
|
8
8
|
from frozendict import frozendict
|
|
9
9
|
|
|
10
|
-
from preparse.
|
|
10
|
+
from preparse.enums.Nargs import Nargs
|
|
11
11
|
|
|
12
12
|
__all__ = ["Optdict"]
|
|
13
13
|
|
|
@@ -27,9 +27,14 @@ class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
|
27
27
|
@setdoc.basic
|
|
28
28
|
def __cmp__(self: Self, other: Any, /) -> Optional[int]:
|
|
29
29
|
if type(self) is type(other):
|
|
30
|
-
return
|
|
30
|
+
return cast(
|
|
31
|
+
Optional[int],
|
|
32
|
+
cmp3.cmp(self._data, other._data, mode="eq_strict"),
|
|
33
|
+
)
|
|
31
34
|
else:
|
|
32
|
-
return
|
|
35
|
+
return cast(
|
|
36
|
+
Optional[int], cmp3.cmp(self._data, other, mode="eq_strict")
|
|
37
|
+
)
|
|
33
38
|
|
|
34
39
|
__format__ = object.__format__
|
|
35
40
|
|
|
@@ -50,8 +55,8 @@ class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
|
50
55
|
@data.setter
|
|
51
56
|
def data(self: Self, value: Any) -> None:
|
|
52
57
|
a: frozendict[Hashable, object]
|
|
53
|
-
x: map
|
|
54
|
-
y: map
|
|
58
|
+
x: map[str]
|
|
59
|
+
y: map[Nargs]
|
|
55
60
|
a = frozendict(value)
|
|
56
61
|
x = map(str, a.keys())
|
|
57
62
|
y = map(nargs, a.values())
|
|
@@ -8,15 +8,15 @@ from typing import Any, Optional, Self, cast
|
|
|
8
8
|
import click as cl
|
|
9
9
|
import setdoc
|
|
10
10
|
from copyable import Copyable
|
|
11
|
-
from datarepr import datarepr
|
|
12
|
-
from tofunc import tofunc
|
|
11
|
+
from datarepr import datarepr
|
|
12
|
+
from tofunc import tofunc
|
|
13
13
|
|
|
14
|
-
from preparse._processing import
|
|
15
|
-
from preparse._utils.dataprop import dataprop
|
|
14
|
+
from preparse._processing import process
|
|
16
15
|
from preparse.core.Click import Click
|
|
17
|
-
from preparse.core.enums import *
|
|
18
16
|
from preparse.core.Optdict import Optdict
|
|
19
|
-
from preparse.
|
|
17
|
+
from preparse.enums.Nargs import Nargs
|
|
18
|
+
from preparse.enums.Tuning import Tuning
|
|
19
|
+
from preparse.warnings.PreparseWarning import PreparseWarning
|
|
20
20
|
|
|
21
21
|
__all__ = ["PreParser"]
|
|
22
22
|
|
|
@@ -36,7 +36,7 @@ class PreParser(Copyable):
|
|
|
36
36
|
expectsabbr: Any = True,
|
|
37
37
|
expectsposix: Any = False,
|
|
38
38
|
optdict: Any = (),
|
|
39
|
-
prog:
|
|
39
|
+
prog: object = None,
|
|
40
40
|
reconcilesorders: Any = True,
|
|
41
41
|
special: Any = Tuning.MAINTAIN,
|
|
42
42
|
warn: Callable = str, # type: ignore[type-arg]
|
|
@@ -59,18 +59,31 @@ class PreParser(Copyable):
|
|
|
59
59
|
def __repr__(self: Self) -> str:
|
|
60
60
|
return datarepr(type(self).__name__, **self.todict())
|
|
61
61
|
|
|
62
|
-
@
|
|
63
|
-
def allowslong(self: Self
|
|
64
|
-
return bool
|
|
62
|
+
@property
|
|
63
|
+
def allowslong(self: Self) -> bool:
|
|
64
|
+
return cast(bool, self._data["allowslong"])
|
|
65
65
|
|
|
66
|
-
@
|
|
67
|
-
def
|
|
68
|
-
|
|
66
|
+
@allowslong.setter
|
|
67
|
+
def allowslong(self: Self, value: Any) -> None:
|
|
68
|
+
self._data["allowslong"] = bool(value)
|
|
69
69
|
|
|
70
|
-
@
|
|
71
|
-
def
|
|
70
|
+
@property
|
|
71
|
+
def allowsshort(self: Self) -> bool:
|
|
72
|
+
return cast(bool, self._data["allowsshort"])
|
|
73
|
+
|
|
74
|
+
@allowsshort.setter
|
|
75
|
+
def allowsshort(self: Self, value: Any) -> None:
|
|
76
|
+
self._data["allowsshort"] = bool(value)
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def bundling(self: Self) -> Tuning:
|
|
80
|
+
"This property decides how to approach the bundling of short options."
|
|
81
|
+
return cast(Tuning, self._data["bundling"])
|
|
82
|
+
|
|
83
|
+
@bundling.setter
|
|
84
|
+
def bundling(self: Self, value: int) -> None:
|
|
72
85
|
"This property decides how to approach the bundling of short options."
|
|
73
|
-
|
|
86
|
+
self._data["bundling"] = Tuning(value)
|
|
74
87
|
|
|
75
88
|
def click(self: Self, cmd: Any = True, ctx: Any = True) -> Click:
|
|
76
89
|
"This method returns a decorator that infuses the current instance into parse_args."
|
|
@@ -80,31 +93,49 @@ class PreParser(Copyable):
|
|
|
80
93
|
def copy(self: Self) -> Self:
|
|
81
94
|
return type(self)(**self.todict())
|
|
82
95
|
|
|
83
|
-
@
|
|
84
|
-
def expandsabbr(self: Self
|
|
85
|
-
return bool
|
|
96
|
+
@property
|
|
97
|
+
def expandsabbr(self: Self) -> bool:
|
|
98
|
+
return cast(bool, self._data["expandsabbr"])
|
|
99
|
+
|
|
100
|
+
@expandsabbr.setter
|
|
101
|
+
def expandsabbr(self: Self, value: Any, /) -> None:
|
|
102
|
+
self._data["expandsabbr"] = bool(value)
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def expectsabbr(self: Self) -> bool:
|
|
106
|
+
return cast(bool, self._data["expectsabbr"])
|
|
86
107
|
|
|
87
|
-
@
|
|
88
|
-
def expectsabbr(self: Self, value: Any) ->
|
|
89
|
-
|
|
108
|
+
@expectsabbr.setter
|
|
109
|
+
def expectsabbr(self: Self, value: Any) -> None:
|
|
110
|
+
self._data["expectsabbr"] = bool(value)
|
|
90
111
|
|
|
91
|
-
@
|
|
92
|
-
def expectsposix(self: Self
|
|
112
|
+
@property
|
|
113
|
+
def expectsposix(self: Self) -> bool:
|
|
114
|
+
return cast(bool, self._data["expectsposix"])
|
|
115
|
+
|
|
116
|
+
@expectsposix.setter
|
|
117
|
+
def expectsposix(self: Self, value: Any) -> None:
|
|
118
|
+
value_: Any
|
|
93
119
|
if value == "infer":
|
|
94
|
-
|
|
120
|
+
value_ = os.environ.get("POSIXLY_CORRECT")
|
|
95
121
|
else:
|
|
96
|
-
|
|
122
|
+
value_ = value
|
|
123
|
+
self._data["expectsposix"] = bool(value_)
|
|
124
|
+
|
|
125
|
+
@property
|
|
126
|
+
def optdict(self: Self) -> Optdict:
|
|
127
|
+
"This property gives a dictionary of options."
|
|
128
|
+
return cast(Optdict, self._data["optdict"])
|
|
97
129
|
|
|
98
|
-
@
|
|
99
|
-
def optdict(self: Self, value: Any) ->
|
|
130
|
+
@optdict.setter
|
|
131
|
+
def optdict(self: Self, value: Any) -> None:
|
|
100
132
|
"This property gives a dictionary of options."
|
|
101
|
-
|
|
133
|
+
value_: Optdict
|
|
102
134
|
if "optdict" not in self._data.keys():
|
|
103
135
|
self._data["optdict"] = Optdict()
|
|
104
|
-
|
|
136
|
+
value_ = Optdict(value)
|
|
105
137
|
self._data["optdict"].clear()
|
|
106
|
-
self._data["optdict"].update(
|
|
107
|
-
return cast(Optdict, self._data["optdict"])
|
|
138
|
+
self._data["optdict"].update(value_)
|
|
108
139
|
|
|
109
140
|
def parse_args(
|
|
110
141
|
self: Self,
|
|
@@ -113,17 +144,26 @@ class PreParser(Copyable):
|
|
|
113
144
|
"This method parses args."
|
|
114
145
|
return process(args, **self.todict())
|
|
115
146
|
|
|
116
|
-
@
|
|
117
|
-
def prog(self: Self
|
|
147
|
+
@property
|
|
148
|
+
def prog(self: Self) -> str:
|
|
149
|
+
"This property represents the name of the program."
|
|
150
|
+
return cast(str, self._data["prog"])
|
|
151
|
+
|
|
152
|
+
@prog.setter
|
|
153
|
+
def prog(self: Self, value: object, /) -> None:
|
|
118
154
|
"This property represents the name of the program."
|
|
119
155
|
if value is None:
|
|
120
|
-
|
|
156
|
+
self._data["prog"] = str(os.path.basename(sys.argv[0]))
|
|
121
157
|
else:
|
|
122
|
-
|
|
158
|
+
self._data["prog"] = str(value)
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def reconcilesorders(self: Self) -> bool:
|
|
162
|
+
return cast(bool, self._data["reconcilesorders"])
|
|
123
163
|
|
|
124
|
-
@
|
|
125
|
-
def reconcilesorders(self: Self, value: Any) ->
|
|
126
|
-
|
|
164
|
+
@reconcilesorders.setter
|
|
165
|
+
def reconcilesorders(self: Self, value: Any, /) -> None:
|
|
166
|
+
self._data["reconcilesorders"] = bool(value)
|
|
127
167
|
|
|
128
168
|
def reflectClickCommand(self: Self, cmd: cl.Command) -> None:
|
|
129
169
|
"This method causes the current instance to reflect a click.Command object."
|
|
@@ -150,10 +190,15 @@ class PreParser(Copyable):
|
|
|
150
190
|
"This method causes the current instance to reflect a click.Context object."
|
|
151
191
|
self.prog = ctx.info_name
|
|
152
192
|
|
|
153
|
-
@
|
|
154
|
-
def special(self: Self
|
|
193
|
+
@property
|
|
194
|
+
def special(self: Self) -> Tuning:
|
|
195
|
+
"This Tuning property determines the approach towards the special argument."
|
|
196
|
+
return cast(Tuning, self._data["special"])
|
|
197
|
+
|
|
198
|
+
@special.setter
|
|
199
|
+
def special(self: Self, value: int, /) -> None:
|
|
155
200
|
"This Tuning property determines the approach towards the special argument."
|
|
156
|
-
|
|
201
|
+
self._data["special"] = Tuning(value)
|
|
157
202
|
|
|
158
203
|
def todict(self: Self) -> dict[str, Any]:
|
|
159
204
|
"This method returns a dict representing the current instance."
|
|
@@ -166,10 +211,17 @@ class PreParser(Copyable):
|
|
|
166
211
|
else:
|
|
167
212
|
return dict(ans)
|
|
168
213
|
|
|
169
|
-
@
|
|
214
|
+
@property
|
|
170
215
|
def warn(
|
|
171
216
|
self: Self,
|
|
172
|
-
value: Callable[[PreparseWarning], Any],
|
|
173
217
|
) -> Callable[[PreparseWarning], Any]:
|
|
174
218
|
"This property gives a function that takes in the warnings."
|
|
175
|
-
return
|
|
219
|
+
return cast(Callable[[PreparseWarning], Any], self._data["warn"])
|
|
220
|
+
|
|
221
|
+
@warn.setter
|
|
222
|
+
def warn(
|
|
223
|
+
self: Self,
|
|
224
|
+
value: Callable[[PreparseWarning], Any],
|
|
225
|
+
) -> None:
|
|
226
|
+
"This property gives a function that takes in the warnings."
|
|
227
|
+
self._data["warn"] = tofunc(value)
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from typing import Any, Self, cast
|
|
3
|
+
|
|
4
|
+
import setdoc
|
|
5
|
+
|
|
6
|
+
from preparse.warnings.PreparseLongonlyWarning import PreparseLongonlyWarning
|
|
7
|
+
|
|
8
|
+
__all__ = ["PreparseAmbiguousOptionWarning"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
|
|
12
|
+
|
|
13
|
+
@setdoc.basic
|
|
14
|
+
def __post_init__(
|
|
15
|
+
self: Self,
|
|
16
|
+
*,
|
|
17
|
+
prog: Any,
|
|
18
|
+
option: Any,
|
|
19
|
+
possibilities: Iterable[object],
|
|
20
|
+
) -> None:
|
|
21
|
+
self.prog = prog
|
|
22
|
+
self.option = option
|
|
23
|
+
self.possibilities = possibilities
|
|
24
|
+
|
|
25
|
+
def getmsg(self: Self) -> str:
|
|
26
|
+
"This method returns the core message."
|
|
27
|
+
ans: str
|
|
28
|
+
x: Any
|
|
29
|
+
ans = "option '%s' is ambiguous; possibilities:" % self.option
|
|
30
|
+
for x in self.possibilities:
|
|
31
|
+
ans += " '%s'" % x
|
|
32
|
+
return ans
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def possibilities(self: Self) -> tuple[str, ...]:
|
|
36
|
+
return cast(tuple[str, ...], self._data["possibilities"])
|
|
37
|
+
|
|
38
|
+
@possibilities.setter
|
|
39
|
+
def possibilities(self: Self, value: Iterable[object]) -> None:
|
|
40
|
+
self._data["possibilities"] = tuple(map(str, value))
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Any, Self, cast
|
|
3
|
+
|
|
4
|
+
import setdoc
|
|
5
|
+
|
|
6
|
+
from preparse.warnings.PreparseWarning import PreparseWarning
|
|
7
|
+
|
|
8
|
+
__all__ = ["PreparseDualWarning"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PreparseDualWarning(PreparseWarning):
|
|
12
|
+
|
|
13
|
+
@setdoc.basic
|
|
14
|
+
def __post_init__(
|
|
15
|
+
self: Self, *, prog: Any, option: Any, islong: Any
|
|
16
|
+
) -> None:
|
|
17
|
+
self.prog = prog
|
|
18
|
+
self.option = option
|
|
19
|
+
self.islong = islong
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def _longmsg(cls: type[Self]) -> str: ...
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def _shortmsg(cls: type[Self]) -> str: ...
|
|
28
|
+
|
|
29
|
+
def getmsg(self: Self) -> str:
|
|
30
|
+
"This method returns the core message."
|
|
31
|
+
if self.islong:
|
|
32
|
+
return self._longmsg() % self.option
|
|
33
|
+
else:
|
|
34
|
+
return self._shortmsg() % self.option
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def islong(self: Self) -> bool:
|
|
38
|
+
return cast(bool, self._data["islong"])
|
|
39
|
+
|
|
40
|
+
@islong.setter
|
|
41
|
+
def islong(self: Self, value: Any) -> None:
|
|
42
|
+
self._data["islong"] = bool(value)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Self
|
|
2
|
+
|
|
3
|
+
from preparse.warnings.PreparseDualWarning import PreparseDualWarning
|
|
4
|
+
|
|
5
|
+
__all__ = ["PreparseInvalidOptionWarning"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PreparseInvalidOptionWarning(PreparseDualWarning):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def _longmsg(cls: type[Self]) -> str:
|
|
12
|
+
return "unrecognized option '%s'"
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def _shortmsg(cls: type[Self]) -> str:
|
|
16
|
+
return "invalid option -- '%s'"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Self
|
|
2
|
+
|
|
3
|
+
from preparse.warnings.PreparseDualWarning import PreparseDualWarning
|
|
4
|
+
|
|
5
|
+
__all__ = ["PreparseRequiredArgumentWarning"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PreparseRequiredArgumentWarning(PreparseDualWarning):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def _longmsg(cls: type[Self]) -> str:
|
|
12
|
+
return "option '%s' requires an argument"
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def _shortmsg(cls: type[Self]) -> str:
|
|
16
|
+
return "option requires an argument -- '%s'"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Any, Self
|
|
2
|
+
|
|
3
|
+
import setdoc
|
|
4
|
+
|
|
5
|
+
from preparse.warnings.PreparseLongonlyWarning import PreparseLongonlyWarning
|
|
6
|
+
|
|
7
|
+
__all__ = ["PreparseUnallowedArgumentWarning"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PreparseUnallowedArgumentWarning(PreparseLongonlyWarning):
|
|
11
|
+
|
|
12
|
+
# option is always full key without value
|
|
13
|
+
|
|
14
|
+
@setdoc.basic
|
|
15
|
+
def __post_init__(self: Self, *, prog: Any, option: Any) -> None:
|
|
16
|
+
self.prog = prog
|
|
17
|
+
self.option = option
|
|
18
|
+
|
|
19
|
+
def getmsg(self: Self) -> str:
|
|
20
|
+
"This method returns the core message."
|
|
21
|
+
return "option '%s' doesn't allow an argument" % self.option
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Any, Self, cast
|
|
3
|
+
|
|
4
|
+
import setdoc
|
|
5
|
+
from copyable import Copyable
|
|
6
|
+
from datarepr import datarepr
|
|
7
|
+
|
|
8
|
+
__all__ = ["PreparseWarning"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PreparseWarning(Warning, Copyable):
|
|
12
|
+
|
|
13
|
+
_data: dict[str, Any]
|
|
14
|
+
|
|
15
|
+
@setdoc.basic
|
|
16
|
+
def __init__(self: Self, **kwargs: Any) -> None:
|
|
17
|
+
Warning.__init__(self)
|
|
18
|
+
self._data = dict()
|
|
19
|
+
self.__post_init__(**kwargs)
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
@setdoc.basic
|
|
23
|
+
def __post_init__(self: Self, **kwargs: Any) -> None: ...
|
|
24
|
+
|
|
25
|
+
@setdoc.basic
|
|
26
|
+
def __repr__(self: Self) -> str:
|
|
27
|
+
return datarepr(type(self).__name__, **self.todict())
|
|
28
|
+
|
|
29
|
+
@setdoc.basic
|
|
30
|
+
def __str__(self: Self) -> str:
|
|
31
|
+
return f"{self.prog}: {self.getmsg()}"
|
|
32
|
+
|
|
33
|
+
@setdoc.basic
|
|
34
|
+
def copy(self: Self) -> Self:
|
|
35
|
+
return type(self)(**self.todict())
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def getmsg(self: Self) -> str: ...
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def option(self: Self) -> str:
|
|
42
|
+
return cast(str, self._data["option"])
|
|
43
|
+
|
|
44
|
+
@option.setter
|
|
45
|
+
def option(self: Self, value: object) -> None:
|
|
46
|
+
self._data["option"] = str(value)
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def prog(self: Self) -> str:
|
|
50
|
+
return cast(str, self._data["prog"])
|
|
51
|
+
|
|
52
|
+
@prog.setter
|
|
53
|
+
def prog(self: Self, value: object) -> None:
|
|
54
|
+
self._data["prog"] = str(value)
|
|
55
|
+
|
|
56
|
+
def todict(self: Self) -> dict[str, Any]:
|
|
57
|
+
"This method returns a dict representing the current instance."
|
|
58
|
+
ans: dict[str, Any]
|
|
59
|
+
try:
|
|
60
|
+
ans = self._data
|
|
61
|
+
except AttributeError:
|
|
62
|
+
self._data = dict()
|
|
63
|
+
return dict()
|
|
64
|
+
else:
|
|
65
|
+
return dict(ans)
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: preparse
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.7
|
|
4
4
|
Summary: This project preparses args for further parsing later on.
|
|
5
5
|
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -24,7 +24,7 @@ Requires-Dist: copyable<2,>=1.1
|
|
|
24
24
|
Requires-Dist: datahold<4,>=3.0
|
|
25
25
|
Requires-Dist: datarepr<2,>=1.2
|
|
26
26
|
Requires-Dist: frozendict<3,>=2.4.7
|
|
27
|
-
Requires-Dist: setdoc<2,>=1.3
|
|
27
|
+
Requires-Dist: setdoc<2,>=1.3.11
|
|
28
28
|
Requires-Dist: tofunc<2,>=1.1
|
|
29
29
|
Dynamic: license-file
|
|
30
30
|
|
|
@@ -26,14 +26,14 @@ src/preparse/_processing/parsing.py
|
|
|
26
26
|
src/preparse/_processing/pulling.py
|
|
27
27
|
src/preparse/_tests/__init__.py
|
|
28
28
|
src/preparse/_tests/expit.py
|
|
29
|
-
src/preparse/_utils/__init__.py
|
|
30
|
-
src/preparse/_utils/dataprop.py
|
|
31
29
|
src/preparse/core/Click.py
|
|
32
30
|
src/preparse/core/Optdict.py
|
|
33
31
|
src/preparse/core/PreParser.py
|
|
34
32
|
src/preparse/core/__init__.py
|
|
35
|
-
src/preparse/
|
|
36
|
-
src/preparse/
|
|
33
|
+
src/preparse/enums/BaseEnum.py
|
|
34
|
+
src/preparse/enums/Nargs.py
|
|
35
|
+
src/preparse/enums/Tuning.py
|
|
36
|
+
src/preparse/enums/__init__.py
|
|
37
37
|
src/preparse/tests/__init__.py
|
|
38
38
|
src/preparse/tests/data.toml
|
|
39
39
|
src/preparse/tests/expit.toml
|
|
@@ -41,4 +41,12 @@ src/preparse/tests/test_data_toml.py
|
|
|
41
41
|
src/preparse/tests/test_enums.py
|
|
42
42
|
src/preparse/tests/test_expit_toml.py
|
|
43
43
|
src/preparse/tests/test_optdict.py
|
|
44
|
-
src/preparse/tests/test_preparser.py
|
|
44
|
+
src/preparse/tests/test_preparser.py
|
|
45
|
+
src/preparse/warnings/PreparseAmbiguousOptionWarning.py
|
|
46
|
+
src/preparse/warnings/PreparseDualWarning.py
|
|
47
|
+
src/preparse/warnings/PreparseInvalidOptionWarning.py
|
|
48
|
+
src/preparse/warnings/PreparseLongonlyWarning.py
|
|
49
|
+
src/preparse/warnings/PreparseRequiredArgumentWarning.py
|
|
50
|
+
src/preparse/warnings/PreparseUnallowedArgumentWarning.py
|
|
51
|
+
src/preparse/warnings/PreparseWarning.py
|
|
52
|
+
src/preparse/warnings/__init__.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from preparse._utils.dataprop import *
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from typing import *
|
|
2
|
-
|
|
3
|
-
__all__ = ["dataprop"]
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def dataprop(func: Callable) -> property:
|
|
7
|
-
"This magic method implements calling the current instance."
|
|
8
|
-
|
|
9
|
-
def fget(self: Any) -> Any:
|
|
10
|
-
return self._data[func.__name__]
|
|
11
|
-
|
|
12
|
-
def fset(self: Any, value: Any) -> None:
|
|
13
|
-
self._data = getattr(self, "_data", dict())
|
|
14
|
-
self._data[func.__name__] = func(self, value)
|
|
15
|
-
|
|
16
|
-
kwargs: dict[str, Any]
|
|
17
|
-
kwargs = dict()
|
|
18
|
-
kwargs["doc"] = func.__doc__
|
|
19
|
-
kwargs["fget"] = fget
|
|
20
|
-
kwargs["fset"] = fset
|
|
21
|
-
return property(**kwargs)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""This module holds the enums for the project. \
|
|
2
|
-
Following the precedent of getopt, \
|
|
3
|
-
the value of two represents always an intermediary answer \
|
|
4
|
-
between the values zero, meaning no, and one, meaning yes."""
|
|
5
|
-
|
|
6
|
-
import enum
|
|
7
|
-
import operator
|
|
8
|
-
from typing import Self
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
"Tuning",
|
|
12
|
-
"Nargs",
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class BaseEnum(enum.IntEnum):
|
|
17
|
-
@classmethod
|
|
18
|
-
def _missing_(cls: type[Self], value: object) -> Self:
|
|
19
|
-
return cls(2)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class Tuning(BaseEnum):
|
|
23
|
-
MINIMIZE = 0
|
|
24
|
-
MAXIMIZE = 1
|
|
25
|
-
MAINTAIN = 2
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class Nargs(BaseEnum):
|
|
29
|
-
NO_ARGUMENT = 0
|
|
30
|
-
REQUIRED_ARGUMENT = 1
|
|
31
|
-
OPTIONAL_ARGUMENT = 2
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
from collections.abc import Iterable
|
|
3
|
-
from typing import Any, Self
|
|
4
|
-
|
|
5
|
-
import setdoc
|
|
6
|
-
from copyable import Copyable
|
|
7
|
-
from datarepr import datarepr
|
|
8
|
-
|
|
9
|
-
from preparse._utils import *
|
|
10
|
-
|
|
11
|
-
__all__ = [
|
|
12
|
-
"PreparseAmbiguousOptionWarning",
|
|
13
|
-
"PreparseInvalidOptionWarning",
|
|
14
|
-
"PreparseRequiredArgumentWarning",
|
|
15
|
-
"PreparseUnallowedArgumentWarning",
|
|
16
|
-
"PreparseWarning",
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class PreparseWarning(Warning, Copyable):
|
|
21
|
-
|
|
22
|
-
_data: dict[str, Any]
|
|
23
|
-
|
|
24
|
-
@setdoc.basic
|
|
25
|
-
def __repr__(self: Self) -> str:
|
|
26
|
-
return datarepr(type(self).__name__, **self.todict())
|
|
27
|
-
|
|
28
|
-
@setdoc.basic
|
|
29
|
-
def __str__(self: Self) -> str:
|
|
30
|
-
return f"{self.prog}: {self.getmsg()}"
|
|
31
|
-
|
|
32
|
-
@setdoc.basic
|
|
33
|
-
def copy(self: Self) -> Self:
|
|
34
|
-
return type(self)(**self.todict())
|
|
35
|
-
|
|
36
|
-
@abstractmethod
|
|
37
|
-
def getmsg(self: Self) -> str: ...
|
|
38
|
-
|
|
39
|
-
@dataprop
|
|
40
|
-
def option(self: Self, value: Any) -> str:
|
|
41
|
-
return str(value)
|
|
42
|
-
|
|
43
|
-
@dataprop
|
|
44
|
-
def prog(self: Self, value: Any) -> str:
|
|
45
|
-
return str(value)
|
|
46
|
-
|
|
47
|
-
def todict(self: Self) -> dict:
|
|
48
|
-
"This method returns a dict representing the current instance."
|
|
49
|
-
ans: dict
|
|
50
|
-
try:
|
|
51
|
-
ans = self._data
|
|
52
|
-
except AttributeError:
|
|
53
|
-
self._data = dict()
|
|
54
|
-
return dict()
|
|
55
|
-
else:
|
|
56
|
-
return dict(ans)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
class PreparseDualWarning(PreparseWarning):
|
|
60
|
-
|
|
61
|
-
@setdoc.basic
|
|
62
|
-
def __init__(self: Self, *, prog: Any, option: Any, islong: Any) -> None:
|
|
63
|
-
self.prog = prog
|
|
64
|
-
self.option = option
|
|
65
|
-
self.islong = islong
|
|
66
|
-
|
|
67
|
-
@classmethod
|
|
68
|
-
@abstractmethod
|
|
69
|
-
def _longmsg(cls: type[Self]) -> str: ...
|
|
70
|
-
|
|
71
|
-
@classmethod
|
|
72
|
-
@abstractmethod
|
|
73
|
-
def _shortmsg(cls: type[Self]) -> str: ...
|
|
74
|
-
|
|
75
|
-
def getmsg(self: Self) -> str:
|
|
76
|
-
"This method returns the core message."
|
|
77
|
-
if self.islong:
|
|
78
|
-
return self._longmsg() % self.option
|
|
79
|
-
else:
|
|
80
|
-
return self._shortmsg() % self.option
|
|
81
|
-
|
|
82
|
-
@dataprop
|
|
83
|
-
def islong(self: Self, value: Any) -> bool:
|
|
84
|
-
return bool(value)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
class PreparseInvalidOptionWarning(PreparseDualWarning):
|
|
88
|
-
|
|
89
|
-
@classmethod
|
|
90
|
-
def _longmsg(cls: type[Self]) -> str:
|
|
91
|
-
return "unrecognized option '%s'"
|
|
92
|
-
|
|
93
|
-
@classmethod
|
|
94
|
-
def _shortmsg(cls: type[Self]) -> str:
|
|
95
|
-
return "invalid option -- '%s'"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
class PreparseRequiredArgumentWarning(PreparseDualWarning):
|
|
99
|
-
|
|
100
|
-
@classmethod
|
|
101
|
-
def _longmsg(cls: type[Self]) -> str:
|
|
102
|
-
return "option '%s' requires an argument"
|
|
103
|
-
|
|
104
|
-
@classmethod
|
|
105
|
-
def _shortmsg(cls: type[Self]) -> str:
|
|
106
|
-
return "option requires an argument -- '%s'"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
class PreparseLongonlyWarning(PreparseWarning):
|
|
110
|
-
pass # only possible for long options
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
|
|
114
|
-
|
|
115
|
-
@setdoc.basic
|
|
116
|
-
def __init__(
|
|
117
|
-
self: Self, *, prog: Any, option: Any, possibilities: Iterable[object]
|
|
118
|
-
) -> None:
|
|
119
|
-
self.prog = prog
|
|
120
|
-
self.option = option
|
|
121
|
-
self.possibilities = possibilities
|
|
122
|
-
|
|
123
|
-
def getmsg(self: Self) -> str:
|
|
124
|
-
"This method returns the core message."
|
|
125
|
-
ans: str
|
|
126
|
-
x: Any
|
|
127
|
-
ans = "option '%s' is ambiguous; possibilities:" % self.option
|
|
128
|
-
for x in self.possibilities:
|
|
129
|
-
ans += " '%s'" % x
|
|
130
|
-
return ans
|
|
131
|
-
|
|
132
|
-
@dataprop
|
|
133
|
-
def possibilities(self: Self, value: Iterable[object]) -> tuple[str, ...]:
|
|
134
|
-
return tuple(map(str, value))
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
class PreparseUnallowedArgumentWarning(PreparseLongonlyWarning):
|
|
138
|
-
|
|
139
|
-
# option is always full key without value
|
|
140
|
-
|
|
141
|
-
@setdoc.basic
|
|
142
|
-
def __init__(self: Self, *, prog: Any, option: Any) -> None:
|
|
143
|
-
self.prog = prog
|
|
144
|
-
self.option = option
|
|
145
|
-
|
|
146
|
-
def getmsg(self: Self) -> str:
|
|
147
|
-
"This method returns the core message."
|
|
148
|
-
return "option '%s' doesn't allow an argument" % self.option
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|