o
    �¨ÊhÐ  ã                   @   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__© úP/var/www/html/env/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    