Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3811e4

Browse files
committed
merge
2 parents 824f7f3 + 7bf1125 commit a3811e4

13 files changed

Lines changed: 93 additions & 16 deletions

File tree

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ type objects) *must* have the :attr:`ob_size` field.
192192
An optional pointer to the instance print function.
193193

194194
The print function is only called when the instance is printed to a *real* file;
195-
when it is printed to a pseudo-file (like a :class:`StringIO` instance), the
195+
when it is printed to a pseudo-file (like a :class:`io.StringIO` instance), the
196196
instance's :c:member:`~PyTypeObject.tp_repr` or :c:member:`~PyTypeObject.tp_str` function is called to convert it to
197197
a string. These are also called when the type's :c:member:`~PyTypeObject.tp_print` field is
198198
*NULL*. A type should never implement :c:member:`~PyTypeObject.tp_print` in a way that produces

Doc/library/gzip.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The module defines the following items:
6262
value.
6363

6464
The new class instance is based on *fileobj*, which can be a regular file, a
65-
:class:`StringIO` object, or any other object which simulates a file. It
65+
:class:`io.BytesIO` object, or any other object which simulates a file. It
6666
defaults to ``None``, in which case *filename* is opened to provide a file
6767
object.
6868

Doc/library/mailbox.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
674674

675675
In Babyl mailboxes, the headers of a message are not stored contiguously
676676
with the body of the message. To generate a file-like representation, the
677-
headers and body are copied together into a :class:`StringIO` instance
678-
(from the :mod:`StringIO` module), which has an API identical to that of a
677+
headers and body are copied together into a :class:`io.BytesIO` instance,
678+
which has an API identical to that of a
679679
file. As a result, the file-like object is truly independent of the
680680
underlying mailbox but does not save memory compared to a string
681681
representation.

Doc/library/random.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ from sources provided by the operating system.
4545

4646
.. warning::
4747

48-
The generators of the :mod:`random` module should not be used for security
49-
purposes. Use :func:`ssl.RAND_bytes` if you require a cryptographically
50-
secure pseudorandom number generator.
48+
The pseudo-random generators of this module should not be used for
49+
security purposes. Use :func:`os.urandom` or :class:`SystemRandom` if
50+
you require a cryptographically secure pseudo-random number generator.
5151

5252

5353
Bookkeeping functions:

Doc/library/tempfile.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The module defines the following user-callable items:
8282
causes the file to roll over to an on-disk file regardless of its size.
8383

8484
The returned object is a file-like object whose :attr:`_file` attribute
85-
is either a :class:`BytesIO` or :class:`StringIO` object (depending on
85+
is either a :class:`io.BytesIO` or :class:`io.StringIO` object (depending on
8686
whether binary or text *mode* was specified) or a true file
8787
object, depending on whether :func:`rollover` has been called. This
8888
file-like object can be used in a :keyword:`with` statement, just like

Doc/library/unittest.mock.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,9 @@ you wanted a :class:`NonCallableMock` to be used:
10841084
...
10851085
TypeError: 'NonCallableMock' object is not callable
10861086

1087-
Another use case might be to replace an object with a `StringIO` instance:
1087+
Another use case might be to replace an object with a `io.StringIO` instance:
10881088

1089-
>>> from StringIO import StringIO
1089+
>>> from io import StringIO
10901090
>>> def foo():
10911091
... print 'Something'
10921092
...

Doc/library/xml.dom.minidom.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ instead:
5555
.. function:: parseString(string, parser=None)
5656

5757
Return a :class:`Document` that represents the *string*. This method creates a
58-
:class:`StringIO` object for the string and passes that on to :func:`parse`.
58+
:class:`io.StringIO` object for the string and passes that on to :func:`parse`.
5959

6060
Both functions return a :class:`Document` object representing the content of the
6161
document.

Lib/test/test_os.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
import threading
2929
except ImportError:
3030
threading = None
31+
try:
32+
import resource
33+
except ImportError:
34+
resource = None
35+
3136
from test.script_helper import assert_python_ok
3237

3338
with warnings.catch_warnings():
@@ -997,6 +1002,21 @@ def test_urandom_subprocess(self):
9971002
data2 = self.get_urandom_subprocess(16)
9981003
self.assertNotEqual(data1, data2)
9991004

1005+
@unittest.skipUnless(resource, "test requires the resource module")
1006+
def test_urandom_failure(self):
1007+
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
1008+
resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
1009+
try:
1010+
with self.assertRaises(OSError) as cm:
1011+
os.urandom(16)
1012+
self.assertEqual(cm.exception.errno, errno.EMFILE)
1013+
finally:
1014+
# We restore the old limit as soon as possible. If doing it
1015+
# using addCleanup(), code running in between would fail
1016+
# creating any file descriptor.
1017+
resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))
1018+
1019+
10001020
@contextlib.contextmanager
10011021
def _execvpe_mockup(defpath=None):
10021022
"""

Lib/test/test_shutil.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,32 @@ def _filter(src, names):
726726
shutil.rmtree(src_dir)
727727
shutil.rmtree(os.path.dirname(dst_dir))
728728

729+
def test_copytree_retains_permissions(self):
730+
tmp_dir = tempfile.mkdtemp()
731+
src_dir = os.path.join(tmp_dir, 'source')
732+
os.mkdir(src_dir)
733+
dst_dir = os.path.join(tmp_dir, 'destination')
734+
self.addCleanup(shutil.rmtree, tmp_dir)
735+
736+
os.chmod(src_dir, 0o777)
737+
write_file((src_dir, 'permissive.txt'), '123')
738+
os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
739+
write_file((src_dir, 'restrictive.txt'), '456')
740+
os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
741+
restrictive_subdir = tempfile.mkdtemp(dir=src_dir)
742+
os.chmod(restrictive_subdir, 0o600)
743+
744+
shutil.copytree(src_dir, dst_dir)
745+
self.assertEquals(os.stat(src_dir).st_mode, os.stat(dst_dir).st_mode)
746+
self.assertEquals(os.stat(os.path.join(src_dir, 'permissive.txt')).st_mode,
747+
os.stat(os.path.join(dst_dir, 'permissive.txt')).st_mode)
748+
self.assertEquals(os.stat(os.path.join(src_dir, 'restrictive.txt')).st_mode,
749+
os.stat(os.path.join(dst_dir, 'restrictive.txt')).st_mode)
750+
restrictive_subdir_dst = os.path.join(dst_dir,
751+
os.path.split(restrictive_subdir)[1])
752+
self.assertEquals(os.stat(restrictive_subdir).st_mode,
753+
os.stat(restrictive_subdir_dst).st_mode)
754+
729755
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
730756
def test_dont_copy_file_onto_link_to_itself(self):
731757
# Temporarily disable test on Windows.

Lib/test/test_timeout.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit tests for socket timeout feature."""
22

3+
import functools
34
import unittest
45
from test import support
56

@@ -11,6 +12,18 @@
1112
import socket
1213

1314

15+
@functools.lru_cache()
16+
def resolve_address(host, port):
17+
"""Resolve an (host, port) to an address.
18+
19+
We must perform name resolution before timeout tests, otherwise it will be
20+
performed by connect().
21+
"""
22+
with support.transient_internet(host):
23+
return socket.getaddrinfo(host, port, socket.AF_INET,
24+
socket.SOCK_STREAM)[0][4]
25+
26+
1427
class CreationTestCase(unittest.TestCase):
1528
"""Test case for socket.gettimeout() and socket.settimeout()"""
1629

@@ -132,7 +145,7 @@ class TCPTimeoutTestCase(TimeoutTestCase):
132145

133146
def setUp(self):
134147
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
135-
self.addr_remote = ('www.python.org.', 80)
148+
self.addr_remote = resolve_address('www.python.org.', 80)
136149

137150
def tearDown(self):
138151
self.sock.close()
@@ -142,7 +155,7 @@ def testConnectTimeout(self):
142155
# to a host that silently drops our packets. We can't simulate this
143156
# from Python because it's a function of the underlying TCP/IP stack.
144157
# So, the following Snakebite host has been defined:
145-
blackhole = ('blackhole.snakebite.net', 56666)
158+
blackhole = resolve_address('blackhole.snakebite.net', 56666)
146159

147160
# Blackhole has been configured to silently drop any incoming packets.
148161
# No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back
@@ -154,7 +167,7 @@ def testConnectTimeout(self):
154167
# to firewalling or general network configuration. In order to improve
155168
# our confidence in testing the blackhole, a corresponding 'whitehole'
156169
# has also been set up using one port higher:
157-
whitehole = ('whitehole.snakebite.net', 56667)
170+
whitehole = resolve_address('whitehole.snakebite.net', 56667)
158171

159172
# This address has been configured to immediately drop any incoming
160173
# packets as well, but it does it respectfully with regards to the

0 commit comments

Comments
 (0)