ssc_codegen 0.7.3__tar.gz → 0.7.4__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.
Potentially problematic release.
This version of ssc_codegen might be problematic. Click here for more details.
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/PKG-INFO +1 -1
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/pyproject.toml +2 -1
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/__init__.py +1 -1
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/document.py +8 -5
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/document_utlis.py +35 -1
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/.gitignore +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/LICENSE +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/README.md +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/_compat.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/ast_build_utils.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/ast_builder.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/ast_ssc.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/__init__.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/cli_callbacks.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/cli_utils.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/code_callbacks.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/consts.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/main.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/cli/runtime_parse_runners.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/compiler.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/consts.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/__init__.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/ast_utils.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/base.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/dart_universal_html.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/go_goquery.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/js_pure.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/json_to_schema.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/py_base.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/py_bs4.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/py_parsel.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/py_scrapy.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/py_selectolax.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/dart.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/go.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/js.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/py.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/template_bindings.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/json_struct.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/schema.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/selector_utils.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/str_utils.py +0 -0
- {ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/tokens.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ssc_codegen
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.4
|
|
4
4
|
Summary: Python-dsl code converter to html parser for web scraping
|
|
5
5
|
Project-URL: Documentation, https://github.com/vypivshiy/selector_schema_codegen#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/vypivshiy/selector_schema_codegen/issues
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ssc_codegen"
|
|
3
|
-
version = "0.7.
|
|
3
|
+
version = "0.7.4"
|
|
4
4
|
description = "Python-dsl code converter to html parser for web scraping "
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -13,6 +13,7 @@ dependencies = [
|
|
|
13
13
|
"typer>=0.15.1",
|
|
14
14
|
"typing_extensions;python_version<'3.11'",
|
|
15
15
|
]
|
|
16
|
+
|
|
16
17
|
classifiers = [
|
|
17
18
|
"Development Status :: 3 - Alpha",
|
|
18
19
|
"Environment :: Console",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""high-level AST builder interface"""
|
|
2
2
|
|
|
3
|
-
from typing import Type
|
|
3
|
+
from typing import Type, Pattern
|
|
4
4
|
|
|
5
5
|
from typing_extensions import Self
|
|
6
6
|
|
|
@@ -51,7 +51,7 @@ from .ast_ssc import (
|
|
|
51
51
|
ToBool,
|
|
52
52
|
ArrayLengthExpression,
|
|
53
53
|
)
|
|
54
|
-
from .document_utlis import assert_re_expression
|
|
54
|
+
from .document_utlis import assert_re_expression, unverbosify_regex
|
|
55
55
|
from .schema import BaseSchema
|
|
56
56
|
from .selector_utils import validate_css_query, validate_xpath_query
|
|
57
57
|
from .tokens import VariableType
|
|
@@ -458,7 +458,7 @@ class StringDocument(BaseDocument):
|
|
|
458
458
|
)
|
|
459
459
|
return self
|
|
460
460
|
|
|
461
|
-
def re(self, pattern: str, group: int = 1) -> Self:
|
|
461
|
+
def re(self, pattern: str | Pattern, group: int = 1) -> Self:
|
|
462
462
|
"""extract first regex result.
|
|
463
463
|
|
|
464
464
|
NOTE:
|
|
@@ -466,6 +466,7 @@ class StringDocument(BaseDocument):
|
|
|
466
466
|
|
|
467
467
|
- accept STRING, return STRING
|
|
468
468
|
"""
|
|
469
|
+
pattern = unverbosify_regex(pattern)
|
|
469
470
|
assert_re_expression(pattern)
|
|
470
471
|
|
|
471
472
|
if self.stack_last_ret != VariableType.STRING:
|
|
@@ -475,11 +476,12 @@ class StringDocument(BaseDocument):
|
|
|
475
476
|
self._add(RegexExpression(pattern=pattern, group=group))
|
|
476
477
|
return self
|
|
477
478
|
|
|
478
|
-
def re_all(self, pattern: str) -> Self:
|
|
479
|
+
def re_all(self, pattern: str | Pattern) -> Self:
|
|
479
480
|
"""extract all regex results.
|
|
480
481
|
|
|
481
482
|
- accept STRING, return LIST_STRING
|
|
482
483
|
"""
|
|
484
|
+
pattern = unverbosify_regex(pattern)
|
|
483
485
|
assert_re_expression(pattern, max_groups=1)
|
|
484
486
|
if self.stack_last_ret != VariableType.STRING:
|
|
485
487
|
self._raise_wrong_type_error(
|
|
@@ -488,12 +490,13 @@ class StringDocument(BaseDocument):
|
|
|
488
490
|
self._add(RegexAllExpression(pattern=pattern))
|
|
489
491
|
return self
|
|
490
492
|
|
|
491
|
-
def re_sub(self, pattern: str, repl: str = "") -> Self:
|
|
493
|
+
def re_sub(self, pattern: str | Pattern, repl: str = "") -> Self:
|
|
492
494
|
"""Replace substring by `pattern` to `repl`.
|
|
493
495
|
|
|
494
496
|
- accept STRING, return STRING
|
|
495
497
|
- accept LIST_STRING, return LIST_STRING
|
|
496
498
|
"""
|
|
499
|
+
pattern = unverbosify_regex(pattern)
|
|
497
500
|
assert_re_expression(pattern, allow_empty_groups=True)
|
|
498
501
|
|
|
499
502
|
match self.stack_last_ret:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
-
from typing import TYPE_CHECKING
|
|
2
|
+
from typing import TYPE_CHECKING, Pattern
|
|
3
3
|
|
|
4
4
|
from ssc_codegen.ast_ssc import (
|
|
5
5
|
BaseExpression,
|
|
@@ -16,6 +16,40 @@ if TYPE_CHECKING:
|
|
|
16
16
|
from .document import BaseDocument
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
# https://stackoverflow.com/a/14919203
|
|
20
|
+
CM1_RX = r"(?m)(?<!\\)((\\{2})*)#.*$"
|
|
21
|
+
CM2_RX = r"(\\)?((\\{2})*)(#)"
|
|
22
|
+
WS_RX = r"(\\)?((\\{2})*)(\s)\s*"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def unverbosify_regex(pattern: str | Pattern) -> str:
|
|
26
|
+
if isinstance(pattern, str):
|
|
27
|
+
return pattern
|
|
28
|
+
|
|
29
|
+
def strip_escapes(match): # type: ignore
|
|
30
|
+
## if even slashes: delete space and retain slashes
|
|
31
|
+
if match.group(1) is None:
|
|
32
|
+
return match.group(2)
|
|
33
|
+
## if number of slashes is odd: delete slash and keep space (or 'comment')
|
|
34
|
+
elif match.group(1) == "\\":
|
|
35
|
+
return match.group(2) + match.group(4)
|
|
36
|
+
## error
|
|
37
|
+
else:
|
|
38
|
+
raise Exception
|
|
39
|
+
|
|
40
|
+
if pattern.flags & re.X:
|
|
41
|
+
not_verbose_regex = re.sub(
|
|
42
|
+
WS_RX,
|
|
43
|
+
strip_escapes,
|
|
44
|
+
re.sub(
|
|
45
|
+
CM2_RX, strip_escapes, re.sub(CM1_RX, "\\1", pattern.pattern)
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return not_verbose_regex
|
|
50
|
+
return pattern.pattern
|
|
51
|
+
|
|
52
|
+
|
|
19
53
|
def assert_re_expression(
|
|
20
54
|
pattern: str, allow_empty_groups: bool = False, max_groups: int = -1
|
|
21
55
|
) -> None:
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ssc_codegen-0.7.3 → ssc_codegen-0.7.4}/ssc_codegen/converters/templates/template_bindings.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|