HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/genshi/__pycache__/core.cpython-310.pyc
o

!�b�d�@sHdZddlmZddlZddlmZddlZddlZddlm	Z	ddl
mZmZgd�Z
dZGd	d
�d
e�ZGdd�de�ZejZejZejZejZejZejZejZejZejZejZejZd
d�ZGdd�de�Z Gdd�dej!�Z"zddl#m"Z"Wn	e$y�Ynwe"j%Z%dd�Z&Gdd�de�Z'e'd�Z(Gdd�dej!�Z)dS)z#Core classes for markup processing.�)�reduceN)�chain)�
stringrepr)�
stripentities�	striptags)�Stream�Markup�escape�unescape�Attrs�	Namespace�QNamezrestructuredtext enc@s eZdZdZgZiZdd�ZdS)�StreamEventKindz#A kind of event on a markup stream.cCs|j�|t�||��S�N)�
_instances�
setdefault�str�__new__)�cls�val�r�-/usr/lib/python3/dist-packages/genshi/core.pyr$�zStreamEventKind.__new__N)�__name__�
__module__�__qualname__�__doc__�	__slots__rrrrrrrs
rc@s�eZdZdZddgZed�Zed�Zed�Zed�Z	ed�Z
ed	�Zed
�Zed�Z
ed�Zed
�Zed�Zd%dd�Zdd�Zdd�Zdd�Zd&dd�Zd'dd�Zd(dd�Zdd �Zd!d"�Zd#d$�ZdS))ra.Represents a stream of markup events.
    
    This class is basically an iterator over the events.
    
    Stream events are tuples of the form::
    
      (kind, data, position)
    
    where ``kind`` is the event kind (such as `START`, `END`, `TEXT`, etc),
    ``data`` depends on the kind of event, and ``position`` is a
    ``(filename, line, offset)`` tuple that contains the location of the
    original element or text in the input. If the original location is unknown,
    ``position`` is ``(None, -1, -1)``.
    
    Also provided are ways to serialize the stream to text. The `serialize()`
    method will return an iterator over generated strings, while `render()`
    returns the complete generated text at once. Both accept various parameters
    that impact the way the stream is serialized.
    �events�
serializer�START�END�TEXT�XML_DECL�DOCTYPE�START_NS�END_NS�START_CDATA�	END_CDATA�PI�COMMENTNcCs||_||_dS)a:Initialize the stream with a sequence of markup events.
        
        :param events: a sequence or iterable providing the events
        :param serializer: the default serialization method to use for this
                           stream

        :note: Changed in 0.5: added the `serializer` argument
        N)rr)�selfrrrrr�__init__Js	
zStream.__init__cC�
t|j�Sr)�iterr�r+rrr�__iter__V�
zStream.__iter__cCstt||��|jd�S)a�Override the "bitwise or" operator to apply filters or serializers
        to the stream, providing a syntax similar to pipes on Unix shells.
        
        Assume the following stream produced by the `HTML` function:
        
        >>> from genshi.input import HTML
        >>> html = HTML('''<p onclick="alert('Whoa')">Hello, world!</p>''', encoding='utf-8')
        >>> print(html)
        <p onclick="alert('Whoa')">Hello, world!</p>
        
        A filter such as the HTML sanitizer can be applied to that stream using
        the pipe notation as follows:
        
        >>> from genshi.filters import HTMLSanitizer
        >>> sanitizer = HTMLSanitizer()
        >>> print(html | sanitizer)
        <p>Hello, world!</p>
        
        Filters can be any function that accepts and produces a stream (where
        a stream is anything that iterates over events):
        
        >>> def uppercase(stream):
        ...     for kind, data, pos in stream:
        ...         if kind is TEXT:
        ...             data = data.upper()
        ...         yield kind, data, pos
        >>> print(html | sanitizer | uppercase)
        <p>HELLO, WORLD!</p>
        
        Serializers can also be used with this notation:
        
        >>> from genshi.output import TextSerializer
        >>> output = TextSerializer()
        >>> print(html | sanitizer | uppercase | output)
        HELLO, WORLD!
        
        Commonly, serializers should be used at the end of the "pipeline";
        using them somewhere in the middle may produce unexpected results.
        
        :param function: the callable object that should be applied as a filter
        :return: the filtered stream
        :rtype: `Stream`
        )r)r�_ensurer)r+�functionrrr�__or__Ys,z
Stream.__or__cGsttj|f|�S)aLApply filters to the stream.
        
        This method returns a new stream with the given filters applied. The
        filters must be callables that accept the stream object as parameter,
        and return the filtered stream.
        
        The call::
        
            stream.filter(filter1, filter2)
        
        is equivalent to::
        
            stream | filter1 | filter2
        
        :param filters: one or more callable objects that should be applied as
                        filters
        :return: the filtered stream
        :rtype: `Stream`
        )r�operator�or_)r+�filtersrrr�filter�sz
Stream.filtercKsBddlm}|dur|jpd}|jdd|i|��}|||||d�S)a�Return a string representation of the stream.
        
        Any additional keyword arguments are passed to the serializer, and thus
        depend on the `method` parameter value.
        
        :param method: determines how the stream is serialized; can be either
                       "xml", "xhtml", "html", "text", or a custom serializer
                       class; if `None`, the default serialization method of
                       the stream is used
        :param encoding: how the output string should be encoded; if set to
                         `None`, this method returns a `unicode` object
        :param out: a file-like object that the output should be written to
                    instead of being returned as one big string; note that if
                    this is a file or socket (or similar), the `encoding` must
                    not be `None` (that is, the output must be encoded)
        :return: a `str` or `unicode` object (depending on the `encoding`
                 parameter), or `None` if the `out` parameter is provided
        :rtype: `basestring`
        
        :see: XMLSerializer, XHTMLSerializer, HTMLSerializer, TextSerializer
        :note: Changed in 0.5: added the `out` parameter
        r)�encodeN�xml�method)r;�encoding�outr)�
genshi.outputr9r�	serialize)r+r;r<r=�kwargsr9�	generatorrrr�render�s

z
Stream.rendercCsddlm}||��|||�S)aTReturn a new stream that contains the events matching the given
        XPath expression.
        
        >>> from genshi import HTML
        >>> stream = HTML('<doc><elem>foo</elem><elem>bar</elem></doc>', encoding='utf-8')
        >>> print(stream.select('elem'))
        <elem>foo</elem><elem>bar</elem>
        >>> print(stream.select('elem/text()'))
        foobar
        
        Note that the outermost element of the stream becomes the *context
        node* for the XPath test. That means that the expression "doc" would
        not match anything in the example above, because it only tests against
        child elements of the outermost element:
        
        >>> print(stream.select('doc'))
        <BLANKLINE>
        
        You can use the "." expression to match the context node itself
        (although that usually makes little sense):
        
        >>> print(stream.select('.'))
        <doc><elem>foo</elem><elem>bar</elem></doc>
        
        :param path: a string containing the XPath expression
        :param namespaces: mapping of namespace prefixes used in the path
        :param variables: mapping of variable names to values
        :return: the selected substream
        :rtype: `Stream`
        :raises PathSyntaxError: if the given path expression is invalid or not
                                 supported
        r)�Path)�genshi.pathrC�select)r+�path�
namespaces�	variablesrCrrrrE�s!z
Stream.selectr:cKs6ddlm}|dur|jpd}||fi|��t|��S)a�Generate strings corresponding to a specific serialization of the
        stream.
        
        Unlike the `render()` method, this method is a generator that returns
        the serialized output incrementally, as opposed to returning a single
        string.
        
        Any additional keyword arguments are passed to the serializer, and thus
        depend on the `method` parameter value.
        
        :param method: determines how the stream is serialized; can be either
                       "xml", "xhtml", "html", "text", or a custom serializer
                       class; if `None`, the default serialization method of
                       the stream is used
        :return: an iterator over the serialization results (`Markup` or
                 `unicode` objects, depending on the serialization method)
        :rtype: ``iterator``
        :see: XMLSerializer, XHTMLSerializer, HTMLSerializer, TextSerializer
        r)�get_serializerNr:)r>rIrr2)r+r;r@rIrrrr?�s
zStream.serializecCs|��Sr�rBr/rrr�__str__��zStream.__str__cCs|jdd�S)N)r<rJr/rrr�__unicode__��zStream.__unicode__cCs|Srrr/rrr�__html__�szStream.__html__r)NNN)NN)r:)rrrrrrr r!r"r#r$r%r&r'r(r)r*r,r0r4r8rBrEr?rKrMrOrrrrr(s0
.


$rccs��t|�}zt|�}Wn
tyYdSwt|�tus"t|�dkrBt|g|�D]}t|d�r4|��}nt	t
�|�df}|Vq(dS|V|D]}|VqGdS)z@Ensure that every item on the stream is actually a markup event.N��totuple�N���rS)r.�next�
StopIteration�type�tuple�lenr�hasattrrQr"�six�	text_type)�stream�eventrrrr2s$��

�r2c@sVeZdZdZgZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
ddd�Zdd�ZdS)ra?Immutable sequence type that stores the attributes of an element.
    
    Ordering of the attributes is preserved, while access by name is also
    supported.
    
    >>> attrs = Attrs([('href', '#'), ('title', 'Foo')])
    >>> attrs
    Attrs([('href', '#'), ('title', 'Foo')])
    
    >>> 'href' in attrs
    True
    >>> 'tabindex' in attrs
    False
    >>> attrs.get('title')
    'Foo'
    
    Instances may not be manipulated directly. Instead, the operators ``|`` and
    ``-`` can be used to produce new instances that have specific attributes
    added, replaced or removed.
    
    To remove an attribute, use the ``-`` operator. The right hand side can be
    either a string or a set/sequence of strings, identifying the name(s) of
    the attribute(s) to remove:
    
    >>> attrs - 'title'
    Attrs([('href', '#')])
    >>> attrs - ('title', 'href')
    Attrs()
    
    The original instance is not modified, but the operator can of course be
    used with an assignment:

    >>> attrs
    Attrs([('href', '#'), ('title', 'Foo')])
    >>> attrs -= 'title'
    >>> attrs
    Attrs([('href', '#')])
    
    To add a new attribute, use the ``|`` operator, where the right hand value
    is a sequence of ``(name, value)`` tuples (which includes `Attrs`
    instances):
    
    >>> attrs | [('title', 'Bar')]
    Attrs([('href', '#'), ('title', 'Bar')])
    
    If the attributes already contain an attribute with a given name, the value
    of that attribute is replaced:
    
    >>> attrs | [('href', 'http://example.org/')]
    Attrs([('href', 'http://example.org/')])
    cCs |D]\}}||kr
dSqdS)z�Return whether the list includes an attribute with the specified
        name.
        
        :return: `True` if the list includes the attribute
        :rtype: `bool`
        TFr)r+�name�attr�_rrr�__contains__^s
�zAttrs.__contains__cCs$t�||�}t|�turt|�S|S)z�Return an item or slice of the attributes list.
        
        >>> attrs = Attrs([('href', '#'), ('title', 'Foo')])
        >>> attrs[1]
        ('title', 'Foo')
        >>> attrs[1:]
        Attrs([('title', 'Foo')])
        )rW�__getitem__rV�slicer)r+�i�itemsrrrrbjs	zAttrs.__getitem__cCstt�|||��S)z�Return a slice of the attributes list.
        
        >>> attrs = Attrs([('href', '#'), ('title', 'Foo')])
        >>> attrs[1:]
        Attrs([('title', 'Foo')])
        )rrW�__getslice__)r+rd�jrrrrfxszAttrs.__getslice__csTtdd�|D���t�fdd�|D���t��fdd��D���fdd�|D��S)a)Return a new instance that contains the attributes in `attrs` in
        addition to any already existing attributes. Any attributes in the new
        set that have a value of `None` are removed.
        
        :return: a new instance with the merged attributes
        :rtype: `Attrs`
        cSsg|]
\}}|dur|�qSrr��.0�an�avrrr�
<listcomp>�sz Attrs.__or__.<locals>.<listcomp>cs(g|]\}}|�vr|dur||f�qSrrrhr/rrrl���cs(g|]\}}|�vr|��||�f�qSr)�get)ri�sn�sv)�remove�replacerrrl�s�cs(g|]\}}|�vr|�vr||f�qSrrrh)rqr+rrrl�rm)�set�dictr)r+�attrsr)rqrrr+rr4�s
�zAttrs.__or__cCs |sdSdd�dd�|D��S)NzAttrs()zAttrs([%s])z, cSsg|]}t|��qSr)�repr�ri�itemrrrrl��z"Attrs.__repr__.<locals>.<listcomp>)�joinr/rrr�__repr__�szAttrs.__repr__cs(t�tj�r	�f�t�fdd�|D��S)z�Return a new instance with all attributes with a name in `names` are
        removed.
        
        :param names: the names of the attributes to remove
        :return: a new instance with the attribute removed
        :rtype: `Attrs`
        cs g|]\}}|�vr||f�qSrr)rir^r��namesrrrl�s z!Attrs.__sub__.<locals>.<listcomp>)�
isinstancerZ�string_typesr)r+r}rr|r�__sub__�sz
Attrs.__sub__NcCs"|D]\}}||kr|Sq|S)a�Return the value of the attribute with the specified name, or the
        value of the `default` parameter if no such attribute is found.
        
        :param name: the name of the attribute
        :param default: the value to return when the attribute does not exist
        :return: the attribute value, or the `default` value if that attribute
                 does not exist
        :rtype: `object`
        r)r+r^�defaultr_�valuerrrrn�s

�z	Attrs.getcCstd�dd�|D��dfS)a[Return the attributes as a markup event.
        
        The returned event is a `TEXT` event, the data is the value of all
        attributes joined together.
        
        >>> Attrs([('href', '#'), ('title', 'Foo')]).totuple()
        ('TEXT', '#Foo', (None, -1, -1))
        
        :return: a `TEXT` event
        :rtype: `tuple`
        �cSsg|]}|d�qS)�r)ri�xrrrrl�ryz!Attrs.totuple.<locals>.<listcomp>rR)r"rzr/rrrrQ�sz
Attrs.totupler)
rrrrrrarbrfr4r{r�rnrQrrrrr(s3	
rc@sreZdZdZgZdd�Zdd�Zdd�Zdd	�ZeZ	d
d�Z
dd
d�Zeddd��Z
dd�Zddd�Zdd�ZdS)rzeMarks a string as being safe for inclusion in HTML/XML output without
    needing to be escaped.
    cCsttj�|t|���Sr�rrZr[�__add__r	�r+�otherrrrr��rzMarkup.__add__cCsttj�t|�|��Srr�r�rrr�__radd__�rzMarkup.__radd__cCs`t|t�rtt|��tt|�����}nt|ttf�r#ttt|��}nt|�}t	t
j�||��Sr)
r~rt�zip�keys�mapr	�values�listrWrrZr[�__mod__)r+�argsrrrr��s
zMarkup.__mod__cCsttj�||��Sr)rrZr[�__mul__)r+�numrrrr���zMarkup.__mul__cCsdt|�jtj�|�fS)Nz<%s %s>)rVrrZr[r{r/rrrr{�szMarkup.__repr__Tcs$�fdd�|D�}ttj�||��S)aAReturn a `Markup` object which is the concatenation of the strings
        in the given sequence, where this `Markup` object is the separator
        between the joined elements.
        
        Any element in the sequence that is not a `Markup` instance is
        automatically escaped.
        
        :param seq: the sequence of strings to join
        :param escape_quotes: whether double quote characters in the elements
                              should be escaped
        :return: the joined `Markup` object
        :rtype: `Markup`
        :see: `escape`
        csg|]}t|�d��qS))�quotes)r	rw��
escape_quotesrrrl�szMarkup.join.<locals>.<listcomp>)rrZr[rz)r+�seqr��
escaped_itemsrr�rrz�szMarkup.joincCsd|s|�St|�|ur
|St|d�r||���S|�dd��dd��dd�}|r.|�dd	�}||�S)
a�Create a Markup instance from a string and escape special characters
        it may contain (<, >, & and ").
        
        >>> escape('"1 < 2"')
        <Markup '&#34;1 &lt; 2&#34;'>
        
        If the `quotes` parameter is set to `False`, the " character is left
        as is. Escaping quotes is generally only required for strings that are
        to be used in attribute values.
        
        >>> escape('"1 < 2"', quotes=False)
        <Markup '"1 &lt; 2"'>
        
        :param text: the text to escape
        :param quotes: if ``True``, double quote characters are escaped in
                       addition to the other special characters
        :return: the escaped `Markup` string
        :rtype: `Markup`
        rO�&�&amp;�<�&lt;�>�&gt;�"�&#34;)rVrYrOrr)r�textr�rrrr	�s

�z
Markup.escapecCs2|sdSt�|��dd��dd��dd��dd	�S)
z�Reverse-escapes &, <, >, and " and returns a `unicode` object.
        
        >>> Markup('1 &lt; 2').unescape()
        '1 < 2'
        
        :return: the unescaped string
        :rtype: `unicode`
        :see: `genshi.core.unescape`
        r�r�r�r�r�r�r�r�r�)rZr[rrr/rrrr
s
�zMarkup.unescapeFcCstt||d��S)a�Return a copy of the text with any character or numeric entities
        replaced by the equivalent UTF-8 characters.
        
        If the `keepxmlentities` parameter is provided and evaluates to `True`,
        the core XML entities (``&amp;``, ``&apos;``, ``&gt;``, ``&lt;`` and
        ``&quot;``) are not stripped.
        
        :return: a `Markup` instance with entities removed
        :rtype: `Markup`
        :see: `genshi.util.stripentities`
        )�keepxmlentities)rr)r+r�rrrr"szMarkup.stripentitiescCstt|��S)z�Return a copy of the text with all XML/HTML tags removed.
        
        :return: a `Markup` instance with all tags removed
        :rtype: `Markup`
        :see: `genshi.util.striptags`
        )rrr/rrrr0szMarkup.striptagsN)T)F)rrrrrr�r�r�r��__rmul__r{rz�classmethodr	r
rrrrrrr�s	
"
r)rcCst|t�s|S|��S)aoReverse-escapes &, <, >, and " and returns a `unicode` object.
    
    >>> unescape(Markup('1 &lt; 2'))
    '1 < 2'
    
    If the provided `text` object is not a `Markup` instance, it is returned
    unchanged.
    
    >>> unescape('1 &lt; 2')
    '1 &lt; 2'
    
    :param text: the text to unescape
    :return: the unescsaped string
    :rtype: `unicode`
    )r~rr
)r�rrrr
Cs
r
c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZeZ
dd�Zejddkr<dd�Zndd�Zdd�Zdd�ZdS) ra�Utility class creating and testing elements with a namespace.
    
    Internally, namespace URIs are encoded in the `QName` of any element or
    attribute, the namespace URI being enclosed in curly braces. This class
    helps create and test these strings.
    
    A `Namespace` object is instantiated with the namespace URI.
    
    >>> html = Namespace('http://www.w3.org/1999/xhtml')
    >>> html
    Namespace('http://www.w3.org/1999/xhtml')
    >>> html.uri
    'http://www.w3.org/1999/xhtml'
    
    The `Namespace` object can than be used to generate `QName` objects with
    that namespace:
    
    >>> html.body
    QName('http://www.w3.org/1999/xhtml}body')
    >>> html.body.localname
    'body'
    >>> html.body.namespace
    'http://www.w3.org/1999/xhtml'
    
    The same works using item access notation, which is useful for element or
    attribute names that are not valid Python identifiers:
    
    >>> html['body']
    QName('http://www.w3.org/1999/xhtml}body')
    
    A `Namespace` object can also be used to test whether a specific `QName`
    belongs to that namespace using the ``in`` operator:
    
    >>> qname = html.body
    >>> qname in html
    True
    >>> qname in Namespace('http://www.w3.org/2002/06/xhtml2')
    False
    cCst|�|ur|St�|�Sr)rV�objectr)r�urirrrr�s
zNamespace.__new__cCs|jfSr�r�r/rrr�__getnewargs__�rLzNamespace.__getnewargs__cC�|jSrr�r/rrr�__getstate__��zNamespace.__getstate__cCs
||_dSrr��r+r�rrr�__setstate__�r1zNamespace.__setstate__cCst�|�|_dSr)rZr[r�r�rrrr,�szNamespace.__init__cCs|j|jkSr)�	namespacer�)r+�qnamerrrra�rNzNamespace.__contains__cCs
||kSrrr�rrr�__ne__�r1zNamespace.__ne__cCs t|t�r|j|jkS|j|kSr)r~rr�r�rrr�__eq__�s

zNamespace.__eq__cCst|jd|�S)N�})r
r�)r+r^rrrrb�r�zNamespace.__getitem__cCr-r)�hashr�r/rrr�__hash__�r1zNamespace.__hash__r�cCsdt|�jt|j�fS)N�%s(%s))rVrrr�r/rrrr{��zNamespace.__repr__cCsdt|�j|jfS)N�%s(%r))rVrr�r/rrrr{�scCs|j�d�S)Nzutf-8)r�r9r/rrrrK�rNzNamespace.__str__cCr�rr�r/rrrrM�r�zNamespace.__unicode__N)rrrrrr�r�r�r,rar�r�rb�__getattr__r��sys�version_infor{rKrMrrrrrXs$'
rz$http://www.w3.org/XML/1998/namespacec@sJeZdZdZddgZdd�Zdd�Zejdd	krd
d�Z	d
Sdd�Z	d
S)r
a�A qualified element or attribute name.
    
    The unicode value of instances of this class contains the qualified name of
    the element or attribute, in the form ``{namespace-uri}local-name``. The
    namespace URI can be obtained through the additional `namespace` attribute,
    while the local name can be accessed through the `localname` attribute.
    
    >>> qname = QName('foo')
    >>> qname
    QName('foo')
    >>> qname.localname
    'foo'
    >>> qname.namespace
    
    >>> qname = QName('http://www.w3.org/1999/xhtml}body')
    >>> qname
    QName('http://www.w3.org/1999/xhtml}body')
    >>> qname.localname
    'body'
    >>> qname.namespace
    'http://www.w3.org/1999/xhtml'
    r��	localnamecCs�t|�|ur|S|�d�}|�dd�}t|�dkr.tj�|d|�}ttj|�\|_|_	|Stj�||�}dt�|�|_|_	|S)z�Create the `QName` instance.
        
        :param qname: the qualified name as a string of the form
                      ``{namespace-uri}local-name``, where the leading curly
                      brace is optional
        �{r�r�z{%sN)
rV�lstrip�splitrXrZr[rr�r�r�)rr��partsr+rrrr�s
�z
QName.__new__cCs|�d�fS)Nr�)r�r/rrrr��rNzQName.__getnewargs__rr�cCsdt|�jt|�d��fS)Nr�r�)rVrrr�r/rrrr{�szQName.__repr__cCsdt|�j|�d�fS)Nr�r�)rVrr�r/rrrr{�r�N)
rrrrrrr�r�r�r{rrrrr
�sr
)*r�	functoolsrr��	itertoolsrr5rZ�
genshi.compatr�genshi.utilrr�__all__�
__docformat__rrr�rr r!r"r#r$r%r&r'r(r)r*r2rWrr[r�genshi._speedups�ImportErrorr	r
r�
XML_NAMESPACEr
rrrr�<module>sL
	Zz�[