o
    �¨Êh3  ã                   @   sH   d dl mZ d dlmZ d dlmZ G dd„ deƒZG dd„ deƒZdS )	é    )ÚJwt)Ú	iteritems)Ú	urlencodec                       sJ   e Zd ZdZejddf‡ fdd„	Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
‡  ZS )ÚClientCapabilityTokenz1A token to control permissions with Twilio Clienti  Nc                    s�   t t| ƒjd||||dd� || _|| _d| _i | _d|v r(| jdi |d ¤Ž d|v r6| jdi |d ¤Ž d|v rF| j	di |d ¤Ž dS dS )a  
        :param str account_sid: The account sid to which this token is granted access.
        :param str auth_token: The secret key used to sign the token. Note, this auth token is not
                               visible to the user of the token.
        :param int nbf: Time in secs from epic before which this token is considered invalid.
        :param int ttl: the amount of time in seconds from generation that this token is valid for.
        :param kwargs:


        :returns: A new CapabilityToken with zero permissions
        ÚHS256N)Ú	algorithmÚ
secret_keyÚissuerÚnbfÚttlÚvalid_untilÚallow_client_outgoingÚallow_client_incomingÚallow_event_stream© )
Úsuperr   Ú__init__Úaccount_sidÚ
auth_tokenÚclient_nameÚcapabilitiesr   r   r   )Úselfr   r   r
   r   r   Úkwargs©Ú	__class__r   úL/var/www/html/env/lib/python3.10/site-packages/twilio/jwt/client/__init__.pyr   
   s&   
ú	ÿzClientCapabilityToken.__init__c                 K   s6   t ddd|iƒ}|r| dt|dd�¡ || jd< dS )zÁ
        Allow the user of this token to make outgoing connections. Keyword arguments are passed
        to the application.

        :param str application_sid: Application to contact
        ÚclientÚoutgoingÚappSidÚ	appParamsT©ÚdoseqN©ÚScopeURIÚ	add_paramr   r   )r   Úapplication_sidr   Úscoper   r   r   r   ,   s   z+ClientCapabilityToken.allow_client_outgoingc                 C   s    || _ tddd|iƒ| jd< dS )z�
        Allow the user of this token to accept incoming connections.

        :param str client_name: Client name to accept calls from
        r   ÚincomingÚ
clientNameN)r   r#   r   )r   r   r   r   r   r   9   s   z+ClientCapabilityToken.allow_client_incomingc                 K   s6   t ddddiƒ}|r| dt|dd�¡ || jd< d	S )
zL
        Allow the user of this token to access their event stream.
        ÚstreamÚ	subscribeÚpathz/2010-04-01/EventsÚparamsTr    ÚeventsNr"   )r   r   r&   r   r   r   r   B   s   z(ClientCapabilityToken.allow_event_streamc                 C   sJ   d| j v r| jd ur| j d  d| j¡ dd„ | j  ¡ D ƒ}dd |¡iS )Nr   r(   c                 S   s   g | ]}|  ¡ ‘qS r   )Ú
to_payload)Ú.0Ú	scope_urir   r   r   Ú
<listcomp>P   s    z;ClientCapabilityToken._generate_payload.<locals>.<listcomp>r&   ú )r   r   r$   ÚvaluesÚjoin)r   Ú
scope_urisr   r   r   Ú_generate_payloadL   s   z'ClientCapabilityToken._generate_payload)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚGENERATEr   r   r   r   r6   Ú__classcell__r   r   r   r   r      s    "	
r   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )r#   zDA single capability granted to Twilio Client and scoped to a serviceNc                 C   s   || _ || _|p	i | _d S ©N)ÚserviceÚ	privileger,   )r   r>   r?   r,   r   r   r   r   W   s   zScopeURI.__init__c                 C   s   || j |< d S r=   )r,   )r   ÚkeyÚvaluer   r   r   r$   \   ó   zScopeURI.add_paramc                 C   sH   | j rtdd„ t| j ƒD ƒƒ}t|ƒ}d |¡}nd}d | j| j|¡S )Nc                 S   s   g | ]\}}||f‘qS r   r   )r/   ÚkÚvr   r   r   r1   a   s    z'ScopeURI.to_payload.<locals>.<listcomp>z?{}Ú zscope:{}:{}{})r,   Úsortedr   r   Úformatr>   r?   )r   Úsorted_paramsÚencoded_paramsÚparam_stringr   r   r   r.   _   s   zScopeURI.to_payloadc                 C   s   d  |  ¡ ¡S )Nz<ScopeURI {}>)rG   r.   )r   r   r   r   Ú__str__h   rB   zScopeURI.__str__r=   )r7   r8   r9   r:   r   r$   r.   rK   r   r   r   r   r#   T   s    
	r#   N)	Ú
twilio.jwtr   Úsixr   Útwilio.compatr   r   Úobjectr#   r   r   r   r   Ú<module>   s
    M