o
    O`                     @   s    d dl mZ G dd deZdS )    )Jwtc                       s   e Zd ZdZdZdZ fddZedd Zedd	 Z	ed
d Z
dd Zdd Zdd Zdd Zdd Zdd Zd#ddZdd Zd$ddZdd  Zd!d" Z  ZS )%TaskRouterCapabilityTokenv1zhttps://taskrouter.twilio.comz-https://event-bridge.twilio.com/v1/wschannelsc              
      s   t t| j||d|dtj|dd|ddd | ||| || _|| _|| _	|| _
g | _|dd	r;|   |d
d	rE|   |ddrO|   |ddrY|   |ddrc|   |ddrm|   |ddry|   dS dS )a  
        :param str account_sid: Twilio account sid
        :param str auth_token: Twilio auth token used to sign the JWT
        :param str workspace_sid: TaskRouter workspace sid
        :param str channel_id: TaskRouter channel sid
        :param kwargs:
            :param bool allow_web_sockets: shortcut to calling allow_web_sockets, defaults to True
            :param bool allow_fetch_self: shortcut to calling allow_fetch_self, defaults to True
            :param bool allow_update_self: shortcut to calling allow_update_self, defaults to False
            :param bool allow_delete_self: shortcut to calling allow_delete_self, defaults to False
            :param bool allow_fetch_subresources: shortcut to calling allow_fetch_subresources,
                                                  defaults to False
            :param bool allow_update_subresources: shortcut to calling allow_update_subresources,
                                                   defaults to False
            :param bool allow_delete_subresources: shortcut to calling allow_delete_subresources,
                                                   defaults to False
        :returns a new TaskRouterCapabilityToken with capabilities set depending on kwargs.
        HS256nbfttli  valid_untilN)
secret_keyissuer	algorithmr   r   r   allow_web_socketsTallow_fetch_selfallow_update_selfFallow_delete_selfallow_fetch_subresourcesallow_delete_subresourcesallow_update_subresources)superr   __init__getr   GENERATE_validate_inputsaccount_sid
auth_tokenworkspace_sid
channel_idpoliciesr   r   r   r   r   r   r   )selfr   r   r   r   kwargs	__class__ b/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/twilio/jwt/taskrouter/__init__.pyr   	   s:   


	z"TaskRouterCapabilityToken.__init__c                 C   s   d | j| j| jS )Nz{}/{}/Workspaces/{})formatDOMAINVERSIONr   r   r!   r!   r"   workspace_url<   s   z'TaskRouterCapabilityToken.workspace_urlc                 C      t d)Nz,Subclass must set its specific resource_url.NotImplementedErrorr&   r!   r!   r"   resource_url@      z&TaskRouterCapabilityToken.resource_urlc                 C   r(   )Nz5Subclass must set its specific channel_id sid prefix.r)   r&   r!   r!   r"   channel_prefixD   r,   z(TaskRouterCapabilityToken.channel_prefixc                 C      |  | jdd d S )NGETT_make_policyr+   r&   r!   r!   r"   r   H      z*TaskRouterCapabilityToken.allow_fetch_selfc                 C   r.   )NPOSTTr0   r&   r!   r!   r"   r   K   r2   z+TaskRouterCapabilityToken.allow_update_selfc                 C   r.   )NDELETETr0   r&   r!   r!   r"   r   N   r2   z+TaskRouterCapabilityToken.allow_delete_selfc                 C      |  | jd dd d S )N/**r/   Tr0   r&   r!   r!   r"   r   Q      z2TaskRouterCapabilityToken.allow_fetch_subresourcesc                 C   r5   )Nr6   r3   Tr0   r&   r!   r!   r"   r   T   r7   z3TaskRouterCapabilityToken.allow_update_subresourcesc                 C   r5   )Nr6   r4   Tr0   r&   r!   r!   r"   r   W   r7   z3TaskRouterCapabilityToken.allow_delete_subresourcesNc                 C   s<   |p| j }d| j| j|}| |dd | |dd d S )Nz{}/{}/{}r/   Tr3   )r   r#   EVENTS_BASE_URLr   r1   )r   r   web_socket_urlr!   r!   r"   r   Z   s   
z+TaskRouterCapabilityToken.allow_web_socketsc                 C   sR   | j | j| j| j| j| jd}| jdr| j|d< |S | jdr'| j|d< |S )N)r   r   channelversionfriendly_namer   WK
worker_sidWQtaskqueue_sid)r   r   r   r%   r   
startswith)r   payloadr!   r!   r"   _generate_payload`   s   	

z+TaskRouterCapabilityToken._generate_payloadc                 C   s(   | j || ||pi |pi d d S )N)urlmethodallowquery_filterpost_filter)r   appendupper)r   rD   rE   allowedrG   rH   r!   r!   r"   r1   q   s   z&TaskRouterCapabilityToken._make_policyc                 C   sZ   |r| dstd||r| dstd||r$| | js+td|d S )NACzInvalid account sid provided {}WSz!Invalid workspace sid provided {}zInvalid channel id provided {})rA   
ValueErrorr#   r-   )r   r   r   r   r!   r!   r"   r   z   s   z*TaskRouterCapabilityToken._validate_inputsc                 C   s   d |  S )Nz<TaskRouterCapabilityToken {}>)r#   to_jwtr&   r!   r!   r"   __str__   s   z!TaskRouterCapabilityToken.__str__)N)NN)__name__
__module____qualname__r%   r$   r8   r   propertyr'   r+   r-   r   r   r   r   r   r   r   rC   r1   r   rP   __classcell__r!   r!   r   r"   r      s,    3




	
r   N)
twilio.jwtr   r   r!   r!   r!   r"   <module>   s    