selectolax 0.3.20__cp312-cp312-win32.whl → 0.3.23__cp312-cp312-win32.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.

Binary file
selectolax/lexbor.pxd CHANGED
@@ -340,7 +340,8 @@ cdef extern from "lexbor/dom/collection.h" nogil:
340
340
 
341
341
 
342
342
  cdef extern from "lexbor/css/css.h" nogil:
343
- ctypedef struct lxb_css_parser_t
343
+ ctypedef struct lxb_css_parser_t:
344
+ lxb_css_memory_t* memory
344
345
  ctypedef struct lxb_css_syntax_tokenizer_t
345
346
  ctypedef struct lxb_css_memory_t
346
347
 
@@ -560,7 +561,12 @@ cdef extern from "lexbor/selectors/selectors.h" nogil:
560
561
  ctypedef struct lxb_css_selector_specificity_t
561
562
  ctypedef lxb_status_t (*lxb_selectors_cb_f)(lxb_dom_node_t *node, lxb_css_selector_specificity_t *spec,
562
563
  void *ctx)
564
+ ctypedef enum lxb_selectors_opt_t:
565
+ LXB_SELECTORS_OPT_DEFAULT = 0x00
566
+ LXB_SELECTORS_OPT_MATCH_ROOT = 1 << 1
567
+ LXB_SELECTORS_OPT_MATCH_FIRST = 1 << 2
563
568
 
569
+ void lxb_selectors_opt_set(lxb_selectors_t *selectors, lxb_selectors_opt_t opt)
564
570
  lxb_css_selectors_t * lxb_css_selectors_create()
565
571
  lxb_status_t lxb_css_selectors_init(lxb_css_selectors_t *selectors)
566
572
  void lxb_css_parser_selectors_set(lxb_css_parser_t *parser, lxb_css_selectors_t *selectors)
selectolax/lexbor.pyi CHANGED
@@ -79,7 +79,7 @@ class LexborNode:
79
79
  def iter(self, include_text: bool = False) -> Iterator["LexborNode"]: ...
80
80
  def unwrap(self) -> None: ...
81
81
  def unwrap_tags(self, tags: list[str]) -> None: ...
82
- def traverse(self, indluce_text: bool = False) -> Iterator["LexborNode"]: ...
82
+ def traverse(self, include_text: bool = False) -> Iterator["LexborNode"]: ...
83
83
  def replace_with(self, value: bytes | str | "LexborNode") -> None: ...
84
84
  def insert_before(self, value: bytes | str | "LexborNode") -> None: ...
85
85
  def insert_after(self, value: bytes | str | "LexborNode") -> None: ...
@@ -119,4 +119,4 @@ class LexborHTMLParser:
119
119
  def scripts_srcs_contain(self, queries: tuple[str]) -> bool: ...
120
120
  def css_matches(self, selector: str) -> bool: ...
121
121
  def clone(self) -> "LexborHTMLParser": ...
122
- def unwrap_tags(self, tags: list[str]) -> None: ...
122
+ def unwrap_tags(self, tags: list[str]) -> None: ...
@@ -712,6 +712,46 @@ cdef class Node:
712
712
  else:
713
713
  raise TypeError("Expected a string or Node instance, but %s found" % type(value).__name__)
714
714
 
715
+ def insert_child(self, str_or_Node value):
716
+ """
717
+ Insert a node inside (at the end of) the current Node.
718
+
719
+ Parameters
720
+ ----------
721
+ value : str, bytes or Node
722
+ The text or Node instance to insert inside the Node.
723
+ When a text string is passed, it's treated as text. All HTML tags will be escaped.
724
+ Convert and pass the ``Node`` object when you want to work with HTML.
725
+ Does not clone the ``Node`` object.
726
+ All future changes to the passed ``Node`` object will also be taken into account.
727
+
728
+ Examples
729
+ --------
730
+
731
+ >>> tree = HTMLParser('<div>Get <img src=""></div>')
732
+ >>> div = tree.css_first('div')
733
+ >>> div.insert_child('Laptop')
734
+ >>> tree.body.child.html
735
+ '<div>Get <img src="">Laptop</div>'
736
+
737
+ >>> html_parser = HTMLParser('<div>Get <span alt="Laptop"> <div>Laptop</div> </span></div>')
738
+ >>> html_parser2 = HTMLParser('<div>Test</div>')
739
+ >>> span_node = html_parser.css_first('span')
740
+ >>> span_node.insert_child(html_parser2.body.child)
741
+ <div>Get <span alt="Laptop"> <div>Laptop</div> <div>Test</div> </span></div>'
742
+ """
743
+ cdef myhtml_tree_node_t *node
744
+ if isinstance(value, (str, bytes, unicode)):
745
+ bytes_val = to_bytes(value)
746
+ node = myhtml_node_create(self.parser.html_tree, MyHTML_TAG__TEXT, MyHTML_NAMESPACE_HTML)
747
+ myhtml_node_text_set(node, <char*> bytes_val, len(bytes_val), MyENCODING_UTF_8)
748
+ myhtml_node_append_child(self.node, node)
749
+ elif isinstance(value, Node):
750
+ node = myhtml_node_clone_deep(self.parser.html_tree, <myhtml_tree_node_t *> value.node)
751
+ myhtml_node_append_child(self.node, node)
752
+ else:
753
+ raise TypeError("Expected a string or Node instance, but %s found" % type(value).__name__)
754
+
715
755
  def unwrap_tags(self, list tags):
716
756
  """Unwraps specified tags from the HTML tree.
717
757
 
@@ -188,6 +188,6 @@ cdef bool find_matches(HTMLParser parser, myhtml_tree_node_t *node, tuple select
188
188
 
189
189
  collection_size = collection.length
190
190
  myhtml_collection_destroy(collection)
191
- if collection.length > 0:
191
+ if collection_size > 0:
192
192
  return True
193
193
  return False