Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Reimplement tempfile._RandomNameSequence using a generator function. (#1075) | f50354adaaafebe95ad09d09b825804a686ea843 | Serhiy Storchaka | 2017-04-11 19:45:59 |
bpo-29692: Add missing ACKS entry (#1079) | e8a6bb4f3936123f3eca0b6cea05e2875a2722bc | Nick Coghlan | 2017-04-11 09:47:39 |
bpo-29692: contextlib.contextmanager may incorrectly unchain RuntimeError (GH-949) | 00c75e9a45ff0366c185e9e8a2e23af5a35481b0 | svelankar | 2017-04-11 09:11:13 |
Remove superfluous comment in urllib.error. (#1076) | 6fab78e9027f9ebd6414995580781b480433e595 | Senthil Kumaran | 2017-04-11 04:08:35 |
Remove OSError related comment in urllib.request. (#1070) | 6dfcc81f6b1c82a71a1c876e14424fb8b3573447 | Senthil Kumaran | 2017-04-10 02:49:34 |
bpo-29506: Clarify deep copy note in copy module | 19e04942562a980ad2519f6ff79c455a7472783b | Sanyam Khurana | 2017-04-09 10:22:30 |
bpo-26187: Test that set_trace_callback() is not called multiple times (GH-461) | 0e6cb2ea624570ed08c354f1ed1f595dab4192d6 | Aviv Palivoda | 2017-04-09 09:11:59 |
Issue #29798: Handle git worktree in patchcheck (#1058) | 2abfdf5a81383d3b1ed6b7321903a9a168c373c5 | Nick Coghlan | 2017-04-09 08:33:03 |
bpo-29951: Include function name for some error messages in `PyArg_ParseTuple*` (#916) | 64c8f705c0121a4b45ca2c3bc7b47b282e9efcd8 | Michael Seifert | 2017-04-09 07:47:12 |
Remove invalid comment in urllib.request. (#1054) | a2a9ddd923a849124bdd1c484f70f02df6fde0e9 | Senthil Kumaran | 2017-04-09 06:27:25 |
Improvements to typing documentation (#967) | 45d22c256bce3afcf57f49032a6b20fdec4f26ad | Jelle Zijlstra | 2017-04-08 16:09:14 |
bpo-29998: Pickling and copying ImportError now preserves name and path (#1010) | b785396ab451b0c9d6ae9ee5a9e56c810209a6cb | Serhiy Storchaka | 2017-04-08 06:55:07 |
Expand the PySlice_GetIndicesEx macro. (#1023) | b879fe82e7e5c3f7673c9a7fa4aad42bd05445d8 | Serhiy Storchaka | 2017-04-08 06:53:51 |
bpo-29914: Fix default implementations of __reduce__ and __reduce_ex__(). (#843) | 205e00c5cfd495a4dc6dae8e8fa0fb828fb3dca9 | Serhiy Storchaka | 2017-04-08 06:52:59 |
Fix a minor typo. (#1032) | dd9a0a14c89d57e43898d4b866b8c161e4ff8506 | Barry Warsaw | 2017-04-07 18:18:14 |
bpo-29958: Minor improvements to zipfile and tarfile CLI. (#944) | 150cd1916a59e750ce88c65325de9ef0c42c6cb5 | Serhiy Storchaka | 2017-04-07 15:56:12 |
Remove Invalid comment in test_urllib2.py (#1020) | fd0cd07a5a3c964c084f4efc5bbcb89dd2193ee6 | Senthil Kumaran | 2017-04-07 07:19:08 |
bpo-28837: Fix lib2to3 handling of map/zip/filter calls when followed with a 'trailer', e.g. zip()[x] (#24) | 93b4b47e3a720171d67f3b608de406aef462835c | Stuart Berg | 2017-04-06 05:19:40 |
Correct typo in configparser.rst (#1012) | 01fa9ae5460b00bf1ced500c797176ebd3fb060d | Alex Jordan | 2017-04-06 02:21:30 |
bpo-29962: add math.remainder (#950) | a0ce375e10b50f7606cb86b072fed7d8cd574fe7 | Mark Dickinson | 2017-04-05 17:34:27 |
File | Lines added | Lines deleted |
---|---|---|
Lib/tempfile.py | 12 | 23 |
Lib/test/test_tempfile.py | 3 | 2 |
File Lib/tempfile.py changed (mode: 100644) (index 61462357c7..6112208382) | |||
... | ... | def _sanitize_params(prefix, suffix, dir): | |
133 | 133 | return prefix, suffix, dir, output_type | return prefix, suffix, dir, output_type |
134 | 134 | ||
135 | 135 | ||
136 | class _RandomNameSequence: | ||
137 | """An instance of _RandomNameSequence generates an endless | ||
138 | sequence of unpredictable strings which can safely be incorporated | ||
139 | into file names. Each string is six characters long. Multiple | ||
140 | threads can safely use the same instance at the same time. | ||
141 | |||
142 | _RandomNameSequence is an iterator.""" | ||
136 | def _RandomNameSequence(): | ||
137 | """Generate an endless sequence of unpredictable strings which | ||
138 | can safely be incorporated into file names. Each string is 8 | ||
139 | characters long. Multiple threads and forked processes can | ||
140 | safely use the same instance at the same time.""" | ||
143 | 141 | ||
144 | 142 | characters = "abcdefghijklmnopqrstuvwxyz0123456789_" | characters = "abcdefghijklmnopqrstuvwxyz0123456789_" |
145 | |||
146 | @property | ||
147 | def rng(self): | ||
143 | rng_pid = None | ||
144 | while True: | ||
148 | 145 | cur_pid = _os.getpid() | cur_pid = _os.getpid() |
149 | if cur_pid != getattr(self, '_rng_pid', None): | ||
150 | self._rng = _Random() | ||
151 | self._rng_pid = cur_pid | ||
152 | return self._rng | ||
153 | |||
154 | def __iter__(self): | ||
155 | return self | ||
156 | |||
157 | def __next__(self): | ||
158 | c = self.characters | ||
159 | choose = self.rng.choice | ||
160 | letters = [choose(c) for dummy in range(8)] | ||
161 | return ''.join(letters) | ||
146 | if cur_pid != rng_pid: | ||
147 | choose = _Random().choice | ||
148 | rng_pid = cur_pid | ||
149 | letters = [choose(characters) for dummy in range(8)] | ||
150 | yield ''.join(letters) | ||
162 | 151 | ||
163 | 152 | def _candidate_tempdir_list(): | def _candidate_tempdir_list(): |
164 | 153 | """Generate a list of candidate temporary directories which | """Generate a list of candidate temporary directories which |
File Lib/test/test_tempfile.py changed (mode: 100644) (index 51df1ecd7d..367e48dbe9) | |||
1 | 1 | # tempfile.py unit tests. | # tempfile.py unit tests. |
2 | import collections.abc | ||
2 | 3 | import tempfile | import tempfile |
3 | 4 | import errno | import errno |
4 | 5 | import io | import io |
... | ... | class TestGetCandidateNames(BaseTestCase): | |
290 | 291 | """Test the internal function _get_candidate_names.""" | """Test the internal function _get_candidate_names.""" |
291 | 292 | ||
292 | 293 | def test_retval(self): | def test_retval(self): |
293 | # _get_candidate_names returns a _RandomNameSequence object | ||
294 | # _get_candidate_names returns an iterator | ||
294 | 295 | obj = tempfile._get_candidate_names() | obj = tempfile._get_candidate_names() |
295 | self.assertIsInstance(obj, tempfile._RandomNameSequence) | ||
296 | self.assertIsInstance(obj, collections.abc.Iterator) | ||
296 | 297 | ||
297 | 298 | def test_same_thing(self): | def test_same_thing(self): |
298 | 299 | # _get_candidate_names always returns the same object | # _get_candidate_names always returns the same object |