o
    f>h                     @   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   H/var/www/html/venv/lib/python3.10/site-packages/twilio/twiml/__init__.py
<listcomp>
   s    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)from_xml_langinterpret_asfor_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r0   r   r   r   __str__4   s   zTwiML.__str__c                 C   s   | S r'   r   r6   r   r   r   	__enter__7      zTwiML.__enter__c                 C   s   dS )NFr   )r0   exc_type	exc_value	tracebackr   r   r   __exit__:   r9   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"?>{})ETtostringxmldecodeformat)r0   xml_declarationrA   r   r   r   r5   =   s   
zTwiML.to_xmlc                 C   s   |  | | S )z^
        Add a TwiML doc

        :param verb: TwiML Document

        :returns: self
        )nestr0   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+   rH   rF   r   r   r   rE   U   s   z
TwiML.nestc                 C   s   t | j}| j }t|}|D ]}| j| }t|tr(||t	|
  q||t	| q| jrEt| jtrAt| j| _| j|_d }| jD ]}t|t	r]|d urY||_qJ||_qJ| }|| qJ|S r'   )r?   Elementr)   r,   keyssortedrI   boolsetrJ   r   r*   dictjsondumpstextr+   tailrA   rH   )r0   elrL   ar*   
last_childrG   r   r   r   rA   c   s*   




z	TwiML.xmlNc                 K   s   |  t||fi |S r'   )rE   GenericNoder0   r)   r*   r1   r   r   r   	add_child   s   zTwiML.add_child)Tr'   )r   r   r   r.   r4   r7   r8   r=   r5   rH   rE   rA   rZ   r   r   r   r   r   !   s     

!r   c                       s   e Zd Z fddZ  ZS )rX   c                    s&   t t| jdi | || _|| _d S )Nr   )superrX   r4   r)   r*   rY   r(   r   r   r4      s   
zGenericNode.__init__)r   r   r   r4   __classcell__r   r   r\   r   rX      s    rX   )rQ   r   xml.etree.ElementTreeetreeElementTreer?   r   r   	Exceptionr   objectr   rX   r   r   r   r   <module>   s    g