Skip to content

Commit

Permalink
pep-8 formatting changes
Browse files Browse the repository at this point in the history
replaced a print (python2) with warnings.warn
except Exception as (python 2.5+)

Signed-off-by: Luke Inman-Semerau <[email protected]>
  • Loading branch information
vergiliu authored and lukeis committed Dec 9, 2013
1 parent b9d005d commit 60e54db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions py/selenium/webdriver/firefox/firefox_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
WEBDRIVER_PREFERENCES = "webdriver_prefs.json"
EXTENSION_NAME = "[email protected]"

class FirefoxProfile(object):

ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
class FirefoxProfile(object):
ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
DEFAULT_PREFERENCES = None

def __init__(self,profile_directory=None):
def __init__(self, profile_directory=None):
"""
Initialises a new instance of a Firefox Profile
Expand All @@ -67,10 +67,9 @@ def __init__(self,profile_directory=None):
self.profile_dir = self._create_tempfolder()
else:
self.tempfolder = tempfile.mkdtemp()
newprof = os.path.join(self.tempfolder,
"webdriver-py-profilecopy")
newprof = os.path.join(self.tempfolder, "webdriver-py-profilecopy")
shutil.copytree(self.profile_dir, newprof,
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
self.profile_dir = newprof
self._read_existing_userjs(os.path.join(self.profile_dir, "user.js"))
self.extensionsDir = os.path.join(self.profile_dir, "extensions")
Expand Down Expand Up @@ -162,7 +161,7 @@ def encoded(self):
"""
fp = BytesIO()
zipped = zipfile.ZipFile(fp, 'w', zipfile.ZIP_DEFLATED)
path_root = len(self.path) + 1 # account for trailing slash
path_root = len(self.path) + 1 # account for trailing slash
for base, dirs, files in os.walk(self.path):
for fyle in files:
filename = os.path.join(base, fyle)
Expand All @@ -172,8 +171,10 @@ def encoded(self):

def set_proxy(self, proxy):
import warnings
warnings.warn("This method has been deprecated. Please pass in the proxy object to the Driver Object",
DeprecationWarning)

warnings.warn(
"This method has been deprecated. Please pass in the proxy object to the Driver Object",
DeprecationWarning)
if proxy is None:
raise ValueError("proxy can not be None")

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

def _read_existing_userjs(self, userjs):
import warnings

PREF_RE = re.compile(r'user_pref\("(.*)",\s(.*)\)')
try:
with open(userjs) as f:
for usr in f:
matches = re.search(PREF_RE, usr)
try:
self.default_preferences[matches.group(1)] = json.loads(matches.group(2))
self.default_preferences[matches.group(1)] = json.loads(matches.group(2))
except:
print "(skipping) failed to json.loads existing prefernce:", matches.group(1), matches.group(2)
warnings.warn("(skipping) failed to json.loads existing preference: " +
matches.group(1) + matches.group(2))
except:
# The profile given hasn't had any changes made, i.e no users.js
pass
Expand All @@ -241,7 +245,7 @@ def _install_extension(self, addon, unpack=True):
tmpdir = None
xpifile = None
if addon.endswith('.xpi'):
tmpdir = tempfile.mkdtemp(suffix = '.' + os.path.split(addon)[-1])
tmpdir = tempfile.mkdtemp(suffix='.' + os.path.split(addon)[-1])
compressed_file = zipfile.ZipFile(addon, 'r')
for name in compressed_file.namelist():
if name.endswith('/'):
Expand Down Expand Up @@ -323,6 +327,6 @@ def get_text(element):
# Remove the namespace prefix from the tag for comparison
entry = node.nodeName.replace(em, "")
if entry in details.keys():
details.update({ entry: get_text(node) })
details.update({entry: get_text(node)})

return details
2 changes: 1 addition & 1 deletion py/test/selenium/webdriver/common/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def testShouldBeAbleToOverrideTheWindowAlertMethod(self):
self.driver.find_element(by=By.ID, value="alert").click()
try:
self.assertEqual(self.driver.find_element_by_id('text').text, "cheese")
except Exception, e:
except Exception as e:
# if we're here, likely the alert is displayed
# not dismissing it will affect other tests
try:
Expand Down

0 comments on commit 60e54db

Please sign in to comment.