1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
U
\±d8ã@s¢ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl    Z    ddl
m Z ddl m Z ddlmZdZdZdZGdd    „d    eƒZGd
d „d ƒZdS) éN)ÚBytesIO)Úminidom)ÚWebDriverExceptionz webdriver.xpizwebdriver_prefs.jsonzfxdriver@googlecode.comc@seZdZdZdS)ÚAddonFormatErrorz4Exception for not well-formed add-on manifest files.N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__©r
r
úad:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\selenium/webdriver/firefox/firefox_profile.pyr&src@sâeZdZdZdZd$dd„Zdd„Zefdd„Zd    d
„Z    e
d d „ƒZ e
d d„ƒZ e j ddœdd„ƒZ e
dd„ƒZej ddœdd„ƒZe
dd„ƒZej ddœdd„ƒZe
edœdd„ƒZdd„Zdd„Zdd„Zd%d d!„Zd"d#„ZdS)&ÚFirefoxProfileZWEBDRIVER_ANONYMOUS_PROFILENc    Cs"tjdtddtjsLttj tj     t
¡t ¡dd}t   |¡t_W5QRXt tjd¡|_||_d|_|js|| ¡|_n`t ¡|_tj |jd¡}tj|j|t d    d
d ¡d ||_t |jd ¡| tj |jd¡¡tj |jd¡|_tj |jd¡|_tj |j¡rt |jd¡dS)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.
        zAfirefox_profile has been deprecated, please use an Options objecté)Ú
stacklevelúutf-8©ÚencodingZmutableNzwebdriver-py-profilecopyz parent.lockÚlockz .parentlock)Úignoreéízuser.jsÚ
extensionsi¤)ÚwarningsÚwarnÚDeprecationWarningr ÚDEFAULT_PREFERENCESÚopenÚosÚpathÚjoinÚdirnameÚ__file__ÚWEBDRIVER_PREFERENCESÚjsonÚloadÚcopyÚdeepcopyÚdefault_preferencesÚ profile_dirZ
tempfolderÚ_create_tempfolderÚtempfileÚmkdtempÚshutilÚcopytreeÚignore_patternsÚchmodÚ_read_existing_userjsÚ extensionsDirÚ    userPrefsÚisfile)ÚselfZprofile_directoryZ default_prefsZnewprofr
r
r Ú__init__.s>
ÿÿ 
 ÿzFirefoxProfile.__init__cCs||j|<dS)z0sets the preference that we want in the profile.N©r%©r2ÚkeyÚvaluer
r
r Úset_preferenceUszFirefoxProfile.set_preferencecCs| |¡dS)N)Ú_install_extension)r2Ú    extensionr
r
r Ú add_extensionYszFirefoxProfile.add_extensioncCs<tjd ¡D]\}}||jkr||j|<q| |j¡dS)NÚfrozen)r rÚitemsr%Ú_write_user_prefsr5r
r
r Úupdate_preferences\s
 z!FirefoxProfile.update_preferencescCs|jS)z8Gets the profile directory that is currently being used.)r&©r2r
r
r rgszFirefoxProfile.pathcCs|jS)z+Gets the port that WebDriver is working on.)Ú_portr@r
r
r ÚportlszFirefoxProfile.port)Úreturnc    Cspt|tƒstdƒ‚z$t|ƒ}|dks,|dkr4tdƒ‚Wn ttfk
rVtdƒ‚YnX||_| d|j¡dS)z0Sets the port that WebDriver will be running on.zPort needs to be an integeréiÿÿz)Port number must be in the range 1..65535Zwebdriver_firefox_portN)Ú
isinstanceÚintrÚ
ValueErrorÚ    TypeErrorrAr8)r2rBr
r
r rBqs
 cCs
|jdS)NÚ webdriver_accept_untrusted_certsr4r@r
r
r Úaccept_untrusted_certssz%FirefoxProfile.accept_untrusted_certscCs |dkrtdƒ‚| d|¡dS)N©TFú%Please pass in a Boolean to this callrI©rr8©r2r7r
r
r rJƒscCs
|jdS)NÚ!webdriver_assume_untrusted_issuerr4r@r
r
r Úassume_untrusted_cert_issuer‰sz+FirefoxProfile.assume_untrusted_cert_issuercCs |dkrtdƒ‚| d|¡dS)NrKrLrOrMrNr
r
r rPsc        Cs| ¡tƒ}t |dtj¡X}t|jƒd}t |j¡D]6\}}}|D]&}tj     ||¡}| 
|||d…¡qHq:W5QRXt   |  ¡¡ d¡S)znA zipped, base64 encoded string of profile directory for use with
        remote WebDriver JSON wire protocol.ÚwrDNzUTF-8)r?rÚzipfileÚZipFileÚ ZIP_DEFLATEDÚlenrrÚwalkrÚwriteÚbase64Ú    b64encodeÚgetvalueÚdecode)    r2ÚfpZzippedZ    path_rootÚbaseÚ_ÚfilesZfyleÚfilenamer
r
r Úencoded”s"zFirefoxProfile.encodedcCst ¡S)z9Creates a temp folder to store User.js and the extension.)r(r)r@r
r
r r'¢sz!FirefoxProfile._create_tempfolderc
CsPt|jddd6}| ¡D]&\}}| d|›dt |¡›d¡qW5QRXdS)z1writes the current user prefs dictionary to disk.rQrrz user_pref("z", z);
N)rr0r=rWr!Údumps)r2Z
user_prefsÚfr6r7r
r
r r>¦sz FirefoxProfile._write_user_prefsc Csªt d¡}z†t|ddp}|D]d}| |¡}z t | d¡¡|j| d¡<Wqtk
r€t     
d| d¡| d¡›¡YqXqW5QRXWntk
r¤YnXdS)Nzuser_pref\("(.*)",\s(.*)\)rrr rDz5(skipping) failed to json.loads existing preference: ) ÚreÚcompilerÚsearchr!ÚloadsÚgroupr%Ú    Exceptionrr)r2ZuserjsZ pref_patternrcZusrÚmatchesr
r
r r.¬s
 
 ÿz$FirefoxProfile._read_existing_userjsTc
CsÐ|tkrtj tj t¡t¡}d}d}| d¡rtjdtj     |¡dd}t
  |d¡}|  ¡D]¨}| d¡rœtj  tj ||¡¡sšt tj ||¡¡qbtj  tj tj ||¡¡¡sÖt tj tj ||¡¡¡| |¡}ttj ||¡dƒ}| |¡W5QRXqb|}|}| |¡}    |     d    ¡}
|
s<td
|›ƒ‚tj |j|
¡} |sž|    d sž|ržtj |j¡sŒt |j¡t |jd ¡t || d¡ntj | ¡s¼tj|| d d|rÌt |¡dS)zñInstalls 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: ÚunpackrT)Úsymlinks)Ú WEBDRIVER_EXTrrrrrÚendswithr(r)ÚsplitrRrSÚnamelistÚisdirÚmakedirsÚreadrrWÚ_addon_detailsÚgetÚAssertionErrorr/Úexistsr-r*r#r+Úrmtree) r2ZaddonrrZtmpdirZxpifileÚcompressed_fileÚnameÚdatarcZ addon_detailsZaddon_idÚ
addon_pathr
r
r r9¼s>   
 
 
 
 z!FirefoxProfile._install_extensionc
Cs®dddddœ}dd„}dd„}dd    „}tj |¡s@td
|›ƒ‚zæt |¡r”z:t |d ¡}d | ¡krz||     d ¡ƒW¢WS|     d ¡}W5| ¡Xntj 
|¡rtj  |d ¡}tj |¡rêt |dd}    ||         ¡ƒW5QR£WSQRXt tj  |d ¡dd}    |         ¡}W5QRXntd|›ƒ‚Wn>tt fk
rd}
ztt|
ƒt ¡dƒ‚W5d}
~
XYnXzÐt |¡} || dƒ} || dƒ} |  | d¡ d¡}|s°|  d¡ d¡}|jD]0}|j | d¡}||kr¶| |||ƒi¡q¶| d¡s4t|jjƒD]2}|j |¡}|j| dkr| d|ji¡qWn:t k
rp}
ztt|
ƒt ¡dƒ‚W5d}
~
XYnXt!|dtƒr–|d "¡dk|d<| d¡sªtdƒ‚|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)rqrrrÚversioncSs^|jj}d}t|jƒD]B}| |¡j|krd| |¡jkr| |¡j d¡dd}qZq|S)NÚú:rD)ZdocumentElementÚ
attributesÚrangeÚlengthÚitemr7rrv)ÚdocÚurlr‡Ú    namespaceÚir
r
r Úget_namespace_idûsz7FirefoxProfile._addon_details.<locals>.get_namespace_idcSs6g}|jD]}|j|jkr
| |j¡q
d |¡ ¡S)z(Retrieve the text value of a given node.r…)Ú
childNodesZnodeTypeZ    TEXT_NODEÚappendr‚rÚstrip)ÚelementÚrcÚnoder
r
r Úget_texts
 
 z/FirefoxProfile._addon_details.<locals>.get_textcSsft |¡}z|ddd}Wn0tk
rN|d dd¡d|d}YnX||d|dd    d
œS) z[Extracts the details from the contents of a WebExtensions
            `manifest.json` file.Z applicationsZgeckorqrú r…ú@r„F)rqr„rrr)r!rgÚKeyErrorÚreplace)ÚcontentÚmanifestrqr
r
r Úparse_manifest_jsons
"üz:FirefoxProfile._addon_details.<locals>.parse_manifest_jsonzAdd-on path does not exist: rnz manifest.jsonz install.rdfrrz/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#Ú Descriptionrr…rqrrÚtruezAdd-on id could not be found.)#rrr~ÚOSErrorrRÚ
is_zipfileÚcloserSrwrzrxrrr™rÚstrÚsysÚexc_inforÚ parseStringZgetElementsByTagNamerŠrÚnodeNameršÚupdater|rˆr‡r‰rr7rirEÚlower)r2rƒÚdetailsrr–rr€rœZmanifest_json_filenamercÚer‹ÚemÚrdfÚ descriptionr•ÚentryrŽÚ    attributer
r
r r{ìs^   
     (
 
 
 
 
  ( zFirefoxProfile._addon_details)N)T)rrrZANONYMOUS_PROFILE_NAMErr3r8rtr;r?ÚpropertyrrBÚsetterrJrPr£rar'r>r.r9r{r
r
r
r r *s6
'  
 
 
 
 
0r )rXr#r!rrdr*r¤r(rrRÚiorÚxml.domrZselenium.common.exceptionsrrtr ZEXTENSION_NAMErirr r
r
r
r Ú<module>s"