
    Fth7                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZ dZdZdZ G d d	e          Z G d
 d          ZdS )    N)BytesIO)minidom)WebDriverExceptionzwebdriver.xpizwebdriver_prefs.jsonzfxdriver@googlecode.comc                       e Zd ZdZdS )AddonFormatErrorz4Exception for not well-formed add-on manifest files.N)__name__
__module____qualname____doc__     ~/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/selenium/webdriver/firefox/firefox_profile.pyr   r   &   s        >>>>r   r   c                   .   e Zd ZdZdZddZd ZefdZd Z	e
d             Ze
d             Zej        dd
            Ze
d             Zej        dd            Ze
d             Zej        dd            Ze
d	efd            Zd Zd Zd ZddZd ZdS )FirefoxProfileWEBDRIVER_ANONYMOUS_PROFILENc           	         t           j        st          t          j                            t          j                            t                    t                    d          5 }t          j
        |          t           _        ddd           n# 1 swxY w Y   t          j        t           j        d                   | _        || _        d| _        | j        s|                                 | _        nt#          j                    | _        t          j                            | j        d          }t'          j        | j        |t'          j        ddd          	           || _        t          j        | j        d
           |                     t          j                            | j        d                     t          j                            | j        d          | _        t          j                            | j        d          | _        t          j                            | j                  rt          j        | j        d           dS dS )a  Initialises a new instance of a Firefox Profile.

        :args:
         - profile_directory: Directory of profile that you want to use. If a
           directory is passed in it will be cloned and the cloned directory
           will be used by the driver when instantiated.
           This defaults to None and will create a new
           directory when object is created.
        utf-8encodingNmutablezwebdriver-py-profilecopyzparent.locklockz.parentlock)ignore  zuser.js
extensionsi  )r   DEFAULT_PREFERENCESopenospathjoindirname__file__WEBDRIVER_PREFERENCESjsonloadcopydeepcopydefault_preferencesprofile_dir
tempfolder_create_tempfoldertempfilemkdtempshutilcopytreeignore_patternschmod_read_existing_userjsextensionsDir	userPrefsisfile)selfprofile_directorydefault_prefsnewprofs       r   __init__zFirefoxProfile.__init__.   s!    1 	NRW__X668MNNY`   N59Y}5M5M2N N N N N N N N N N N N N N N
 $(=1ST]1^#_#_ , 
	R#6688D&.00DOgll4?4NOOGO '&2HX^`m2n2n     'DHT%u---&&rw||D4Di'P'PQQQW\\$*:LIId&6	BB7>>$.)) 	,HT^U+++++	, 	,s   #BBBc                     || j         |<   dS )z0Sets the preference that we want in the profile.Nr'   r5   keyvalues      r   set_preferencezFirefoxProfile.set_preferenceR   s    (- %%%r   c                 0    |                      |           d S N)_install_extension)r5   	extensions     r   add_extensionzFirefoxProfile.add_extensionV   s    	*****r   c                     t           j        d                                         D ]\  }}|| j        vr
|| j        |<   |                     | j                   d S )Nfrozen)r   r   itemsr'   _write_user_prefsr<   s      r   update_preferencesz!FirefoxProfile.update_preferencesY   sd    (<XFLLNN 	6 	6JC $22205(-t788888r   c                     | j         S )z8Gets the profile directory that is currently being used.)r(   r5   s    r   r   zFirefoxProfile.pathd   s     r   c                     | j         S )z+Gets the port that WebDriver is working on.)_portrK   s    r   portzFirefoxProfile.porti   s     zr   returnc                 2   t          |t                    st          d          	 t          |          }|dk     s|dk    rt          d          n$# t          t          f$ r t          d          w xY w|| _        |                     d| j                   dS )z0Sets the port that WebDriver will be running on.zPort needs to be an integer   i  z)Port number must be in the range 1..65535webdriver_firefox_portN)
isinstanceintr   
ValueError	TypeErrorrM   r?   )r5   rN   s     r   rN   zFirefoxProfile.portn   s     $$$ 	D$%BCCC	Dt99Daxx4%<<()TUUU (I& 	D 	D 	D$%BCCC	D
4djAAAAAs   *A !A2c                     | j         d         S )N webdriver_accept_untrusted_certsr;   rK   s    r   accept_untrusted_certsz%FirefoxProfile.accept_untrusted_certs|   s    '(JKKr   c                 z    t          |t                    st          d          |                     d|           d S )N%Please pass in a Boolean to this callrX   rS   boolr   r?   r5   r>   s     r   rY   z%FirefoxProfile.accept_untrusted_certs   sA    %&& 	N$%LMMM>FFFFFr   c                     | j         d         S )N!webdriver_assume_untrusted_issuerr;   rK   s    r   assume_untrusted_cert_issuerz+FirefoxProfile.assume_untrusted_cert_issuer   s    '(KLLr   c                 z    t          |t                    st          d          |                     d|           d S )Nr[   r`   r\   r^   s     r   ra   z+FirefoxProfile.assume_untrusted_cert_issuer   sA    %&& 	N$%LMMM?GGGGGr   c           	         |                                   t                      }t          j        |dt          j                  5 }t          | j                  dz   }t          j        | j                  D ]I\  }}}|D ]@}t          j        	                    ||          }|
                    |||d                    AJ	 ddd           n# 1 swxY w Y   t          j        |                                                              d          S )znA zipped, base64 encoded string of profile directory for use with
        remote WebDriver JSON wire protocol.wrQ   NzUTF-8)rI   r   zipfileZipFileZIP_DEFLATEDlenr   r   walkr   writebase64	b64encodegetvaluedecode)	r5   fpzipped	path_rootbase_filesfylefilenames	            r   encodedzFirefoxProfile.encoded   sH    	!!!YY_Rg&:;; 	AvDI*I"$'$)"4"4 A Aa! A AD!w||D$77HLL8IJJ+?@@@@AA	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A ..55g>>>s   A;CCCc                 (    t          j                    S )z9Creates a temp folder to store User.js and the extension.)r+   r,   rK   s    r   r*   z!FirefoxProfile._create_tempfolder   s    !!!r   c           
          t          | j        dd          5 }|                                D ]3\  }}|                    d| dt	          j        |           d           4	 ddd           dS # 1 swxY w Y   dS )z1Writes the current user prefs dictionary to disk.rd   r   r   zuser_pref("z", z);
N)r   r3   rG   rj   r#   dumps)r5   
user_prefsfr=   r>   s        r   rH   z FirefoxProfile._write_user_prefs   s    $.#888 	GA(..00 G G
UEcEEdj.?.?EEEFFFFG	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   A	A//A36A3c           
         t          j        d          }	 t          |d          5 }|D ]}|                    |          }	 t	          j        |                    d                    | j        |                    d          <   [# t          $ rC t          j
        d|                    d          |                    d          z               Y w xY w	 d d d            d S # 1 swxY w Y   d S # t          $ r Y d S w xY w)Nzuser_pref\("(.*)",\s(.*)\)r   r      rQ   z5(skipping) failed to json.loads existing preference: )recompiler   searchr#   loadsgroupr'   	Exceptionwarningswarn)r5   userjspref_patternr|   usrmatchess         r   r1   z$FirefoxProfile._read_existing_userjs   sz   z"?@@	fw/// 1  C*11#66GEIZPWP]P]^_P`P`EaEa0q1A1ABB$    yT[TaTabcTdTdgngtgtuvgwgwTwyy    	                   	 	 	DD	sZ   C0 C#ABC#A
CC#CC#C0 #C''C0 *C'+C0 0
C>=C>Tc           	      D   |t           k    rGt          j                            t          j                            t
                    t                     }d}d}|                    d          rt          j        dt          j        	                    |          d         z             }t          j        |d          }|                                D ]}|                    d          rpt          j                            t          j                            ||                    s2t          j        t          j                            ||                     t          j                            t          j                            t          j                            ||                              sOt          j        t          j                            t          j                            ||                               |                    |          }t!          t          j                            ||          d          5 }|                    |           ddd           n# 1 swxY w Y   |}|}|                     |          }	|	                    d	          }
|
sJ d
|             t          j                            | j        |
          }|sz|	d         sr|rpt          j                            | j                  s3t          j        | j                   t          j        | j        d           t/          j        ||dz              n6t          j                            |          st/          j        ||d           |rt/          j        |           dS dS )zInstalls addon from a filepath, url or directory of addons in the
        profile.

        - path: url, absolute path to .xpi, or directory of addons
        - unpack: whether to unpack unless specified otherwise in the install.rdf
        Nz.xpi.)suffixr/wbidz!The addon id could not be found: unpackr   T)symlinks)WEBDRIVER_EXTr   r   r   r    r!   endswithr+   r,   splitre   rf   namelistisdirmakedirsreadr   rj   _addon_detailsgetr2   existsr0   r-   r%   r.   rmtree)r5   addonr   tmpdirxpifilecompressed_filenamedatar|   addon_detailsaddon_id
addon_paths               r   rB   z!FirefoxProfile._install_extension   s4    M!!GLL!:!:MJJE>>&!! 	%S27==3G3G3K-KLLLF%oeS99O'0022 	& 	&==%% &7==fd)C)CDD @BGLL$>$>???7==fd9S9S)T)TUU QBGOOBGLL4N4N$O$OPPP*//55Dbgll6488$?? &1& & & & & & & & & & & & & & &GE ++E22 $$T**DDDUDDDDx W\\$"4h??
 	BmH5 	B' 	B7>>$"455 4D.///+U333Kf!455557>>*-- BzDAAAA  	"M&!!!!!	" 	"s   I''I+	.I+	c                    ddddd}d }d }d }t           j                            |          st          d|           	 t	          j        |          r	 t	          j        |d          }d	|                                v r2 ||                    d	                    |	                                 S |                    d
          }|	                                 n+# |	                                 w xY wt           j        
                    |          rt           j                            |d	          }t           j                            |          rFt          |d          5 }	 ||	                                          cddd           S # 1 swxY w Y   t          t           j                            |d
          d          5 }	|	                                }ddd           n# 1 swxY w Y   nt          d|           nM# t          t          f$ r9}
t          t          |
          t!          j                    d                   d}
~
ww xY w	 t%          j        |          } ||d          } ||d          }|                    |dz                                 d          }|s(|                    d                              d          }|j        D ]A}|j                            |d          }||v r |                    | ||          i           B|                    d          s`t7          |j        j                  D ]F}|j                            |          }|j        |dz   k    r|                    d|j        i           GnF# t@          $ r9}
t          t          |
          t!          j                    d                   d}
~
ww xY wtC          |d         t                    r!|d         "                                dk    |d<   |                    d          st          d          |S )a  Returns a dictionary of details about the addon.

        :param addon_path: path to the add-on directory or XPI

        Returns::

            {'id':      u'rainbow@colors.org', # id of the addon
             'version': u'1.4',                # version of the addon
             'name':    u'Rainbow',            # name of the addon
             'unpack':  False }                # whether to unpack the addon
        NF)r   r   r   versionc                 4   | j         j        }d}t          |j                  D ]t}|                    |          j        |k    rTd|                    |          j        v r8|                    |          j                            d          d         dz   } nu|S )N :rQ   )documentElement
attributesrangelengthitemr>   r   r   )docurlr   	namespaceis        r   get_namespace_idz7FirefoxProfile._addon_details.<locals>.get_namespace_id   s    ,7JI:,--  ??1%%+s22jooa00555$.OOA$6$6$;$A$A#$F$Fq$IC$O	r   c                     g }| j         D ],}|j        |j        k    r|                    |j                   -d                    |                                          S )z(Retrieve the text value of a given node.r   )
childNodesnodeType	TEXT_NODEappendr   r   strip)elementrcnodes      r   get_textz/FirefoxProfile._addon_details.<locals>.get_text  sY    B* ) )=DN22IIdi(((772;;$$&&&r   c                     t          j        |           }	 |d         d         d         }n8# t          $ r+ |d                             dd          dz   |d         z   }Y nw xY w||d         |d         d	d
S )z[Extracts the details from the contents of a WebExtensions
            `manifest.json` file.applicationsgeckor   r    r   @r   F)r   r   r   r   )r#   r   KeyErrorreplace)contentmanifestr   s      r   parse_manifest_jsonz:FirefoxProfile._addon_details.<locals>.parse_manifest_json  s     z'**HSn-g6t< S S Sf%--c266<x	?RRS #I. +	  s   + 2A A zAdd-on path does not exist: r   zmanifest.jsonzinstall.rdfr   r   z/Add-on path is neither an XPI nor a directory: r~   z#http://www.mozilla.org/2004/em-rdf#z+http://www.w3.org/1999/02/22-rdf-syntax-ns#Descriptionr   r   r   r   truezAdd-on id could not be found.)#r   r   r   OSErrorre   
is_zipfilerf   r   r   closer   r   r   r   r   strsysexc_infor   parseStringgetElementsByTagNamer   r   nodeNamer   updater   r   r   r   r   r>   r   rS   lower)r5   r   detailsr   r   r   r   r   manifest_json_filenamer|   er   emrdfdescriptionr   entryr   	attributes                      r   r   zFirefoxProfile._addon_details   s    NN		 		 			' 	' 	'	 	 	 w~~j)) 	GEEEFFF	>!*-- ^,&-oj#&F&FO&/*B*B*D*DDD22?3G3G3X3XYY $))++++  /33MBBH#))++++O))++++z** 	^)+j/)R)R&7>>"899 =4wGGG =12216688<<= = = = = = = = = = = = = = = = "',,z=AAGTTT (XY vvxxH( ( ( ( ( ( ( ( ( ( ( ( ( ( ( \PZ\\]]]" 	> 	> 	>"3q663<>>!+<===	>	>%h//C "!#'LMMB""3(UVVC2233FGGLLQOOK N!66}EEJJ1MM#. < <--b"55G##NNE88D>>#:;;;;;t$$ @{5<== @ @A + 6 ; ;A > >I ~d22io'>??? 	> 	> 	>"3q663<>>!+<===	> gh'-- 	D ' 1 7 7 9 9V CGH {{4   	D"#BCCCs   H AC   H 5C  
H  C66A2H (FH FH F2H G-!H -G11H 4G15H I4IID?N 
O$4OOrA   )rO   N)T)r   r	   r
   ANONYMOUS_PROFILE_NAMEr   r9   r?   r   rD   rI   propertyr   rN   setterrY   ra   r   rw   r*   rH   r1   rB   r   r   r   r   r   r   *   s       :!, !, !, !,H. . . '4 + + + +9 9 9     X    X 
[B B B [B L L XL "G G G #"G
 M M XM "(H H H )(H ? ? ? ? X?" " "G G G   ." ." ." ."`m m m m mr   r   )rk   r%   r#   r   r   r-   r   r+   r   re   ior   xml.domr   selenium.common.exceptionsr   r   r"   EXTENSION_NAMEr   r   r   r   r   r   <module>r      s  $    				 				  



                9 9 9 9 9 9. *? ? ? ? ?y ? ? ?l l l l l l l l l lr   