Skip to content

Commit 952f0e4

Browse files
committed
Clean up docs for standard_library and http/client.py diff
1 parent 4b7fa03 commit 952f0e4

2 files changed

Lines changed: 33 additions & 73 deletions

File tree

docs/source/quickstart.rst

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ and converts a few Python 3-only constructs to a form compatible with
5454
both Py3 and Py2. Most remaining Python 3 code should simply work on
5555
Python 2.
5656

57+
For a realistic example, you can see the included `backported
58+
http.client module
59+
<https://github.com/PythonCharmers/python-future/blob/master/future/standard_library/http/client.py>`_,
60+
and look at the diff between this and the Python 3.3 module (e.g.
61+
``/usr/lib/python3.3/http/client.py``).
62+
5763
See :ref:`backwards-conversion` for more details.
5864

65+
66+
5967

6068
To convert existing Python 2 code
6169
---------------------------------
@@ -80,35 +88,40 @@ be accessed under their Python 3 names and locations in Python 2::
8088
import queue
8189
import configparser
8290
import test.support
91+
import html.parser
8392
from collections import UserList
8493
from itertools import filterfalse, zip_longest
94+
from http.client import HttpConnection
8595
# and other moved modules and definitions
8696

87-
:mod:`future` also includes backports for these stdlib packages from Py3
97+
:mod:`future` also includes backports for these stdlib modules from Py3
8898
that were heavily refactored versus Py2::
8999
90-
import html, html.entities, html.parser
91-
import http, http.client, http.server
100+
import html
101+
import html.entities
102+
import html.parser
103+
104+
import http
105+
import http.client
106+
import http.server
92107

93108
These modules are currently not supported, but we aim to support them in
94109
the future::
95110
96-
import http.cookies, http.cookiejar
97-
import urllib, urllib.parse, urllib.request, urllib.error
111+
import http.cookies
112+
import http.cookiejar
98113

114+
import urllib
115+
import urllib.parse
116+
import urllib.request
117+
import urllib.error
99118

100-
For more information, see :ref:`standard-library`.
119+
If you need one of these, please open an issue `here
120+
<https://github.com/PythonCharmers/python-future>`_.
101121

122+
For more information on interfaces that have changed in the standard library
123+
between Python 2 and Python 3, see :ref:`_stdlib-incompatibilities`.
102124

103-
For examples of code fragments that run identically on Python 3 and 2,
104-
see :ref:`code-examples`.
105-
106-
For a more substantial example, you can see the included `backported
107-
http.client module
108-
<https://github.com/PythonCharmers/python-future/blob/master/future/standard_library/http/client.py>`_,
109-
but be warned: there is not much to see. It is mostly the same as the
110-
Python 3.3 standard library code.
111-
112125

113126
.. _utilities-guide:
114127

future/standard_library/http/client.py

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""HTTP/1.1 client library
22
3-
From Python 3.3
3+
A backport of the Python 3.3 module to Python 2.7 using ``future``.
44
5-
<intro stuff goes here>
6-
<other stuff, too>
5+
--------------
76
87
HTTPConnection goes through a number of "states", which define when a client
98
may legally make another request or fetch the response for a particular
@@ -70,8 +69,8 @@
7069

7170
from __future__ import (absolute_import, division,
7271
print_function, unicode_literals)
73-
from future.utils import isbytes, istext
7472
from future.builtins import *
73+
from future.utils import isbytes, istext
7574

7675
import email.parser
7776
import email.message
@@ -83,9 +82,10 @@
8382
# from urllib.parse import urlsplit
8483
# Use the Py2.7 equivalent:
8584
from urlparse import urlsplit
86-
from array import array
85+
8786
import warnings
8887
import numbers
88+
from array import array
8989

9090
__all__ = ["HTTPResponse", "HTTPConnection",
9191
"HTTPException", "NotConnected", "UnknownProtocol",
@@ -1202,59 +1202,6 @@ def connect(self):
12021202
__all__.append("HTTPSConnection")
12031203

12041204

1205-
######################################
1206-
# class HTTPSConnection(HTTPConnection):
1207-
# "This class allows communication via SSL."
1208-
1209-
# default_port = HTTPS_PORT
1210-
1211-
# # XXX Should key_file and cert_file be deprecated in favour of context?
1212-
1213-
# def __init__(self, host, port=None, key_file=None, cert_file=None,
1214-
# strict=_strict_sentinel, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
1215-
# source_address=None, context=None, check_hostname=None):
1216-
# super(HTTPSConnection, self).__init__(host, port, strict, timeout,
1217-
# source_address)
1218-
# self.key_file = key_file
1219-
# self.cert_file = cert_file
1220-
# if context is None:
1221-
# # Some reasonable defaults
1222-
# context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
1223-
# context.options |= ssl.OP_NO_SSLv2
1224-
# will_verify = context.verify_mode != ssl.CERT_NONE
1225-
# if check_hostname is None:
1226-
# check_hostname = will_verify
1227-
# elif check_hostname and not will_verify:
1228-
# raise ValueError("check_hostname needs a SSL context with "
1229-
# "either CERT_OPTIONAL or CERT_REQUIRED")
1230-
# if key_file or cert_file:
1231-
# context.load_cert_chain(cert_file, key_file)
1232-
# self._context = context
1233-
# self._check_hostname = check_hostname
1234-
1235-
# def connect(self):
1236-
# "Connect to a host on a given (SSL) port."
1237-
1238-
# sock = socket.create_connection((self.host, self.port),
1239-
# self.timeout, self.source_address)
1240-
1241-
# if self._tunnel_host:
1242-
# self.sock = sock
1243-
# self._tunnel()
1244-
1245-
# server_hostname = self.host if ssl.HAS_SNI else None
1246-
# self.sock = self._context.wrap_socket(sock,
1247-
# server_hostname=server_hostname)
1248-
# try:
1249-
# if self._check_hostname:
1250-
# ssl.match_hostname(self.sock.getpeercert(), self.host)
1251-
# except Exception:
1252-
# self.sock.shutdown(socket.SHUT_RDWR)
1253-
# self.sock.close()
1254-
# raise
1255-
1256-
# __all__.append("HTTPSConnection")
1257-
12581205
class HTTPException(Exception):
12591206
# Subclasses that define an __init__ must call Exception.__init__
12601207
# or define self.args. Otherwise, str() will fail.

0 commit comments

Comments
 (0)