From 657b97ba58130920bcd869257b4de8d76fec3849 Mon Sep 17 00:00:00 2001 From: HelioGuilherme66 Date: Tue, 31 Jan 2017 23:35:43 +0000 Subject: [PATCH] Fixes types for both python 2.7 and 3.x. --- src/Selenium2Library/keywords/_browsermanagement.py | 4 ++++ src/Selenium2Library/keywords/_element.py | 5 +++++ src/Selenium2Library/keywords/_logging.py | 1 + src/Selenium2Library/keywords/keywordgroup.py | 7 +++---- src/Selenium2Library/locators/customlocator.py | 6 ++++++ src/Selenium2Library/utils/__init__.py | 3 ++- src/Selenium2Library/utils/events/event.py | 1 + 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Selenium2Library/keywords/_browsermanagement.py b/src/Selenium2Library/keywords/_browsermanagement.py index d15cd1a2f..59359c3c2 100644 --- a/src/Selenium2Library/keywords/_browsermanagement.py +++ b/src/Selenium2Library/keywords/_browsermanagement.py @@ -12,6 +12,10 @@ from .keywordgroup import KeywordGroup +try: + unicode = unicode +except: + unicode = str ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) FIREFOX_PROFILE_DIR = os.path.join(ROOT_DIR, 'resources', 'firefoxprofile') diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 3a461a74f..a5f36008c 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -8,6 +8,11 @@ from .keywordgroup import KeywordGroup +try: + unicode = unicode +except NameError: + basestring = (str,bytes) + class _ElementKeywords(KeywordGroup): diff --git a/src/Selenium2Library/keywords/_logging.py b/src/Selenium2Library/keywords/_logging.py index 5c4a86381..f2b40e628 100644 --- a/src/Selenium2Library/keywords/_logging.py +++ b/src/Selenium2Library/keywords/_logging.py @@ -2,6 +2,7 @@ from robot.api import logger from robot.libraries.BuiltIn import BuiltIn + try: from robot.libraries.BuiltIn import RobotNotRunningError except ImportError: # Support RF < 2.8.5 diff --git a/src/Selenium2Library/keywords/keywordgroup.py b/src/Selenium2Library/keywords/keywordgroup.py index 47b43486f..2d60eb0c6 100644 --- a/src/Selenium2Library/keywords/keywordgroup.py +++ b/src/Selenium2Library/keywords/keywordgroup.py @@ -1,7 +1,7 @@ import sys import inspect - from decorator import decorator +from future.utils import with_metaclass def _run_on_failure_decorator(method, *args, **kwargs): @@ -32,6 +32,5 @@ def __new__(cls, clsname, bases, dict): dict[name] = decorator(_run_on_failure_decorator, method) return type.__new__(cls, clsname, bases, dict) - -class KeywordGroup(object): - __metaclass__ = KeywordGroupMetaClass +class KeywordGroup(with_metaclass(KeywordGroupMetaClass, object)): + pass diff --git a/src/Selenium2Library/locators/customlocator.py b/src/Selenium2Library/locators/customlocator.py index 6f68752d7..6ccddfeb4 100644 --- a/src/Selenium2Library/locators/customlocator.py +++ b/src/Selenium2Library/locators/customlocator.py @@ -1,5 +1,11 @@ +from builtins import object from robot.libraries.BuiltIn import BuiltIn +try: + unicode = unicode +except NameError: + basestring = (str,bytes) + class CustomLocator(object): diff --git a/src/Selenium2Library/utils/__init__.py b/src/Selenium2Library/utils/__init__.py index f43c24c57..5042e56fe 100644 --- a/src/Selenium2Library/utils/__init__.py +++ b/src/Selenium2Library/utils/__init__.py @@ -1,10 +1,11 @@ +from builtins import str from . import events from .browsercache import BrowserCache from .librarylistener import LibraryListener def escape_xpath_value(value): - value = unicode(value) + value = str(value) if '"' in value and '\'' in value: parts_wo_apos = value.split('\'') return "concat('%s')" % "', \"'\", '".join(parts_wo_apos) diff --git a/src/Selenium2Library/utils/events/event.py b/src/Selenium2Library/utils/events/event.py index 91b2baaf4..7c4013940 100644 --- a/src/Selenium2Library/utils/events/event.py +++ b/src/Selenium2Library/utils/events/event.py @@ -1,4 +1,5 @@ import abc +from builtins import object class Event(object):