39
39
WEBDRIVER_PREFERENCES = "webdriver_prefs.json"
40
40
EXTENSION_NAME = "fxdriver@googlecode.com"
41
41
42
- class FirefoxProfile (object ):
43
42
44
- ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
43
+ class FirefoxProfile (object ):
44
+ ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
45
45
DEFAULT_PREFERENCES = None
46
46
47
- def __init__ (self ,profile_directory = None ):
47
+ def __init__ (self , profile_directory = None ):
48
48
"""
49
49
Initialises a new instance of a Firefox Profile
50
50
@@ -67,10 +67,9 @@ def __init__(self,profile_directory=None):
67
67
self .profile_dir = self ._create_tempfolder ()
68
68
else :
69
69
self .tempfolder = tempfile .mkdtemp ()
70
- newprof = os .path .join (self .tempfolder ,
71
- "webdriver-py-profilecopy" )
70
+ newprof = os .path .join (self .tempfolder , "webdriver-py-profilecopy" )
72
71
shutil .copytree (self .profile_dir , newprof ,
73
- ignore = shutil .ignore_patterns ("parent.lock" , "lock" , ".parentlock" ))
72
+ ignore = shutil .ignore_patterns ("parent.lock" , "lock" , ".parentlock" ))
74
73
self .profile_dir = newprof
75
74
self ._read_existing_userjs (os .path .join (self .profile_dir , "user.js" ))
76
75
self .extensionsDir = os .path .join (self .profile_dir , "extensions" )
@@ -162,7 +161,7 @@ def encoded(self):
162
161
"""
163
162
fp = BytesIO ()
164
163
zipped = zipfile .ZipFile (fp , 'w' , zipfile .ZIP_DEFLATED )
165
- path_root = len (self .path ) + 1 # account for trailing slash
164
+ path_root = len (self .path ) + 1 # account for trailing slash
166
165
for base , dirs , files in os .walk (self .path ):
167
166
for fyle in files :
168
167
filename = os .path .join (base , fyle )
@@ -172,8 +171,10 @@ def encoded(self):
172
171
173
172
def set_proxy (self , proxy ):
174
173
import warnings
175
- warnings .warn ("This method has been deprecated. Please pass in the proxy object to the Driver Object" ,
176
- DeprecationWarning )
174
+
175
+ warnings .warn (
176
+ "This method has been deprecated. Please pass in the proxy object to the Driver Object" ,
177
+ DeprecationWarning )
177
178
if proxy is None :
178
179
raise ValueError ("proxy can not be None" )
179
180
@@ -215,15 +216,18 @@ def _write_user_prefs(self, user_prefs):
215
216
f .write ('user_pref("%s", %s);\n ' % (key , json .dumps (value )))
216
217
217
218
def _read_existing_userjs (self , userjs ):
219
+ import warnings
220
+
218
221
PREF_RE = re .compile (r'user_pref\("(.*)",\s(.*)\)' )
219
222
try :
220
223
with open (userjs ) as f :
221
224
for usr in f :
222
225
matches = re .search (PREF_RE , usr )
223
226
try :
224
- self .default_preferences [matches .group (1 )] = json .loads (matches .group (2 ))
227
+ self .default_preferences [matches .group (1 )] = json .loads (matches .group (2 ))
225
228
except :
226
- print "(skipping) failed to json.loads existing prefernce:" , matches .group (1 ), matches .group (2 )
229
+ warnings .warn ("(skipping) failed to json.loads existing preference: " +
230
+ matches .group (1 ) + matches .group (2 ))
227
231
except :
228
232
# The profile given hasn't had any changes made, i.e no users.js
229
233
pass
@@ -241,7 +245,7 @@ def _install_extension(self, addon, unpack=True):
241
245
tmpdir = None
242
246
xpifile = None
243
247
if addon .endswith ('.xpi' ):
244
- tmpdir = tempfile .mkdtemp (suffix = '.' + os .path .split (addon )[- 1 ])
248
+ tmpdir = tempfile .mkdtemp (suffix = '.' + os .path .split (addon )[- 1 ])
245
249
compressed_file = zipfile .ZipFile (addon , 'r' )
246
250
for name in compressed_file .namelist ():
247
251
if name .endswith ('/' ):
@@ -323,6 +327,6 @@ def get_text(element):
323
327
# Remove the namespace prefix from the tag for comparison
324
328
entry = node .nodeName .replace (em , "" )
325
329
if entry in details .keys ():
326
- details .update ({ entry : get_text (node ) })
330
+ details .update ({entry : get_text (node )})
327
331
328
332
return details
0 commit comments