ssc_codegen 0.27.0__tar.gz → 0.29.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.
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/PKG-INFO +1 -1
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/pyproject.toml +1 -1
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/js_pure.py +12 -7
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/py_bs4.py +10 -6
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/kdl/reader.py +0 -1
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/main.py +14 -3
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/.gitignore +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/LICENSE +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/README.md +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/__init__.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/_logging.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/__init__.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/array.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/base.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/cast.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/control.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/extract.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/helpers.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/jsondef.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/module.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/predicate_containers.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/predicate_ops.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/regex.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/selectors.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/string.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/struct.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/transform.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/typedef.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/ast/types.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/base.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/helpers.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/py_lxml.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/py_parsel.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/py_render.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/py_slax.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/converters/request_spec.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/__init__.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/adapter.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/contexts.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/expressions.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/format.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/linting.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/module_handler.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/predicates.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/reader.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/struct_parser.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/core/type_checking.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/document_utils.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/exceptions.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/health.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/kdl/__init__.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/kdl/dict_reader.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/kdl/parser.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/parsers/__init__.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/parsers/curl.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/parsers/http.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/pseudo_selectors.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/regex_utils.py +0 -0
- {ssc_codegen-0.27.0 → ssc_codegen-0.29.0}/ssc_codegen/selector_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ssc_codegen
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.29.0
|
|
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
|
|
@@ -259,7 +259,7 @@ def pre_utilities(node: a.Utilities, _: ConverterContext):
|
|
|
259
259
|
" * @property {string} cause",
|
|
260
260
|
" */",
|
|
261
261
|
"",
|
|
262
|
-
"async function
|
|
262
|
+
"async function sscParseResponse(_resp) {",
|
|
263
263
|
" const _status = _resp.status;",
|
|
264
264
|
" const _headers = Object.fromEntries"
|
|
265
265
|
"([..._resp.headers.entries()]);",
|
|
@@ -268,7 +268,7 @@ def pre_utilities(node: a.Utilities, _: ConverterContext):
|
|
|
268
268
|
" return [_status, _headers, _body];",
|
|
269
269
|
"}",
|
|
270
270
|
"",
|
|
271
|
-
"function
|
|
271
|
+
"function sscParseResponseAxios(_resp) {",
|
|
272
272
|
" const _status = _resp.status;",
|
|
273
273
|
" const _headers = {};",
|
|
274
274
|
" for (const [k, v] of Object.entries(_resp.headers || {})) "
|
|
@@ -419,14 +419,17 @@ def pre_struct_item(node: a.StructItem, ctx: ConverterContext):
|
|
|
419
419
|
def pre_struct_list(node: a.StructList, ctx: ConverterContext):
|
|
420
420
|
return _js_struct_header(node, ctx)
|
|
421
421
|
|
|
422
|
+
|
|
422
423
|
@JS_CONVERTER(a.StructFlatList, post_callback="}")
|
|
423
424
|
def pre_struct_flatlist(node: a.StructFlatList, ctx: ConverterContext):
|
|
424
425
|
return _js_struct_header(node, ctx)
|
|
425
426
|
|
|
427
|
+
|
|
426
428
|
@JS_CONVERTER(a.StructDict, post_callback="}")
|
|
427
429
|
def pre_struct_dict(node: a.StructDict, ctx: ConverterContext):
|
|
428
430
|
return _js_struct_header(node, ctx)
|
|
429
431
|
|
|
432
|
+
|
|
430
433
|
@JS_CONVERTER(a.StructTable, post_callback="}")
|
|
431
434
|
def pre_struct_table(node: a.StructTable, ctx: ConverterContext):
|
|
432
435
|
return _js_struct_header(node, ctx)
|
|
@@ -464,7 +467,7 @@ def pre_struct_rest(node: a.StructRest, ctx: ConverterContext):
|
|
|
464
467
|
)
|
|
465
468
|
lines.extend(doc_lines)
|
|
466
469
|
lines.append(f"class {name} " + "{")
|
|
467
|
-
#
|
|
470
|
+
# sscDispatchErr static method (first member of class body)
|
|
468
471
|
lines.extend(_emit_dispatch_err_js(node, ctx.deeper()))
|
|
469
472
|
return lines
|
|
470
473
|
|
|
@@ -475,7 +478,7 @@ def pre_struct_docstring(node: a.StructDocstring, ctx: ConverterContext):
|
|
|
475
478
|
|
|
476
479
|
|
|
477
480
|
def _emit_dispatch_err_js(node: a.Struct, ctx: ConverterContext) -> list[str]:
|
|
478
|
-
"""Emit `
|
|
481
|
+
"""Emit `sscDispatchErr` static method inside a REST class body."""
|
|
479
482
|
i1 = ctx.indent # class-body level
|
|
480
483
|
i2 = i1 + ctx.indent_char # method body
|
|
481
484
|
i3 = i2 + ctx.indent_char # nested (if ...)
|
|
@@ -487,7 +490,7 @@ def _emit_dispatch_err_js(node: a.Struct, ctx: ConverterContext) -> list[str]:
|
|
|
487
490
|
field_errors = [e for e in errors if e.conditions or e.required_keys]
|
|
488
491
|
|
|
489
492
|
lines: list[str] = [
|
|
490
|
-
f"{i1}static
|
|
493
|
+
f"{i1}static sscDispatchErr(_status, _headers, _body) {{",
|
|
491
494
|
f"{i2}if (_status >= 200 && _status < 300) {{",
|
|
492
495
|
]
|
|
493
496
|
for err in field_errors:
|
|
@@ -1964,7 +1967,9 @@ def _js_rest_method(node: a.RequestConfig, ctx: ConverterContext) -> list[str]:
|
|
|
1964
1967
|
|
|
1965
1968
|
# Shared response extraction + dispatch
|
|
1966
1969
|
parser_fn = (
|
|
1967
|
-
"
|
|
1970
|
+
"sscParseResponseAxios"
|
|
1971
|
+
if http_client == "axios"
|
|
1972
|
+
else "sscParseResponse"
|
|
1968
1973
|
)
|
|
1969
1974
|
parse_prefix = "" if http_client == "axios" else "await "
|
|
1970
1975
|
lines.append(
|
|
@@ -1973,7 +1978,7 @@ def _js_rest_method(node: a.RequestConfig, ctx: ConverterContext) -> list[str]:
|
|
|
1973
1978
|
)
|
|
1974
1979
|
struct_pascal = to_pascal_case(struct_name) if struct_name else ""
|
|
1975
1980
|
lines.append(
|
|
1976
|
-
f"{i2}const _err = {struct_pascal}.
|
|
1981
|
+
f"{i2}const _err = {struct_pascal}.sscDispatchErr(_status, _headers, _body);"
|
|
1977
1982
|
)
|
|
1978
1983
|
lines.append(f"{i2}if (_err !== null) return _err;")
|
|
1979
1984
|
lines.append(
|
|
@@ -98,7 +98,7 @@ def runtime_export_names(node: a.Node) -> list[str]:
|
|
|
98
98
|
names = list(_BASE_EXPORT_NAMES)
|
|
99
99
|
if _module_has_rest(node):
|
|
100
100
|
names.extend(
|
|
101
|
-
["Ok", "Err", "UnknownErr", "TransportErr", "
|
|
101
|
+
["Ok", "Err", "UnknownErr", "TransportErr", "ssc_parse_response"]
|
|
102
102
|
)
|
|
103
103
|
return names
|
|
104
104
|
|
|
@@ -199,7 +199,7 @@ def rest_utilities(node: a.Node) -> list[str]:
|
|
|
199
199
|
" value: None = None",
|
|
200
200
|
" headers: Mapping[str, str] = field(default_factory=dict)",
|
|
201
201
|
"\n\n",
|
|
202
|
-
"def
|
|
202
|
+
"def ssc_parse_response(_resp):",
|
|
203
203
|
" _status = _resp.status_code",
|
|
204
204
|
" _headers = {k.lower(): v for k, v in _resp.headers.items()}",
|
|
205
205
|
" try:",
|
|
@@ -459,7 +459,7 @@ def _emit_dispatch_err(node: a.StructBase, ctx: ConverterContext) -> list[str]:
|
|
|
459
459
|
|
|
460
460
|
lines: list[str] = [
|
|
461
461
|
f"{i1}@staticmethod",
|
|
462
|
-
f"{i1}def
|
|
462
|
+
f"{i1}def ssc_dispatch_err("
|
|
463
463
|
f"_status: int, _headers: Mapping[str, str], _body: Any"
|
|
464
464
|
f") -> {union_type}:",
|
|
465
465
|
f"{i2}if 200 <= _status < 300:",
|
|
@@ -597,7 +597,7 @@ def pre_struct_rest(node: a.StructRest, ctx: ConverterContext):
|
|
|
597
597
|
lines.append("")
|
|
598
598
|
# Class header
|
|
599
599
|
lines.append(f"class {name}:")
|
|
600
|
-
#
|
|
600
|
+
# ssc_dispatch_err staticmethod (first member of class body, needs class-level indent)
|
|
601
601
|
lines.extend(_emit_dispatch_err(node, ctx.deeper()))
|
|
602
602
|
return lines
|
|
603
603
|
|
|
@@ -1824,8 +1824,12 @@ def _emit_rest_methods(
|
|
|
1824
1824
|
lines.append(f"{i3})")
|
|
1825
1825
|
lines.append(f"{i2}except httpx.HTTPError as _exc:")
|
|
1826
1826
|
lines.append(f"{i3}return TransportErr(cause=repr(_exc))")
|
|
1827
|
-
lines.append(
|
|
1828
|
-
|
|
1827
|
+
lines.append(
|
|
1828
|
+
f"{i2}_status, _headers, _body = ssc_parse_response(_resp)"
|
|
1829
|
+
)
|
|
1830
|
+
lines.append(
|
|
1831
|
+
f"{i2}_err = cls.ssc_dispatch_err(_status, _headers, _body)"
|
|
1832
|
+
)
|
|
1829
1833
|
lines.append(f"{i2}if _err is not None:")
|
|
1830
1834
|
lines.append(f"{i3}return _err")
|
|
1831
1835
|
lines.append(
|
|
@@ -280,6 +280,7 @@ def generate(
|
|
|
280
280
|
parsed.append((kdl_file, ast))
|
|
281
281
|
except Exception as exc:
|
|
282
282
|
if verbose:
|
|
283
|
+
typer.echo(f"ERROR {kdl_file}:", err=True)
|
|
283
284
|
typer.echo(traceback.format_exc(), err=True)
|
|
284
285
|
else:
|
|
285
286
|
typer.echo(f" ERROR {kdl_file}: {exc}", err=True)
|
|
@@ -320,6 +321,7 @@ def generate(
|
|
|
320
321
|
typer.echo(f" {kdl_file} -> {out_file}")
|
|
321
322
|
except Exception as exc:
|
|
322
323
|
if verbose:
|
|
324
|
+
typer.echo(f"ERROR {kdl_file}:", err=True)
|
|
323
325
|
typer.echo(traceback.format_exc(), err=True)
|
|
324
326
|
else:
|
|
325
327
|
typer.echo(f" ERROR {kdl_file}: {exc}", err=True)
|
|
@@ -395,9 +397,18 @@ def check(
|
|
|
395
397
|
total_errors = 0
|
|
396
398
|
|
|
397
399
|
for kdl_file in kdl_files:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
400
|
+
try:
|
|
401
|
+
_, errs = parse_module(
|
|
402
|
+
kdl_file.read_text(encoding="utf-8"), source_path=kdl_file
|
|
403
|
+
)
|
|
404
|
+
except Exception as exc:
|
|
405
|
+
if verbose:
|
|
406
|
+
typer.echo(f"ERROR {kdl_file}:", err=True)
|
|
407
|
+
typer.echo(traceback.format_exc(), err=True)
|
|
408
|
+
else:
|
|
409
|
+
typer.echo(f" ERROR {kdl_file}: {exc}", err=True)
|
|
410
|
+
total_errors += 1
|
|
411
|
+
continue
|
|
401
412
|
all_results.extend(errs)
|
|
402
413
|
|
|
403
414
|
if errs:
|
|
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
|
|
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
|