a
    !f                     @   sf   d dl Z d dlZd dlm  mZ dd Zdd ZG dd deZ	G dd	 d	e
ZG d
d deZdS )    Nc                 C   sB   | rd| vr| S d dd | dD }|d  |dd   S )N_ c                 S   s   g | ]}|  qS  )title).0xr   r   V/var/www/html/python-backend/venv/lib/python3.9/site-packages/twilio/twiml/__init__.py
<listcomp>
       zlower_camel.<locals>.<listcomp>r      )joinsplitlower)stringresultr   r   r   lower_camel   s    r   c                 C   s@   | s| S t d| std| dd  d | dd   S )zj
    Attempt to format language parameter as 'ww-WW'.

    :param string language: language parameter
    z^[a-zA-Z]{2}[_-][a-zA-Z]{2}$z%Invalid value for language parameter.r      -      )rematchTwiMLExceptionr   upper)languager   r   r   format_language   s
    r   c                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__r   r   r   r   r      s   r   c                   @   sh   e Zd ZddddddZdd Zd	d
 Zdd Zdd ZdddZdd Z	dd Z
dd ZdddZdS )TwiMLfromzxml:langzinterpret-asforbreak)Zfrom_Zxml_langZinterpret_asZfor_Zbreak_c                 K   sR   | j j| _d | _g | _i | _| D ](\}}|d ur$|| jt| j	||< q$d S N)
	__class__r   namevalueverbsattrsitemsr   MAPget)selfkwargskvr   r   r   __init__*   s    
zTwiML.__init__c                 C   s   |   S r#   )to_xmlr,   r   r   r   __str__4   s    zTwiML.__str__c                 C   s   | S r#   r   r2   r   r   r   	__enter__7   s    zTwiML.__enter__c                 C   s   dS )NFr   )r,   exc_type	exc_value	tracebackr   r   r   __exit__:   s    zTwiML.__exit__Tc                 C   s*   t j|  ddd}|r&d|S |S )z
        Return the contents of this verb as an XML string

        :param bool xml_declaration: Include the XML declaration. Defaults to True
        zutf-8)encodingz(<?xml version="1.0" encoding="UTF-8"?>{})ETZtostringxmldecodeformat)r,   Zxml_declarationr;   r   r   r   r1   =   s
    zTwiML.to_xmlc                 C   s   |  | | S )z^
        Add a TwiML doc

        :param verb: TwiML Document

        :returns: self
        )nestr,   verbr   r   r   appendJ   s    
zTwiML.appendc                 C   s,   t |tst |tstd| j| |S )z
        Add a TwiML doc. Unlike `append()`, this returns the created verb.

        :param verb: TwiML Document

        :returns: the TwiML verb
        z-Only nesting of TwiML and strings are allowed)
isinstancer   strr   r'   rA   r?   r   r   r   r>   U   s    z
TwiML.nestc                 C   s   t | j}| j }t|}|D ]>}| j| }t|trP||t	|
  q"||t	| q"| jrt| jtrt| j| _| j|_d }| jD ]8}t|t	r|d ur||_q||_q| }|| q|S r#   )r:   ZElementr%   r(   keyssortedrB   boolsetrC   r   r&   dictjsondumpstextr'   tailr;   rA   )r,   elrD   ar&   Z
last_childr@   r   r   r   r;   c   s*    




z	TwiML.xmlNc                 K   s   |  t||fi |S r#   )r>   GenericNoder,   r%   r&   r-   r   r   r   	add_child   s    zTwiML.add_child)T)N)r   r   r   r*   r0   r3   r4   r8   r1   rA   r>   r;   rQ   r   r   r   r   r   !   s   

!r   c                       s   e Zd Z fddZ  ZS )rO   c                    s&   t t| jf i | || _|| _d S r#   )superrO   r0   r%   r&   rP   r$   r   r   r0      s    zGenericNode.__init__)r   r   r   r0   __classcell__r   r   rS   r   rO      s   rO   )rI   r   Zxml.etree.ElementTreeetreeZElementTreer:   r   r   	Exceptionr   objectr   rO   r   r   r   r   <module>   s   g