o
    ѷ6i1                     @   s   d dl mZ d dlmZ G dd dZG dd dZG dd dZG d	d
 d
ZG dd dZG dd dZ	G dd dZ
G dd dZG dd dZG dd dZG dd dZG dd dZdS )    )Any)command_builderc                   @   s    e Zd ZdZdZdZdZdZdS )SameSitez5Represents the possible same site values for cookies.strictlaxnonedefaultN)__name__
__module____qualname____doc__STRICTLAXNONEDEFAULT r   r   k/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/selenium/webdriver/common/bidi/storage.pyr      s    r   c                   @   s8   e Zd ZdZdZdZdedefddZdefd	d
Z	dS )
BytesValuezRepresents a bytes value.base64stringtypevaluec                 C      || _ || _d S Nr   r   )selfr   r   r   r   r   __init__&      
zBytesValue.__init__returnc                 C      | j | jdS )z~Converts the BytesValue to a dictionary.

        Returns:
            A dictionary representation of the BytesValue.
        r   r   r   r   r   r   to_dict*      zBytesValue.to_dictN)
r	   r
   r   r   TYPE_BASE64TYPE_STRINGstrr   dictr!   r   r   r   r   r       s    r   c                   @   sz   e Zd ZdZ						ddededededB dedB dedB d	edB d
edB dedB fddZe	de
dd fddZdS )CookiezRepresents a cookie.Nnamer   domainpathsize	http_onlysecure	same_siteexpiryc
           
      C   :   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   	r(   r   r)   r*   r+   r,   r-   r.   r/   
r   r(   r   r)   r*   r+   r,   r-   r.   r/   r   r   r   r   6      
zCookie.__init__datar   c                 C   s   | d}|std| d}|stdt| di  d| di  d}| t||t|| d| d| d	| d
| d| dd	S )zCreates a Cookie instance from a dictionary.

        Args:
            data: A dictionary containing the cookie information.

        Returns:
            A new instance of Cookie.
        r(   z$name is required and cannot be emptyr)   z&domain is required and cannot be emptyr   r   r*   r+   httpOnlyr-   sameSiter/   r1   )get
ValueErrorr   r%   )clsr4   r(   r)   r   r   r   r   	from_dictL   s$   

&zCookie.from_dict)NNNNNN)r	   r
   r   r   r%   r   intboolr   classmethodr&   r:   r   r   r   r   r'   3   s:    	

r'   c                   @   s   e Zd ZdZ									ddedB dedB dedB dedB dedB dedB d	edB d
edB dedB fddZde	ee
f fddZdS )CookieFilterz Represents a filter for cookies.Nr(   r   r)   r*   r+   r,   r-   r.   r/   c
           
      C   r0   r   r1   r2   r   r   r   r   o   r3   zCookieFilter.__init__r   c                 C   s   i }| j dur| j |d< | jdur| j |d< | jdur"| j|d< | jdur,| j|d< | jdur6| j|d< | jdur@| j|d< | jdurJ| j|d< | jdurT| j|d	< | j	dur^| j	|d
< |S )zConverts the CookieFilter to a dictionary.

        Returns:
            A dictionary representation of the CookieFilter.
        Nr(   r   r)   r*   r+   r5   r-   r6   r/   )
r(   r   r!   r)   r*   r+   r,   r-   r.   r/   r   resultr   r   r   r!      s(   
















zCookieFilter.to_dict)	NNNNNNNNN)r	   r
   r   r   r%   r   r;   r<   r   r&   r   r!   r   r   r   r   r>   l   s>    	

r>   c                   @   sB   e Zd ZdZddedB dedB fddZededd fd	d
ZdS )PartitionKeyz#Represents a storage partition key.Nuser_contextsource_originc                 C   r   r   rB   rC   r   rB   rC   r   r   r   r      r   zPartitionKey.__init__r4   r   c                 C   s   | | d| ddS )zCreates a PartitionKey instance from a dictionary.

        Args:
            data: A dictionary containing the partition key information.

        Returns:
            A new instance of PartitionKey.
        userContextsourceOriginrD   )r7   )r9   r4   r   r   r   r:      s   
zPartitionKey.from_dictNN)	r	   r
   r   r   r%   r   r=   r&   r:   r   r   r   r   rA      s
    rA   c                   @   s,   e Zd ZdZdefddZdefddZdS )	"BrowsingContextPartitionDescriptorz3Represents a browsing context partition descriptor.contextc                 C   s   d| _ || _d S )NrJ   r   rJ   )r   rJ   r   r   r   r      r   z+BrowsingContextPartitionDescriptor.__init__r   c                 C   r   )zConverts the BrowsingContextPartitionDescriptor to a dictionary.

        Returns:
            Dict: A dictionary representation of the BrowsingContextPartitionDescriptor.
        rK   rK   r    r   r   r   r!      r"   z*BrowsingContextPartitionDescriptor.to_dictNr	   r
   r   r   r%   r   r&   r!   r   r   r   r   rI      s    rI   c                   @   s:   e Zd ZdZd
dedB dedB fddZdefdd	ZdS )StorageKeyPartitionDescriptorz.Represents a storage key partition descriptor.NrB   rC   c                 C   s   d| _ || _|| _d S )N
storageKeyr   rB   rC   rE   r   r   r   r      s   
z&StorageKeyPartitionDescriptor.__init__r   c                 C   s6   d| j i}| jdur| j|d< | jdur| j|d< |S )zConverts the StorageKeyPartitionDescriptor to a dictionary.

        Returns:
            Dict: A dictionary representation of the StorageKeyPartitionDescriptor.
        r   NrF   rG   rO   r?   r   r   r   r!      s   




z%StorageKeyPartitionDescriptor.to_dictrH   rL   r   r   r   r   rM      s    rM   c                   @   sp   e Zd ZdZ					ddededededB dedB dedB d	edB d
edB fddZde	ee
f fddZdS )PartialCookiez(Represents a partial cookie for setting.Nr(   r   r)   r*   r,   r-   r.   r/   c	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r   )r(   r   r)   r*   r,   r-   r.   r/   )	r   r(   r   r)   r*   r,   r-   r.   r/   r   r   r   r      s   
zPartialCookie.__init__r   c                 C   s~   | j | j | jd}| jdur| j|d< | jdur| j|d< | jdur)| j|d< | jdur3| j|d< | jdur=| j|d< |S )zConverts the PartialCookie to a dictionary.

        Returns:
        -------
            Dict: A dictionary representation of the PartialCookie.
        )r(   r   r)   Nr*   r5   r-   r6   r/   )	r(   r   r!   r)   r*   r,   r-   r.   r/   r?   r   r   r   r!      s   









zPartialCookie.to_dict)NNNNN)r	   r
   r   r   r%   r   r<   r;   r   r&   r   r!   r   r   r   r   rP      s2    	
rP   c                   @   s<   e Zd ZdZdee defddZede	dd fdd	Z
d
S )GetCookiesResultz.Represents the result of a getCookies command.cookiespartition_keyc                 C   r   r   rR   rS   )r   rR   rS   r   r   r   r     r   zGetCookiesResult.__init__r4   r   c                 C   s4   dd | dg D }t| di }| ||dS )zCreates a GetCookiesResult instance from a dictionary.

        Args:
            data: A dictionary containing the get cookies result information.

        Returns:
            A new instance of GetCookiesResult.
        c                 S   s   g | ]}t |qS r   )r'   r:   ).0cookier   r   r   
<listcomp>  s    z.GetCookiesResult.from_dict.<locals>.<listcomp>rR   partitionKeyrT   )r7   rA   r:   )r9   r4   rR   rS   r   r   r   r:     s   
zGetCookiesResult.from_dictN)r	   r
   r   r   listr'   rA   r   r=   r&   r:   r   r   r   r   rQ     s
    rQ   c                   @   4   e Zd ZdZdefddZededd fddZd	S )
SetCookieResultz-Represents the result of a setCookie command.rS   c                 C   
   || _ d S r   rS   r   rS   r   r   r   r   '     
zSetCookieResult.__init__r4   r   c                 C      t |di }| |dS )zCreates a SetCookieResult instance from a dictionary.

        Args:
            data: A dictionary containing the set cookie result information.

        Returns:
            A new instance of SetCookieResult.
        rX   r]   rA   r:   r7   r9   r4   rS   r   r   r   r:   *     

zSetCookieResult.from_dictN	r	   r
   r   r   rA   r   r=   r&   r:   r   r   r   r   r[   $  
    r[   c                   @   rZ   )
DeleteCookiesResultz1Represents the result of a deleteCookies command.rS   c                 C   r\   r   r]   r^   r   r   r   r   ;  r_   zDeleteCookiesResult.__init__r4   r   c                 C   r`   )zCreates a DeleteCookiesResult instance from a dictionary.

        Args:
            data: A dictionary containing the delete cookies result information.

        Returns:
            A new instance of DeleteCookiesResult.
        rX   r]   ra   rb   r   r   r   r:   >  rc   zDeleteCookiesResult.from_dictNrd   r   r   r   r   rf   8  re   rf   c                   @   s   e Zd ZdZdd Z		ddedB deeB dB defdd	Z		dd
e
deeB dB defddZ		ddedB deeB dB defddZdS )Storagez*BiDi implementation of the storage module.c                 C   r\   r   )conn)r   rh   r   r   r   r   O  r_   zStorage.__init__Nfilter	partitionr   c                 C   H   i }|dur|  |d< |dur|  |d< | jtd|}t|S )a  Gets cookies matching the specified filter.

        Args:
            filter: Optional filter to specify which cookies to retrieve.
            partition: Optional partition key to limit the scope of the operation.

        Returns:
            A GetCookiesResult containing the cookies and partition key.

        Example:
            result = await storage.get_cookies(
                filter=CookieFilter(name="sessionId"),
                partition=PartitionKey(...)
            )
        Nri   rj   zstorage.getCookies)r!   rh   executer   rQ   r:   r   ri   rj   paramsr@   r   r   r   get_cookiesR  s   
zStorage.get_cookiesrV   c                 C   s<   d|  i}|dur|  |d< | jtd|}t|S )zSets a cookie in the browser.

        Args:
            cookie: The cookie to set.
            partition: Optional partition descriptor.

        Returns:
            The result of the set cookie command.
        rV   Nrj   zstorage.setCookie)r!   rh   rl   r   r[   r:   )r   rV   rj   rn   r@   r   r   r   
set_cookieo  s
   
zStorage.set_cookiec                 C   rk   )a  Deletes cookies that match the given parameters.

        Args:
            filter: Optional filter to match cookies to delete.
            partition: Optional partition descriptor.

        Returns:
            The result of the delete cookies command.
        Nri   rj   zstorage.deleteCookies)r!   rh   rl   r   rf   r:   rm   r   r   r   delete_cookies  s   
zStorage.delete_cookiesrH   r   )r	   r
   r   r   r   r>   rI   rM   rQ   ro   rP   r[   rp   rf   rq   r   r   r   r   rg   L  s:    

 


rg   N)typingr   %selenium.webdriver.common.bidi.commonr   r   r   r'   r>   rA   rI   rM   rP   rQ   r[   rf   rg   r   r   r   r   <module>   s   	950