17153
17165
class ModifiedUndoDelegator(UndoDelegator):
17154
17166
"Extend base class: forbid insert/delete before the I/O mark"
17156
@@ -417,6 +428,9 @@
17168
@@ -417,7 +428,8 @@
17157
17169
except socket.timeout, err:
17158
17170
self.display_no_subprocess_error()
17160
+ # Can't regiter self.tkconsole.stdin, since run.py wants to
17161
+ # call non-TextIO methods on it (such as getvar)
17162
+ # XXX should be renamed to "console"
17163
self.rpcclt.register("stdin", self.tkconsole)
17172
- self.rpcclt.register("stdin", self.tkconsole)
17173
+ self.rpcclt.register("console", self.tkconsole)
17174
+ self.rpcclt.register("stdin", self.tkconsole.stdin)
17164
17175
self.rpcclt.register("stdout", self.tkconsole.stdout)
17165
17176
self.rpcclt.register("stderr", self.tkconsole.stderr)
17166
@@ -870,13 +884,14 @@
17177
self.rpcclt.register("flist", self.tkconsole.flist)
17178
@@ -870,13 +882,14 @@
17167
17179
self.save_stderr = sys.stderr
17168
17180
self.save_stdin = sys.stdin
17169
17181
from idlelib import IOBinding
17170
+ self.stdin = PseudoInputFile(self)
17171
self.stdout = PseudoFile(self, "stdout", IOBinding.encoding)
17172
self.stderr = PseudoFile(self, "stderr", IOBinding.encoding)
17173
self.console = PseudoFile(self, "console", IOBinding.encoding)
17182
- self.stdout = PseudoFile(self, "stdout", IOBinding.encoding)
17183
- self.stderr = PseudoFile(self, "stderr", IOBinding.encoding)
17184
- self.console = PseudoFile(self, "console", IOBinding.encoding)
17185
+ self.stdin = PseudoInputFile(self, "stdin", IOBinding.encoding)
17186
+ self.stdout = PseudoOutputFile(self, "stdout", IOBinding.encoding)
17187
+ self.stderr = PseudoOutputFile(self, "stderr", IOBinding.encoding)
17188
+ self.console = PseudoOutputFile(self, "console", IOBinding.encoding)
17174
17189
if not use_subprocess:
17175
17190
sys.stdout = self.stdout
17176
17191
sys.stderr = self.stderr
17196
17212
+ return 'disabled'
17197
17213
+ return super(PyShell, self).rmenu_check_paste()
17199
class PseudoFile(object):
17215
+class PseudoFile(io.TextIOBase):
17201
17217
def __init__(self, shell, tags, encoding=None):
17202
@@ -1260,6 +1288,8 @@
17203
self.encoding = encoding
17205
def write(self, s):
17221
- self.encoding = encoding
17222
+ self._encoding = encoding
17224
- def write(self, s):
17225
- self.shell.write(s, self.tags)
17227
+ def encoding(self):
17228
+ return self._encoding
17230
- def writelines(self, lines):
17231
- for line in lines:
17238
+ return '<%s>' % self.tags
17244
+class PseudoOutputFile(PseudoFile):
17246
+ def writable(self):
17249
+ def write(self, s):
17251
+ raise ValueError("write to closed file")
17206
17252
+ if not isinstance(s, (basestring, bytearray)):
17207
17253
+ raise TypeError('must be string, not ' + type(s).__name__)
17208
self.shell.write(s, self.tags)
17210
def writelines(self, lines):
17211
@@ -1272,6 +1302,15 @@
17215
+class PseudoInputFile(object):
17216
+ def __init__(self, shell):
17217
+ self.readline = shell.readline
17218
+ self.isatty = shell.isatty
17220
+ def write(self, s):
17221
+ raise io.UnsupportedOperation("not writable")
17222
+ writelines = write
17254
+ return self.shell.write(s, self.tags)
17257
+class PseudoInputFile(PseudoFile):
17259
+ def __init__(self, shell, tags, encoding=None):
17260
+ PseudoFile.__init__(self, shell, tags, encoding)
17261
+ self._line_buffer = ''
17263
+ def readable(self):
17266
+ def read(self, size=-1):
17268
+ raise ValueError("read from closed file")
17271
+ elif not isinstance(size, int):
17272
+ raise TypeError('must be int, not ' + type(size).__name__)
17273
+ result = self._line_buffer
17274
+ self._line_buffer = ''
17277
+ line = self.shell.readline()
17278
+ if not line: break
17281
+ while len(result) < size:
17282
+ line = self.shell.readline()
17283
+ if not line: break
17285
+ self._line_buffer = result[size:]
17286
+ result = result[:size]
17289
+ def readline(self, size=-1):
17291
+ raise ValueError("read from closed file")
17294
+ elif not isinstance(size, int):
17295
+ raise TypeError('must be int, not ' + type(size).__name__)
17296
+ line = self._line_buffer or self.shell.readline()
17299
+ self._line_buffer = line[size:]
17300
+ return line[:size]
17225
17303
usage_msg = """\
17227
@@ -1412,8 +1451,10 @@
17305
USAGE: idle [-deins] [-t title] [file]*
17306
@@ -1412,8 +1495,10 @@
17229
17308
if enable_edit:
17230
17309
if not (cmd or script):
17549
17628
import linecache
17551
17630
import socket
17552
@@ -248,6 +249,43 @@
17632
from idlelib import RemoteObjectBrowser
17633
from idlelib import StackViewer
17634
from idlelib import rpc
17635
+from idlelib import PyShell
17636
+from idlelib import IOBinding
17640
@@ -248,19 +251,19 @@
17553
17641
quitting = True
17554
17642
thread.interrupt_main()
17556
+class _RPCFile(io.TextIOBase):
17557
+ """Wrapper class for the RPC proxy to typecheck arguments
17558
+ that may not support pickling. The base class is there only
17559
+ to support type tests; all implementations come from the remote
17562
+ def __init__(self, rpc):
17563
+ super.__setattr__(self, 'rpc', rpc)
17565
+ def __getattribute__(self, name):
17566
+ # When accessing the 'rpc' attribute, or 'write', use ours
17567
+ if name in ('rpc', 'write', 'writelines'):
17568
+ return io.TextIOBase.__getattribute__(self, name)
17569
+ # Else only look into the remote object only
17570
+ return getattr(self.rpc, name)
17572
+ def __setattr__(self, name, value):
17573
+ return setattr(self.rpc, name, value)
17576
+ def _ensure_string(func):
17578
+ if not isinstance(s, basestring):
17579
+ raise TypeError('must be str, not ' + type(s).__name__)
17580
+ return func(self, s)
17583
+class _RPCOutputFile(_RPCFile):
17584
+ @_RPCFile._ensure_string
17585
+ def write(self, s):
17586
+ return self.rpc.write(s)
17588
+class _RPCInputFile(_RPCFile):
17589
+ @_RPCFile._ensure_string
17590
+ def write(self, s):
17591
+ raise io.UnsupportedOperation("not writable")
17592
+ writelines = write
17594
17645
class MyHandler(rpc.RPCHandler):
17596
@@ -255,9 +293,10 @@
17597
17648
"""Override base method"""
17598
17649
executive = Executive(self)
17599
17650
self.register("exec", executive)
17600
17651
- sys.stdin = self.console = self.get_remote_proxy("stdin")
17601
17652
- sys.stdout = self.get_remote_proxy("stdout")
17602
17653
- sys.stderr = self.get_remote_proxy("stderr")
17603
+ self.console = self.get_remote_proxy("stdin")
17604
+ sys.stdin = _RPCInputFile(self.console)
17605
+ sys.stdout = _RPCOutputFile(self.get_remote_proxy("stdout"))
17606
+ sys.stderr = _RPCOutputFile(self.get_remote_proxy("stderr"))
17607
from idlelib import IOBinding
17608
sys.stdin.encoding = sys.stdout.encoding = \
17609
sys.stderr.encoding = IOBinding.encoding
17654
- from idlelib import IOBinding
17655
- sys.stdin.encoding = sys.stdout.encoding = \
17656
- sys.stderr.encoding = IOBinding.encoding
17657
+ self.console = self.get_remote_proxy("console")
17658
+ sys.stdin = PyShell.PseudoInputFile(self.console, "stdin",
17659
+ IOBinding.encoding)
17660
+ sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout",
17661
+ IOBinding.encoding)
17662
+ sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr",
17663
+ IOBinding.encoding)
17664
self.interp = self.get_remote_proxy("interp")
17665
rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
17610
17667
diff -r 70274d53c1dd Lib/io.py
17611
17668
--- a/Lib/io.py
17612
17669
+++ b/Lib/io.py
21576
21633
def test_extended_set_del_slice(self):
21577
21634
indices = (0, None, 1, 3, 19, 300, 1<<333, -1, -2, -31, -300)
21578
21635
for start in indices:
21636
@@ -905,6 +925,7 @@
21637
self.assertEqual(bytes(b"abc") < b"ab", False)
21638
self.assertEqual(bytes(b"abc") <= b"ab", False)
21640
+ @test.test_support.requires_docstrings
21641
def test_doc(self):
21642
self.assertIsNotNone(bytearray.__doc__)
21643
self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
21579
21644
diff -r 70274d53c1dd Lib/test/test_bz2.py
21580
21645
--- a/Lib/test/test_bz2.py
21581
21646
+++ b/Lib/test/test_bz2.py
22121
@@ -1495,6 +1551,14 @@
22186
@@ -674,6 +730,50 @@
22187
def test_empty(self):
22188
self.assertEqual(codecs.escape_decode(""), ("", 0))
22190
+ def test_raw(self):
22191
+ for b in ''.join(map(chr, range(256))):
22193
+ self.assertEqual(codecs.escape_decode(b + '0'),
22196
+ def test_escape(self):
22197
+ self.assertEqual(codecs.escape_decode(b"[\\\n]"), (b"[]", 4))
22198
+ self.assertEqual(codecs.escape_decode(br'[\"]'), (b'["]', 4))
22199
+ self.assertEqual(codecs.escape_decode(br"[\']"), (b"[']", 4))
22200
+ self.assertEqual(codecs.escape_decode(br"[\\]"), (br"[\]", 4))
22201
+ self.assertEqual(codecs.escape_decode(br"[\a]"), (b"[\x07]", 4))
22202
+ self.assertEqual(codecs.escape_decode(br"[\b]"), (b"[\x08]", 4))
22203
+ self.assertEqual(codecs.escape_decode(br"[\t]"), (b"[\x09]", 4))
22204
+ self.assertEqual(codecs.escape_decode(br"[\n]"), (b"[\x0a]", 4))
22205
+ self.assertEqual(codecs.escape_decode(br"[\v]"), (b"[\x0b]", 4))
22206
+ self.assertEqual(codecs.escape_decode(br"[\f]"), (b"[\x0c]", 4))
22207
+ self.assertEqual(codecs.escape_decode(br"[\r]"), (b"[\x0d]", 4))
22208
+ self.assertEqual(codecs.escape_decode(br"[\7]"), (b"[\x07]", 4))
22209
+ self.assertEqual(codecs.escape_decode(br"[\8]"), (br"[\8]", 4))
22210
+ self.assertEqual(codecs.escape_decode(br"[\78]"), (b"[\x078]", 5))
22211
+ self.assertEqual(codecs.escape_decode(br"[\41]"), (b"[!]", 5))
22212
+ self.assertEqual(codecs.escape_decode(br"[\418]"), (b"[!8]", 6))
22213
+ self.assertEqual(codecs.escape_decode(br"[\101]"), (b"[A]", 6))
22214
+ self.assertEqual(codecs.escape_decode(br"[\1010]"), (b"[A0]", 7))
22215
+ self.assertEqual(codecs.escape_decode(br"[\501]"), (b"[A]", 6))
22216
+ self.assertEqual(codecs.escape_decode(br"[\x41]"), (b"[A]", 6))
22217
+ self.assertEqual(codecs.escape_decode(br"[\X41]"), (br"[\X41]", 6))
22218
+ self.assertEqual(codecs.escape_decode(br"[\x410]"), (b"[A0]", 7))
22219
+ for b in ''.join(map(chr, range(256))):
22220
+ if b not in '\n"\'\\abtnvfr01234567x':
22221
+ self.assertEqual(codecs.escape_decode('\\' + b),
22224
+ def test_errors(self):
22225
+ self.assertRaises(ValueError, codecs.escape_decode, br"\x")
22226
+ self.assertRaises(ValueError, codecs.escape_decode, br"[\x]")
22227
+ self.assertEqual(codecs.escape_decode(br"[\x]\x", "ignore"), (b"[]", 6))
22228
+ self.assertEqual(codecs.escape_decode(br"[\x]\x", "replace"), (b"[?]?", 6))
22229
+ self.assertRaises(ValueError, codecs.escape_decode, br"\x0")
22230
+ self.assertRaises(ValueError, codecs.escape_decode, br"[\x0]")
22231
+ self.assertEqual(codecs.escape_decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
22232
+ self.assertEqual(codecs.escape_decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
22234
class RecodingTest(unittest.TestCase):
22235
def test_recoding(self):
22236
f = StringIO.StringIO()
22237
@@ -1495,6 +1595,14 @@
24685
24801
def test_main():
24686
24802
run_unittest(TestCase)
24803
diff -r 70274d53c1dd Lib/test/test_itertools.py
24804
--- a/Lib/test/test_itertools.py
24805
+++ b/Lib/test/test_itertools.py
24806
@@ -906,6 +906,12 @@
24808
self.assertRaises(ReferenceError, getattr, p, '__class__')
24810
+ # Issue 13454: Crash when deleting backward iterator from tee()
24811
+ def test_tee_del_backward(self):
24812
+ forward, backward = tee(repeat(None, 20000000))
24813
+ any(forward) # exhaust the iterator
24816
def test_StopIteration(self):
24817
self.assertRaises(StopIteration, izip().next)
24687
24819
diff -r 70274d53c1dd Lib/test/test_logging.py
24688
24820
--- a/Lib/test/test_logging.py
24689
24821
+++ b/Lib/test/test_logging.py
28641
28785
+ @unittest.skipUnless(_testcapi.UINT_MAX < sys.maxint,
28642
28786
+ "needs UINT_MAX < sys.maxint")
28643
28787
+ @test_support.bigmemtest(minsize=_testcapi.UINT_MAX + 1,
28644
+ memuse=1 + 4 // len(u'\U00010000'))
28788
+ memuse=2 + 4 // len(u'\U00010000'))
28645
28789
+ def test_issue16335(self, size):
28790
+ func = self.test_issue16335
28791
+ if size < func.minsize:
28792
+ raise unittest.SkipTest("not enough memory: %.1fG minimum needed" %
28793
+ (func.minsize * func.memuse / float(1024**3),))
28646
28794
+ # very very long bogus character name
28647
28795
+ x = b'\\N{SPACE' + b'x' * int(_testcapi.UINT_MAX + 1) + b'}'
28648
28796
+ self.assertEqual(len(x), len(b'\\N{SPACE}') +
36193
36377
diff -r 70274d53c1dd Modules/itertoolsmodule.c
36194
36378
--- a/Modules/itertoolsmodule.c
36195
36379
+++ b/Modules/itertoolsmodule.c
36196
@@ -903,11 +903,13 @@
36380
@@ -401,14 +401,31 @@
36385
+teedataobject_safe_decref(PyObject *obj)
36387
+ while (obj && Py_TYPE(obj) == &teedataobject_type &&
36388
+ Py_REFCNT(obj) == 1) {
36389
+ PyObject *nextlink = ((teedataobject *)obj)->nextlink;
36390
+ ((teedataobject *)obj)->nextlink = NULL;
36398
teedataobject_clear(teedataobject *tdo)
36404
for (i=0 ; i<tdo->numread ; i++)
36405
Py_CLEAR(tdo->values[i]);
36406
- Py_CLEAR(tdo->nextlink);
36407
+ tmp = tdo->nextlink;
36408
+ tdo->nextlink = NULL;
36409
+ teedataobject_safe_decref(tmp);
36413
@@ -475,6 +492,8 @@
36415
if (to->index >= LINKCELLS) {
36416
link = teedataobject_jumplink(to->dataobj);
36417
+ if (link == NULL)
36419
Py_DECREF(to->dataobj);
36420
to->dataobj = (teedataobject *)link;
36422
@@ -903,11 +922,13 @@
36198
36424
ok = PyObject_IsTrue(good);
36199
36425
Py_DECREF(good);
36528
36754
* Normally, an invalid fd is likely to be a C program error and therefore
36529
36755
* an assertion can be useful, but it does contradict the POSIX standard
36530
36756
* which for write(2) states:
36531
@@ -1956,7 +1956,9 @@
36757
@@ -441,9 +441,10 @@
36760
/* Return a dictionary corresponding to the POSIX environment table */
36761
-#ifdef WITH_NEXT_FRAMEWORK
36762
+#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
36763
/* On Darwin/MacOSX a shared library or framework has no access to
36764
-** environ directly, we must obtain it with _NSGetEnviron().
36765
+** environ directly, we must obtain it with _NSGetEnviron(). See also
36766
+** man environ(7).
36768
#include <crt_externs.h>
36769
static char **environ;
36770
@@ -463,7 +464,7 @@
36774
-#ifdef WITH_NEXT_FRAMEWORK
36775
+#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
36776
if (environ == NULL)
36777
environ = *_NSGetEnviron();
36779
@@ -1956,7 +1957,9 @@
36532
36780
"getcwd() -> path\n\n\
36533
36781
Return a string representing the current working directory.");
38662
38921
diff -r 70274d53c1dd Objects/unicodeobject.c
38663
38922
--- a/Objects/unicodeobject.c
38664
38923
+++ b/Objects/unicodeobject.c
38665
@@ -1861,7 +1861,7 @@
38926
/* --- Globals ------------------------------------------------------------
38928
- The globals are initialized by the _PyUnicode_Init() API and should
38929
- not be used before calling that API.
38930
+NOTE: In the interpreter's initialization phase, some globals are currently
38931
+ initialized dynamically as needed. In the process Unicode objects may
38932
+ be created before the Unicode type is ready.
38936
@@ -93,15 +94,27 @@
38939
/* Free list for Unicode objects */
38940
-static PyUnicodeObject *free_list;
38941
-static int numfree;
38942
+static PyUnicodeObject *free_list = NULL;
38943
+static int numfree = 0;
38945
/* The empty Unicode object is shared to improve performance. */
38946
-static PyUnicodeObject *unicode_empty;
38947
+static PyUnicodeObject *unicode_empty = NULL;
38949
+#define _Py_RETURN_UNICODE_EMPTY() \
38951
+ if (unicode_empty != NULL) \
38952
+ Py_INCREF(unicode_empty); \
38954
+ unicode_empty = _PyUnicode_New(0); \
38955
+ if (unicode_empty != NULL) \
38956
+ Py_INCREF(unicode_empty); \
38958
+ return (PyObject *)unicode_empty; \
38961
/* Single character Unicode strings in the Latin-1 range are being
38963
-static PyUnicodeObject *unicode_latin1[256];
38964
+static PyUnicodeObject *unicode_latin1[256] = {NULL};
38966
/* Default encoding to use and assume when NULL is passed as encoding
38967
parameter; it is initialized by _PyUnicode_Init().
38968
@@ -110,7 +123,7 @@
38969
PyUnicode_GetDefaultEncoding() APIs to access this global.
38972
-static char unicode_default_encoding[100];
38973
+static char unicode_default_encoding[100 + 1] = "ascii";
38975
/* Fast detection of the most frequent whitespace characters */
38976
const unsigned char _Py_ascii_whitespace[] = {
38977
@@ -204,7 +217,7 @@
38979
#define BLOOM_MASK unsigned long
38981
-static BLOOM_MASK bloom_linebreak;
38982
+static BLOOM_MASK bloom_linebreak = ~(BLOOM_MASK)0;
38984
#define BLOOM_ADD(mask, ch) ((mask |= (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
38985
#define BLOOM(mask, ch) ((mask & (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
38986
@@ -448,10 +461,8 @@
38989
/* Optimization for empty strings */
38990
- if (size == 0 && unicode_empty != NULL) {
38991
- Py_INCREF(unicode_empty);
38992
- return (PyObject *)unicode_empty;
38995
+ _Py_RETURN_UNICODE_EMPTY();
38997
/* Single character Unicode objects in the Latin-1 range are
38998
shared when using this constructor */
38999
@@ -497,10 +508,8 @@
39002
/* Optimization for empty strings */
39003
- if (size == 0 && unicode_empty != NULL) {
39004
- Py_INCREF(unicode_empty);
39005
- return (PyObject *)unicode_empty;
39008
+ _Py_RETURN_UNICODE_EMPTY();
39010
/* Single characters are shared when using this constructor.
39011
Restrict to ASCII, since the input must be UTF-8. */
39012
@@ -1162,13 +1171,10 @@
39015
/* Convert to Unicode */
39017
- Py_INCREF(unicode_empty);
39018
- v = (PyObject *)unicode_empty;
39021
- v = PyUnicode_Decode(s, len, encoding, errors);
39024
+ _Py_RETURN_UNICODE_EMPTY();
39026
+ v = PyUnicode_Decode(s, len, encoding, errors);
39030
@@ -1381,7 +1387,7 @@
39032
strncpy(unicode_default_encoding,
39034
- sizeof(unicode_default_encoding));
39035
+ sizeof(unicode_default_encoding) - 1);
39039
@@ -1861,7 +1867,7 @@
38666
39040
illegal prefix. See RFC 3629 for details */
38667
39041
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00-0F */
38668
39042
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38671
39045
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38672
39046
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38673
39047
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38674
@@ -2217,7 +2217,7 @@
39048
@@ -2217,7 +2223,7 @@
38676
39050
PyObject *errorHandler = NULL;
38677
39051
PyObject *exc = NULL;
38899
39273
Create a new Unicode object from the given encoded string.\n\
38900
39274
encoding defaults to the current default string encoding.\n\
38901
@@ -8850,6 +8883,12 @@
39275
@@ -8817,8 +8856,6 @@
39277
void _PyUnicode_Init(void)
39281
/* XXX - move this array to unicodectype.c ? */
39282
Py_UNICODE linebreak[] = {
39283
0x000A, /* LINE FEED */
39284
@@ -8832,15 +8869,12 @@
39287
/* Init the implementation */
39288
- free_list = NULL;
39290
- unicode_empty = _PyUnicode_New(0);
39291
- if (!unicode_empty)
39294
- strcpy(unicode_default_encoding, "ascii");
39295
- for (i = 0; i < 256; i++)
39296
- unicode_latin1[i] = NULL;
39297
+ if (!unicode_empty) {
39298
+ unicode_empty = _PyUnicode_New(0);
39299
+ if (!unicode_empty)
39303
if (PyType_Ready(&PyUnicode_Type) < 0)
39304
Py_FatalError("Can't initialize 'unicode'");
39306
@@ -8850,6 +8884,12 @@
38904
39309
PyType_Ready(&EncodingMapType);