← Back
Editing: _textattributes.cpython-38.pyc
U W[w# � @ s� d Z ddlmZ ddlmZ G dd� dee�ZG dd� de�ZG dd � d e�ZG d d� de�Z G dd � d e �Z G dd� de �ZG dd� de�ZG dd� de�Z G dd� dee�ZG dd� de�Zddd�ZdddgZdS )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} � )�print_function)�FancyEqMixinc @ s6 e Zd ZdZdZdd� Zdd� Zdd� Zd dd�Zd S )� _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. ��childrenc C s g | _ d S �Nr ��self� r �@/usr/lib/python3/dist-packages/twisted/python/_textattributes.py�__init__+ s z_Attribute.__init__c C s dt | �jt| �f S )Nz<%s %r>)�type�__name__�varsr r r r �__repr__/ s z_Attribute.__repr__c C sB t |ttttf�st�t |ttf�r2| j�|� n| j�|� | S r ) � isinstance�list�tupler �str�AssertionErrorr �extend�append)r �itemr r r �__getitem__3 s z_Attribute.__getitem__N�toVT102c C sX |dkrt � }| jD ]>}t|t�r6|�||�� |� qt||�}||� � ||� qdS )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 r r � serialize�copy�getattr)r �write�attrs�attributeRendererZchZ renderMethr r r r <