o
    ѷ6i3<                     @   s   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d	 ZG d
d dZ	G dd dZ
G dd dZG dd dZdS )    )Enum)Any)command_builderc                   @   s   e Zd ZdZdZdZdS )ScreenOrientationNaturalzNatural screen orientation.portrait	landscapeN)__name__
__module____qualname____doc__PORTRAIT	LANDSCAPE r   r   m/var/www/hoanhtaovolam_webdjango/env/lib/python3.10/site-packages/selenium/webdriver/common/bidi/emulation.pyr      s    r   c                   @   s    e Zd ZdZdZdZdZdZdS )ScreenOrientationTypezScreen orientation type.zportrait-primaryzportrait-secondaryzlandscape-primaryzlandscape-secondaryN)r   r	   r
   r   PORTRAIT_PRIMARYPORTRAIT_SECONDARYLANDSCAPE_PRIMARYLANDSCAPE_SECONDARYr   r   r   r   r      s    r   c                 C   s:   t | |r| S z||  W S  ty   td|  w )NzInvalid orientation: )
isinstancelower
ValueError)value
enum_classr   r   r   _convert_to_enum(   s   
r   c                   @   s@   e Zd ZdZdeeB deeB fddZdeeef fddZ	d	S )
ScreenOrientationz,Represents screen orientation configuration.naturaltypec                 C   s   t |t| _t |t| _dS )ag  Initialize ScreenOrientation.

        Args:
            natural: Natural screen orientation ("portrait" or "landscape").
            type: Screen orientation type ("portrait-primary", "portrait-secondary",
                "landscape-primary", or "landscape-secondary").

        Raises:
            ValueError: If natural or type values are invalid.
        N)r   r   r   r   r   )selfr   r   r   r   r   __init__4   s   zScreenOrientation.__init__returnc                 C   s   | j j| jjdS )N)r   r   )r   r   r   r   r   r   r   to_dictG   s   zScreenOrientation.to_dictN)
r   r	   r
   r   r   strr   r   dictr"   r   r   r   r   r   1   s    
r   c                   @   s"  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 fddZedd Zejdd Zedd Z	e	jdd Z	edd Z
e
jdd Z
edd Zejdd Zedd Zejdd Zedd Zejdd Zedd  Zejd!d  Zd"eeedB f fd#d$ZdS )&GeolocationCoordinatesz#Represents geolocation coordinates.      ?Nlatitude	longitudeaccuracyaltitudealtitude_accuracyheadingspeedc                 C   s.   || _ || _|| _|| _|| _|| _|| _dS )a  Initialize GeolocationCoordinates.

        Args:
            latitude: Latitude coordinate (-90.0 to 90.0).
            longitude: Longitude coordinate (-180.0 to 180.0).
            accuracy: Accuracy in meters (>= 0.0), defaults to 1.0.
            altitude: Altitude in meters or None, defaults to None.
            altitude_accuracy: Altitude accuracy in meters (>= 0.0) or None, defaults to None.
            heading: Heading in degrees (0.0 to 360.0) or None, defaults to None.
            speed: Speed in meters per second (>= 0.0) or None, defaults to None.

        Raises:
            ValueError: If coordinates are out of valid range or if altitude_accuracy is provided without altitude.
        Nr'   r(   r)   r*   r+   r,   r-   )r   r'   r(   r)   r*   r+   r,   r-   r   r   r   r   Q   s   
zGeolocationCoordinates.__init__c                 C      | j S N)	_latituder!   r   r   r   r'   q      zGeolocationCoordinates.latitudec                 C   .   d|  krdkst d t d|| _d S )Ng     Vg     V@z'latitude must be between -90.0 and 90.0)r   r1   r   r   r   r   r   r'   u   
   
c                 C   r/   r0   )
_longituder!   r   r   r   r(   {   r2   z GeolocationCoordinates.longitudec                 C   r3   )Ng     fg     f@z*longitude must be between -180.0 and 180.0)r   r6   r4   r   r   r   r(      r5   c                 C   r/   r0   )	_accuracyr!   r   r   r   r)      r2   zGeolocationCoordinates.accuracyc                 C   s   |dk rt d|| _d S )N        zaccuracy must be >= 0.0)r   r7   r4   r   r   r   r)      s   
c                 C   r/   r0   	_altituder!   r   r   r   r*      r2   zGeolocationCoordinates.altitudec                 C   
   || _ d S r0   r9   r4   r   r   r   r*      s   
c                 C   r/   r0   )_altitude_accuracyr!   r   r   r   r+      r2   z(GeolocationCoordinates.altitude_accuracyc                 C   s<   |d ur| j d u rtd|d ur|dk rtd|| _d S )Nz0altitude_accuracy cannot be set without altituder8   z altitude_accuracy must be >= 0.0)r*   r   r<   r4   r   r   r   r+      s
   
c                 C   r/   r0   )_headingr!   r   r   r   r,      r2   zGeolocationCoordinates.headingc                 C   s6   |d urd|  krdk st d t d|| _d S )Nr8   g     v@z%heading must be between 0.0 and 360.0)r   r=   r4   r   r   r   r,      s
   
c                 C   r/   r0   )_speedr!   r   r   r   r-      r2   zGeolocationCoordinates.speedc                 C   s"   |d ur|dk rt d|| _d S )Nr8   zspeed must be >= 0.0)r   r>   r4   r   r   r   r-      s   
r    c                 C   sf   | 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r1| j|d< |S )N)r'   r(   r)   r*   altitudeAccuracyr,   r-   r.   )r   resultr   r   r   r"      s   







zGeolocationCoordinates.to_dict)r&   NNNN)r   r	   r
   r   floatr   propertyr'   setterr(   r)   r*   r+   r,   r-   r$   r#   r"   r   r   r   r   r%   N   sf    
 













r%   c                   @   s<   e Zd ZdZdZefdefddZdeeef fddZd	S )
GeolocationPositionErrorz(Represents a geolocation position error.positionUnavailabler   c                 C   s&   || j krtd| j  d|| _d S )Nztype must be "")TYPE_POSITION_UNAVAILABLEr   r   )r   r   r   r   r   r      s   

z!GeolocationPositionError.__init__r    c                 C   s
   d| j iS )Nr   )r   r!   r   r   r   r"         
z GeolocationPositionError.to_dictN)	r   r	   r
   r   rG   r#   r   r$   r"   r   r   r   r   rD      s
    rD   c                   @   sf  e Zd ZdZdd Z				ddedB dedB dee dB dee dB d	df
d
dZ				ddedB dee dB dee dB d	dfddZ
			ddedB dee dB dee dB d	dfddZ			ddedB dee dB dee dB d	dfddZ			ddedB dee dB dee dB d	dfddZ			ddedB dee dB dee dB d	dfddZdS )	Emulationz,BiDi implementation of the emulation module.c                 C   r;   r0   )conn)r   rJ   r   r   r   r      rH   zEmulation.__init__Ncoordinateserrorcontextsuser_contextsr    c                 C   s   |dur|durt d|dur|durt d|du r$|du r$t di }|dur1| |d< n
|dur;| |d< |durD||d< n|durL||d< | jtd	| dS )
aT  Set geolocation override for the given contexts or user contexts.

        Args:
            coordinates: Geolocation coordinates to emulate, or None.
            error: Geolocation error to emulate, or None.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both coordinates and error are provided, or if both contexts
                and user_contexts are provided, or if neither contexts nor
                user_contexts are provided.
        Nz)Cannot specify both coordinates and error-Cannot specify both contexts and userContexts,Must specify either contexts or userContextsrK   rL   rM   userContextsz emulation.setGeolocationOverrider   r"   rJ   executer   )r   rK   rL   rM   rN   paramsr   r   r   set_geolocation_override   s    
z"Emulation.set_geolocation_overridetimezonec                 C   p   |dur|durt d|du r|du rt dd|i}|dur%||d< n|dur-||d< | jtd| dS )a   Set timezone override for the given contexts or user contexts.

        Args:
            timezone: Timezone identifier (IANA timezone name or offset string like '+01:00'),
                or None to clear the override.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both contexts and user_contexts are provided, or if neither
                contexts nor user_contexts are provided.
        N.Cannot specify both contexts and user_contexts-Must specify either contexts or user_contextsrV   rM   rQ   zemulation.setTimezoneOverrider   rJ   rS   r   )r   rV   rM   rN   rT   r   r   r   set_timezone_override  s   
zEmulation.set_timezone_overridelocalec                 C   rW   )a  Set locale override for the given contexts or user contexts.

        Args:
            locale: Locale string as per BCP 47, or None to clear override.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both contexts and user_contexts are provided, or if neither
                contexts nor user_contexts are provided, or if locale is invalid.
        NrO   rP   r\   rM   rQ   zemulation.setLocaleOverriderZ   )r   r\   rM   rN   rT   r   r   r   set_locale_override-     
zEmulation.set_locale_overrideFenabledc                 C   s|   |rt d|dur|durt d|du r|du rt dd|i}|dur+||d< n|dur3||d< | jtd| dS )	aI  Set scripting enabled override for the given contexts or user contexts.

        Args:
            enabled: False to disable scripting, None to clear the override.
                Note: Only emulation of disabled JavaScript is supported.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both contexts and user_contexts are provided, or if neither
                contexts nor user_contexts are provided, or if enabled is True.
        zROnly emulation of disabled JavaScript is supported (enabled must be False or None)NrO   rP   r_   rM   rQ   zemulation.setScriptingEnabledrZ   )r   r_   rM   rN   rT   r   r   r   set_scripting_enabledM  s   
zEmulation.set_scripting_enabledscreen_orientationc                 C   s   |dur|durt d|du r|du rt dd|dur!| ndi}|dur-||d< n|dur5||d< | jtd| dS )a   Set screen orientation override for the given contexts or user contexts.

        Args:
            screen_orientation: ScreenOrientation object to emulate, or None to clear the override.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both contexts and user_contexts are provided, or if neither
                contexts nor user_contexts are provided.
        NrO   rP   screenOrientationrM   rQ   z&emulation.setScreenOrientationOverriderR   )r   ra   rM   rN   rT   r   r   r   set_screen_orientation_overrideq  s   
z)Emulation.set_screen_orientation_override
user_agentc                 C   rW   )a  Set user agent override for the given contexts or user contexts.

        Args:
            user_agent: User agent string to emulate, or None to clear the override.
            contexts: List of browsing context IDs to apply the override to.
            user_contexts: List of user context IDs to apply the override to.

        Raises:
            ValueError: If both contexts and user_contexts are provided, or if neither
                contexts nor user_contexts are provided.
        NrX   rY   	userAgentrM   rQ   zemulation.setUserAgentOverriderZ   )r   rd   rM   rN   rT   r   r   r   set_user_agent_override  r^   z!Emulation.set_user_agent_override)NNNN)NNN)FNN)r   r	   r
   r   r   r%   rD   listr#   rU   r[   r]   boolr`   r   rc   rf   r   r   r   r   rI      s    


-


#


"


&


$

rI   N)enumr   typingr   %selenium.webdriver.common.bidi.commonr   r   r   r   r   r%   rD   rI   r   r   r   r   <module>   s   		