Skip to content

Commit

Permalink
Python 2.7 support removal WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbrzt committed Aug 29, 2019
1 parent c297af0 commit b3d2c18
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 118 deletions.
20 changes: 1 addition & 19 deletions .travis.yml
Expand Up @@ -7,39 +7,21 @@ env:
global:
- NEWEST_PYTHON=3.7
python:
# <https://docs.travis-ci.com/user/languages/python/>
- 2.7
# Python 3.4 fails installing packages
# <https://travis-ci.org/jakubroztocil/httpie/jobs/403263566#L636>
# - 3.4
- 3.5
- 3.6
# - 3.7 # is done in the matrix below as described in travis-ci/travis-ci#9069
- pypy
# pypy3 currently fails because of a Flask issue
# - pypy3

cache: pip
matrix:
include:

# Manually defined macOS builds
# Manually defined macOS build
# <https://docs.travis-ci.com/user/multi-os/#Python-example-(unsupported-languages)>

# FIXME: stock macOS python fails with InterpreterNotFound
# <https://travis-ci.org/jakubroztocil/httpie/jobs/578189209>
# - os: osx
# language: generic
# env:
# # Stock macOS Python
# - TOXENV=py27-osx-builtin
# - BREW_PYTHON_PACKAGE=
- os: osx
language: generic
env:
# Latest Python 2.7 from Homebrew
- TOXENV=py27
- BREW_PYTHON_PACKAGE=python@2
- os: osx
language: generic
env:
Expand Down
30 changes: 2 additions & 28 deletions README.rst
Expand Up @@ -47,7 +47,6 @@ Main features
* Custom headers
* Persistent sessions
* Wget-like downloads
* Python 2.7 and 3.x support
* Linux, macOS and Windows support
* Plugins
* Documentation
Expand Down Expand Up @@ -125,12 +124,7 @@ and always provides the latest version) is to use `pip`_:
Python version
--------------

Although Python 2.7 is supported as well, it is strongly recommended to
install HTTPie against the latest Python 3.x whenever possible. That will
ensure that some of the newer HTTP features, such as
`SNI (Server Name Indication)`_, work out of the box.
Python 3 is the default for Homebrew installations starting with version 0.9.4.
To see which version HTTPie uses, run ``http --debug``.
Starting with version 2.0.0 (currently under development) Python 3.x is required.


Unstable version
Expand Down Expand Up @@ -945,26 +939,6 @@ available set of protocols may vary depending on your OpenSSL installation.)
$ http --ssl=ssl3 https://vulnerable.example.org
SNI (Server Name Indication)
----------------------------
If you use HTTPie with `Python version`_ lower than 2.7.9
(can be verified with ``http --debug``) and need to talk to servers that
use SNI (Server Name Indication) you need to install some additional
dependencies:
.. code-block:: bash
$ pip install --upgrade requests[security]
You can use the following command to test SNI support:
.. code-block:: bash
$ http https://sni.velox.ch
Output options
==============
Expand Down Expand Up @@ -1755,4 +1729,4 @@ have contributed.
.. |downloads| image:: https://pepy.tech/badge/httpie
:target: https://pepy.tech/project/httpie
:alt: Download count
2 changes: 1 addition & 1 deletion httpie/__init__.py
Expand Up @@ -2,7 +2,7 @@
HTTPie - a CLI, cURL-like tool for humans.
"""
__version__ = '1.0.3'
__version__ = '2.0.0-dev'
__author__ = 'Jakub Roztocil'
__licence__ = 'BSD'

Expand Down
1 change: 0 additions & 1 deletion httpie/client.py
Expand Up @@ -7,7 +7,6 @@

from httpie import sessions
from httpie import __version__
from httpie.compat import str
from httpie.input import SSL_VERSION_ARG_MAPPING
from httpie.plugins import plugin_manager
from httpie.utils import repr_dict_nice
Expand Down
35 changes: 0 additions & 35 deletions httpie/compat.py
@@ -1,39 +1,4 @@
"""
Python 2.7, and 3.x compatibility.
"""
import sys


is_py2 = sys.version_info[0] == 2
is_py27 = sys.version_info[:2] == (2, 7)
is_py3 = sys.version_info[0] == 3
is_pypy = 'pypy' in sys.version.lower()
is_windows = 'win32' in str(sys.platform).lower()


if is_py2:
# noinspection PyShadowingBuiltins
bytes = str
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
str = unicode
elif is_py3:
# noinspection PyShadowingBuiltins
str = str
# noinspection PyShadowingBuiltins
bytes = bytes


try: # pragma: no cover
# noinspection PyUnresolvedReferences,PyCompatibility
from urllib.parse import urlsplit
except ImportError: # pragma: no cover
# noinspection PyUnresolvedReferences,PyCompatibility
from urlparse import urlsplit

try: # pragma: no cover
# noinspection PyCompatibility
from urllib.request import urlopen
except ImportError: # pragma: no cover
# noinspection PyCompatibility,PyUnresolvedReferences
from urllib2 import urlopen
3 changes: 1 addition & 2 deletions httpie/core.py
Expand Up @@ -19,7 +19,6 @@
from pygments import __version__ as pygments_version

from httpie import __version__ as httpie_version, ExitStatus
from httpie.compat import str, bytes, is_py3
from httpie.client import get_response
from httpie.downloads import Downloader
from httpie.context import Environment
Expand Down Expand Up @@ -132,7 +131,7 @@ def program(args, env, log_error):
'flush': env.stdout_isatty or args.stream
}
try:
if env.is_windows and is_py3 and 'colors' in args.prettify:
if env.is_windows and 'colors' in args.prettify:
write_stream_with_colors_win_py3(**write_stream_kwargs)
else:
write_stream(**write_stream_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion httpie/downloads.py
Expand Up @@ -12,11 +12,11 @@
import threading
from time import sleep, time
from mailbox import Message
from urllib.parse import urlsplit

from httpie.output.streams import RawStream
from httpie.models import HTTPResponse
from httpie.utils import humanize_bytes
from httpie.compat import urlsplit


PARTIAL_CONTENT = 206
Expand Down
14 changes: 2 additions & 12 deletions httpie/input.py
Expand Up @@ -15,10 +15,11 @@

# TODO: Use MultiDict for headers once added to `requests`.
# https://github.com/jakubroztocil/httpie/issues/130
from urllib.parse import urlsplit

from httpie.plugins import plugin_manager
from requests.structures import CaseInsensitiveDict

from httpie.compat import urlsplit, str, is_pypy, is_py27
from httpie.sessions import VALID_SESSION_NAME_PATTERN
from httpie.utils import load_json_preserve_order

Expand Down Expand Up @@ -615,17 +616,6 @@ def __call__(self, string):
class RequestItemsDict(OrderedDict):
"""Multi-value dict for URL parameters and form data."""

if is_pypy and is_py27:
# Manually set keys when initialized with an iterable as PyPy
# doesn't call __setitem__ in such case (pypy3 does).
def __init__(self, *args, **kwargs):
if len(args) == 1 and isinstance(args[0], Iterable):
super(RequestItemsDict, self).__init__(**kwargs)
for k, v in args[0]:
self[k] = v
else:
super(RequestItemsDict, self).__init__(*args, **kwargs)

# noinspection PyMethodOverriding
def __setitem__(self, key, value):
""" If `key` is assigned more than once, `self[key]` holds a
Expand Down
2 changes: 1 addition & 1 deletion httpie/models.py
@@ -1,4 +1,4 @@
from httpie.compat import urlsplit, str
from urllib.parse import urlsplit


class HTTPMessage(object):
Expand Down
1 change: 0 additions & 1 deletion httpie/output/streams.py
@@ -1,7 +1,6 @@
from itertools import chain
from functools import partial

from httpie.compat import str
from httpie.context import Environment
from httpie.models import HTTPRequest, HTTPResponse
from httpie.input import (OUT_REQ_BODY, OUT_REQ_HEAD,
Expand Down
2 changes: 1 addition & 1 deletion httpie/sessions.py
Expand Up @@ -3,10 +3,10 @@
"""
import re
import os
from urllib.parse import urlsplit

from requests.cookies import RequestsCookieJar, create_cookie

from httpie.compat import urlsplit
from httpie.config import BaseConfigDict, DEFAULT_CONFIG_DIR
from httpie.plugins import plugin_manager

Expand Down
8 changes: 2 additions & 6 deletions setup.py
Expand Up @@ -7,7 +7,6 @@
from setuptools.command.test import test as TestCommand

import httpie
from httpie.compat import is_py27


class PyTest(TestCommand):
Expand All @@ -34,9 +33,6 @@ def run_tests(self):
'mock',
]

if is_py27:
tests_require.append('pyOpenSSL')


install_requires = [
'requests>=2.21.0',
Expand Down Expand Up @@ -77,7 +73,7 @@ def long_description():
version=httpie.__version__,
description=httpie.__doc__.strip(),
long_description=long_description(),
url='http://httpie.org/',
url='https://httpie.org/',
download_url='https://github.com/jakubroztocil/httpie',
author=httpie.__author__,
author_email='jakub@roztocil.co',
Expand All @@ -95,14 +91,14 @@ def long_description():
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_downloads.py
@@ -1,12 +1,12 @@
import os
import tempfile
import time
from urllib.request import urlopen

import pytest
import mock
from requests.structures import CaseInsensitiveDict

from httpie.compat import urlopen
from httpie.downloads import (
parse_content_range, filename_from_content_disposition, filename_from_url,
get_unique_filename, ContentRangeError, Downloader,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_output.py
@@ -1,11 +1,11 @@
import os
from tempfile import gettempdir
from urllib.request import urlopen

import pytest

from utils import MockEnvironment, http, HTTP_OK, COLOR, CRLF
from httpie import ExitStatus
from httpie.compat import urlopen
from httpie.output.formatters.colors import get_lexer


Expand Down
1 change: 0 additions & 1 deletion tests/test_ssl.py
Expand Up @@ -5,7 +5,6 @@
import requests.exceptions

from httpie import ExitStatus
from httpie.compat import is_pypy
from httpie.input import SSL_VERSION_ARG_MAPPING
from utils import HTTP_OK, TESTS_ROOT, http

Expand Down
1 change: 0 additions & 1 deletion tests/utils.py
Expand Up @@ -9,7 +9,6 @@
from httpie import ExitStatus, EXIT_STATUS_LABELS
from httpie.context import Environment
from httpie.core import main
from httpie.compat import bytes, str


TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
Expand Down
7 changes: 1 addition & 6 deletions tox.ini
Expand Up @@ -4,16 +4,14 @@

[tox]
# pypy3 currently fails because of a Flask issue
envlist = py27, py37, pypy
envlist = py37


[testenv]
# pyOpenSSL only needed for Python 2.7
deps =
mock
pytest
pytest-httpbin>=0.0.6
pyOpenSSL


commands =
Expand All @@ -23,6 +21,3 @@ commands =
--verbose \
--doctest-modules \
{posargs:./httpie ./tests}

[testenv:py27-osx-builtin]
basepython = /usr/bin/python2.7

0 comments on commit b3d2c18

Please sign in to comment.