selectolax 0.3.30__cp311-cp311-macosx_10_9_x86_64.whl → 0.3.32__cp311-cp311-macosx_10_9_x86_64.whl
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 selectolax might be problematic. Click here for more details.
- selectolax/__init__.py +1 -1
- selectolax/lexbor/attrs.pxi +27 -9
- selectolax/lexbor/node.pxi +3 -0
- selectolax/lexbor/selection.pxi +1 -0
- selectolax/lexbor.c +17024 -19207
- selectolax/lexbor.cpython-311-darwin.so +0 -0
- selectolax/lexbor.pxd +5 -6
- selectolax/lexbor.pyi +716 -66
- selectolax/parser.c +15911 -17594
- selectolax/parser.cpython-311-darwin.so +0 -0
- selectolax/parser.pyi +487 -43
- {selectolax-0.3.30.dist-info → selectolax-0.3.32.dist-info}/METADATA +6 -16
- selectolax-0.3.32.dist-info/RECORD +26 -0
- selectolax-0.3.30.dist-info/RECORD +0 -26
- {selectolax-0.3.30.dist-info → selectolax-0.3.32.dist-info}/WHEEL +0 -0
- {selectolax-0.3.30.dist-info → selectolax-0.3.32.dist-info}/licenses/LICENSE +0 -0
- {selectolax-0.3.30.dist-info → selectolax-0.3.32.dist-info}/top_level.txt +0 -0
selectolax/__init__.py
CHANGED
selectolax/lexbor/attrs.pxi
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
cimport cython
|
|
2
2
|
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
3
5
|
@cython.final
|
|
4
6
|
cdef class LexborAttributes:
|
|
5
7
|
"""A dict-like object that represents attributes."""
|
|
@@ -23,16 +25,32 @@ cdef class LexborAttributes:
|
|
|
23
25
|
yield key.decode(_ENCODING)
|
|
24
26
|
attr = attr.next
|
|
25
27
|
|
|
26
|
-
def __setitem__(self, str key, value):
|
|
27
|
-
value =
|
|
28
|
+
def __setitem__(self, str key, object value):
|
|
29
|
+
value = value
|
|
28
30
|
bytes_key = key.encode(_ENCODING)
|
|
29
|
-
bytes_value = value.encode(_ENCODING)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
bytes_value = value.encode(_ENCODING) if value else b""
|
|
32
|
+
cdef lxb_dom_attr_t *attr
|
|
33
|
+
cdef lxb_dom_document_t *doc
|
|
34
|
+
|
|
35
|
+
if value is None:
|
|
36
|
+
# N.B. This is suboptimal, but there is not API to set empty attributes
|
|
37
|
+
attr = lxb_dom_element_set_attribute(
|
|
38
|
+
<lxb_dom_element_t *> self.node,
|
|
39
|
+
<lxb_char_t *> bytes_key, len(bytes_key),
|
|
40
|
+
NULL, 0
|
|
41
|
+
)
|
|
42
|
+
doc = (<lxb_dom_node_t*>attr).owner_document
|
|
43
|
+
lexbor_str_destroy(attr.value, doc.text, 0)
|
|
44
|
+
attr.value = NULL
|
|
45
|
+
|
|
46
|
+
elif isinstance(value, str) or isinstance(value, unicode) :
|
|
47
|
+
lxb_dom_element_set_attribute(
|
|
48
|
+
<lxb_dom_element_t *> self.node,
|
|
49
|
+
<lxb_char_t *> bytes_key, len(bytes_key),
|
|
50
|
+
<lxb_char_t *> bytes_value, len(bytes_value),
|
|
51
|
+
)
|
|
52
|
+
else:
|
|
53
|
+
raise TypeError("Expected str or unicode, got %s" % type(value))
|
|
36
54
|
|
|
37
55
|
def __delitem__(self, key):
|
|
38
56
|
try:
|
selectolax/lexbor/node.pxi
CHANGED
|
@@ -273,6 +273,9 @@ cdef class LexborNode:
|
|
|
273
273
|
>>> tag.decompose()
|
|
274
274
|
|
|
275
275
|
"""
|
|
276
|
+
if self.node == <lxb_dom_node_t *> lxb_dom_document_root(&self.parser.document.dom_document):
|
|
277
|
+
raise SelectolaxError("Decomposing the root node is not allowed.")
|
|
278
|
+
|
|
276
279
|
if recursive:
|
|
277
280
|
lxb_dom_node_destroy_deep(<lxb_dom_node_t *> self.node)
|
|
278
281
|
else:
|
selectolax/lexbor/selection.pxi
CHANGED
|
@@ -75,6 +75,7 @@ cdef class LexborCSSSelector:
|
|
|
75
75
|
status = lxb_selectors_find(self.selectors, node.node, selectors_list,
|
|
76
76
|
<lxb_selectors_cb_f> css_matcher_callback, <void *> self)
|
|
77
77
|
if status != LXB_STATUS_OK:
|
|
78
|
+
lxb_css_selector_list_destroy_memory(selectors_list)
|
|
78
79
|
raise SelectolaxError("Can't parse CSS selector.")
|
|
79
80
|
result = bool(self.results)
|
|
80
81
|
self.results = []
|