
    pe                         d dl Z d dlmZmZmZ d dlmZ d dlmZ de dZ	 e j                  e	      j                  Zdedee   d	dfd
ZddZdeded	efdZy)    N)AnyCallableOptional)etree)HTML5_WHITESPACE[z]+fnamefuncreturnc                 D    t        j                  d      }|||| <   y|| = y)a  Register a custom extension function to use in XPath expressions.

    The function ``func`` registered under ``fname`` identifier will be called
    for every matching node, being passed a ``context`` parameter as well as
    any parameters passed from the corresponding XPath expression.

    If ``func`` is ``None``, the extension function will be removed.

    See more `in lxml documentation`_.

    .. _`in lxml documentation`: https://lxml.de/extensions.html#xpath-extension-functions

    N)r   FunctionNamespace)r	   r
   ns_fnss      1lib/python3.12/site-packages/parsel/xpathfuncs.pyset_xpathfuncr      s*     $$T*Fu5M    c                  $    t        dt               y )Nz	has-class)r   	has_class r   r   setupr   "   s    +y)r   contextclassesc                 @   | j                   j                  d      s>|st        d      |D ]  }t        |t              rt        d       d| j                   d<   | j
                  j                  d      }|yd|z   dz   }t        d|      }|D ]  }d|z   dz   |vs y y)zbhas-class function.

    Return True if all ``classes`` are present in element's class attr.

    args_checkedz4XPath error: has-class must have at least 1 argumentz0XPath error: has-class arguments must be stringsTclassF )eval_contextget
ValueError
isinstancestrcontext_nodereplace_html5_whitespaces)r   r   cnode_clsclss        r   r   r   &   s     ##N3F   	Aa% F 	
 04^,##''0HX~#H(h7H 9s?(* r   )r   N)retypingr   r   r   lxmlr   
w3lib.htmlr   regexcompilesubr"   r    r   r   boolr   r   r   r   <module>r.      s{    	 * *  ' R &BJJu-11  HX$6 4 **s c d r   