Skip to content

Commit edc321a

Browse files
committed
Py2.6 compatibility: use 3-argument create_connection() from future.backports.socket (issue #162)
1 parent e7e3d40 commit edc321a

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

docs/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ What's new in version 0.15.1 (in development)
99
=============================================
1010

1111
- ``futurize``: Moved exec fixer to stage1. The forward-compatible ``exec(a, b)`` idiom is supported in Python 2.6 and 2.7. See https://docs.python.org/2/reference/simple_stmts.html#exec.
12+
- Use 3-argument socket.create_connection() backport to restore Py2.6 compatibility in ``urllib.request.urlopen()`` (issue #162)
1213

1314

1415
What's new in version 0.15.0 (2015-07-25)

src/future/backports/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
# future.backports package
1+
"""
2+
future.backports package
3+
"""
4+
25
from __future__ import absolute_import
6+
37
import sys
8+
49
__future_module__ = True
510
from future.standard_library import import_top_level_modules
611

12+
713
if sys.version_info[0] == 3:
814
import_top_level_modules()
915

16+
1017
from .misc import (ceil,
1118
OrderedDict,
1219
Counter,

src/future/backports/http/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
from future.backports.email import parser as email_parser
7777
from future.backports.email import message as email_message
78+
from future.backports.socket import create_connection as socket_create_connection
7879
import io
7980
import os
8081
import socket
@@ -843,7 +844,7 @@ def _tunnel(self):
843844

844845
def connect(self):
845846
"""Connect to the host and port specified in __init__."""
846-
self.sock = socket.create_connection((self.host,self.port),
847+
self.sock = socket_create_connection((self.host,self.port),
847848
self.timeout, self.source_address)
848849
if self._tunnel_host:
849850
self._tunnel()
@@ -1226,7 +1227,7 @@ def __init__(self, host, port=None, key_file=None, cert_file=None,
12261227
def connect(self):
12271228
"Connect to a host on a given (SSL) port."
12281229

1229-
sock = socket.create_connection((self.host, self.port),
1230+
sock = socket_create_connection((self.host, self.port),
12301231
self.timeout, self.source_address)
12311232

12321233
if self._tunnel_host:
@@ -1266,7 +1267,7 @@ def connect(self):
12661267
# def connect(self):
12671268
# "Connect to a host on a given (SSL) port."
12681269

1269-
# sock = socket.create_connection((self.host, self.port),
1270+
# sock = socket_create_connection((self.host, self.port),
12701271
# self.timeout, self.source_address)
12711272
# if self._tunnel_host:
12721273
# self.sock = sock

src/future/backports/misc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- subprocess.check_output (for Python 2.6)
1111
- reprlib.recursive_repr (for Python 2.6+)
1212
"""
13+
from __future__ import absolute_import
1314

1415
import subprocess
1516
from math import ceil as oldceil

src/future/tests/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import print_function
1+
from __future__ import print_function, absolute_import
22
import os
33
import tempfile
44
import unittest
@@ -362,6 +362,9 @@ def _run_test_script(self, filename='mytestscript.py',
362362
fn,
363363
'----\n%s\n----' % f.read(),
364364
)
365+
if not hasattr(e, 'output'):
366+
# The attribute CalledProcessError.output doesn't exist on Py2.6
367+
e.output = None
365368
raise VerboseCalledProcessError(msg, e.returncode, e.cmd, output=e.output)
366369
return output
367370

src/future/types/newrange.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Read more at
1818
https://late.am/post/2012/06/18/what-the-heck-is-an-xrange
1919
"""
20+
from __future__ import absolute_import
2021

2122
from collections import Sequence, Iterator
2223
from itertools import islice

0 commit comments

Comments
 (0)