selectolax 0.3.32__cp39-cp39-macosx_11_0_arm64.whl → 0.3.34__cp39-cp39-macosx_11_0_arm64.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 +3 -5
- selectolax/lexbor/attrs.pxi +0 -1
- selectolax/lexbor/node.pxi +99 -41
- selectolax/lexbor/selection.pxi +27 -25
- selectolax/lexbor/util.pxi +1 -0
- selectolax/lexbor.c +6414 -6703
- selectolax/lexbor.cpython-39-darwin.so +0 -0
- selectolax/lexbor.pxd +32 -35
- selectolax/lexbor.pyi +51 -1
- selectolax/lexbor.pyx +48 -17
- selectolax/modest/node.pxi +37 -36
- selectolax/modest/selection.pxi +24 -22
- selectolax/modest/util.pxi +1 -0
- selectolax/parser.c +4526 -5292
- selectolax/parser.cpython-39-darwin.so +0 -0
- selectolax/parser.pxd +17 -20
- selectolax/parser.pyi +2 -2
- selectolax/parser.pyx +28 -31
- selectolax/utils.pxi +13 -3
- selectolax-0.3.34.dist-info/METADATA +32 -0
- selectolax-0.3.34.dist-info/RECORD +26 -0
- selectolax-0.3.32.dist-info/METADATA +0 -187
- selectolax-0.3.32.dist-info/RECORD +0 -26
- {selectolax-0.3.32.dist-info → selectolax-0.3.34.dist-info}/WHEEL +0 -0
- {selectolax-0.3.32.dist-info → selectolax-0.3.34.dist-info}/licenses/LICENSE +0 -0
- {selectolax-0.3.32.dist-info → selectolax-0.3.34.dist-info}/top_level.txt +0 -0
selectolax/modest/selection.pxi
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
cimport cython
|
|
2
|
+
from cpython.exc cimport PyErr_SetObject
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
@cython.final
|
|
4
6
|
cdef class CSSSelector:
|
|
@@ -28,35 +30,33 @@ cdef class CSSSelector:
|
|
|
28
30
|
|
|
29
31
|
return collection
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
cdef _create_css_parser(self):
|
|
33
|
+
cdef int _create_css_parser(self) except -1:
|
|
33
34
|
cdef mystatus_t status
|
|
34
35
|
|
|
35
36
|
cdef mycss_t *mycss = mycss_create()
|
|
36
37
|
status = mycss_init(mycss)
|
|
37
38
|
|
|
38
39
|
if status != 0:
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
PyErr_SetObject(RuntimeError, "Can't init MyCSS object.")
|
|
41
|
+
return -1
|
|
41
42
|
|
|
42
43
|
self.css_entry = mycss_entry_create()
|
|
43
44
|
status = mycss_entry_init(mycss, self.css_entry)
|
|
44
45
|
|
|
45
46
|
if status != 0:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
PyErr_SetObject(RuntimeError, "Can't init MyCSS Entry object.")
|
|
48
|
+
return -1
|
|
49
|
+
return 0
|
|
49
50
|
|
|
50
|
-
cdef _prepare_selector(self, mycss_entry_t *css_entry,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
myencoding_t.MyENCODING_UTF_8,
|
|
55
|
-
selector, selector_size,
|
|
56
|
-
&out_status)
|
|
51
|
+
cdef int _prepare_selector(self, mycss_entry_t *css_entry, const char *selector, size_t selector_size) except -1:
|
|
52
|
+
cdef mystatus_t out_status
|
|
53
|
+
self.selectors_list = mycss_selectors_parse(mycss_entry_selectors(css_entry), myencoding_t.MyENCODING_UTF_8,
|
|
54
|
+
selector, selector_size, &out_status)
|
|
57
55
|
|
|
58
56
|
if (self.selectors_list == NULL) or (self.selectors_list.flags and MyCSS_SELECTORS_FLAGS_SELECTOR_BAD):
|
|
59
|
-
|
|
57
|
+
PyErr_SetObject(ValueError, "Bad CSS Selectors: %s" % self.c_selector.decode('utf-8'))
|
|
58
|
+
return -1
|
|
59
|
+
return 0
|
|
60
60
|
|
|
61
61
|
def __dealloc__(self):
|
|
62
62
|
mycss_selectors_list_destroy(mycss_entry_selectors(self.css_entry), self.selectors_list, 1)
|
|
@@ -77,12 +77,11 @@ cdef class Selector:
|
|
|
77
77
|
cdef Node node
|
|
78
78
|
cdef list nodes
|
|
79
79
|
|
|
80
|
-
def __init__(self, Node node, query):
|
|
80
|
+
def __init__(self, Node node, str query):
|
|
81
81
|
"""custom init, because __cinit__ doesn't accept C types"""
|
|
82
82
|
self.node = node
|
|
83
83
|
self.nodes = find_nodes(node.parser, node.node, query) if query else [node, ]
|
|
84
84
|
|
|
85
|
-
|
|
86
85
|
cpdef css(self, str query):
|
|
87
86
|
"""Evaluate CSS selector against current scope."""
|
|
88
87
|
cdef Node current_node
|
|
@@ -106,6 +105,7 @@ cdef class Selector:
|
|
|
106
105
|
def text_contains(self, str text, bool deep=True, str separator='', bool strip=False):
|
|
107
106
|
"""Filter all current matches given text."""
|
|
108
107
|
nodes = []
|
|
108
|
+
cdef Node node
|
|
109
109
|
for node in self.nodes:
|
|
110
110
|
node_text = node.text(deep=deep, separator=separator, strip=strip)
|
|
111
111
|
if node_text and text in node_text:
|
|
@@ -116,6 +116,7 @@ cdef class Selector:
|
|
|
116
116
|
def any_text_contains(self, str text, bool deep=True, str separator='', bool strip=False):
|
|
117
117
|
"""Returns True if any node in the current search scope contains specified text"""
|
|
118
118
|
nodes = []
|
|
119
|
+
cdef Node node
|
|
119
120
|
for node in self.nodes:
|
|
120
121
|
node_text = node.text(deep=deep, separator=separator, strip=strip)
|
|
121
122
|
if node_text and text in node_text:
|
|
@@ -142,7 +143,8 @@ cdef class Selector:
|
|
|
142
143
|
|
|
143
144
|
Similar to `string-length` in XPath.
|
|
144
145
|
"""
|
|
145
|
-
nodes = []
|
|
146
|
+
cdef list nodes = []
|
|
147
|
+
cdef Node node
|
|
146
148
|
for node in self.nodes:
|
|
147
149
|
attr = node.attributes.get(attribute)
|
|
148
150
|
if attr and start and start in attr:
|
|
@@ -157,16 +159,15 @@ cdef class Selector:
|
|
|
157
159
|
cdef find_nodes(HTMLParser parser, myhtml_tree_node_t *node, str query):
|
|
158
160
|
cdef myhtml_collection_t *collection
|
|
159
161
|
cdef CSSSelector selector = CSSSelector(query)
|
|
160
|
-
|
|
161
|
-
result =
|
|
162
|
+
cdef Node n
|
|
163
|
+
cdef list result = []
|
|
162
164
|
collection = selector.find(node)
|
|
163
165
|
|
|
164
166
|
if collection == NULL:
|
|
165
167
|
return result
|
|
166
168
|
|
|
167
169
|
for i in range(collection.length):
|
|
168
|
-
n = Node()
|
|
169
|
-
n._init(collection.list[i], parser)
|
|
170
|
+
n = Node.new(collection.list[i], parser)
|
|
170
171
|
result.append(n)
|
|
171
172
|
myhtml_collection_destroy(collection)
|
|
172
173
|
return result
|
|
@@ -176,6 +177,7 @@ cdef bool find_matches(HTMLParser parser, myhtml_tree_node_t *node, tuple select
|
|
|
176
177
|
cdef myhtml_collection_t *collection
|
|
177
178
|
cdef CSSSelector selector
|
|
178
179
|
cdef int collection_size
|
|
180
|
+
cdef str query
|
|
179
181
|
|
|
180
182
|
for query in selectors:
|
|
181
183
|
selector = CSSSelector(query)
|