
    vKg5                         S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJr  S SKJr  S SKJr  Sr\" S5       " S S	\5      5       r " S
 S5      rg)    N)BytesIO)minidom)
deprecated)WebDriverExceptionzwebdriver_prefs.json/Addons must be added after starting the sessionc                       \ rS rSrSrSrg)AddonFormatError&   z4Exception for not well-formed add-on manifest files. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       j/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/selenium/webdriver/firefox/firefox_profile.pyr	   r	   &   s    >r   r	   c                      \ rS rSrSrSS jrS r\" S5      SS j5       rS r	\
S 5       r\
\" S	5      S
 5       5       r\R                  \" S	5      SS j5       5       r\
\" S5      S 5       5       r\R                  \" S5      SS j5       5       r\
\" S5      S 5       5       r\R                  \" S5      SS j5       5       r\
S\4S j5       rS r\" S5      SS j5       r\" S5      S 5       rSrg)FirefoxProfile+   Nc           	      ^   0 U l         U(       a  [        R                  R                  [        R
                  " 5       S5      n[        R                  " X[        R                  " SSS5      S9  X l	        [        R                  " U R                  S5        g	[        R
                  " 5       U l	        [        R                  (       du  [        [        R                  R                  [        R                  R                  [        5      [         5      SS9 n["        R$                  " U5      [        l        S	S	S	5        [&        R(                  " [        R                  S
   5      U l         [        R                  S   R+                  5        H  u  pEXPR                   U'   M     g	! , (       d  f       Ns= f)aI  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.
zwebdriver-py-profilecopyzparent.locklockz.parentlock)ignore  utf-8encodingNmutablefrozen)_desired_preferencesospathjointempfilemkdtempshutilcopytreeignore_patterns_profile_dirchmodr   DEFAULT_PREFERENCESopendirname__file__WEBDRIVER_PREFERENCESjsonloadcopydeepcopyitems)selfprofile_directorynewprofdefault_prefskeyvalues         r   __init__FirefoxProfile.__init__.   s"    %'!ggll8#3#3#57QRGOO!63I3I-Y_an3o !(HHT&&. ( 0 0 2D!55GGLL!:<QR]d"9==9QN6
 )-n6X6XYb6c(dD%,@@JPPR
16))#. S s    F
F,c                      X R                   U'   g)z0Sets the preference that we want in the profile.Nr    )r5   r9   r:   s      r   set_preferenceFirefoxProfile.set_preferenceM   s    ).!!#&r   r   c                 &    U R                  U5        g N)_install_extension)r5   	extensions     r   add_extensionFirefoxProfile.add_extensionQ   s    	*r   c           
         [         R                  R                  U R                  S5      n[         R                  R	                  U5      (       a(  [         R
                  " US5        U R                  U5        [        USSS9 nU R                  R                  5        H1  u  p4UR                  SU S[        R                  " U5       S35        M3     S	S	S	5        g	! , (       d  f       g	= f)
z&Writes the desired user prefs to disk.zuser.jsi  wr   r   zuser_pref("z", z);
N)r!   r"   r#   r)   isfiler*   _read_existing_userjsr,   r    r4   writer0   dumps)r5   
user_prefsfr9   r:   s        r   update_preferences!FirefoxProfile.update_preferencesU   s    WW\\$"3"3Y?
77>>*%%HHZ'&&z2*cG4"77==?
+cU#djj.?-@EF @ 544s   AC
C)c                     U R                   $ )z8Gets the profile directory that is currently being used.)r)   r5   s    r   r"   FirefoxProfile.patha   s        r   z'The port is stored in the Service classc                     U R                   $ )z+Gets the port that WebDriver is working on.)_portrR   s    r   portFirefoxProfile.portf   s     zzr   returnc                    [        U[        5      (       d  [        S5      e [        U5      nUS:  d  US:  a  [        S5      e Xl        U R                  SU R
                  5        g! [        [        4 a    [        S5      ef = f)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	TypeErrorrU   r?   )r5   rV   s     r   rV   rW   l   s     $$$$%BCC	Dt9Dax4%<()TUU ( 
4djjA I& 	D$%BCC	Ds   "A( (Bz8Allowing untrusted certs is toggled in the Options classc                      U R                   S   $ )N webdriver_accept_untrusted_certsr>   rR   s    r   accept_untrusted_certs%FirefoxProfile.accept_untrusted_certs{   s     (()KLLr   c                 h    [        U[        5      (       d  [        S5      eU R                  SU5        g )N%Please pass in a Boolean to this callra   r\   boolr   r?   r5   r:   s     r   rb   rc      s.     %&&$%LMM>Fr   c                      U R                   S   $ )N!webdriver_assume_untrusted_issuerr>   rR   s    r   assume_untrusted_cert_issuer+FirefoxProfile.assume_untrusted_cert_issuer   s     (()LMMr   c                 h    [        U[        5      (       d  [        S5      eU R                  SU5        g )Nre   rj   rf   rh   s     r   rk   rl      s.     %&&$%LMM?Gr   c           	      8   U R                   (       a  U R                  5         [        5       n[        R                  " US[        R
                  SS9 n[        U R                  5      S-   n[        R                  " U R                  5       HB  u  pEnU H6  n[        R                  R                  XG5      nUR                  XUS 5        M8     MD     SSS5        [        R                  " UR                  5       5      R                  S5      $ ! , (       d  f       NA= f)zUUpdates preferences and creates a zipped, base64 encoded string of
profile directory.rH   F)strict_timestampsrZ   NzUTF-8)r    rO   r   zipfileZipFileZIP_DEFLATEDlenr"   r!   walkr#   rK   base64	b64encodegetvaluedecode)	r5   fpzipped	path_rootbase_filesfylefilenames	            r   encodedFirefoxProfile.encoded   s     $$##%Y__Rg&:&:eTX^DII*I"$''$))"4!D!ww||D7HLLIJ+?@ " #5 U .55g>> UTs   A?D
Dc           
         [         R                  " S5      n[        USS9 nU HV  nUR                  U5      n [        R
                  " UR                  S5      5      U R                  UR                  S5      '   MX     SSS5        g! [         a>    [        R                  " SUR                  S5      UR                  S5      -    35         M  f = f! , (       d  f       g= f)zJReads existing preferences and adds them to desired preference
dictionary.zuser_pref\("(.*)",\s(.*)\)r   r      rZ   z5(skipping) failed to json.loads existing preference: N)recompiler,   searchr0   loadsgroupr    	Exceptionwarningswarn)r5   userjspref_patternrN   usrmatchess         r   rJ   $FirefoxProfile._read_existing_userjs   s     zz"?@&7+q&--c2BF**W]][\M]B^D--gmmA.>?  ,+
 ! MMOPWP]P]^_P`cjcpcpqrcsPsOtu ,+s0   CAB:CACCCC
C c           	         SnSnUR                  S5      (       Ga  [        R                  " S[        R                  R                  U5      S   -   S9n[        R                  " US5      nUR                  5        GH  nUR                  S5      (       ax  [        R                  R                  [        R                  R                  X65      5      (       d5  [        R                  " [        R                  R                  X65      5        M  M  [        R                  R                  [        R                  R                  [        R                  R                  X65      5      5      (       dP  [        R                  " [        R                  R                  [        R                  R                  X65      5      5        UR                  U5      n[        [        R                  R                  X65      S5       nUR                  U5        SSS5        GM     UnUnU R!                  U5      n	U	R#                  S	5      n
U
(       d
   S
U 35       e[        R                  R                  U R$                  S5      n[        R                  R                  X5      nU(       d|  U	S   (       dr  U(       ak  [        R                  R'                  U5      (       d-  [        R                  " U5        [        R(                  " US5        [*        R,                  " XLS-   5        O9[        R                  R'                  U5      (       d  [*        R.                  " XSS9  U(       a  [*        R0                  " U5        gg! , (       d  f       GM  = f)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: 
extensionsunpackr   T)symlinks)endswithr$   r%   r!   r"   splitrp   rq   namelistisdirr#   makedirsr-   readr,   rK   _addon_detailsgetr)   existsr*   r&   r2   r'   rmtree)r5   addonr   tmpdirxpifilecompressed_filenamedatarN   addon_detailsaddon_idextensions_dir
addon_paths                r   rC   !FirefoxProfile._install_extension   sC    >>&!!%%S277==3G3K-KLF%ooeS9O'002==%%77==f)CDDBGGLL$>? E 77==f9S)TUUBGGOOBGGLL4N$OP*//5Dbggll68$?1 @? 3 GE ++E2 $$T*D<UGDDx d&7&7FWW\\.;
mH5'77>>.11N+/KKf!4577>>*--DA MM&! / @?s   4M..
M>	c                    SSSSS.nS nS nS n[         R                  R                  U5      (       d  [        SU 35      e [        R
                  " U5      (       af  [        R                  " US5       nS	UR                  5       ;   a   U" UR                  S	5      5      sSSS5        $ UR                  S
5      nSSS5        O[         R                  R                  U5      (       a  [         R                  R                  US	5      n[         R                  R                  U5      (       a*  [        USS9 n	U" U	R                  5       5      sSSS5        $ [        [         R                  R                  US
5      SS9 n	U	R                  5       nSSS5        O[        SU 35      e ["        R$                  " W5      nU" US5      nU" US5      nUR'                  US-   5      R)                  S5      nU(       d   UR'                  S5      R)                  S5      nUR*                   H@  nUR,                  R/                  US5      nUU;   d  M'  UR1                  UU" U5      05        MB     UR3                  S5      (       ds  [5        UR6                  R8                  5       HP  nUR6                  R)                  U5      nUR:                  US-   :X  d  M3  UR1                  SUR<                  05        MR     [A        US   [        5      (       a  US   RC                  5       S:H  US'   UR3                  S5      (       d  [        S5      eU$ ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! [        [        4 a0  n
[        [        U
5      [        R                   " 5       S   5      eSn
A
ff = f! [>         a0  n
[        [        U
5      [        R                   " 5       S   5      eSn
A
ff = f)al  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                 T   U R                   R                  nSn[        UR                  5       Hv  nUR	                  U5      R
                  U:X  d  M$  SUR	                  U5      R                  ;   d  ME  UR	                  U5      R                  R                  S5      S   S-   n  U$    U$ )N :rZ   )documentElement
attributesrangelengthitemr:   r   r   )docurlr   	namespaceis        r   get_namespace_id7FirefoxProfile._addon_details.<locals>.get_namespace_id   s    ,,77JI:,,-??1%++s2jooa0555$.OOA$6$;$;$A$A#$Fq$IC$O	 . r   c                     / nU R                    H:  nUR                  UR                  :X  d  M  UR                  UR                  5        M<     SR                  U5      R                  5       $ )z(Retrieve the text value of a given node.r   )
childNodesnodeType	TEXT_NODEappendr   r#   strip)elementrcnodes      r   get_text/FirefoxProfile._addon_details.<locals>.get_text   sP    B**==DNN2IIdii( + 772;$$&&r   c                     [         R                  " U 5      n US   S   S   nUUS   US   S	S
.$ ! [         a!    US   R                  SS5      S-   US   -   n N7f = f)zOExtracts the details from the contents of a WebExtensions
`manifest.json` file.applicationsgeckor   r    r   @r   F)r   r   r   r   )r0   r   KeyErrorreplace)contentmanifestr   s      r   parse_manifest_json:FirefoxProfile._addon_details.<locals>.parse_manifest_json  s     zz'*HSn-g6t< #I. +	   Sf%--c26<x	?RRSs   0 (A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   OSErrorrp   
is_zipfilerq   r   r   r   r#   r,   r   r	   strsysexc_infor   parseStringgetElementsByTagNamer   r   nodeNamer   updater   r   r   r   r   r:   r   r\   lower)r5   r   detailsr   r   r   r   r   manifest_json_filenamerN   er   emrdfdescriptionr   entryr   	attributes                      r   r   FirefoxProfile._addon_details   sH    N			'	 ww~~j))8EFF	>!!*--__Z5&/*B*B*DD2?3G3G3XY 65  /33MBH	 65
 z**)+j/)R&77>>"8994wG121668< HG "'',,z=AGTXY vvxH UT  OPZ|\]]	>%%h/C "#'LMB"3(UVC2233FGLLQOK!66}EJJ1M#..--b"5G#NNE8D>#:;	 /
 ;;t$${55<<=A + 6 6 ; ;A >I ~~d2ioo'>? > gh'-- ' 1 7 7 9V CGH {{4  "#BCCc 65 HG UT " 	>"3q63<<>!+<==	>.  	>"3q63<<>!+<==	>s   2M= 6+M!	M= +M<M= A2M= 7M	M= (M= ?M+M= M= (B!O  BO  !O  
MM= M= 
M(#M= +
M:5M= :M= =N=+N88N= 
O:
+O55O:)r    rU   r)   rB   )rX   N)T)r   r   r   r   r+   r;   r?   r   rE   rO   propertyr"   rV   setterrb   rk   r   r   rJ   rC   r   r   r   r   r   r   r   +   s   7>/ AB+ C+G ! ! 9: ;  
[[9:B ; B JKM L M ""JKG L #G
 JKN L N "((JKH L )H ? ? ? AB," C,"\ ABg Cgr   r   )ru   r2   r0   r!   r   r&   r   r$   r   rp   ior   xml.domr   typing_extensionsr   selenium.common.exceptionsr   r/   r   r	   r   r   r   r   <module>r      sd   $    	 	  
      ( 9.  =>?y ? ??] ]r   