
    >i*                     R    d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	  G d de      Z
y)    )suppress)Options)PageLoadState)ArgumentAlreadyExistsInOptionsArgumentNotFoundInOptionsWrongPrefsDictc                      e Zd ZdZd Zedee   fd       Zej                  dee   fd       Zedefd       Z
e
j                  defd	       Z
edefd
       Zej                  defd       ZdefdZdefdZedefd       Zej                  defd       ZdefdZdefdZdefdZdefdZedefd       Zej                  defd       Zedefd       Zej                  defd       Zedefd       Zej                  defd        Zedefd!       Zej                  defd"       Zedefd#       Zej                  d$efd%       Zedefd&       Zej                  defd'       Zedefd(       Zej                  d)efd*       Zedefd+       Zej                  defd,       Zedefd-       Zej                  d.efd/       Zy0)1ChromiumOptionsz
    A class to manage command-line options for a browser instance.

    This class allows the user to specify command-line arguments and
    the binary location of the browser executable.
    c                     g | _         d| _        d| _        i | _        d| _        d| _        t        j                  | _        y)z
        Initializes the Options instance.

        Sets up an empty list for command-line arguments and a string
        for the binary location of the browser.
         
   FN)	
_arguments_binary_location_start_timeout_browser_preferences	_headless_webrtc_leak_protectionr   COMPLETE_page_load_stateselfs    \/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/browser/options.py__init__zChromiumOptions.__init__   s@      " $&!',$ - 6 6    returnc                     | j                   S )z
        Gets the list of command-line arguments.

        Returns:
            list: A list of command-line arguments added to the options.
        r   r   s    r   	argumentszChromiumOptions.arguments#   s     r   	args_listc                     || _         y)z
        Sets the list of command-line arguments.

        Args:
            args_list (list): A list of command-line arguments.
        Nr   )r   r   s     r   r   zChromiumOptions.arguments-   s     $r   c                     | j                   S )z
        Gets the location of the browser binary.

        Returns:
            str: The file path to the browser executable.
        r   r   s    r   binary_locationzChromiumOptions.binary_location7   s     $$$r   locationc                     || _         y)z
        Sets the location of the browser binary.

        Args:
            location (str): The file path to the browser executable.
        Nr"   )r   r$   s     r   r#   zChromiumOptions.binary_locationA   s     !)r   c                     | j                   S )z
        Gets the timeout to verify the browser's running state.

        Returns:
            int: The timeout in seconds.
        r   r   s    r   start_timeoutzChromiumOptions.start_timeoutK   s     """r   timeoutc                     || _         y)z
        Sets the timeout to verify the browser's running state.

        Args:
            timeout (int): The timeout in seconds.
        Nr'   )r   r)   s     r   r(   zChromiumOptions.start_timeoutU   s     &r   argumentc                 r    || j                   vr| j                   j                  |       yt        d|       )a  
        Adds a command-line argument to the options.

        Args:
            argument (str): The command-line argument to be added.

        Raises:
            ArgumentAlreadyExistsInOptions: If the argument is already in the list of arguments.
        zArgument already exists: N)r   appendr   r   r+   s     r   add_argumentzChromiumOptions.add_argument_   s5     4??*OO""8,03LXJ1WXXr   c                 r    || j                   vrt        d|       | j                   j                  |       y)a   
        Removes a command-line argument from the options.

        Args:
            argument (str): The command-line argument to be removed.

        Raises:
            ArgumentNotFoundInOptions: If the argument is not in the list of arguments.
        zArgument not found: N)r   r   remover.   s     r   remove_argumentzChromiumOptions.remove_argumentn   s5     4??*+.B8*,MNNx(r   c                     | j                   S N)r   r   s    r   browser_preferencesz#ChromiumOptions.browser_preferences|   s    (((r   preferencesc                     t        |t              st        d      |j                  d      rt        i | j
                  || _        y )Nz.The experimental options value must be a dict.prefs)
isinstancedict
ValueErrorgetr   r   )r   r6   s     r   r5   z#ChromiumOptions.browser_preferences   sB    +t,MNN??7#  $Pt'@'@$PK$P!r   pathc                 d    | j                   }|dd D ]  }|j                  |i       } |||d   <   y)aI  
        Safely sets a nested value in self._browser_preferences,
        creating intermediate dicts as needed.

        Arguments:
            path -- List of keys representing the nested
                    path (e.g., ['plugins', 'always_open_pdf_externally'])
            value -- The value to set at the given path
        N)r   
setdefault)r   r=   valuedkeys        r   _set_pref_pathzChromiumOptions._set_pref_path   sA     %%9 	&CS"%A	&$r(r   c                     | j                   }t        t        t              5  |D ]  }||   }	 |cddd       S # 1 sw Y   yxY w)a=  
        Safely gets a nested value from self._browser_preferences.

        Arguments:
            path -- List of keys representing the nested
                    path (e.g., ['plugins', 'always_open_pdf_externally'])

        Returns:
            The value at the given path, or None if path doesn't exist
        N)r   r   KeyError	TypeError)r   r=   nested_preferencesrC   s       r   _get_pref_pathzChromiumOptions._get_pref_path   sQ     "66h	* 	& =%7%<"=%	& 	& 	& s	   9Ac                 ,    | j                  ddg|       y)z
        Set the default directory where downloaded files will be saved.

        Usage: Sets the 'download.default_directory' preference for Chrome.

        Arguments:
            path: Absolute path to the download destination folder.
        downloaddefault_directoryNrD   )r   r=   s     r   set_default_download_directoryz.ChromiumOptions.set_default_download_directory   s     	Z)<=tDr   	languagesc                 ,    | j                  ddg|       y)z
        Set the accepted languages for the browser.

        Usage: Sets the 'intl.accept_languages' preference.

        Arguments:
            languages: A comma-separated string of language codes (e.g., 'pt-BR,pt,en-US,en').
        intlaccept_languagesNrM   )r   rO   s     r   set_accept_languagesz$ChromiumOptions.set_accept_languages   s     	V%78)Dr   c                 (    | j                  ddg      S )NrK   prompt_for_downloadrI   r   s    r   rU   z#ChromiumOptions.prompt_for_download   s    ""J0E#FGGr   enabledc                 ,    | j                  ddg|       y)z
        Enable or disable download prompt confirmation.

        Usage: Sets the 'download.prompt_for_download' preference.

        Arguments:
            enabled: If True, Chrome will ask for confirmation before downloading.
        rK   rU   NrM   r   rW   s     r   rU   z#ChromiumOptions.prompt_for_download   s     	Z)>?Ir   c                 .    | j                  g d      dk(  S )Nprofiledefault_content_setting_valuespopupsr   rV   r   s    r   block_popupszChromiumOptions.block_popups   s    ""#Z[_```r   blockc                 >    | j                  g d|rd       yd       y)z
        Block or allow pop-up windows.

        Usage: Sets the 'profile.default_content_setting_values.popups' preference.

        Arguments:
            block: If True, pop-ups will be blocked (value = 0); otherwise allowed (value = 1).
        r[   r      NrM   r   r`   s     r   r_   zChromiumOptions.block_popups   s!     	C%Q	
UV	
r   c                 (    | j                  ddg      S )Nr\   password_manager_enabledrV   r   s    r   re   z(ChromiumOptions.password_manager_enabled   s    ""I/I#JKKr   c                 R    | j                  ddg|       | j                  dg|       y)z
        Enable or disable Chrome's password manager.

        Usage: Sets the 'profile.password_manager_enabled' preference.

        Arguments:
            enabled: If True, the password manager is active.
        r\   re   credentials_enable_serviceNrM   rY   s     r   re   z(ChromiumOptions.password_manager_enabled   s.     	Y(BCWM9:GDr   c                 2    d}| j                  g d      |k(  S )N   r\   r]   notificationsrV   )r   block_notifications_true_values     r   block_notificationsz#ChromiumOptions.block_notifications   s$    )*& ^_-.	
r   c                 >    | j                  g d|rd       yd       y)a  
        Block or allow site notifications.

        Usage: Sets the 'profile.default_content_setting_values.notifications' preference.

        Arguments:
            block: If True, notifications will be blocked (value = 2);
            otherwise allowed (value = 1).
        rj   ri   rb   NrM   rc   s     r   rm   z#ChromiumOptions.block_notifications   s"     	JA	
	
r   c                 .    | j                  g d      dk(  S )Nr\   r]   automatic_downloadsrb   rV   r   s    r   allow_automatic_downloadsz)ChromiumOptions.allow_automatic_downloads  s&      ! 
 	
r   allowc                 >    | j                  g d|rd       yd       y)a(  
        Allow or block automatic multiple downloads.

        Usage: Sets the 'profile.default_content_setting_values.automatic_downloads' preference.

        Arguments:
            allow: If True, automatic downloads are allowed (value = 1);
            otherwise blocked (value = 2).
        rp   rb   ri   NrM   )r   rs   s     r   rr   z)ChromiumOptions.allow_automatic_downloads  s"     	PA	
	
r   c                 (    | j                  ddg      S )Npluginsalways_open_pdf_externallyrV   r   s    r   open_pdf_externallyz#ChromiumOptions.open_pdf_externally&  s    ""I/K#LMMr   c                 ,    | j                  ddg|       y)a  
        Block or allow geolocation access.

        Usage: Sets the 'profile.managed_default_content_settings.geolocation' preference.

        Arguments:
            block: If True, location access is blocked (value = 2); otherwise allowed (value = 1).
        rv   rw   NrM   rY   s     r   rx   z#ChromiumOptions.open_pdf_externally*  s     	Y(DEwOr   c                     | j                   S r4   )r   r   s    r   headlesszChromiumOptions.headless6  s    ~~r   r{   c                     || _         d| j                  v }| j                  | j                  d}||k(  ry  ||   d       y )Nz
--headlessTF)r   r   r/   r2   )r   r{   has_argumentmethods_maps       r   r{   zChromiumOptions.headless:  sG    !#t~~5!..t7K7KL|#Hl+r   c                     | j                   S r4   )r   r   s    r   webrtc_leak_protectionz&ChromiumOptions.webrtc_leak_protectionC  s    +++r   c                     || _         d}|| j                  v }| j                  | j                  d}||k(  ry  ||   |       y )Nz9--force-webrtc-ip-handling-policy=disable_non_proxied_udpr}   )r   r   r/   r2   )r   rW   r+   r~   r   s        r   r   z&ChromiumOptions.webrtc_leak_protectionG  sM    '.$N4>>1!..t7K7KLl"GX&r   c                     | j                   S r4   r   r   s    r   page_load_statezChromiumOptions.page_load_stateQ  s    $$$r   statec                     || _         y r4   r   )r   r   s     r   r   zChromiumOptions.page_load_stateU  s
     %r   N) __name__
__module____qualname____doc__r   propertyliststrr   setterr#   intr(   r/   r2   r:   r5   rD   rI   rN   rS   boolrU   r_   re   rm   rr   rx   r{   r   r   r    r   r   r
   r
      s   7 49   $49 $ $ % % % ) ) ) #s # # &S & &YS Y) ) )T ) ) Qt Q  Q4 4 $	E3 	E	Ec 	E HT H H 	J4 	J  	J ad a a 
$ 
 
 L$ L L $$
E 
E %
E 
T 
 
 
 
  
 
4 
 
 %%
t 
 &
 NT N N 	P4 	P  	P $   __, , , , , , ""'d ' #' % % % &] & &r   r
   N)
contextlibr   pydoll.browser.interfacesr   pydoll.constantsr   pydoll.exceptionsr   r   r   r
   r   r   r   <module>r      s&     - * K&g K&r   