Skip to content

Commit 60e54db

Browse files
vergiliulukeis
authored andcommitted
pep-8 formatting changes
replaced a print (python2) with warnings.warn except Exception as (python 2.5+) Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
1 parent b9d005d commit 60e54db

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Diff for: py/selenium/webdriver/firefox/firefox_profile.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
WEBDRIVER_PREFERENCES = "webdriver_prefs.json"
4040
EXTENSION_NAME = "fxdriver@googlecode.com"
4141

42-
class FirefoxProfile(object):
4342

44-
ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
43+
class FirefoxProfile(object):
44+
ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
4545
DEFAULT_PREFERENCES = None
4646

47-
def __init__(self,profile_directory=None):
47+
def __init__(self, profile_directory=None):
4848
"""
4949
Initialises a new instance of a Firefox Profile
5050
@@ -67,10 +67,9 @@ def __init__(self,profile_directory=None):
6767
self.profile_dir = self._create_tempfolder()
6868
else:
6969
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")
7271
shutil.copytree(self.profile_dir, newprof,
73-
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
72+
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
7473
self.profile_dir = newprof
7574
self._read_existing_userjs(os.path.join(self.profile_dir, "user.js"))
7675
self.extensionsDir = os.path.join(self.profile_dir, "extensions")
@@ -162,7 +161,7 @@ def encoded(self):
162161
"""
163162
fp = BytesIO()
164163
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
166165
for base, dirs, files in os.walk(self.path):
167166
for fyle in files:
168167
filename = os.path.join(base, fyle)
@@ -172,8 +171,10 @@ def encoded(self):
172171

173172
def set_proxy(self, proxy):
174173
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)
177178
if proxy is None:
178179
raise ValueError("proxy can not be None")
179180

@@ -215,15 +216,18 @@ def _write_user_prefs(self, user_prefs):
215216
f.write('user_pref("%s", %s);\n' % (key, json.dumps(value)))
216217

217218
def _read_existing_userjs(self, userjs):
219+
import warnings
220+
218221
PREF_RE = re.compile(r'user_pref\("(.*)",\s(.*)\)')
219222
try:
220223
with open(userjs) as f:
221224
for usr in f:
222225
matches = re.search(PREF_RE, usr)
223226
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))
225228
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))
227231
except:
228232
# The profile given hasn't had any changes made, i.e no users.js
229233
pass
@@ -241,7 +245,7 @@ def _install_extension(self, addon, unpack=True):
241245
tmpdir = None
242246
xpifile = None
243247
if addon.endswith('.xpi'):
244-
tmpdir = tempfile.mkdtemp(suffix = '.' + os.path.split(addon)[-1])
248+
tmpdir = tempfile.mkdtemp(suffix='.' + os.path.split(addon)[-1])
245249
compressed_file = zipfile.ZipFile(addon, 'r')
246250
for name in compressed_file.namelist():
247251
if name.endswith('/'):
@@ -323,6 +327,6 @@ def get_text(element):
323327
# Remove the namespace prefix from the tag for comparison
324328
entry = node.nodeName.replace(em, "")
325329
if entry in details.keys():
326-
details.update({ entry: get_text(node) })
330+
details.update({entry: get_text(node)})
327331

328332
return details

Diff for: py/test/selenium/webdriver/common/alerts_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def testShouldBeAbleToOverrideTheWindowAlertMethod(self):
3333
self.driver.find_element(by=By.ID, value="alert").click()
3434
try:
3535
self.assertEqual(self.driver.find_element_by_id('text').text, "cheese")
36-
except Exception, e:
36+
except Exception as e:
3737
# if we're here, likely the alert is displayed
3838
# not dismissing it will affect other tests
3939
try:

0 commit comments

Comments
 (0)