selectolax 0.3.30__cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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 ADDED
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ __author__ = """Artem Golubin"""
5
+ __email__ = 'me@rushter.com'
6
+ __version__ = '0.3.30'
7
+
8
+ from . import parser
9
+ from . import lexbor
10
+ from . import modest
selectolax/base.pxi ADDED
@@ -0,0 +1,4 @@
1
+
2
+ class SelectolaxError(Exception):
3
+ """An exception that indicates error."""
4
+ pass
@@ -0,0 +1,103 @@
1
+ cimport cython
2
+
3
+ @cython.final
4
+ cdef class LexborAttributes:
5
+ """A dict-like object that represents attributes."""
6
+ cdef lxb_dom_node_t *node
7
+ cdef unicode decode_errors
8
+
9
+ @staticmethod
10
+ cdef LexborAttributes create(lxb_dom_node_t *node):
11
+ obj = <LexborAttributes> LexborAttributes.__new__(LexborAttributes)
12
+ obj.node = node
13
+ return obj
14
+
15
+ def __iter__(self):
16
+ cdef lxb_dom_attr_t *attr = lxb_dom_element_first_attribute_noi(<lxb_dom_element_t *> self.node)
17
+ cdef size_t str_len = 0
18
+ attributes = dict()
19
+
20
+ while attr != NULL:
21
+ key = lxb_dom_attr_local_name_noi(attr, &str_len)
22
+ if key is not NULL:
23
+ yield key.decode(_ENCODING)
24
+ attr = attr.next
25
+
26
+ def __setitem__(self, str key, value):
27
+ value = str(value)
28
+ bytes_key = key.encode(_ENCODING)
29
+ bytes_value = value.encode(_ENCODING)
30
+
31
+ lxb_dom_element_set_attribute(
32
+ <lxb_dom_element_t *> self.node,
33
+ <lxb_char_t *> bytes_key, len(bytes_key),
34
+ <lxb_char_t *> bytes_value, len(bytes_value),
35
+ )
36
+
37
+ def __delitem__(self, key):
38
+ try:
39
+ self.__getitem__(key)
40
+ except KeyError:
41
+ raise KeyError(key)
42
+ bytes_key = key.encode(_ENCODING)
43
+ lxb_dom_element_remove_attribute(
44
+ <lxb_dom_element_t *> self.node,
45
+ <lxb_char_t *> bytes_key, len(bytes_key),
46
+ )
47
+
48
+ def __getitem__(self, str key):
49
+ bytes_key = key.encode(_ENCODING)
50
+ cdef lxb_dom_attr_t * attr = lxb_dom_element_attr_by_name(
51
+ <lxb_dom_element_t *> self.node,
52
+ <lxb_char_t *> bytes_key, len(bytes_key)
53
+ )
54
+ cdef size_t str_len = 0
55
+ if attr != NULL:
56
+ value = lxb_dom_attr_value_noi(attr, &str_len)
57
+ return value.decode(_ENCODING) if value else None
58
+ raise KeyError(key)
59
+
60
+ def __len__(self):
61
+ return len(list(self.__iter__()))
62
+
63
+ def keys(self):
64
+ return self.__iter__()
65
+
66
+ def items(self):
67
+ for key in self.__iter__():
68
+ yield key, self[key]
69
+
70
+ def values(self):
71
+ for key in self.__iter__():
72
+ yield self[key]
73
+
74
+ def get(self, key, default=None):
75
+ try:
76
+ return self[key]
77
+ except KeyError:
78
+ return default
79
+
80
+ def sget(self, key, default=""):
81
+ """Same as get, but returns empty strings instead of None values for empty attributes."""
82
+ try:
83
+ val = self[key]
84
+ if val is None:
85
+ val = ""
86
+ return val
87
+ except KeyError:
88
+ return default
89
+
90
+ def __contains__(self, key):
91
+ try:
92
+ self[key]
93
+ except KeyError:
94
+ return False
95
+ else:
96
+ return True
97
+
98
+ def __repr__(self):
99
+ cdef lxb_char_t *c_text
100
+ cdef size_t str_len = 0
101
+ c_text = lxb_dom_element_qualified_name(<lxb_dom_element_t *> self.node, &str_len)
102
+ tag_name = c_text.decode(_ENCODING, 'ignore') if c_text != NULL else 'unknown'
103
+ return "<%s attributes, %s items>" % (tag_name, len(self))