Skip to content

Commit

Permalink
Merge pull request #392 from PaulBrandUWV/remove_python_2
Browse files Browse the repository at this point in the history
Remove support for python 2
  • Loading branch information
lucagiove authored May 6, 2024
2 parents d787215 + a7e1cfd commit eb4259c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 46 deletions.
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
except ImportError:
from distutils.core import setup

PY3 = sys.version_info > (3,)

CLASSIFIERS = """
Development Status :: 5 - Production/Stable
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Expand All @@ -26,8 +22,7 @@
Topic :: Software Development :: Testing
"""[1:-1]

TEST_REQUIRE = ['robotframework>=3.2.1', 'pytest', 'flask', 'six', 'coverage', 'flake8'] if PY3 \
else ['robotframework>=3.2.1', 'pytest', 'flask', 'coverage', 'flake8', 'mock']
TEST_REQUIRE = ['robotframework>=3.2.1', 'pytest', 'flask', 'six', 'coverage', 'flake8']

VERSION = None
version_file = join(dirname(abspath(__file__)), 'src', 'RequestsLibrary', 'version.py')
Expand Down
18 changes: 3 additions & 15 deletions src/RequestsLibrary/SessionKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from robot.utils.asserts import assert_equal

from RequestsLibrary import utils
from RequestsLibrary.compat import httplib, PY3, RetryAdapter
from RequestsLibrary.compat import httplib, RetryAdapter
from .RequestsKeywords import RequestsKeywords
from RequestsLibrary.exceptions import InvalidResponse, InvalidExpectedStatus
from RequestsLibrary.utils import is_string_type
Expand Down Expand Up @@ -602,20 +602,8 @@ def _capture_output(self):
def _print_debug(self):
if self.debug >= 1:
sys.stdout = sys.__stdout__ # Restore stdout
if PY3:
debug_info = ''.join(
self.http_log.content).replace(
'\\r',
'').replace(
'\'',
'')
else:
debug_info = ''.join(
self.http_log.content).replace(
'\\r',
'').decode('string_escape').replace(
'\'',
'')
debug_info = ''.join(
self.http_log.content).replace('\\r','').replace('\'','')

# Remove empty lines
debug_info = "\n".join(
Expand Down
14 changes: 3 additions & 11 deletions src/RequestsLibrary/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
import sys
from requests.packages.urllib3.util import Retry

PY3 = sys.version_info > (3,)

if PY3:
import http.client as httplib # noqa
from urllib.parse import urlencode # noqa
from urllib.parse import urljoin # noqa
else:
import httplib # noqa
from urllib import urlencode # noqa
from urlparse import urljoin # noqa

import http.client as httplib # noqa
from urllib.parse import urlencode # noqa
from urllib.parse import urljoin # noqa

class RetryAdapter(Retry):

Expand Down
17 changes: 3 additions & 14 deletions src/RequestsLibrary/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from requests.structures import CaseInsensitiveDict
from robot.api import logger

from RequestsLibrary.compat import urlencode, PY3
from RequestsLibrary.compat import urlencode
from RequestsLibrary.exceptions import UnknownStatusError


Expand Down Expand Up @@ -74,20 +74,10 @@ def json_pretty_print(content):


def is_string_type(data):
if PY3 and isinstance(data, str):
return True
elif not PY3 and isinstance(data, unicode): # noqa
return True
return False

return isinstance(data, str)

def is_file_descriptor(fd):
if PY3 and isinstance(fd, io.IOBase):
return True
if not PY3 and isinstance(fd, file): # noqa
return True
return False

return isinstance(fd, io.IOBase)

def utf8_urlencode(data):
if is_string_type(data):
Expand All @@ -103,7 +93,6 @@ def utf8_urlencode(data):
utf8_data[k] = v
return urlencode(utf8_data)


def format_data_according_to_header(session, data, headers):
# when data is an open file descriptor we ignore it
if is_file_descriptor(data):
Expand Down

0 comments on commit eb4259c

Please sign in to comment.