ssc_codegen 0.12.0__tar.gz → 0.12.1__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.
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/PKG-INFO +2 -3
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/README.md +1 -1
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/pyproject.toml +3 -2
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/__init__.py +1 -1
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/main.py +1 -1
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/js_pure.py +88 -29
- ssc_codegen-0.12.1/ssc_codegen/converters/templates/js_pure.py +38 -0
- ssc_codegen-0.12.0/ssc_codegen/converters/templates/js_pure.py +0 -135
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/.gitignore +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/LICENSE +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/_compat.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_array.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_cast.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_core.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_filter.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_selectors.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_string.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_/nodes_validate.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_build/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_build/builder.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_build/main.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_build/utils.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_grep_rules/js_rules.yml +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/ast_grep_rules/py_rules.yml +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/ast_grep.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/cli_callbacks.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/cli_utils.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/code_callbacks.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/consts.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/cli/runtime_parse_runners.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/compiler.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/go_goquery.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/helpers.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/lua_htmlparser.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/py_base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/py_bs4.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/py_lxml.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/py_parsel.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/py_selectolax.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/go_goquery.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/lua_base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/lua_css_compat.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/lua_re_compat.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/py_base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/document.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/document_utlis.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/json_struct.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/json_to_scc.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/logs.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/pseudo_selectors.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/schema.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/selector_utils.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/static_checker/__init__.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/static_checker/base.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/static_checker/callbacks.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/str_utils.py +0 -0
- {ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/tokens.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ssc_codegen
|
|
3
|
-
Version: 0.12.
|
|
3
|
+
Version: 0.12.1
|
|
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
|
|
@@ -26,7 +26,6 @@ Requires-Dist: colorama>=0.4.6; sys_platform == 'win32'
|
|
|
26
26
|
Requires-Dist: cssselect>=1.2.0
|
|
27
27
|
Requires-Dist: httpx>=0.28.1
|
|
28
28
|
Requires-Dist: ichrome>=4.0.4
|
|
29
|
-
Requires-Dist: jinja2>=3.1.6
|
|
30
29
|
Requires-Dist: lxml>=5.3.0
|
|
31
30
|
Requires-Dist: parsel>=1.10.0
|
|
32
31
|
Requires-Dist: soupsieve>=2.6
|
|
@@ -66,7 +65,7 @@ Current support converters
|
|
|
66
65
|
| ... | parsel | Y | Y | N | ... | ... |
|
|
67
66
|
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
68
67
|
| ... | lxml | Y | Y | N | ... | ... |
|
|
69
|
-
| js (ES6)`2` | pure (firefox/chrome extension/nodejs) | Y | Y | Y |
|
|
68
|
+
| js (ES6)`2` | pure (firefox/chrome extension/nodejs) | Y | Y | Y | JSDoc | prettier |
|
|
70
69
|
| go (1.10+) **(UNSTABLE)** | goquery, gjson (`4`) | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
71
70
|
| lua (5.2+), luajit(2+) **(UNSTABLE)**`5` | lua-htmlparser, lrexlib(opt), dkjson | N | Y | N | EmmyLua | LuaFormatter |
|
|
72
71
|
|
|
@@ -29,7 +29,7 @@ Current support converters
|
|
|
29
29
|
| ... | parsel | Y | Y | N | ... | ... |
|
|
30
30
|
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
31
31
|
| ... | lxml | Y | Y | N | ... | ... |
|
|
32
|
-
| js (ES6)`2` | pure (firefox/chrome extension/nodejs) | Y | Y | Y |
|
|
32
|
+
| js (ES6)`2` | pure (firefox/chrome extension/nodejs) | Y | Y | Y | JSDoc | prettier |
|
|
33
33
|
| go (1.10+) **(UNSTABLE)** | goquery, gjson (`4`) | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
34
34
|
| lua (5.2+), luajit(2+) **(UNSTABLE)**`5` | lua-htmlparser, lrexlib(opt), dkjson | N | Y | N | EmmyLua | LuaFormatter |
|
|
35
35
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ssc_codegen"
|
|
3
|
-
version = "0.12.
|
|
3
|
+
version = "0.12.1"
|
|
4
4
|
description = "Python-dsl code converter to html parser for web scraping "
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -10,7 +10,6 @@ dependencies = [
|
|
|
10
10
|
"cssselect>=1.2.0",
|
|
11
11
|
"httpx>=0.28.1",
|
|
12
12
|
"ichrome>=4.0.4",
|
|
13
|
-
"jinja2>=3.1.6",
|
|
14
13
|
"lxml>=5.3.0",
|
|
15
14
|
"parsel>=1.10.0",
|
|
16
15
|
"soupsieve>=2.6",
|
|
@@ -61,8 +60,10 @@ dev = [
|
|
|
61
60
|
"coverage>=7.6.12",
|
|
62
61
|
"httpx>=0.28.1",
|
|
63
62
|
"mypy>=1.14.1",
|
|
63
|
+
"parsel>=1.10.0",
|
|
64
64
|
"pytest>=8.3.4",
|
|
65
65
|
"ruff>=0.9.3",
|
|
66
|
+
"selectolax>=0.3.27",
|
|
66
67
|
]
|
|
67
68
|
# python generated code tests
|
|
68
69
|
tests = [
|
|
@@ -478,7 +478,7 @@ def parse_from_url(
|
|
|
478
478
|
] = True,
|
|
479
479
|
) -> None:
|
|
480
480
|
from ssc_codegen.compiler import Compiler
|
|
481
|
-
from ssc_codegen.converters.
|
|
481
|
+
from ssc_codegen.converters.py_bs4 import CONVERTER
|
|
482
482
|
|
|
483
483
|
cls_target, schema_config = _validate_parser_target(cls_target)
|
|
484
484
|
|
|
@@ -149,19 +149,7 @@ from ssc_codegen.converters.helpers import (
|
|
|
149
149
|
is_first_node_cond,
|
|
150
150
|
is_prev_node_atomic_cond,
|
|
151
151
|
)
|
|
152
|
-
from ssc_codegen.converters.templates.js_pure import
|
|
153
|
-
HELPER_FUNCTIONS,
|
|
154
|
-
J2_STRUCT_INIT,
|
|
155
|
-
J2_PRE_LIST_STR_TRIM,
|
|
156
|
-
J2_PRE_STR_LEFT_TRIM,
|
|
157
|
-
J2_PRE_LIST_STR_LEFT_TRIM,
|
|
158
|
-
J2_PRE_STR_RIGHT_TRIM,
|
|
159
|
-
J2_PRE_LIST_STR_RIGHT_TRIM,
|
|
160
|
-
J2_PRE_XPATH,
|
|
161
|
-
J2_PRE_XPATH_ALL,
|
|
162
|
-
J2_PRE_STR_TRIM,
|
|
163
|
-
J2_IS_XPATH,
|
|
164
|
-
)
|
|
152
|
+
from ssc_codegen.converters.templates.js_pure import HELPER_FUNCTIONS
|
|
165
153
|
from ssc_codegen.str_utils import (
|
|
166
154
|
wrap_backtick,
|
|
167
155
|
to_upper_camel_case,
|
|
@@ -299,7 +287,17 @@ def pre_parse_field(node: StructFieldMethod) -> str:
|
|
|
299
287
|
|
|
300
288
|
@CONVERTER(StructInitMethod.kind)
|
|
301
289
|
def pre_struct_init(_node: StructInitMethod) -> str:
|
|
302
|
-
|
|
290
|
+
code = [
|
|
291
|
+
"constructor(doc){",
|
|
292
|
+
"if (typeof doc === 'string'){",
|
|
293
|
+
"this._doc = new DOMParser().parseFromString(doc, 'text/html');",
|
|
294
|
+
"} else if (doc instanceof Document || doc instanceof Element){",
|
|
295
|
+
"this._doc = doc.cloneNode(true);",
|
|
296
|
+
"} else {",
|
|
297
|
+
'throw new Error("Invalid input: Expected a Document, Element, or string");}',
|
|
298
|
+
"}",
|
|
299
|
+
]
|
|
300
|
+
return "\n".join(code)
|
|
303
301
|
|
|
304
302
|
|
|
305
303
|
JSDOC_TYPES = {
|
|
@@ -576,42 +574,88 @@ def pre_list_str_fmt(node: ExprListStringFormat) -> str:
|
|
|
576
574
|
def pre_str_trim(node: ExprStringTrim) -> str:
|
|
577
575
|
prv, nxt = prev_next_var(node)
|
|
578
576
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
579
|
-
|
|
577
|
+
code = [
|
|
578
|
+
f"let {nxt} = (function (str, chars) {{",
|
|
579
|
+
"return str.replace(new RegExp(`^[${chars}]+|[${chars}]+$`, 'g'), '');",
|
|
580
|
+
f"}})({prv}, {substr});",
|
|
581
|
+
]
|
|
582
|
+
return "\n".join(code)
|
|
580
583
|
|
|
581
584
|
|
|
582
585
|
@CONVERTER(ExprListStringTrim.kind)
|
|
583
586
|
def pre_list_str_trim(node: ExprListStringTrim) -> str:
|
|
584
587
|
prv, nxt = prev_next_var(node)
|
|
585
588
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
586
|
-
|
|
589
|
+
code = [
|
|
590
|
+
f"let {nxt} = {prv}.map(e =>",
|
|
591
|
+
"(function (str, chars) {",
|
|
592
|
+
"return str.replace(new RegExp(`^[${chars}]+|[${chars}]+$`, 'g'), '');",
|
|
593
|
+
f"}})(e, {substr})",
|
|
594
|
+
");",
|
|
595
|
+
]
|
|
596
|
+
return "\n".join(code)
|
|
587
597
|
|
|
588
598
|
|
|
589
599
|
@CONVERTER(ExprStringLeftTrim.kind)
|
|
590
600
|
def pre_str_left_trim(node: ExprStringLeftTrim) -> str:
|
|
591
601
|
prv, nxt = prev_next_var(node)
|
|
592
602
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
593
|
-
|
|
603
|
+
"""
|
|
604
|
+
let {{ nxt }} = (function (str, chars) {
|
|
605
|
+
return str.replace(new RegExp(`^[${chars}]+`, 'g'), '');
|
|
606
|
+
})({{ prv }}, {{ substr }});
|
|
607
|
+
"""
|
|
608
|
+
code = [
|
|
609
|
+
f"let {nxt} = (function (str, chars) {{",
|
|
610
|
+
"return str.replace(new RegExp(`^[${chars}]+`, 'g'), '');",
|
|
611
|
+
f"}})({prv}, {substr});",
|
|
612
|
+
]
|
|
613
|
+
return "\n".join(code)
|
|
594
614
|
|
|
595
615
|
|
|
596
616
|
@CONVERTER(ExprListStringLeftTrim.kind)
|
|
597
617
|
def pre_list_str_left_trim(node: ExprListStringLeftTrim) -> str:
|
|
598
618
|
prv, nxt = prev_next_var(node)
|
|
599
619
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
600
|
-
|
|
620
|
+
|
|
621
|
+
code = [
|
|
622
|
+
f"let {nxt} = {prv}.map(e =>",
|
|
623
|
+
"(function (str, chars) {",
|
|
624
|
+
"return str.replace(new RegExp(`^[${chars}]+`, 'g'), '');",
|
|
625
|
+
f"}})(e, {substr})",
|
|
626
|
+
]
|
|
627
|
+
return "\n".join(code)
|
|
601
628
|
|
|
602
629
|
|
|
603
630
|
@CONVERTER(ExprStringRightTrim.kind)
|
|
604
631
|
def pre_str_right_trim(node: ExprStringRightTrim) -> str:
|
|
605
632
|
prv, nxt = prev_next_var(node)
|
|
606
633
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
607
|
-
|
|
634
|
+
"""
|
|
635
|
+
let {{ nxt }} = (function (str, chars) {
|
|
636
|
+
return str.replace(new RegExp(`[${chars}]+$`, 'g'), '');
|
|
637
|
+
})({{ prv }}, {{ substr }});
|
|
638
|
+
"""
|
|
639
|
+
code = [
|
|
640
|
+
f"let {nxt} = (function (str, chars) {{",
|
|
641
|
+
"return str.replace(new RegExp(`[${chars}]+$`, 'g'), '');",
|
|
642
|
+
f"}})({prv}, {substr});",
|
|
643
|
+
]
|
|
644
|
+
return "\n".join(code)
|
|
608
645
|
|
|
609
646
|
|
|
610
647
|
@CONVERTER(ExprListStringRightTrim.kind)
|
|
611
648
|
def pre_list_str_right_trim(node: ExprListStringRightTrim) -> str:
|
|
612
649
|
prv, nxt = prev_next_var(node)
|
|
613
650
|
substr = js_get_classvar_hook_or_value(node, "substr")
|
|
614
|
-
|
|
651
|
+
code = [
|
|
652
|
+
f"let {nxt} = {prv}.map(e =>",
|
|
653
|
+
"(function (str, chars) {",
|
|
654
|
+
"return str.replace(new RegExp(`[${chars}]+$`, 'g'), '');",
|
|
655
|
+
f"}})(e, {substr})",
|
|
656
|
+
");",
|
|
657
|
+
]
|
|
658
|
+
return "\n".join(code)
|
|
615
659
|
|
|
616
660
|
|
|
617
661
|
@CONVERTER(ExprStringSplit.kind)
|
|
@@ -814,11 +858,14 @@ def pre_is_xpath(node: ExprIsXpath) -> str:
|
|
|
814
858
|
prv, nxt = prev_next_var(node)
|
|
815
859
|
query = js_get_classvar_hook_or_value(node, "query")
|
|
816
860
|
msg = js_get_classvar_hook_or_value(node, "msg")
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
861
|
+
code = [
|
|
862
|
+
f"if (document.evaluate({query}, {prv}, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue === null) {{",
|
|
863
|
+
f"throw new Error({msg});",
|
|
864
|
+
"}",
|
|
865
|
+
]
|
|
866
|
+
if not is_last_var_no_ret(node):
|
|
867
|
+
code.append(f"let {nxt} = {prv};")
|
|
868
|
+
return "\n".join(code)
|
|
822
869
|
|
|
823
870
|
|
|
824
871
|
@CONVERTER(ExprToInt.kind)
|
|
@@ -884,7 +931,13 @@ def pre_css_all(node: ExprCssAll) -> str:
|
|
|
884
931
|
def pre_xpath(node: ExprXpath) -> str:
|
|
885
932
|
prv, nxt = prev_next_var(node)
|
|
886
933
|
query = js_get_classvar_hook_or_value(node, "query")
|
|
887
|
-
|
|
934
|
+
|
|
935
|
+
code = [
|
|
936
|
+
f"let {nxt} = document.evaluate(",
|
|
937
|
+
f"{query}, {prv}, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null",
|
|
938
|
+
").singleNodeValue;",
|
|
939
|
+
]
|
|
940
|
+
return "\n".join(code)
|
|
888
941
|
|
|
889
942
|
|
|
890
943
|
@CONVERTER(ExprXpathAll.kind)
|
|
@@ -892,9 +945,15 @@ def pre_xpath_all(node: ExprXpathAll) -> str:
|
|
|
892
945
|
prv, nxt = prev_next_var(node)
|
|
893
946
|
query = js_get_classvar_hook_or_value(node, "query")
|
|
894
947
|
snapshot_var = f"s{nxt}"
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
948
|
+
code = [
|
|
949
|
+
f"let {snapshot_var} = {prv}.evaluate(",
|
|
950
|
+
f"{query}, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null",
|
|
951
|
+
");",
|
|
952
|
+
f"let {nxt} = Array.from({{ length: {snapshot_var}.snapshotLength }}, (_, i) => ",
|
|
953
|
+
f"{snapshot_var}.snapshotItem(i)",
|
|
954
|
+
");",
|
|
955
|
+
]
|
|
956
|
+
return "\n".join(code)
|
|
898
957
|
|
|
899
958
|
|
|
900
959
|
@CONVERTER(ExprGetHtmlAttr.kind)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# used functions instead consts arrow functions for allow rewrite it wout errors
|
|
2
|
+
HELPER_FUNCTIONS = r"""
|
|
3
|
+
function sscUnescape(v) {
|
|
4
|
+
return v
|
|
5
|
+
.replace(/&/g, '&')
|
|
6
|
+
.replace(/</g, '<')
|
|
7
|
+
.replace(/>/g, '>')
|
|
8
|
+
.replace(/"/g, '"')
|
|
9
|
+
.replace(/'/g, "'")
|
|
10
|
+
.replace(///g, '/')
|
|
11
|
+
.replace(/ /g, ' ')
|
|
12
|
+
.replace(/&#x([0-9a-fA-F]+);/g, function(_, hex) {
|
|
13
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
14
|
+
})
|
|
15
|
+
.replace(/\\u([0-9a-fA-F]{4})/g, function(_, hex) {
|
|
16
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
17
|
+
})
|
|
18
|
+
.replace(/\\x([0-9a-fA-F]{2})/g, function(_, hex) {
|
|
19
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
20
|
+
})
|
|
21
|
+
.replace(/\\([bfnrt])/g, function(_, ch) {
|
|
22
|
+
return { b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' }[ch];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sscRmPrefix(v, p) {
|
|
27
|
+
return v.startsWith(p) ? v.slice(p.length) : v;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sscRmSuffix(v, s) {
|
|
31
|
+
return v.endsWith(s) ? v.slice(0, -s.length) : v;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function sscRmPrefixSuffix(v, p, s) {
|
|
35
|
+
return sscRmSuffix(sscRmPrefix(v, p), s);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
"""
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
from jinja2 import Template
|
|
2
|
-
|
|
3
|
-
# used functions instead consts arrow functions for allow rewrite it wout errors
|
|
4
|
-
HELPER_FUNCTIONS = r"""
|
|
5
|
-
function sscUnescape(v) {
|
|
6
|
-
return v
|
|
7
|
-
.replace(/&/g, '&')
|
|
8
|
-
.replace(/</g, '<')
|
|
9
|
-
.replace(/>/g, '>')
|
|
10
|
-
.replace(/"/g, '"')
|
|
11
|
-
.replace(/'/g, "'")
|
|
12
|
-
.replace(///g, '/')
|
|
13
|
-
.replace(/ /g, ' ')
|
|
14
|
-
.replace(/&#x([0-9a-fA-F]+);/g, function(_, hex) {
|
|
15
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
16
|
-
})
|
|
17
|
-
.replace(/\\u([0-9a-fA-F]{4})/g, function(_, hex) {
|
|
18
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
19
|
-
})
|
|
20
|
-
.replace(/\\x([0-9a-fA-F]{2})/g, function(_, hex) {
|
|
21
|
-
return String.fromCharCode(parseInt(hex, 16));
|
|
22
|
-
})
|
|
23
|
-
.replace(/\\([bfnrt])/g, function(_, ch) {
|
|
24
|
-
return { b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' }[ch];
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function sscRmPrefix(v, p) {
|
|
29
|
-
return v.startsWith(p) ? v.slice(p.length) : v;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function sscRmSuffix(v, s) {
|
|
33
|
-
return v.endsWith(s) ? v.slice(0, -s.length) : v;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function sscRmPrefixSuffix(v, p, s) {
|
|
37
|
-
return sscRmSuffix(sscRmPrefix(v, p), s);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
J2_STRUCT_INIT = """
|
|
43
|
-
constructor(doc){
|
|
44
|
-
if (typeof doc === 'string'){
|
|
45
|
-
this._doc = new DOMParser().parseFromString(doc, 'text/html');
|
|
46
|
-
} else if (doc instanceof Document || doc instanceof Element){
|
|
47
|
-
this._doc = doc.cloneNode(true);
|
|
48
|
-
} else {
|
|
49
|
-
throw new Error("Invalid input: Expected a Document, Element, or string");}
|
|
50
|
-
}
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
J2_PRE_STR_TRIM = Template(
|
|
54
|
-
"""
|
|
55
|
-
let {{ nxt }} = (function (str, chars) {
|
|
56
|
-
return str.replace(new RegExp(`^[${chars}]+|[${chars}]+$`, 'g'), '');
|
|
57
|
-
})({{ prv }}, {{ substr }});
|
|
58
|
-
"""
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
J2_PRE_LIST_STR_TRIM = Template(
|
|
63
|
-
"""
|
|
64
|
-
let {{ nxt }} = {{ prv }}.map(e =>
|
|
65
|
-
(function (str, chars) {
|
|
66
|
-
return str.replace(new RegExp(`^[${chars}]+|[${chars}]+$`, 'g'), '');
|
|
67
|
-
})(e, {{ substr }})
|
|
68
|
-
);
|
|
69
|
-
"""
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
J2_PRE_STR_LEFT_TRIM = Template(
|
|
73
|
-
"""
|
|
74
|
-
let {{ nxt }} = (function (str, chars) {
|
|
75
|
-
return str.replace(new RegExp(`^[${chars}]+`, 'g'), '');
|
|
76
|
-
})({{ prv }}, {{ substr }});
|
|
77
|
-
"""
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
J2_PRE_LIST_STR_LEFT_TRIM = Template(
|
|
81
|
-
"""
|
|
82
|
-
let {{ nxt }} = {{ prv }}.map(e =>
|
|
83
|
-
(function (str, chars) {
|
|
84
|
-
return str.replace(new RegExp(`^[${chars}]+`, 'g'), '');
|
|
85
|
-
})(e, {{ substr }})
|
|
86
|
-
);
|
|
87
|
-
"""
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
J2_PRE_STR_RIGHT_TRIM = Template(
|
|
91
|
-
"""
|
|
92
|
-
let {{ nxt }} = (function (str, chars) {
|
|
93
|
-
return str.replace(new RegExp(`[${chars}]+$`, 'g'), '');
|
|
94
|
-
})({{ prv }}, {{ substr }});
|
|
95
|
-
"""
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
J2_PRE_LIST_STR_RIGHT_TRIM = Template(
|
|
99
|
-
"""
|
|
100
|
-
let {{ nxt }} = {{ prv }}.map(e =>
|
|
101
|
-
(function (str, chars) {
|
|
102
|
-
return str.replace(new RegExp(`[${chars}]+$`, 'g'), '');
|
|
103
|
-
})(e, {{ substr }})
|
|
104
|
-
);
|
|
105
|
-
"""
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
J2_PRE_XPATH = Template("""
|
|
109
|
-
let {{ nxt }} = document.evaluate(
|
|
110
|
-
"{{ query }}", {{ prv }}, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
|
|
111
|
-
).singleNodeValue;
|
|
112
|
-
""")
|
|
113
|
-
|
|
114
|
-
J2_PRE_XPATH_ALL = Template("""
|
|
115
|
-
let {{ snapshot_var }} = {{ prv }}.evaluate(
|
|
116
|
-
"{{ query }}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
|
|
117
|
-
);
|
|
118
|
-
let {{ nxt }} = Array.from({ length: {{ snapshot_var }}.snapshotLength }, (_, i) =>
|
|
119
|
-
{{ snapshot_var }}.snapshotItem(i)
|
|
120
|
-
);
|
|
121
|
-
""")
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
J2_IS_XPATH = Template("""
|
|
125
|
-
if (document.evaluate("{{ query }}", {{ prv }}, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue === null) throw new Error({{ msg }});
|
|
126
|
-
""")
|
|
127
|
-
# TODO: use in covverter
|
|
128
|
-
JS_HAS_ATTR = Template("""
|
|
129
|
-
if (!{{prv}}?.hasAttribute({{key}}) throw new Error({{ msg }});
|
|
130
|
-
""")
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
JS_HAS_ATTR_ALL = Template("""
|
|
134
|
-
if (!{{prv}}.every(e => e?.hasAttribute({{key}}));}) throw new Error({{ msg }});
|
|
135
|
-
""")
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ssc_codegen-0.12.0 → ssc_codegen-0.12.1}/ssc_codegen/converters/templates/lua_css_compat.py
RENAMED
|
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
|