Commit fe625581 authored by Éric Araujo's avatar Éric Araujo

Branch merge

parents ad6e3113 4066eca6
......@@ -646,6 +646,14 @@ with sub-interpreters:
:c:func:`PyGILState_Release` on the same thread.
.. c:function:: PyThreadState PyGILState_GetThisThreadState()
Get the current thread state for this thread. May return ``NULL`` if no
GILState API has been used on the current thread. Note that the main thread
always has such a thread-state, even if no auto-thread-state call has been
made on the main thread. This is mainly a helper/diagnostic function.
The following macros are normally used without a trailing semicolon; look for
example usage in the Python source distribution.
......
......@@ -1628,7 +1628,7 @@ with the :class:`Pool` class.
the process pool as separate tasks. The (approximate) size of these
chunks can be specified by setting *chunksize* to a positive integer.
.. method:: map_async(func, iterable[, chunksize[, callback]])
.. method:: map_async(func, iterable[, chunksize[, callback[, error_callback]]])
A variant of the :meth:`.map` method which returns a result object.
......
......@@ -709,9 +709,9 @@ placeholder syntax, delimiter character, or the entire regular expression used
to parse template strings. To do this, you can override these class attributes:
* *delimiter* -- This is the literal string describing a placeholder introducing
delimiter. The default value ``$``. Note that this should *not* be a regular
expression, as the implementation will call :meth:`re.escape` on this string as
needed.
delimiter. The default value is ``$``. Note that this should *not* be a
regular expression, as the implementation will call :meth:`re.escape` on this
string as needed.
* *idpattern* -- This is the regular expression describing the pattern for
non-braced placeholders (the braces will be added automatically as
......
......@@ -191,13 +191,13 @@ interface) that compare the cost of using :func:`hasattr` vs.
:keyword:`try`/:keyword:`except` to test for missing and present object
attributes. ::
% timeit.py 'try:' ' str.__bool__' 'except AttributeError:' ' pass'
$ python -m timeit 'try:' ' str.__bool__' 'except AttributeError:' ' pass'
100000 loops, best of 3: 15.7 usec per loop
% timeit.py 'if hasattr(str, "__bool__"): pass'
$ python -m timeit 'if hasattr(str, "__bool__"): pass'
100000 loops, best of 3: 4.26 usec per loop
% timeit.py 'try:' ' int.__bool__' 'except AttributeError:' ' pass'
$ python -m timeit 'try:' ' int.__bool__' 'except AttributeError:' ' pass'
1000000 loops, best of 3: 1.43 usec per loop
% timeit.py 'if hasattr(int, "__bool__"): pass'
$ python -m timeit 'if hasattr(int, "__bool__"): pass'
100000 loops, best of 3: 2.23 usec per loop
::
......@@ -238,10 +238,10 @@ To give the :mod:`timeit` module access to functions you define, you can pass a
``setup`` parameter which contains an import statement::
def test():
"Stupid test function"
"""Stupid test function"""
L = [i for i in range(100)]
if __name__=='__main__':
if __name__ == '__main__':
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print(t.timeit())
......
......@@ -18,10 +18,10 @@ Turtle graphics is a popular way for introducing programming to kids. It was
part of the original Logo programming language developed by Wally Feurzig and
Seymour Papert in 1966.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it the
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it the
command ``turtle.forward(15)``, and it moves (on-screen!) 15 pixels in the
direction it is facing, drawing a line as it moves. Give it the command
``turtle.left(25)``, and it rotates in-place 25 degrees clockwise.
``turtle.right(25)``, and it rotates in-place 25 degrees clockwise.
.. sidebar:: Turtle star
......
......@@ -782,8 +782,8 @@ Some smaller changes made to the core Python language are:
(Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
* The :keyword:`import` statement will no longer try a relative import
if an absolute import (e.g. ``from .os import sep``) fails. This
* The :keyword:`import` statement will no longer try an absolute import
if a relative import (e.g. ``from .os import sep``) fails. This
fixes a bug, but could possibly break certain :keyword:`import`
statements that were only working by accident. (Fixed by Meador Inge;
:issue:`7902`.)
......
......@@ -197,7 +197,7 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
/* Helper/diagnostic function - get the current thread state for
this thread. May return NULL if no GILState API has been used
on the current thread. Note the main thread always has such a
on the current thread. Note that the main thread always has such a
thread-state, even if no auto-thread-state call has been made
on the main thread.
*/
......
......@@ -323,68 +323,3 @@ del types
# Helper for instance creation without calling __init__
class _EmptyClass:
pass
def _test():
l = [None, 1, 2, 3.14, 'xyzzy', (1, 2), [3.14, 'abc'],
{'abc': 'ABC'}, (), [], {}]
l1 = copy(l)
print(l1==l)
l1 = map(copy, l)
print(l1==l)
l1 = deepcopy(l)
print(l1==l)
class C:
def __init__(self, arg=None):
self.a = 1
self.arg = arg
if __name__ == '__main__':
import sys
file = sys.argv[0]
else:
file = __file__
self.fp = open(file)
self.fp.close()
def __getstate__(self):
return {'a': self.a, 'arg': self.arg}
def __setstate__(self, state):
for key, value in state.items():
setattr(self, key, value)
def __deepcopy__(self, memo=None):
new = self.__class__(deepcopy(self.arg, memo))
new.a = self.a
return new
c = C('argument sketch')
l.append(c)
l2 = copy(l)
print(l == l2)
print(l)
print(l2)
l2 = deepcopy(l)
print(l == l2)
print(l)
print(l2)
l.append({l[1]: l, 'xyz': l[2]})
l3 = copy(l)
import reprlib
print(map(reprlib.repr, l))
print(map(reprlib.repr, l1))
print(map(reprlib.repr, l2))
print(map(reprlib.repr, l3))
l3 = deepcopy(l)
print(map(reprlib.repr, l))
print(map(reprlib.repr, l1))
print(map(reprlib.repr, l2))
print(map(reprlib.repr, l3))
class odict(dict):
def __init__(self, d = {}):
self.a = 99
dict.__init__(self, d)
def __setitem__(self, k, i):
dict.__setitem__(self, k, i)
self.a
o = odict({"A" : "B"})
x = deepcopy(o)
print(o, x)
if __name__ == '__main__':
_test()
......@@ -17,7 +17,7 @@ class TestCopy(unittest.TestCase):
# Attempt full line coverage of copy.py from top to bottom
def test_exceptions(self):
self.assertTrue(copy.Error is copy.error)
self.assertIs(copy.Error, copy.error)
self.assertTrue(issubclass(copy.Error, Exception))
# The copy() method
......@@ -54,20 +54,26 @@ class TestCopy(unittest.TestCase):
def test_copy_reduce_ex(self):
class C(object):
def __reduce_ex__(self, proto):
c.append(1)
return ""
def __reduce__(self):
raise support.TestFailed("shouldn't call this")
self.fail("shouldn't call this")
c = []
x = C()
y = copy.copy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
self.assertEqual(c, [1])
def test_copy_reduce(self):
class C(object):
def __reduce__(self):
c.append(1)
return ""
c = []
x = C()
y = copy.copy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
self.assertEqual(c, [1])
def test_copy_cant(self):
class C(object):
......@@ -91,7 +97,7 @@ class TestCopy(unittest.TestCase):
"hello", "hello\u1234", f.__code__,
NewStyle, range(10), Classic, max]
for x in tests:
self.assertTrue(copy.copy(x) is x, repr(x))
self.assertIs(copy.copy(x), x)
def test_copy_list(self):
x = [1, 2, 3]
......@@ -185,9 +191,9 @@ class TestCopy(unittest.TestCase):
x = [x, x]
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y[0] is not x[0])
self.assertTrue(y[0] is y[1])
self.assertIsNot(y, x)
self.assertIsNot(y[0], x[0])
self.assertIs(y[0], y[1])
def test_deepcopy_issubclass(self):
# XXX Note: there's no way to test the TypeError coming out of
......@@ -227,20 +233,26 @@ class TestCopy(unittest.TestCase):
def test_deepcopy_reduce_ex(self):
class C(object):
def __reduce_ex__(self, proto):
c.append(1)
return ""
def __reduce__(self):
raise support.TestFailed("shouldn't call this")
self.fail("shouldn't call this")
c = []
x = C()
y = copy.deepcopy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
self.assertEqual(c, [1])
def test_deepcopy_reduce(self):
class C(object):
def __reduce__(self):
c.append(1)
return ""
c = []
x = C()
y = copy.deepcopy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
self.assertEqual(c, [1])
def test_deepcopy_cant(self):
class C(object):
......@@ -264,14 +276,14 @@ class TestCopy(unittest.TestCase):
"hello", "hello\u1234", f.__code__,
NewStyle, range(10), Classic, max]
for x in tests:
self.assertTrue(copy.deepcopy(x) is x, repr(x))
self.assertIs(copy.deepcopy(x), x)
def test_deepcopy_list(self):
x = [[1, 2], 3]
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(x is not y)
self.assertTrue(x[0] is not y[0])
self.assertIsNot(x, y)
self.assertIsNot(x[0], y[0])
def test_deepcopy_reflexive_list(self):
x = []
......@@ -279,16 +291,26 @@ class TestCopy(unittest.TestCase):
y = copy.deepcopy(x)
for op in comparisons:
self.assertRaises(RuntimeError, op, y, x)
self.assertTrue(y is not x)
self.assertTrue(y[0] is y)
self.assertIsNot(y, x)
self.assertIs(y[0], y)
self.assertEqual(len(y), 1)
def test_deepcopy_empty_tuple(self):
x = ()
y = copy.deepcopy(x)
self.assertIs(x, y)
def test_deepcopy_tuple(self):
x = ([1, 2], 3)
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(x is not y)
self.assertTrue(x[0] is not y[0])
self.assertIsNot(x, y)
self.assertIsNot(x[0], y[0])
def test_deepcopy_tuple_of_immutables(self):
x = ((1, 2), 3)
y = copy.deepcopy(x)
self.assertIs(x, y)
def test_deepcopy_reflexive_tuple(self):
x = ([],)
......@@ -296,16 +318,16 @@ class TestCopy(unittest.TestCase):
y = copy.deepcopy(x)
for op in comparisons:
self.assertRaises(RuntimeError, op, y, x)
self.assertTrue(y is not x)
self.assertTrue(y[0] is not x[0])
self.assertTrue(y[0][0] is y)
self.assertIsNot(y, x)
self.assertIsNot(y[0], x[0])
self.assertIs(y[0][0], y)
def test_deepcopy_dict(self):
x = {"foo": [1, 2], "bar": 3}
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(x is not y)
self.assertTrue(x["foo"] is not y["foo"])
self.assertIsNot(x, y)
self.assertIsNot(x["foo"], y["foo"])
def test_deepcopy_reflexive_dict(self):
x = {}
......@@ -315,8 +337,8 @@ class TestCopy(unittest.TestCase):
self.assertRaises(TypeError, op, y, x)
for op in equality_comparisons:
self.assertRaises(RuntimeError, op, y, x)
self.assertTrue(y is not x)
self.assertTrue(y['foo'] is y)
self.assertIsNot(y, x)
self.assertIs(y['foo'], y)
self.assertEqual(len(y), 1)
def test_deepcopy_keepalive(self):
......@@ -349,7 +371,7 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_inst_deepcopy(self):
class C:
......@@ -362,8 +384,8 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_inst_getinitargs(self):
class C:
......@@ -376,8 +398,8 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_inst_getstate(self):
class C:
......@@ -390,8 +412,8 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_inst_setstate(self):
class C:
......@@ -404,8 +426,8 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_inst_getstate_setstate(self):
class C:
......@@ -420,8 +442,8 @@ class TestCopy(unittest.TestCase):
x = C([42])
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y, x)
self.assertIsNot(y.foo, x.foo)
def test_deepcopy_reflexive_inst(self):
class C:
......@@ -429,8 +451,8 @@ class TestCopy(unittest.TestCase):
x = C()
x.foo = x
y = copy.deepcopy(x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is y)
self.assertIsNot(y, x)
self.assertIs(y.foo, y)
# _reconstruct()
......@@ -440,9 +462,9 @@ class TestCopy(unittest.TestCase):
return ""
x = C()
y = copy.copy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
y = copy.deepcopy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
def test_reconstruct_nostate(self):
class C(object):
......@@ -451,9 +473,9 @@ class TestCopy(unittest.TestCase):
x = C()
x.foo = 42
y = copy.copy(x)
self.assertTrue(y.__class__ is x.__class__)
self.assertIs(y.__class__, x.__class__)
y = copy.deepcopy(x)
self.assertTrue(y.__class__ is x.__class__)
self.assertIs(y.__class__, x.__class__)
def test_reconstruct_state(self):
class C(object):
......@@ -467,7 +489,7 @@ class TestCopy(unittest.TestCase):
self.assertEqual(y, x)
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y.foo, x.foo)
def test_reconstruct_state_setstate(self):
class C(object):
......@@ -483,7 +505,7 @@ class TestCopy(unittest.TestCase):
self.assertEqual(y, x)
y = copy.deepcopy(x)
self.assertEqual(y, x)
self.assertTrue(y.foo is not x.foo)
self.assertIsNot(y.foo, x.foo)
def test_reconstruct_reflexive(self):
class C(object):
......@@ -491,8 +513,8 @@ class TestCopy(unittest.TestCase):
x = C()
x.foo = x
y = copy.deepcopy(x)
self.assertTrue(y is not x)
self.assertTrue(y.foo is y)
self.assertIsNot(y, x)
self.assertIs(y.foo, y)
# Additions for Python 2.3 and pickle protocol 2
......@@ -506,12 +528,12 @@ class TestCopy(unittest.TestCase):
x = C([[1, 2], 3])
y = copy.copy(x)
self.assertEqual(x, y)
self.assertTrue(x is not y)
self.assertTrue(x[0] is y[0])
self.assertIsNot(x, y)
self.assertIs(x[0], y[0])
y = copy.deepcopy(x)
self.assertEqual(x, y)
self.assertTrue(x is not y)
self.assertTrue(x[0] is not y[0])
self.assertIsNot(x, y)
self.assertIsNot(x[0], y[0])
def test_reduce_5tuple(self):
class C(dict):
......@@ -523,12 +545,12 @@ class TestCopy(unittest.TestCase):
x = C([("foo", [1, 2]), ("bar", 3)])
y = copy.copy(x)
self.assertEqual(x, y)
self.assertTrue(x is not y)
self.assertTrue(x["foo"] is y["foo"])
self.assertIsNot(x, y)
self.assertIs(x["foo"], y["foo"])
y = copy.deepcopy(x)
self.assertEqual(x, y)
self.assertTrue(x is not y)
self.assertTrue(x["foo"] is not y["foo"])
self.assertIsNot(x, y)
self.assertIsNot(x["foo"], y["foo"])
def test_copy_slots(self):
class C(object):
......@@ -536,7 +558,7 @@ class TestCopy(unittest.TestCase):
x = C()
x.foo = [42]
y = copy.copy(x)
self.assertTrue(x.foo is y.foo)
self.assertIs(x.foo, y.foo)
def test_deepcopy_slots(self):
class C(object):
......@@ -545,7 +567,7 @@ class TestCopy(unittest.TestCase):
x.foo = [42]
y = copy.deepcopy(x)
self.assertEqual(x.foo, y.foo)
self.assertTrue(x.foo is not y.foo)
self.assertIsNot(x.foo, y.foo)
def test_deepcopy_dict_subclass(self):
class C(dict):
......@@ -562,7 +584,7 @@ class TestCopy(unittest.TestCase):
y = copy.deepcopy(x)
self.assertEqual(x, y)
self.assertEqual(x._keys, y._keys)
self.assertTrue(x is not y)
self.assertIsNot(x, y)
x['bar'] = 1
self.assertNotEqual(x, y)
self.assertNotEqual(x._keys, y._keys)
......@@ -575,8 +597,8 @@ class TestCopy(unittest.TestCase):
y = copy.copy(x)
self.assertEqual(list(x), list(y))
self.assertEqual(x.foo, y.foo)
self.assertTrue(x[0] is y[0])
self.assertTrue(x.foo is y.foo)
self.assertIs(x[0], y[0])
self.assertIs(x.foo, y.foo)
def test_deepcopy_list_subclass(self):
class C(list):
......@@ -586,8 +608,8 @@ class TestCopy(unittest.TestCase):
y = copy.deepcopy(x)
self.assertEqual(list(x), list(y))
self.assertEqual(x.foo, y.foo)
self.assertTrue(x[0] is not y[0])
self.assertTrue(x.foo is not y.foo)
self.assertIsNot(x[0], y[0])
self.assertIsNot(x.foo, y.foo)
def test_copy_tuple_subclass(self):
class C(tuple):
......@@ -604,8 +626,8 @@ class TestCopy(unittest.TestCase):
self.assertEqual(tuple(x), ([1, 2], 3))
y = copy.deepcopy(x)
self.assertEqual(tuple(y), ([1, 2], 3))
self.assertTrue(x is not y)
self.assertTrue(x[0] is not y[0])
self.assertIsNot(x, y)
self.assertIsNot(x[0], y[0])
def test_getstate_exc(self):
class EvilState(object):
......@@ -633,10 +655,10 @@ class TestCopy(unittest.TestCase):
obj = C()
x = weakref.ref(obj)
y = _copy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
del obj
y = _copy(x)
self.assertTrue(y is x)
self.assertIs(y, x)
def test_copy_weakref(self):
self._check_weakref(copy.copy)
......@@ -652,7 +674,7 @@ class TestCopy(unittest.TestCase):
u[a] = b
u[c] = d
v = copy.copy(u)
self.assertFalse(v is u)
self.assertIsNot(v, u)
self.assertEqual(v, u)
self.assertEqual(v[a], b)
self.assertEqual(v[c], d)
......@@ -682,8 +704,8 @@ class TestCopy(unittest.TestCase):
v = copy.deepcopy(u)
self.assertNotEqual(v, u)
self.assertEqual(len(v), 2)
self.assertFalse(v[a] is b)
self.assertFalse(v[c] is d)
self.assertIsNot(v[a], b)
self.assertIsNot(v[c], d)
self.assertEqual(v[a].i, b.i)
self.assertEqual(v[c].i, d.i)
del c
......@@ -702,12 +724,12 @@ class TestCopy(unittest.TestCase):
self.assertNotEqual(v, u)
self.assertEqual(len(v), 2)
(x, y), (z, t) = sorted(v.items(), key=lambda pair: pair[0].i)
self.assertFalse(x is a)
self.assertIsNot(x, a)
self.assertEqual(x.i, a.i)
self.assertTrue(y is b)
self.assertFalse(z is c)
self.assertIs(y, b)
self.assertIsNot(z, c)
self.assertEqual(z.i, c.i)
self.assertTrue(t is d)
self.assertIs(t, d)
del x, y, z, t
del d
self.assertEqual(len(v), 1)
......@@ -720,7 +742,7 @@ class TestCopy(unittest.TestCase):
f.b = f.m
g = copy.deepcopy(f)
self.assertEqual(g.m, g.b)
self.assertTrue(g.b.__self__ is g)
self.assertIs(g.b.__self__, g)
g.b()
......
......@@ -135,7 +135,9 @@ class ProxyTests(unittest.TestCase):
proxies = urllib.request.getproxies_environment()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self.assertEqual('localhost', proxies['no'])
# List of no_proxies with space.
self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com')
self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com'))
class urlopen_HttpTests(unittest.TestCase):
"""Test urlopen() opening a fake http connection."""
......
......@@ -27,10 +27,10 @@ Turtle graphics is a popular way for introducing programming to
kids. It was part of the original Logo programming language developed
by Wally Feurzig and Seymour Papert in 1966.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
the direction it is facing, drawing a line as it moves. Give it the
command turtle.left(25), and it rotates in-place 25 degrees clockwise.
command turtle.right(25), and it rotates in-place 25 degrees clockwise.
By combining together these and similar commands, intricate shapes and
pictures can easily be drawn.
......
......@@ -7,10 +7,10 @@ Turtle graphics is a popular way for introducing programming to
kids. It was part of the original Logo programming language developed
by Wally Feurzig and Seymour Papert in 1966.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
the direction it is facing, drawing a line as it moves. Give it the
command turtle.left(25), and it rotates in-place 25 degrees clockwise.
command turtle.right(25), and it rotates in-place 25 degrees clockwise.
By combining together these and similar commands, intricate shapes and
pictures can easily be drawn.
......
......@@ -2274,7 +2274,8 @@ def proxy_bypass_environment(host):
# strip port off host
hostonly, port = splitport(host)
# check if the host ends with any of the DNS suffixes
for name in no_proxy.split(','):
no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')]
for name in no_proxy_list:
if name and (hostonly.endswith(name) or host.endswith(name)):
return 1
# otherwise, don't bypass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment