Skip to content

Commit 154c3f5

Browse files
authored
Merge branch 'master' into patch-3
2 parents 89c8030 + 907ab88 commit 154c3f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+628
-292
lines changed

TESTING.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ The test suite can be run with:
44

55
$ tox
66

7-
which tests the module under a number of different python versions, where available.
7+
which tests the module under a number of different python versions, where available, or with:
8+
9+
$ py.test
10+
11+
To execute a single test:
12+
13+
$ pytest -k test_chained_exceptions_stacktrace

docs/compatible_idioms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ urllib module
12701270
~~~~~~~~~~~~~
12711271

12721272
``urllib`` is the hardest module to use from Python 2/3 compatible code.
1273-
You may like to use Requests (http://python-requests.org) instead.
1273+
You might want to switch to Requests (http://python-requests.org) instead.
12741274

12751275
.. code:: python
12761276

docs/credits.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Python-Future is largely written by Ed Schofield <[email protected]> with th
5050
- Grant Bakker
5151
- Jacob Beck
5252
- Nate Bogdanowicz
53+
- Christian Clauss
5354
- Denis Cornehl
5455
- Nicolas Delaby
5556
- Jon Dufresne
@@ -79,7 +80,6 @@ Python-Future is largely written by Ed Schofield <[email protected]> with th
7980
- Jeff Tratner
8081
- Tim Tröndle
8182
- Brad Walker
82-
- cclaus (GiHub user)
8383
- lsm (GiHub user)
8484
- Mystic-Mirage (GitHub user)
8585
- str4d (GitHub user)

docs/futurize.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ The complete list of fixers applied in Stage 2 is::
237237
lib2to3.fixes.fix_operator
238238
lib2to3.fixes.fix_raw_input
239239
lib2to3.fixes.fix_zip
240-
240+
241241
libfuturize.fixes.fix_basestring
242242
libfuturize.fixes.fix_cmp
243243
libfuturize.fixes.fix_division_safe
@@ -269,6 +269,7 @@ Not applied::
269269
lib2to3.fixes.fix_xrange # Custom one because of a bug with Py3.3's lib2to3
270270

271271

272+
272273
.. Ideally the output of this stage should not be a ``SyntaxError`` on either
273274
.. Python 3 or Python 2.
274275

docs/futurize_overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ use the ``-w`` flag.
5151

5252
For complex projects, it is probably best to divide the porting into two stages.
5353
Stage 1 is for "safe" changes that modernize the code but do not break Python
54-
2.7 compatibility or introduce a depdendency on the ``future`` package. Stage 2
54+
2.7 compatibility or introduce a dependency on the ``future`` package. Stage 2
5555
is to complete the process.

docs/notebooks/Writing Python 2-3 compatible code.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@
17471747
"source": [
17481748
"# Python 2 and 3: option 3\n",
17491749
"try:\n",
1750-
" import itertools.imap as map\n",
1750+
" from itertools import imap as map\n",
17511751
"except ImportError:\n",
17521752
" pass\n",
17531753
"\n",
@@ -1845,7 +1845,7 @@
18451845
"source": [
18461846
"# Python 2 and 3: option 2\n",
18471847
"try:\n",
1848-
" import itertools.imap as map\n",
1848+
" from itertools import imap as map\n",
18491849
"except ImportError:\n",
18501850
" pass\n",
18511851
"\n",

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"past.builtins",
4747
"past.types",
4848
"past.utils",
49-
# "past.tests",
5049
"past.translation",
5150
"libfuturize",
5251
"libfuturize.fixes",

src/future/backports/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from future.standard_library import import_top_level_modules
1111

1212

13-
if sys.version_info[0] == 3:
13+
if sys.version_info[0] >= 3:
1414
import_top_level_modules()
1515

1616

src/future/backports/email/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def set_boundary(self, boundary):
800800
# There was no Content-Type header, and we don't know what type
801801
# to set it to, so raise an exception.
802802
raise errors.HeaderParseError('No Content-Type header found')
803-
newparams = []
803+
newparams = list()
804804
foundp = False
805805
for pk, pv in params:
806806
if pk.lower() == 'boundary':
@@ -814,10 +814,10 @@ def set_boundary(self, boundary):
814814
# instead???
815815
newparams.append(('boundary', '"%s"' % boundary))
816816
# Replace the existing Content-Type header with the new value
817-
newheaders = []
817+
newheaders = list()
818818
for h, v in self._headers:
819819
if h.lower() == 'content-type':
820-
parts = []
820+
parts = list()
821821
for k, v in newparams:
822822
if v == '':
823823
parts.append(k)

src/future/backports/http/client.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,19 @@ def _safe_readinto(self, b):
696696
while total_bytes < len(b):
697697
if MAXAMOUNT < len(mvb):
698698
temp_mvb = mvb[0:MAXAMOUNT]
699-
n = self.fp.readinto(temp_mvb)
699+
if PY2:
700+
data = self.fp.read(len(temp_mvb))
701+
n = len(data)
702+
temp_mvb[:n] = data
703+
else:
704+
n = self.fp.readinto(temp_mvb)
700705
else:
701-
n = self.fp.readinto(mvb)
706+
if PY2:
707+
data = self.fp.read(len(mvb))
708+
n = len(data)
709+
mvb[:n] = data
710+
else:
711+
n = self.fp.readinto(mvb)
702712
if not n:
703713
raise IncompleteRead(bytes(mvb[0:total_bytes]), len(b))
704714
mvb = mvb[n:]

src/future/backports/http/cookiejar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333
from __future__ import division
3434
from __future__ import absolute_import
3535
from future.builtins import filter, int, map, open, str
36-
from future.utils import as_native_str
36+
from future.utils import as_native_str, PY2
3737

3838
__all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy',
3939
'FileCookieJar', 'LWPCookieJar', 'LoadError', 'MozillaCookieJar']
4040

4141
import copy
4242
import datetime
4343
import re
44-
re.ASCII = 0
44+
if PY2:
45+
re.ASCII = 0
4546
import time
4647
from future.backports.urllib.parse import urlparse, urlsplit, quote
4748
from future.backports.http.client import HTTP_PORT

src/future/backports/http/cookies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@
138138
# Import our required modules
139139
#
140140
import re
141-
re.ASCII = 0 # for py2 compatibility
141+
if PY2:
142+
re.ASCII = 0 # for py2 compatibility
142143
import string
143144

144145
__all__ = ["CookieError", "BaseCookie", "SimpleCookie"]

src/future/backports/misc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import subprocess
1818
from math import ceil as oldceil
19-
from collections import Mapping, MutableMapping
2019

2120
from operator import itemgetter as _itemgetter, eq as _eq
2221
import sys
@@ -25,7 +24,12 @@
2524
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
2625
from socket import getaddrinfo, SOCK_STREAM, error, socket
2726

28-
from future.utils import iteritems, itervalues, PY26, PY3
27+
from future.utils import iteritems, itervalues, PY2, PY26, PY3
28+
29+
if PY2:
30+
from collections import Mapping, MutableMapping
31+
else:
32+
from collections.abc import Mapping, MutableMapping
2933

3034

3135
def ceil(x):

src/future/backports/urllib/request.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@
109109
import socket
110110
import sys
111111
import time
112-
import collections
113112
import tempfile
114113
import contextlib
115114
import warnings
116115

116+
from future.utils import PY2
117+
118+
if PY2:
119+
from collections import Iterable
120+
else:
121+
from collections.abc import Iterable
122+
117123
# check for SSL
118124
try:
119125
import ssl
@@ -1221,7 +1227,7 @@ def do_request_(self, request):
12211227
mv = memoryview(data)
12221228
size = len(mv) * mv.itemsize
12231229
except TypeError:
1224-
if isinstance(data, collections.Iterable):
1230+
if isinstance(data, Iterable):
12251231
raise ValueError("Content-Length should be specified "
12261232
"for iterable data of type %r %r" % (type(data),
12271233
data))

src/future/builtins/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# The isinstance import is no longer needed. We provide it only for
1212
# backward-compatibility with future v0.8.2. It will be removed in future v1.0.
1313
from future.builtins.misc import (ascii, chr, hex, input, isinstance, next,
14-
oct, open, pow, round, super)
14+
oct, open, pow, round, super, max, min)
1515
from future.utils import PY3
1616

1717
if PY3:
@@ -43,7 +43,7 @@
4343
__all__ = ['filter', 'map', 'zip',
4444
'ascii', 'chr', 'hex', 'input', 'next', 'oct', 'open', 'pow',
4545
'round', 'super',
46-
'bytes', 'dict', 'int', 'list', 'object', 'range', 'str',
46+
'bytes', 'dict', 'int', 'list', 'object', 'range', 'str', 'max', 'min'
4747
]
4848

4949
else:

src/future/builtins/misc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- ``open`` (equivalent to io.open on Py2)
1414
- ``super`` (backport of Py3's magic zero-argument super() function
1515
- ``round`` (new "Banker's Rounding" behaviour from Py3)
16+
- ``max`` (new default option from Py3.4)
17+
- ``min`` (new default option from Py3.4)
1618
1719
``isinstance`` is also currently exported for backwards compatibility
1820
with v0.8.2, although this has been deprecated since v0.9.
@@ -59,6 +61,8 @@
5961
from future.builtins.newnext import newnext as next
6062
from future.builtins.newround import newround as round
6163
from future.builtins.newsuper import newsuper as super
64+
from future.builtins.new_min_max import newmax as max
65+
from future.builtins.new_min_max import newmin as min
6266
from future.types.newint import newint
6367

6468
_SENTINEL = object()
@@ -89,11 +93,12 @@ def pow(x, y, z=_SENTINEL):
8993
else:
9094
return _builtin_pow(x+0j, y, z)
9195

96+
9297
# ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
9398
# callable = __builtin__.callable
9499

95100
__all__ = ['ascii', 'chr', 'hex', 'input', 'isinstance', 'next', 'oct',
96-
'open', 'pow', 'round', 'super']
101+
'open', 'pow', 'round', 'super', 'max', 'min']
97102

98103
else:
99104
import builtins
@@ -109,8 +114,14 @@ def pow(x, y, z=_SENTINEL):
109114
pow = builtins.pow
110115
round = builtins.round
111116
super = builtins.super
112-
113-
__all__ = []
117+
if utils.PY34_PLUS:
118+
max = builtins.max
119+
min = builtins.min
120+
__all__ = []
121+
else:
122+
from future.builtins.new_min_max import newmax as max
123+
from future.builtins.new_min_max import newmin as min
124+
__all__ = ['min', 'max']
114125

115126
# The callable() function was removed from Py3.0 and 3.1 and
116127
# reintroduced into Py3.2+. ``future`` doesn't support Py3.0/3.1. If we ever

src/future/builtins/new_min_max.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from future import utils
2+
if utils.PY2:
3+
from __builtin__ import max as _builtin_max, min as _builtin_min
4+
else:
5+
from builtins import max as _builtin_max, min as _builtin_min
6+
7+
8+
def newmin(*args, **kwargs):
9+
return new_min_max(_builtin_min, *args, **kwargs)
10+
11+
12+
def newmax(*args, **kwargs):
13+
return new_min_max(_builtin_max, *args, **kwargs)
14+
15+
16+
def new_min_max(_builtin_func, *args, **kwargs):
17+
"""
18+
To support the argument "default" introduced in python 3.4 for min and max
19+
:param _builtin_func: builtin min or builtin max
20+
:param args:
21+
:param kwargs:
22+
:return: returns the min or max based on the arguments passed
23+
"""
24+
25+
for key, _ in kwargs.items():
26+
if key not in set(['key', 'default']):
27+
raise TypeError('Illegal argument %s', key)
28+
29+
if len(args) == 0:
30+
raise TypeError
31+
32+
if len(args) != 1 and kwargs.get('default') is not None:
33+
raise TypeError
34+
35+
if len(args) == 1:
36+
try:
37+
next(iter(args[0]))
38+
except StopIteration:
39+
if kwargs.get('default') is not None:
40+
return kwargs.get('default')
41+
else:
42+
raise ValueError('iterable is an empty sequence')
43+
if kwargs.get('key') is not None:
44+
return _builtin_func(args[0], key=kwargs.get('key'))
45+
else:
46+
return _builtin_func(args[0])
47+
48+
if len(args) > 1:
49+
if kwargs.get('key') is not None:
50+
return _builtin_func(args, key=kwargs.get('key'))
51+
else:
52+
return _builtin_func(args)

src/future/moves/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
__future_module__ = True
55
from future.standard_library import import_top_level_modules
66

7-
if sys.version_info[0] == 3:
7+
if sys.version_info[0] >= 3:
88
import_top_level_modules()

src/future/moves/urllib/request.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,8 @@
1111
proxy_bypass,
1212
quote,
1313
request_host,
14-
splitattr,
15-
splithost,
16-
splitpasswd,
17-
splitport,
18-
splitquery,
19-
splittag,
20-
splittype,
21-
splituser,
22-
splitvalue,
2314
thishost,
24-
to_bytes,
2515
unquote,
26-
unwrap,
2716
url2pathname,
2817
urlcleanup,
2918
urljoin,
@@ -32,6 +21,18 @@
3221
urlretrieve,
3322
urlsplit,
3423
urlunparse)
24+
25+
from urllib.parse import (splitattr,
26+
splithost,
27+
splitpasswd,
28+
splitport,
29+
splitquery,
30+
splittag,
31+
splittype,
32+
splituser,
33+
splitvalue,
34+
to_bytes,
35+
unwrap)
3536
else:
3637
__future_module__ = True
3738
with suspend_hooks():

src/future/tests/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ def convert_check(self, before, expected, stages=(1, 2), all_imports=False,
272272
else:
273273
headers = ''
274274

275-
self.compare(output, headers + reformat_code(expected),
275+
reformatted = reformat_code(expected)
276+
if headers in reformatted:
277+
headers = ''
278+
279+
self.compare(output, headers + reformatted,
276280
ignore_imports=ignore_imports)
277281

278282
def unchanged(self, code, **kwargs):

0 commit comments

Comments
 (0)