From python-3000-checkins at python.org Fri Apr 14 13:33:28 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 14 Apr 2006 13:33:28 +0200 (CEST) Subject: [Python-3000-checkins] r45381 - python/branches/p3yk/Parser/parsetok.c python/branches/p3yk/Parser/tokenizer.c Message-ID: <20060414113328.E2C981E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 14 13:33:28 2006 New Revision: 45381 Modified: python/branches/p3yk/Parser/parsetok.c python/branches/p3yk/Parser/tokenizer.c Log: Make 'python -tt' the default, meaning Python won't allow mixing tabs and spaces for indentation. Adds a '-ttt' option to turn the errors back into warnings; I'm not yet sure whether that's desireable for Py3K. Also remove the magic for setting the size of tabs based on emacs/vim-style comments. Python now always considers tabstops to be every-8-spaces. Modified: python/branches/p3yk/Parser/parsetok.c ============================================================================== --- python/branches/p3yk/Parser/parsetok.c (original) +++ python/branches/p3yk/Parser/parsetok.c Fri Apr 14 13:33:28 2006 @@ -47,11 +47,8 @@ } tok->filename = filename ? filename : ""; - if (Py_TabcheckFlag || Py_VerboseFlag) { - tok->altwarning = (tok->filename != NULL); - if (Py_TabcheckFlag >= 2) - tok->alterror++; - } + if (Py_TabcheckFlag >= 3) + tok->alterror = 0; return parsetok(tok, g, start, err_ret, flags); } @@ -79,12 +76,8 @@ return NULL; } tok->filename = filename; - if (Py_TabcheckFlag || Py_VerboseFlag) { - tok->altwarning = (filename != NULL); - if (Py_TabcheckFlag >= 2) - tok->alterror++; - } - + if (Py_TabcheckFlag >= 3) + tok->alterror = 0; return parsetok(tok, g, start, err_ret, flags); } Modified: python/branches/p3yk/Parser/tokenizer.c ============================================================================== --- python/branches/p3yk/Parser/tokenizer.c (original) +++ python/branches/p3yk/Parser/tokenizer.c Fri Apr 14 13:33:28 2006 @@ -120,8 +120,8 @@ tok->lineno = 0; tok->level = 0; tok->filename = NULL; - tok->altwarning = 0; - tok->alterror = 0; + tok->altwarning = 1; + tok->alterror = 1; tok->alttabsize = 1; tok->altindstack[0] = 0; tok->decoding_state = 0; @@ -1207,41 +1207,10 @@ /* Set start of current token */ tok->start = tok->cur - 1; - /* Skip comment, while looking for tab-setting magic */ - if (c == '#') { - static char *tabforms[] = { - "tab-width:", /* Emacs */ - ":tabstop=", /* vim, full form */ - ":ts=", /* vim, abbreviated form */ - "set tabsize=", /* will vi never die? */ - /* more templates can be added here to support other editors */ - }; - char cbuf[80]; - char *tp, **cp; - tp = cbuf; - do { - *tp++ = c = tok_nextc(tok); - } while (c != EOF && c != '\n' && - tp - cbuf + 1 < sizeof(cbuf)); - *tp = '\0'; - for (cp = tabforms; - cp < tabforms + sizeof(tabforms)/sizeof(tabforms[0]); - cp++) { - if ((tp = strstr(cbuf, *cp))) { - int newsize = atoi(tp + strlen(*cp)); - - if (newsize >= 1 && newsize <= 40) { - tok->tabsize = newsize; - if (Py_VerboseFlag) - PySys_WriteStderr( - "Tab size set to %d\n", - newsize); - } - } - } + /* Skip comment */ + if (c == '#') while (c != EOF && c != '\n') c = tok_nextc(tok); - } /* Check for EOF and errors now */ if (c == EOF) { From python-3000-checkins at python.org Sat Apr 15 11:03:17 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:03:17 +0200 (CEST) Subject: [Python-3000-checkins] r45422 - python/branches/p3yk/Lib/test/test_descrtut.py Message-ID: <20060415090317.4CDBD1E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:03:16 2006 New Revision: 45422 Modified: python/branches/p3yk/Lib/test/test_descrtut.py Log: - Fix doctest results to account for classes being new-style, and thus printing differently. - Fix doctest for classic-class behaviour, make it test new-style behaviour on an implicitly-new-style class instead. Modified: python/branches/p3yk/Lib/test/test_descrtut.py ============================================================================== --- python/branches/p3yk/Lib/test/test_descrtut.py (original) +++ python/branches/p3yk/Lib/test/test_descrtut.py Sat Apr 15 11:03:16 2006 @@ -265,19 +265,19 @@ ... print "classmethod", cls, y >>> C.foo(1) - classmethod test.test_descrtut.C 1 + classmethod 1 >>> c = C() >>> c.foo(1) - classmethod test.test_descrtut.C 1 + classmethod 1 >>> class D(C): ... pass >>> D.foo(1) - classmethod test.test_descrtut.D 1 + classmethod 1 >>> d = D() >>> d.foo(1) - classmethod test.test_descrtut.D 1 + classmethod 1 This prints "classmethod __main__.D 1" both times; in other words, the class passed as the first argument of foo() is the class involved in the @@ -293,11 +293,11 @@ >>> E.foo(1) E.foo() called - classmethod test.test_descrtut.C 1 + classmethod 1 >>> e = E() >>> e.foo(1) E.foo() called - classmethod test.test_descrtut.C 1 + classmethod 1 In this example, the call to C.foo() from E.foo() will see class C as its first argument, not class E. This is to be expected, since the call @@ -386,7 +386,7 @@ This example is implicit in the writeup. ->>> class A: # classic class +>>> class A: # implicit new-style class ... def save(self): ... print "called A.save()" >>> class B(A): @@ -398,9 +398,9 @@ ... pass >>> D().save() -called A.save() +called C.save() ->>> class A(object): # new class +>>> class A(object): # explicit new-style class ... def save(self): ... print "called A.save()" >>> class B(A): From python-3000-checkins at python.org Sat Apr 15 11:04:58 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:04:58 +0200 (CEST) Subject: [Python-3000-checkins] r45423 - python/branches/p3yk/Lib/test/test_descr.py Message-ID: <20060415090458.A298A1E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:04:57 2006 New Revision: 45423 Modified: python/branches/p3yk/Lib/test/test_descr.py Log: Remove tests for classic-class and mixed-classic-class/new-style behaviour. (New-style class behaviour was already thoroughly tested) Modified: python/branches/p3yk/Lib/test/test_descr.py ============================================================================== --- python/branches/p3yk/Lib/test/test_descr.py (original) +++ python/branches/p3yk/Lib/test/test_descr.py Sat Apr 15 11:04:57 2006 @@ -267,39 +267,8 @@ for arg in 2, 2L, 2j, 2e0, [2], "2", u"2", (2,), {2:2}, type, test_dir: dir(arg) - # Try classic classes. - class C: - Cdata = 1 - def Cmethod(self): pass - - cstuff = ['Cdata', 'Cmethod', '__doc__', '__module__'] - vereq(dir(C), cstuff) - verify('im_self' in dir(C.Cmethod)) - - c = C() # c.__doc__ is an odd thing to see here; ditto c.__module__. - vereq(dir(c), cstuff) - - c.cdata = 2 - c.cmethod = lambda self: 0 - vereq(dir(c), cstuff + ['cdata', 'cmethod']) - verify('im_self' in dir(c.Cmethod)) - - class A(C): - Adata = 1 - def Amethod(self): pass - - astuff = ['Adata', 'Amethod'] + cstuff - vereq(dir(A), astuff) - verify('im_self' in dir(A.Amethod)) - a = A() - vereq(dir(a), astuff) - verify('im_self' in dir(a.Amethod)) - a.adata = 42 - a.amethod = lambda self: 3 - vereq(dir(a), astuff + ['adata', 'amethod']) - - # The same, but with new-style classes. Since these have object as a - # base class, a lot more gets sucked in. + # Test dir on custom classes. Since these have object as a + # base class, a lot of stuff gets sucked in. def interesting(strings): return [s for s in strings if not s.startswith('_')] @@ -882,96 +851,6 @@ vereq(Frag().__int__(), 42) vereq(int(Frag()), 42) - # MI mixing classic and new-style classes. - - class A: - x = 1 - - class B(A): - pass - - class C(A): - x = 2 - - class D(B, C): - pass - vereq(D.x, 1) - - # Classic MRO is preserved for a classic base class. - class E(D, object): - pass - vereq(E.__mro__, (E, D, B, A, C, object)) - vereq(E.x, 1) - - # But with a mix of classic bases, their MROs are combined using - # new-style MRO. - class F(B, C, object): - pass - vereq(F.__mro__, (F, B, C, A, object)) - vereq(F.x, 2) - - # Try something else. - class C: - def cmethod(self): - return "C a" - def all_method(self): - return "C b" - - class M1(C, object): - def m1method(self): - return "M1 a" - def all_method(self): - return "M1 b" - - vereq(M1.__mro__, (M1, C, object)) - m = M1() - vereq(m.cmethod(), "C a") - vereq(m.m1method(), "M1 a") - vereq(m.all_method(), "M1 b") - - class D(C): - def dmethod(self): - return "D a" - def all_method(self): - return "D b" - - class M2(D, object): - def m2method(self): - return "M2 a" - def all_method(self): - return "M2 b" - - vereq(M2.__mro__, (M2, D, C, object)) - m = M2() - vereq(m.cmethod(), "C a") - vereq(m.dmethod(), "D a") - vereq(m.m2method(), "M2 a") - vereq(m.all_method(), "M2 b") - - class M3(M1, M2, object): - def m3method(self): - return "M3 a" - def all_method(self): - return "M3 b" - vereq(M3.__mro__, (M3, M1, M2, D, C, object)) - m = M3() - vereq(m.cmethod(), "C a") - vereq(m.dmethod(), "D a") - vereq(m.m1method(), "M1 a") - vereq(m.m2method(), "M2 a") - vereq(m.m3method(), "M3 a") - vereq(m.all_method(), "M3 b") - - class Classic: - pass - try: - class New(Classic): - __metaclass__ = type - except TypeError: - pass - else: - raise TestFailed, "new class with only classic bases - shouldn't be" - def diamond(): if verbose: print "Testing multiple inheritance special cases..." class A(object): @@ -3619,29 +3498,6 @@ else: raise TestFailed, "shouldn't be able to create inheritance cycles" - # let's throw a classic class into the mix: - class Classic: - def meth2(self): - return 3 - - D.__bases__ = (C, Classic) - - vereq(d.meth2(), 3) - vereq(e.meth2(), 3) - try: - d.a - except AttributeError: - pass - else: - raise TestFailed, "attribute should have vanished" - - try: - D.__bases__ = (Classic,) - except TypeError: - pass - else: - raise TestFailed, "new-style class must have a new-style base" - def test_mutable_bases_with_failing_mro(): if verbose: print "Testing mutable bases with failing mro..." From python-3000-checkins at python.org Sat Apr 15 11:07:21 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:07:21 +0200 (CEST) Subject: [Python-3000-checkins] r45424 - python/branches/p3yk/Lib/test/test_itertools.py Message-ID: <20060415090721.0C7A51E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:07:20 2006 New Revision: 45424 Modified: python/branches/p3yk/Lib/test/test_itertools.py Log: Fix tests that were trying to make iteration blow up, on broken iterators. Since the broken iterators are now new-style classes, iter() was able to do the valid-iterator check sooner (on instantiation instead of on first call), making the tests blow up sooner than expected. Modified: python/branches/p3yk/Lib/test/test_itertools.py ============================================================================== --- python/branches/p3yk/Lib/test/test_itertools.py (original) +++ python/branches/p3yk/Lib/test/test_itertools.py Sat Apr 15 11:07:20 2006 @@ -560,7 +560,7 @@ self.assertEqual(list(chain(g(s))), list(g(s))) self.assertEqual(list(chain(g(s), g(s))), list(g(s))+list(g(s))) self.assertRaises(TypeError, chain, X(s)) - self.assertRaises(TypeError, list, chain(N(s))) + self.assertRaises(TypeError, chain, N(s)) self.assertRaises(ZeroDivisionError, list, chain(E(s))) def test_cycle(self): @@ -571,7 +571,7 @@ actual = list(islice(cycle(g(s)), tgtlen)) self.assertEqual(actual, expected) self.assertRaises(TypeError, cycle, X(s)) - self.assertRaises(TypeError, list, cycle(N(s))) + self.assertRaises(TypeError, cycle, N(s)) self.assertRaises(ZeroDivisionError, list, cycle(E(s))) def test_groupby(self): @@ -579,7 +579,7 @@ for g in (G, I, Ig, S, L, R): self.assertEqual([k for k, sb in groupby(g(s))], list(g(s))) self.assertRaises(TypeError, groupby, X(s)) - self.assertRaises(TypeError, list, groupby(N(s))) + self.assertRaises(TypeError, groupby, N(s)) self.assertRaises(ZeroDivisionError, list, groupby(E(s))) def test_ifilter(self): @@ -587,7 +587,7 @@ for g in (G, I, Ig, S, L, R): self.assertEqual(list(ifilter(isEven, g(s))), filter(isEven, g(s))) self.assertRaises(TypeError, ifilter, isEven, X(s)) - self.assertRaises(TypeError, list, ifilter(isEven, N(s))) + self.assertRaises(TypeError, ifilter, isEven, N(s)) self.assertRaises(ZeroDivisionError, list, ifilter(isEven, E(s))) def test_ifilterfalse(self): @@ -595,7 +595,7 @@ for g in (G, I, Ig, S, L, R): self.assertEqual(list(ifilterfalse(isEven, g(s))), filter(isOdd, g(s))) self.assertRaises(TypeError, ifilterfalse, isEven, X(s)) - self.assertRaises(TypeError, list, ifilterfalse(isEven, N(s))) + self.assertRaises(TypeError, ifilterfalse, isEven, N(s)) self.assertRaises(ZeroDivisionError, list, ifilterfalse(isEven, E(s))) def test_izip(self): @@ -604,7 +604,7 @@ self.assertEqual(list(izip(g(s))), zip(g(s))) self.assertEqual(list(izip(g(s), g(s))), zip(g(s), g(s))) self.assertRaises(TypeError, izip, X(s)) - self.assertRaises(TypeError, list, izip(N(s))) + self.assertRaises(TypeError, izip, N(s)) self.assertRaises(ZeroDivisionError, list, izip(E(s))) def test_imap(self): @@ -613,7 +613,7 @@ self.assertEqual(list(imap(onearg, g(s))), map(onearg, g(s))) self.assertEqual(list(imap(operator.pow, g(s), g(s))), map(operator.pow, g(s), g(s))) self.assertRaises(TypeError, imap, onearg, X(s)) - self.assertRaises(TypeError, list, imap(onearg, N(s))) + self.assertRaises(TypeError, imap, onearg, N(s)) self.assertRaises(ZeroDivisionError, list, imap(onearg, E(s))) def test_islice(self): @@ -621,7 +621,7 @@ for g in (G, I, Ig, S, L, R): self.assertEqual(list(islice(g(s),1,None,2)), list(g(s))[1::2]) self.assertRaises(TypeError, islice, X(s), 10) - self.assertRaises(TypeError, list, islice(N(s), 10)) + self.assertRaises(TypeError, islice, N(s), 10) self.assertRaises(ZeroDivisionError, list, islice(E(s), 10)) def test_starmap(self): @@ -630,7 +630,7 @@ ss = zip(s, s) self.assertEqual(list(starmap(operator.pow, g(ss))), map(operator.pow, g(s), g(s))) self.assertRaises(TypeError, starmap, operator.pow, X(ss)) - self.assertRaises(TypeError, list, starmap(operator.pow, N(ss))) + self.assertRaises(TypeError, starmap, operator.pow, N(ss)) self.assertRaises(ZeroDivisionError, list, starmap(operator.pow, E(ss))) def test_takewhile(self): @@ -642,7 +642,7 @@ tgt.append(elem) self.assertEqual(list(takewhile(isEven, g(s))), tgt) self.assertRaises(TypeError, takewhile, isEven, X(s)) - self.assertRaises(TypeError, list, takewhile(isEven, N(s))) + self.assertRaises(TypeError, takewhile, isEven, N(s)) self.assertRaises(ZeroDivisionError, list, takewhile(isEven, E(s))) def test_dropwhile(self): @@ -654,7 +654,7 @@ tgt.append(elem) self.assertEqual(list(dropwhile(isOdd, g(s))), tgt) self.assertRaises(TypeError, dropwhile, isOdd, X(s)) - self.assertRaises(TypeError, list, dropwhile(isOdd, N(s))) + self.assertRaises(TypeError, dropwhile, isOdd, N(s)) self.assertRaises(ZeroDivisionError, list, dropwhile(isOdd, E(s))) def test_tee(self): @@ -664,7 +664,7 @@ self.assertEqual(list(it1), list(g(s))) self.assertEqual(list(it2), list(g(s))) self.assertRaises(TypeError, tee, X(s)) - self.assertRaises(TypeError, list, tee(N(s))[0]) + self.assertRaises(TypeError, tee, N(s)) self.assertRaises(ZeroDivisionError, list, tee(E(s))[0]) class LengthTransparency(unittest.TestCase): From python-3000-checkins at python.org Sat Apr 15 11:10:44 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:10:44 +0200 (CEST) Subject: [Python-3000-checkins] r45425 - in python/branches/p3yk/Lib/test: output/test_augassign test_augassign.py Message-ID: <20060415091044.266111E4020@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:10:43 2006 New Revision: 45425 Modified: python/branches/p3yk/Lib/test/output/test_augassign python/branches/p3yk/Lib/test/test_augassign.py Log: Fix the superficial augmented-assignment tests to deal with true division. Add (equally superficial) >>=/<<= test in the process. Relies on floats that should be extremely close to the int '6' printing as '6.0', but I believe that's a valid assumption ;P Modified: python/branches/p3yk/Lib/test/output/test_augassign ============================================================================== --- python/branches/p3yk/Lib/test/output/test_augassign (original) +++ python/branches/p3yk/Lib/test/output/test_augassign Sat Apr 15 11:10:43 2006 @@ -1,6 +1,9 @@ test_augassign +6.0 6 -[6] +[6.0] +6 +6.0 6 [1, 2, 3, 4, 1, 2, 3, 4] [1, 2, 1, 2, 3] @@ -22,9 +25,9 @@ __mul__ called __rmul__ called __imul__ called -__div__ called -__rdiv__ called -__idiv__ called +__truediv__ called +__rtruediv__ called +__itruediv__ called __floordiv__ called __rfloordiv__ called __ifloordiv__ called Modified: python/branches/p3yk/Lib/test/test_augassign.py ============================================================================== --- python/branches/p3yk/Lib/test/test_augassign.py (original) +++ python/branches/p3yk/Lib/test/test_augassign.py Sat Apr 15 11:10:43 2006 @@ -5,42 +5,51 @@ x *= 2 x **= 2 x -= 8 -x /= 2 -x //= 1 x %= 12 +x >>= 1 x &= 2 x |= 5 x ^= 1 +x <<= 2 +x /= 2 +x //= 2 print x +print int(x) x = [2] x[0] += 1 x[0] *= 2 x[0] **= 2 x[0] -= 8 -x[0] /= 2 -x[0] //= 2 x[0] %= 12 +x[0] >>= 1 x[0] &= 2 x[0] |= 5 x[0] ^= 1 +x[0] <<= 2 +x[0] /= 2 +x[0] //= 2 print x +print int(x[0]) x = {0: 2} x[0] += 1 x[0] *= 2 x[0] **= 2 x[0] -= 8 -x[0] /= 2 -x[0] //= 1 x[0] %= 12 +x[0] >>= 1 x[0] &= 2 x[0] |= 5 x[0] ^= 1 +x[0] <<= 2 +x[0] /= 2 +x[0] //= 2 print x[0] +print int(x[0]) x = [1,2] x += [3,4] From python-3000-checkins at python.org Sat Apr 15 11:12:14 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:12:14 +0200 (CEST) Subject: [Python-3000-checkins] r45426 - python/branches/p3yk/Lib/test/test_bisect.py Message-ID: <20060415091214.CD9271E4020@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:12:14 2006 New Revision: 45426 Modified: python/branches/p3yk/Lib/test/test_bisect.py Log: Fix test_bisect in the same way as test_itertools: iter() blows up a lot sooner for new-style broken-iterators, expect it to. Modified: python/branches/p3yk/Lib/test/test_bisect.py ============================================================================== --- python/branches/p3yk/Lib/test/test_bisect.py (original) +++ python/branches/p3yk/Lib/test/test_bisect.py Sat Apr 15 11:12:14 2006 @@ -185,11 +185,11 @@ def test_len_only(self): for f in (bisect_left, bisect_right, insort_left, insort_right): - self.assertRaises(AttributeError, f, LenOnly(), 10) + self.assertRaises(TypeError, f, LenOnly(), 10) def test_get_only(self): for f in (bisect_left, bisect_right, insort_left, insort_right): - self.assertRaises(AttributeError, f, GetOnly(), 10) + self.assertRaises(TypeError, f, GetOnly(), 10) def test_cmp_err(self): seq = [CmpErr(), CmpErr(), CmpErr()] From python-3000-checkins at python.org Sat Apr 15 11:13:20 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:13:20 +0200 (CEST) Subject: [Python-3000-checkins] r45427 - python/branches/p3yk/Lib/test/test_inspect.py Message-ID: <20060415091320.288581E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:13:19 2006 New Revision: 45427 Modified: python/branches/p3yk/Lib/test/test_inspect.py Log: - Remove tests for classic class behaviour - Expect a new-style class tree in the getclasstree test. Modified: python/branches/p3yk/Lib/test/test_inspect.py ============================================================================== --- python/branches/p3yk/Lib/test/test_inspect.py (original) +++ python/branches/p3yk/Lib/test/test_inspect.py Sat Apr 15 11:13:19 2006 @@ -139,11 +139,13 @@ ('StupidGit', mod.StupidGit)]) tree = inspect.getclasstree([cls[1] for cls in classes], 1) self.assertEqual(tree, - [(mod.ParrotDroppings, ()), - (mod.StupidGit, ()), - [(mod.MalodorousPervert, (mod.StupidGit,)), - [(mod.FesteringGob, (mod.MalodorousPervert, - mod.ParrotDroppings)) + [(object, ()), + [(mod.ParrotDroppings, (object,)), + (mod.StupidGit, (object,)), + [(mod.MalodorousPervert, (mod.StupidGit,)), + [(mod.FesteringGob, (mod.MalodorousPervert, + mod.ParrotDroppings)) + ] ] ] ]) @@ -255,17 +257,6 @@ return [t[:3] for t in inspect.classify_class_attrs(cls)] class TestClassesAndFunctions(unittest.TestCase): - def test_classic_mro(self): - # Test classic-class method resolution order. - class A: pass - class B(A): pass - class C(A): pass - class D(B, C): pass - - expected = (D, B, A, C) - got = inspect.getmro(D) - self.assertEqual(expected, got) - def test_newstyle_mro(self): # The same w/ new-class MRO. class A(object): pass @@ -308,67 +299,6 @@ self.assertArgSpecEquals(sublistOfOne, [['foo']]) - def test_classify_oldstyle(self): - class A: - def s(): pass - s = staticmethod(s) - - def c(cls): pass - c = classmethod(c) - - def getp(self): pass - p = property(getp) - - def m(self): pass - - def m1(self): pass - - datablob = '1' - - attrs = attrs_wo_objs(A) - self.assert_(('s', 'static method', A) in attrs, 'missing static method') - self.assert_(('c', 'class method', A) in attrs, 'missing class method') - self.assert_(('p', 'property', A) in attrs, 'missing property') - self.assert_(('m', 'method', A) in attrs, 'missing plain method') - self.assert_(('m1', 'method', A) in attrs, 'missing plain method') - self.assert_(('datablob', 'data', A) in attrs, 'missing data') - - class B(A): - def m(self): pass - - attrs = attrs_wo_objs(B) - self.assert_(('s', 'static method', A) in attrs, 'missing static method') - self.assert_(('c', 'class method', A) in attrs, 'missing class method') - self.assert_(('p', 'property', A) in attrs, 'missing property') - self.assert_(('m', 'method', B) in attrs, 'missing plain method') - self.assert_(('m1', 'method', A) in attrs, 'missing plain method') - self.assert_(('datablob', 'data', A) in attrs, 'missing data') - - - class C(A): - def m(self): pass - def c(self): pass - - attrs = attrs_wo_objs(C) - self.assert_(('s', 'static method', A) in attrs, 'missing static method') - self.assert_(('c', 'method', C) in attrs, 'missing plain method') - self.assert_(('p', 'property', A) in attrs, 'missing property') - self.assert_(('m', 'method', C) in attrs, 'missing plain method') - self.assert_(('m1', 'method', A) in attrs, 'missing plain method') - self.assert_(('datablob', 'data', A) in attrs, 'missing data') - - class D(B, C): - def m1(self): pass - - attrs = attrs_wo_objs(D) - self.assert_(('s', 'static method', A) in attrs, 'missing static method') - self.assert_(('c', 'class method', A) in attrs, 'missing class method') - self.assert_(('p', 'property', A) in attrs, 'missing property') - self.assert_(('m', 'method', B) in attrs, 'missing plain method') - self.assert_(('m1', 'method', D) in attrs, 'missing plain method') - self.assert_(('datablob', 'data', A) in attrs, 'missing data') - - # Repeat all that, but w/ new-style classes. def test_classify_newstyle(self): class A(object): From python-3000-checkins at python.org Sat Apr 15 11:15:11 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:15:11 +0200 (CEST) Subject: [Python-3000-checkins] r45428 - python/branches/p3yk/Lib/test/test_getargs2.py Message-ID: <20060415091511.DE6081E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:15:11 2006 New Revision: 45428 Modified: python/branches/p3yk/Lib/test/test_getargs2.py Log: Fix tests for PyArg_Parse*; The PyArg_Parse functions no longer (noisily) convert float arguments to integer-taking format characters, so fix the test to expect the failure. Modified: python/branches/p3yk/Lib/test/test_getargs2.py ============================================================================== --- python/branches/p3yk/Lib/test/test_getargs2.py (original) +++ python/branches/p3yk/Lib/test/test_getargs2.py Sat Apr 15 11:15:11 2006 @@ -67,7 +67,7 @@ def test_b(self): from _testcapi import getargs_b # b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX) - self.failUnlessEqual(3, getargs_b(3.14)) + self.assertRaises(TypeError, getargs_b, 3.14) self.failUnlessEqual(99, getargs_b(Long())) self.failUnlessEqual(99, getargs_b(Int())) @@ -83,7 +83,7 @@ def test_B(self): from _testcapi import getargs_B # B returns 'unsigned char', no range checking - self.failUnlessEqual(3, getargs_B(3.14)) + self.assertRaises(TypeError, getargs_B, 3.14) self.failUnlessEqual(99, getargs_B(Long())) self.failUnlessEqual(99, getargs_B(Int())) @@ -100,7 +100,7 @@ def test_H(self): from _testcapi import getargs_H # H returns 'unsigned short', no range checking - self.failUnlessEqual(3, getargs_H(3.14)) + self.assertRaises(TypeError, getargs_H, 3.14) self.failUnlessEqual(99, getargs_H(Long())) self.failUnlessEqual(99, getargs_H(Int())) @@ -117,7 +117,7 @@ def test_I(self): from _testcapi import getargs_I # I returns 'unsigned int', no range checking - self.failUnlessEqual(3, getargs_I(3.14)) + self.assertRaises(TypeError, getargs_I, 3.14) self.failUnlessEqual(99, getargs_I(Long())) self.failUnlessEqual(99, getargs_I(Int())) @@ -153,7 +153,7 @@ def test_i(self): from _testcapi import getargs_i # i returns 'int', and does range checking (INT_MIN ... INT_MAX) - self.failUnlessEqual(3, getargs_i(3.14)) + self.assertRaises(TypeError, getargs_i, 3.14) self.failUnlessEqual(99, getargs_i(Long())) self.failUnlessEqual(99, getargs_i(Int())) @@ -169,7 +169,7 @@ def test_l(self): from _testcapi import getargs_l # l returns 'long', and does range checking (LONG_MIN ... LONG_MAX) - self.failUnlessEqual(3, getargs_l(3.14)) + self.assertRaises(TypeError, getargs_l, 3.14) self.failUnlessEqual(99, getargs_l(Long())) self.failUnlessEqual(99, getargs_l(Int())) From python-3000-checkins at python.org Sat Apr 15 11:16:17 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:16:17 +0200 (CEST) Subject: [Python-3000-checkins] r45429 - python/branches/p3yk/Lib/test/test_enumerate.py Message-ID: <20060415091617.67F3B1E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:16:16 2006 New Revision: 45429 Modified: python/branches/p3yk/Lib/test/test_enumerate.py Log: Adjust test_enumerate to accomodate for iter() blowing up sooner than expected, when dealing with new-style broken-iterators. Modified: python/branches/p3yk/Lib/test/test_enumerate.py ============================================================================== --- python/branches/p3yk/Lib/test/test_enumerate.py (original) +++ python/branches/p3yk/Lib/test/test_enumerate.py Sat Apr 15 11:16:16 2006 @@ -92,7 +92,7 @@ self.assertRaises(TypeError, self.enum, X(self.seq)) def test_illformediterable(self): - self.assertRaises(TypeError, list, self.enum(N(self.seq))) + self.assertRaises(TypeError, self.enum, N(self.seq)) def test_exception_propagation(self): self.assertRaises(ZeroDivisionError, list, self.enum(E(self.seq))) From python-3000-checkins at python.org Sat Apr 15 11:19:16 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sat, 15 Apr 2006 11:19:16 +0200 (CEST) Subject: [Python-3000-checkins] r45430 - python/branches/p3yk/Lib/test/test_class.py Message-ID: <20060415091916.9C10A1E4005@bag.python.org> Author: thomas.wouters Date: Sat Apr 15 11:19:16 2006 New Revision: 45430 Modified: python/branches/p3yk/Lib/test/test_class.py Log: Make test_class work (but still fail) even though class.__dict__ is now a 'dictproxy' (which is a read-only non-dict mapping type that can't be passed to exec.) The failures the test finds are behavioural differences between old- and new-style classes that may or may not be intended. Modified: python/branches/p3yk/Lib/test/test_class.py ============================================================================== --- python/branches/p3yk/Lib/test/test_class.py (original) +++ python/branches/p3yk/Lib/test/test_class.py Sat Apr 15 11:19:16 2006 @@ -115,9 +115,12 @@ print "__%(method)s__:", args """ +d = {} for method in testmeths: - exec method_template % locals() in AllTests.__dict__ - + exec method_template % locals() in d +for k in d: + setattr(AllTests, k, d[k]) +del d, k del method, method_template # this also tests __init__ of course. From python-3000-checkins at python.org Sat Apr 15 11:35:39 2006 From: python-3000-checkins at python.org (brett.cannon) Date: Sat, 15 Apr 2006 11:35:39 +0200 (CEST) Subject: [Python-3000-checkins] r45431 - python/branches/p3yk/Misc/NEWS Message-ID: <20060415093539.6F76F1E4078@bag.python.org> Author: brett.cannon Date: Sat Apr 15 11:35:38 2006 New Revision: 45431 Modified: python/branches/p3yk/Misc/NEWS Log: Mention how __coerce__ has been removed. Modified: python/branches/p3yk/Misc/NEWS ============================================================================== --- python/branches/p3yk/Misc/NEWS (original) +++ python/branches/p3yk/Misc/NEWS Sat Apr 15 11:35:38 2006 @@ -35,6 +35,8 @@ Core and Builtins ----------------- +- __coerce__ has been removed. + - Classic classes are a thing of the past. All classes are new style. - Exceptions *must* derive from BaseException. From python-3000-checkins at python.org Mon Apr 17 15:16:51 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Mon, 17 Apr 2006 15:16:51 +0200 (CEST) Subject: [Python-3000-checkins] r45485 - python/branches/p3yk/Lib/test/test_xrange.py Message-ID: <20060417131651.6E3DB1E4007@bag.python.org> Author: thomas.wouters Date: Mon Apr 17 15:16:50 2006 New Revision: 45485 Modified: python/branches/p3yk/Lib/test/test_xrange.py Log: Fix xrange tests now that xrange() (like many other places) no longer silently converts floats to integers when expecting integer values. Modified: python/branches/p3yk/Lib/test/test_xrange.py ============================================================================== --- python/branches/p3yk/Lib/test/test_xrange.py (original) +++ python/branches/p3yk/Lib/test/test_xrange.py Mon Apr 17 15:16:50 2006 @@ -43,7 +43,10 @@ self.assertRaises(TypeError, xrange, 1, 2, 3, 4) self.assertRaises(ValueError, xrange, 1, 2, 0) - self.assertRaises(OverflowError, xrange, 1e100, 1e101, 1e101) + self.assertRaises(TypeError, xrange, 0.0, 2, 1) + self.assertRaises(TypeError, xrange, 1, 2.0, 1) + self.assertRaises(TypeError, xrange, 1, 2, 1.0) + self.assertRaises(TypeError, xrange, 1e100, 1e101, 1e101) self.assertRaises(TypeError, xrange, 0, "spam") self.assertRaises(TypeError, xrange, 0, 42, "spam") From python-3000-checkins at python.org Tue Apr 18 01:13:01 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Tue, 18 Apr 2006 01:13:01 +0200 (CEST) Subject: [Python-3000-checkins] r45500 - in python/branches/p3yk/Lib: idlelib/WindowList.py plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py Message-ID: <20060417231301.1063F1E4007@bag.python.org> Author: guido.van.rossum Date: Tue Apr 18 01:13:00 2006 New Revision: 45500 Modified: python/branches/p3yk/Lib/idlelib/WindowList.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py Log: Fix two errors that prevented "make libinstall" from working: - a line indented with tabs; - a function named 'as'. Modified: python/branches/p3yk/Lib/idlelib/WindowList.py ============================================================================== --- python/branches/p3yk/Lib/idlelib/WindowList.py (original) +++ python/branches/p3yk/Lib/idlelib/WindowList.py Tue Apr 18 01:13:00 2006 @@ -45,7 +45,7 @@ try: callback() except: - t, v, tb = sys.exc_info() + t, v, tb = sys.exc_info() print "warning: callback failed in WindowList", t, ":", v registry = WindowList() Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py Tue Apr 18 01:13:00 2006 @@ -300,8 +300,8 @@ if _arguments.has_key('----'): return _arguments['----'] - def as(self, _object, _attributes={}, **_arguments): - """as: Coercion + def as_(self, _object, _attributes={}, **_arguments): + """as_: Coercion Required argument: an AE object reference Keyword argument _attributes: AppleEvent attribute dictionary Returns: anything From python-3000-checkins at python.org Tue Apr 18 01:38:14 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Tue, 18 Apr 2006 01:38:14 +0200 (CEST) Subject: [Python-3000-checkins] r45501 - python/branches/p3yk/Lib/test/output/test_class Message-ID: <20060417233814.765171E4007@bag.python.org> Author: guido.van.rossum Date: Tue Apr 18 01:38:13 2006 New Revision: 45501 Modified: python/branches/p3yk/Lib/test/output/test_class Log: Fix the expected output file; new classes just behave differently... (There are some other problems with test_class.py that aren't as easily fixed. :-( ) Modified: python/branches/p3yk/Lib/test/output/test_class ============================================================================== --- python/branches/p3yk/Lib/test/output/test_class (original) +++ python/branches/p3yk/Lib/test/output/test_class Tue Apr 18 01:38:13 2006 @@ -1,52 +1,28 @@ test_class __init__: () -__coerce__: (1,) __add__: (1,) -__coerce__: (1,) __radd__: (1,) -__coerce__: (1,) __sub__: (1,) -__coerce__: (1,) __rsub__: (1,) -__coerce__: (1,) __mul__: (1,) -__coerce__: (1,) __rmul__: (1,) -__coerce__: (1,) -__div__: (1,) -__coerce__: (1,) -__rdiv__: (1,) -__coerce__: (1,) +__truediv__: (1,) +__rtruediv__: (1,) __mod__: (1,) -__coerce__: (1,) __rmod__: (1,) -__coerce__: (1,) __divmod__: (1,) -__coerce__: (1,) __rdivmod__: (1,) -__coerce__: (1,) __pow__: (1,) -__coerce__: (1,) __rpow__: (1,) -__coerce__: (1,) __rshift__: (1,) -__coerce__: (1,) __rrshift__: (1,) -__coerce__: (1,) __lshift__: (1,) -__coerce__: (1,) __rlshift__: (1,) -__coerce__: (1,) __and__: (1,) -__coerce__: (1,) __rand__: (1,) -__coerce__: (1,) __or__: (1,) -__coerce__: (1,) __ror__: (1,) -__coerce__: (1,) __xor__: (1,) -__coerce__: (1,) __rxor__: (1,) __contains__: (1,) __getitem__: (1,) @@ -61,9 +37,9 @@ __getitem__: ((slice(None, 42, None), Ellipsis, slice(None, 24, None), 24, 100),) __setitem__: ((slice(None, 42, None), Ellipsis, slice(None, 24, None), 24, 100), 'Strange') __delitem__: ((slice(None, 42, None), Ellipsis, slice(None, 24, None), 24, 100),) -__getitem__: (slice(0, 42, None),) -__setitem__: (slice(0, 42, None), 'The Answer') -__delitem__: (slice(0, 42, None),) +__getitem__: (slice(None, 42, None),) +__setitem__: (slice(None, 42, None), 'The Answer') +__delitem__: (slice(None, 42, None),) __neg__: () __pos__: () __abs__: () @@ -75,25 +51,15 @@ __hash__: () __repr__: () __str__: () -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) -__coerce__: (1,) __cmp__: (1,) __del__: () __getattr__: ('spam',) From python-3000-checkins at python.org Tue Apr 18 23:41:36 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Tue, 18 Apr 2006 23:41:36 +0200 (CEST) Subject: [Python-3000-checkins] r45550 - python/branches/p3yk/Lib/test/test_pkg.py Message-ID: <20060418214136.D491D1E4002@bag.python.org> Author: thomas.wouters Date: Tue Apr 18 23:41:36 2006 New Revision: 45550 Modified: python/branches/p3yk/Lib/test/test_pkg.py Log: Use explicit relative import for an, ehm, relative import. Modified: python/branches/p3yk/Lib/test/test_pkg.py ============================================================================== --- python/branches/p3yk/Lib/test/test_pkg.py (original) +++ python/branches/p3yk/Lib/test/test_pkg.py Tue Apr 18 23:41:36 2006 @@ -146,7 +146,7 @@ ("t5 __init__"+os.extsep+"py", "import t5.foo"), ("t5 string"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), ("t5 foo"+os.extsep+"py", - "print __name__, 'loading'; import string; print string.spam"), + "print __name__, 'loading'; from . import string; print string.spam"), ], """ import t5 From python-3000-checkins at python.org Thu Apr 20 18:07:40 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Thu, 20 Apr 2006 18:07:40 +0200 (CEST) Subject: [Python-3000-checkins] r45583 - in python/branches/p3yk/Lib: repr.py test/test_repr.py Message-ID: <20060420160740.1B5BE1E400B@bag.python.org> Author: guido.van.rossum Date: Thu Apr 20 18:07:39 2006 New Revision: 45583 Modified: python/branches/p3yk/Lib/repr.py python/branches/p3yk/Lib/test/test_repr.py Log: Fix test failures for repr.py. But shouldn't we kill this module? How many pprint clones do we need? Modified: python/branches/p3yk/Lib/repr.py ============================================================================== --- python/branches/p3yk/Lib/repr.py (original) +++ python/branches/p3yk/Lib/repr.py Thu Apr 20 18:07:39 2006 @@ -18,7 +18,7 @@ self.maxdeque = 6 self.maxstring = 30 self.maxlong = 40 - self.maxother = 20 + self.maxother = 30 def repr(self, x): return self.repr1(x, self.maxlevel) @@ -31,12 +31,7 @@ if hasattr(self, 'repr_' + typename): return getattr(self, 'repr_' + typename)(x, level) else: - s = __builtin__.repr(x) - if len(s) > self.maxother: - i = max(0, (self.maxother-3)//2) - j = max(0, self.maxother-3-i) - s = s[:i] + '...' + s[len(s)-j:] - return s + return self.repr_instance(x, level) def _repr_iterable(self, x, level, left, right, maxiter, trail=''): n = len(x) @@ -112,9 +107,9 @@ # exceptions -- then make up something except: return '<%s instance at %x>' % (x.__class__.__name__, id(x)) - if len(s) > self.maxstring: - i = max(0, (self.maxstring-3)//2) - j = max(0, self.maxstring-3-i) + if len(s) > self.maxother: + i = max(0, (self.maxother-3)//2) + j = max(0, self.maxother-3-i) s = s[:i] + '...' + s[len(s)-j:] return s Modified: python/branches/p3yk/Lib/test/test_repr.py ============================================================================== --- python/branches/p3yk/Lib/test/test_repr.py (original) +++ python/branches/p3yk/Lib/test/test_repr.py Thu Apr 20 18:07:39 2006 @@ -111,7 +111,7 @@ s = r(ClassWithFailingRepr) self.failUnless(s.startswith("")) - self.failUnless(s.find("...") == 8) + self.failUnless(s.find("...") in [12, 13]) def test_file(self): fp = open(unittest.__file__) @@ -249,8 +249,7 @@ ''') from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar # Module name may be prefixed with "test.", depending on how run. - self.failUnless(repr(bar.bar).startswith( - "" % bar.__name__) def test_instance(self): touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\ @@ -260,7 +259,7 @@ from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz ibaz = baz.baz() self.failUnless(repr(ibaz).startswith( - "<%s.baz instance at 0x" % baz.__name__)) + "<%s.baz object at 0x" % baz.__name__)) def test_method(self): eq = self.assertEquals @@ -275,7 +274,7 @@ # Bound method next iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() self.failUnless(repr(iqux.amethod).startswith( - ' Author: thomas.wouters Date: Fri Apr 21 00:36:57 2006 New Revision: 45588 Modified: python/branches/p3yk/Lib/xdrlib.py Log: Fix typical truedivision problem (using the result of division as an index.) Modified: python/branches/p3yk/Lib/xdrlib.py ============================================================================== --- python/branches/p3yk/Lib/xdrlib.py (original) +++ python/branches/p3yk/Lib/xdrlib.py Fri Apr 21 00:36:57 2006 @@ -80,7 +80,7 @@ if n < 0: raise ValueError, 'fstring size must be nonnegative' data = s[:n] - n = ((n+3)/4)*4 + n = ((n+3)//4)*4 data = data + (n - len(data)) * '\0' self.__buf.write(data) @@ -192,7 +192,7 @@ if n < 0: raise ValueError, 'fstring size must be nonnegative' i = self.__pos - j = i + (n+3)/4*4 + j = i + (n+3)//4*4 if j > len(self.__buf): raise EOFError self.__pos = j From python-3000-checkins at python.org Fri Apr 21 00:42:38 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 00:42:38 +0200 (CEST) Subject: [Python-3000-checkins] r45589 - in python/branches/p3yk: Lib/test/test_exceptions.py Python/errors.c Message-ID: <20060420224238.4C7B51E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 00:42:37 2006 New Revision: 45589 Modified: python/branches/p3yk/Lib/test/test_exceptions.py python/branches/p3yk/Python/errors.c Log: Fix (and add test for) missing check for BaseException subclasses in the C API. Modified: python/branches/p3yk/Lib/test/test_exceptions.py ============================================================================== --- python/branches/p3yk/Lib/test/test_exceptions.py (original) +++ python/branches/p3yk/Lib/test/test_exceptions.py Fri Apr 21 00:42:37 2006 @@ -171,10 +171,15 @@ # test that setting an exception at the C level works even if the # exception object can't be constructed. -class BadException: +class BadException(Exception): def __init__(self): raise RuntimeError, "can't instantiate BadException" +# Exceptions must inherit from BaseException, raising invalid exception +# should instead raise SystemError +class InvalidException: + pass + def test_capi1(): import _testcapi try: @@ -201,8 +206,21 @@ else: print "Expected exception" +def test_capi3(): + import _testcapi + try: + _testcapi.raise_exception(InvalidException, 1) + except SystemError: + pass + except InvalidException: + raise AssertionError("Managed to raise InvalidException"); + else: + print "Expected SystemError exception" + + if not sys.platform.startswith('java'): test_capi1() test_capi2() + test_capi3() unlink(TESTFN) Modified: python/branches/p3yk/Python/errors.c ============================================================================== --- python/branches/p3yk/Python/errors.c (original) +++ python/branches/p3yk/Python/errors.c Fri Apr 21 00:42:37 2006 @@ -47,6 +47,15 @@ void PyErr_SetObject(PyObject *exception, PyObject *value) { + if (exception != NULL && + !PyExceptionClass_Check(exception)) { + PyObject *excstr = PyObject_Repr(exception); + PyErr_Format(PyExc_SystemError, + "exception %s not a BaseException subclass", + PyString_AS_STRING(excstr)); + Py_DECREF(excstr); + return; + } Py_XINCREF(exception); Py_XINCREF(value); PyErr_Restore(exception, value, (PyObject *)NULL); From python-3000-checkins at python.org Fri Apr 21 11:17:16 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 21 Apr 2006 11:17:16 +0200 (CEST) Subject: [Python-3000-checkins] r45592 - python/branches/p3yk/Lib/test/test_pyclbr.py Message-ID: <20060421091716.1F78E1E400F@bag.python.org> Author: guido.van.rossum Date: Fri Apr 21 11:17:15 2006 New Revision: 45592 Modified: python/branches/p3yk/Lib/test/test_pyclbr.py Log: Fix the problems in this test. Boy this is a painful thing to debug -- it's fundamentally unmaintainable. Should we throw away pyclbr, or rewrite it using the AST? Modified: python/branches/p3yk/Lib/test/test_pyclbr.py ============================================================================== --- python/branches/p3yk/Lib/test/test_pyclbr.py (original) +++ python/branches/p3yk/Lib/test/test_pyclbr.py Fri Apr 21 11:17:15 2006 @@ -57,6 +57,8 @@ ignore are ignored. If no module is provided, the appropriate module is loaded with __import__.''' + ignore = set(ignore) | set(['object']) + if module == None: # Import it. # ('' is to work around an API silliness in __import__) @@ -164,7 +166,7 @@ 'getproxies_internetconfig',)) # not on all platforms cm('pickle') cm('aifc', ignore=('openfp',)) # set with = in module - cm('Cookie') + cm('Cookie', ignore=('Cookie',)) # Cookie is an alias for SmartCookie cm('sre_parse', ignore=('dump',)) # from sre_constants import * cm('pdb') cm('pydoc') From python-3000-checkins at python.org Fri Apr 21 11:46:13 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 11:46:13 +0200 (CEST) Subject: [Python-3000-checkins] r45594 - in python/branches/p3yk: Lib/re.py Message-ID: <20060421094613.500B61E400C@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 11:46:12 2006 New Revision: 45594 Removed: python/branches/p3yk/Lib/re.py Modified: python/branches/p3yk/ (props changed) Log: Merge trunk's 43068, deleting re.py. This leaves the branch in a broken state (unless you happen to have a re.pyc lying around), but it'll be fixed in the next merge. Deleted: /python/branches/p3yk/Lib/re.py ============================================================================== --- /python/branches/p3yk/Lib/re.py Fri Apr 21 11:46:12 2006 +++ (empty file) @@ -1,6 +0,0 @@ -"""Minimal "re" compatibility wrapper. See "sre" for documentation.""" - -engine = "sre" # Some apps might use this undocumented variable - -from sre import * -from sre import __all__ From python-3000-checkins at python.org Fri Apr 21 11:47:10 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 11:47:10 +0200 (CEST) Subject: [Python-3000-checkins] r45595 - in python/branches/p3yk: Lib/re.py Lib/sre.py Lib/test/regrtest.py Lib/test/test___all__.py Lib/test/test_re.py Modules/_sre.c Message-ID: <20060421094710.4F32D1E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 11:47:09 2006 New Revision: 45595 Added: python/branches/p3yk/Lib/re.py - copied unchanged from r43069, python/trunk/Lib/re.py Removed: python/branches/p3yk/Lib/sre.py Modified: python/branches/p3yk/ (props changed) python/branches/p3yk/Lib/test/regrtest.py python/branches/p3yk/Lib/test/test___all__.py python/branches/p3yk/Lib/test/test_re.py python/branches/p3yk/Modules/_sre.c Log: Merge trunk up to 43069, putting re.py back and hopefully making the branch usable again. Deleted: /python/branches/p3yk/Lib/sre.py ============================================================================== --- /python/branches/p3yk/Lib/sre.py Fri Apr 21 11:47:09 2006 +++ (empty file) @@ -1,315 +0,0 @@ -# -# Secret Labs' Regular Expression Engine -# -# re-compatible interface for the sre matching engine -# -# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. -# -# This version of the SRE library can be redistributed under CNRI's -# Python 1.6 license. For any other use, please contact Secret Labs -# AB (info at pythonware.com). -# -# Portions of this engine have been developed in cooperation with -# CNRI. Hewlett-Packard provided funding for 1.6 integration and -# other compatibility work. -# - -r"""Support for regular expressions (RE). - -This module provides regular expression matching operations similar to -those found in Perl. It supports both 8-bit and Unicode strings; both -the pattern and the strings being processed can contain null bytes and -characters outside the US ASCII range. - -Regular expressions can contain both special and ordinary characters. -Most ordinary characters, like "A", "a", or "0", are the simplest -regular expressions; they simply match themselves. You can -concatenate ordinary characters, so last matches the string 'last'. - -The special characters are: - "." Matches any character except a newline. - "^" Matches the start of the string. - "$" Matches the end of the string. - "*" Matches 0 or more (greedy) repetitions of the preceding RE. - Greedy means that it will match as many repetitions as possible. - "+" Matches 1 or more (greedy) repetitions of the preceding RE. - "?" Matches 0 or 1 (greedy) of the preceding RE. - *?,+?,?? Non-greedy versions of the previous three special characters. - {m,n} Matches from m to n repetitions of the preceding RE. - {m,n}? Non-greedy version of the above. - "\\" Either escapes special characters or signals a special sequence. - [] Indicates a set of characters. - A "^" as the first character indicates a complementing set. - "|" A|B, creates an RE that will match either A or B. - (...) Matches the RE inside the parentheses. - The contents can be retrieved or matched later in the string. - (?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below). - (?:...) Non-grouping version of regular parentheses. - (?P...) The substring matched by the group is accessible by name. - (?P=name) Matches the text matched earlier by the group named name. - (?#...) A comment; ignored. - (?=...) Matches if ... matches next, but doesn't consume the string. - (?!...) Matches if ... doesn't match next. - -The special sequences consist of "\\" and a character from the list -below. If the ordinary character is not on the list, then the -resulting RE will match the second character. - \number Matches the contents of the group of the same number. - \A Matches only at the start of the string. - \Z Matches only at the end of the string. - \b Matches the empty string, but only at the start or end of a word. - \B Matches the empty string, but not at the start or end of a word. - \d Matches any decimal digit; equivalent to the set [0-9]. - \D Matches any non-digit character; equivalent to the set [^0-9]. - \s Matches any whitespace character; equivalent to [ \t\n\r\f\v]. - \S Matches any non-whitespace character; equiv. to [^ \t\n\r\f\v]. - \w Matches any alphanumeric character; equivalent to [a-zA-Z0-9_]. - With LOCALE, it will match the set [0-9_] plus characters defined - as letters for the current locale. - \W Matches the complement of \w. - \\ Matches a literal backslash. - -This module exports the following functions: - match Match a regular expression pattern to the beginning of a string. - search Search a string for the presence of a pattern. - sub Substitute occurrences of a pattern found in a string. - subn Same as sub, but also return the number of substitutions made. - split Split a string by the occurrences of a pattern. - findall Find all occurrences of a pattern in a string. - compile Compile a pattern into a RegexObject. - purge Clear the regular expression cache. - escape Backslash all non-alphanumerics in a string. - -Some of the functions in this module takes flags as optional parameters: - I IGNORECASE Perform case-insensitive matching. - L LOCALE Make \w, \W, \b, \B, dependent on the current locale. - M MULTILINE "^" matches the beginning of lines as well as the string. - "$" matches the end of lines as well as the string. - S DOTALL "." matches any character at all, including the newline. - X VERBOSE Ignore whitespace and comments for nicer looking RE's. - U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale. - -This module also defines an exception 'error'. - -""" - -import sys -import sre_compile -import sre_parse - -# public symbols -__all__ = [ "match", "search", "sub", "subn", "split", "findall", - "compile", "purge", "template", "escape", "I", "L", "M", "S", "X", - "U", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE", - "UNICODE", "error" ] - -__version__ = "2.2.1" - -# flags -I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case -L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale -U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode locale -M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline -S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline -X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments - -# sre extensions (experimental, don't rely on these) -T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking -DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation - -# sre exception -error = sre_compile.error - -# -------------------------------------------------------------------- -# public interface - -def match(pattern, string, flags=0): - """Try to apply the pattern at the start of the string, returning - a match object, or None if no match was found.""" - return _compile(pattern, flags).match(string) - -def search(pattern, string, flags=0): - """Scan through string looking for a match to the pattern, returning - a match object, or None if no match was found.""" - return _compile(pattern, flags).search(string) - -def sub(pattern, repl, string, count=0): - """Return the string obtained by replacing the leftmost - non-overlapping occurrences of the pattern in string by the - replacement repl. repl can be either a string or a callable; - if a callable, it's passed the match object and must return - a replacement string to be used.""" - return _compile(pattern, 0).sub(repl, string, count) - -def subn(pattern, repl, string, count=0): - """Return a 2-tuple containing (new_string, number). - new_string is the string obtained by replacing the leftmost - non-overlapping occurrences of the pattern in the source - string by the replacement repl. number is the number of - substitutions that were made. repl can be either a string or a - callable; if a callable, it's passed the match object and must - return a replacement string to be used.""" - return _compile(pattern, 0).subn(repl, string, count) - -def split(pattern, string, maxsplit=0): - """Split the source string by the occurrences of the pattern, - returning a list containing the resulting substrings.""" - return _compile(pattern, 0).split(string, maxsplit) - -def findall(pattern, string, flags=0): - """Return a list of all non-overlapping matches in the string. - - If one or more groups are present in the pattern, return a - list of groups; this will be a list of tuples if the pattern - has more than one group. - - Empty matches are included in the result.""" - return _compile(pattern, flags).findall(string) - -if sys.hexversion >= 0x02020000: - __all__.append("finditer") - def finditer(pattern, string, flags=0): - """Return an iterator over all non-overlapping matches in the - string. For each match, the iterator returns a match object. - - Empty matches are included in the result.""" - return _compile(pattern, flags).finditer(string) - -def compile(pattern, flags=0): - "Compile a regular expression pattern, returning a pattern object." - return _compile(pattern, flags) - -def purge(): - "Clear the regular expression cache" - _cache.clear() - _cache_repl.clear() - -def template(pattern, flags=0): - "Compile a template pattern, returning a pattern object" - return _compile(pattern, flags|T) - -_alphanum = {} -for c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890': - _alphanum[c] = 1 -del c - -def escape(pattern): - "Escape all non-alphanumeric characters in pattern." - s = list(pattern) - alphanum = _alphanum - for i in range(len(pattern)): - c = pattern[i] - if c not in alphanum: - if c == "\000": - s[i] = "\\000" - else: - s[i] = "\\" + c - return pattern[:0].join(s) - -# -------------------------------------------------------------------- -# internals - -_cache = {} -_cache_repl = {} - -_pattern_type = type(sre_compile.compile("", 0)) - -_MAXCACHE = 100 - -def _compile(*key): - # internal: compile pattern - cachekey = (type(key[0]),) + key - p = _cache.get(cachekey) - if p is not None: - return p - pattern, flags = key - if isinstance(pattern, _pattern_type): - return pattern - if not sre_compile.isstring(pattern): - raise TypeError, "first argument must be string or compiled pattern" - try: - p = sre_compile.compile(pattern, flags) - except error, v: - raise error, v # invalid expression - if len(_cache) >= _MAXCACHE: - _cache.clear() - _cache[cachekey] = p - return p - -def _compile_repl(*key): - # internal: compile replacement pattern - p = _cache_repl.get(key) - if p is not None: - return p - repl, pattern = key - try: - p = sre_parse.parse_template(repl, pattern) - except error, v: - raise error, v # invalid expression - if len(_cache_repl) >= _MAXCACHE: - _cache_repl.clear() - _cache_repl[key] = p - return p - -def _expand(pattern, match, template): - # internal: match.expand implementation hook - template = sre_parse.parse_template(template, pattern) - return sre_parse.expand_template(template, match) - -def _subx(pattern, template): - # internal: pattern.sub/subn implementation helper - template = _compile_repl(template, pattern) - if not template[0] and len(template[1]) == 1: - # literal replacement - return template[1][0] - def filter(match, template=template): - return sre_parse.expand_template(template, match) - return filter - -# register myself for pickling - -import copy_reg - -def _pickle(p): - return _compile, (p.pattern, p.flags) - -copy_reg.pickle(_pattern_type, _pickle, _compile) - -# -------------------------------------------------------------------- -# experimental stuff (see python-dev discussions for details) - -class Scanner: - def __init__(self, lexicon, flags=0): - from sre_constants import BRANCH, SUBPATTERN - self.lexicon = lexicon - # combine phrases into a compound pattern - p = [] - s = sre_parse.Pattern() - s.flags = flags - for phrase, action in lexicon: - p.append(sre_parse.SubPattern(s, [ - (SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))), - ])) - p = sre_parse.SubPattern(s, [(BRANCH, (None, p))]) - s.groups = len(p) - self.scanner = sre_compile.compile(p) - def scan(self, string): - result = [] - append = result.append - match = self.scanner.scanner(string).match - i = 0 - while 1: - m = match() - if not m: - break - j = m.end() - if i == j: - break - action = self.lexicon[m.lastindex-1][1] - if callable(action): - self.match = m - action = action(self, m.group()) - if action is not None: - append(action) - i = j - return result, string[i:] Modified: python/branches/p3yk/Lib/test/regrtest.py ============================================================================== --- python/branches/p3yk/Lib/test/regrtest.py (original) +++ python/branches/p3yk/Lib/test/regrtest.py Fri Apr 21 11:47:09 2006 @@ -110,7 +110,7 @@ import getopt import random import warnings -import sre +import re import cStringIO import traceback @@ -525,7 +525,7 @@ _path_created.clear() warnings.filters[:] = fs gc.collect() - sre.purge() + re.purge() _strptime._regex_cache.clear() urlparse.clear_cache() urllib.urlcleanup() Modified: python/branches/p3yk/Lib/test/test___all__.py ============================================================================== --- python/branches/p3yk/Lib/test/test___all__.py (original) +++ python/branches/p3yk/Lib/test/test___all__.py Fri Apr 21 11:47:09 2006 @@ -145,7 +145,6 @@ self.check_all("smtplib") self.check_all("sndhdr") self.check_all("socket") - self.check_all("sre") self.check_all("_strptime") self.check_all("symtable") self.check_all("tabnanny") Modified: python/branches/p3yk/Lib/test/test_re.py ============================================================================== --- python/branches/p3yk/Lib/test/test_re.py (original) +++ python/branches/p3yk/Lib/test/test_re.py Fri Apr 21 11:47:09 2006 @@ -3,7 +3,7 @@ from test.test_support import verbose, run_unittest import re -from sre import Scanner +from re import Scanner import sys, os, traceback from weakref import proxy Modified: python/branches/p3yk/Modules/_sre.c ============================================================================== --- python/branches/p3yk/Modules/_sre.c (original) +++ python/branches/p3yk/Modules/_sre.c Fri Apr 21 11:47:09 2006 @@ -51,6 +51,8 @@ #define SRE_MODULE "sre" #endif +#define SRE_PY_MODULE "re" + /* defining this one enables tracing */ #undef VERBOSE @@ -2455,7 +2457,7 @@ } else { /* not a literal; hand it over to the template compiler */ filter = call( - SRE_MODULE, "_subx", + SRE_PY_MODULE, "_subx", PyTuple_Pack(2, self, template) ); if (!filter) @@ -2872,7 +2874,7 @@ /* delegate to Python code */ return call( - SRE_MODULE, "_expand", + SRE_PY_MODULE, "_expand", PyTuple_Pack(3, self->pattern, self, template) ); } From python-3000-checkins at python.org Fri Apr 21 11:43:36 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 11:43:36 +0200 (CEST) Subject: [Python-3000-checkins] r45593 - in python/branches/p3yk: Doc/lib/libcodecs.tex Doc/whatsnew/whatsnew25.tex Include/codecs.h Lib/StringIO.py Lib/codecs.py Lib/encodings/__init__.py Lib/encodings/ascii.py Lib/encodings/base64_codec.py Lib/encodings/bz2_codec.py Lib/encodings/charmap.py Lib/encodings/cp037.py Lib/encodings/cp1006.py Lib/encodings/cp1026.py Lib/encodings/cp1140.py Lib/encodings/cp1250.py Lib/encodings/cp1251.py Lib/encodings/cp1252.py Lib/encodings/cp1253.py Lib/encodings/cp1254.py Lib/encodings/cp1255.py Lib/encodings/cp1256.py Lib/encodings/cp1257.py Lib/encodings/cp1258.py Lib/encodings/cp424.py Lib/encodings/cp437.py Lib/encodings/cp500.py Lib/encodings/cp737.py Lib/encodings/cp775.py Lib/encodings/cp850.py Lib/encodings/cp852.py Lib/encodings/cp855.py Lib/encodings/cp856.py Lib/encodings/cp857.py Lib/encodings/cp860.py Lib/encodings/cp861.py Lib/encodings/cp862.py Lib/encodings/cp863.py Lib/encodings/cp864.py Lib/encodings/cp865.py Lib/encodings/cp866.py Lib/encodings/cp869.py Lib/encodings/cp874.py Lib/encodings/cp875.py Lib/encodings/hex_codec.py Lib/encodings/hp_roman8.py Lib/encodings/idna.py Lib/encodings/iso8859_1.py Lib/encodings/iso8859_10.py Lib/encodings/iso8859_11.py Lib/encodings/iso8859_13.py Lib/encodings/iso8859_14.py Lib/encodings/iso8859_15.py Lib/encodings/iso8859_16.py Lib/encodings/iso8859_2.py Lib/encodings/iso8859_3.py Lib/encodings/iso8859_4.py Lib/encodings/iso8859_5.py Lib/encodings/iso8859_6.py Lib/encodings/iso8859_7.py Lib/encodings/iso8859_8.py Lib/encodings/iso8859_9.py Lib/encodings/koi8_r.py Lib/encodings/koi8_u.py Lib/encodings/latin_1.py Lib/encodings/mac_arabic.py Lib/encodings/mac_centeuro.py Lib/encodings/mac_croatian.py Lib/encodings/mac_cyrillic.py Lib/encodings/mac_farsi.py Lib/encodings/mac_greek.py Lib/encodings/mac_iceland.py Lib/encodings/mac_latin2.py Lib/encodings/mac_roman.py Lib/encodings/mac_romanian.py Lib/encodings/mac_turkish.py Lib/encodings/mbcs.py Lib/encodings/palmos.py Lib/encodings/ptcp154.py Lib/encodings/punycode.py Lib/encodings/quopri_codec.py Lib/encodings/raw_unicode_escape.py Lib/encodings/rot_13.py Lib/encodings/string_escape.py Lib/encodings/tis_620.py Lib/encodings/undefined.py Lib/encodings/unicode_escape.py Lib/encodings/unicode_internal.py Lib/encodings/utf_16.py Lib/encodings/utf_16_be.py Lib/encodings/utf_16_le.py Lib/encodings/utf_7.py Lib/encodings/utf_8.py Lib/encodings/utf_8_sig.py Lib/encodings/uu_codec.py Lib/encodings/zlib_codec.py Lib/logging/__init__.py Lib/runpy.py Lib/test/regrtest.py Lib/test/test_StringIO.py Lib/test/test___all__.py Lib/test/test_codecs.py Lib/test/test_hashlib_speed.py Lib/test/test_runpy.py Lib/test/time_hashlib.py Makefile.pre.in Modules/_ctypes/_ctypes.c Modules/_ctypes/cfield.c Modules/_ctypes/ctypes.h Modules/_testcapimodule.c Modules/cStringIO.c Modules/main.c Modules/xxmodule.c Objects/obmalloc.c Python/codecs.c Tools/buildbot/clean.bat Tools/unicode/Makefile Tools/unicode/gencodec.py Message-ID: <20060421094336.645421E400C@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 11:43:23 2006 New Revision: 45593 Added: python/branches/p3yk/Lib/runpy.py - copied unchanged from r43067, python/trunk/Lib/runpy.py python/branches/p3yk/Lib/test/test_runpy.py - copied unchanged from r43067, python/trunk/Lib/test/test_runpy.py python/branches/p3yk/Lib/test/time_hashlib.py - copied unchanged from r43067, python/trunk/Lib/test/time_hashlib.py Removed: python/branches/p3yk/Lib/test/test_hashlib_speed.py Modified: python/branches/p3yk/ (props changed) python/branches/p3yk/Doc/lib/libcodecs.tex python/branches/p3yk/Doc/whatsnew/whatsnew25.tex python/branches/p3yk/Include/codecs.h python/branches/p3yk/Lib/StringIO.py python/branches/p3yk/Lib/codecs.py python/branches/p3yk/Lib/encodings/__init__.py python/branches/p3yk/Lib/encodings/ascii.py python/branches/p3yk/Lib/encodings/base64_codec.py python/branches/p3yk/Lib/encodings/bz2_codec.py python/branches/p3yk/Lib/encodings/charmap.py python/branches/p3yk/Lib/encodings/cp037.py python/branches/p3yk/Lib/encodings/cp1006.py python/branches/p3yk/Lib/encodings/cp1026.py python/branches/p3yk/Lib/encodings/cp1140.py python/branches/p3yk/Lib/encodings/cp1250.py python/branches/p3yk/Lib/encodings/cp1251.py python/branches/p3yk/Lib/encodings/cp1252.py python/branches/p3yk/Lib/encodings/cp1253.py python/branches/p3yk/Lib/encodings/cp1254.py python/branches/p3yk/Lib/encodings/cp1255.py python/branches/p3yk/Lib/encodings/cp1256.py python/branches/p3yk/Lib/encodings/cp1257.py python/branches/p3yk/Lib/encodings/cp1258.py python/branches/p3yk/Lib/encodings/cp424.py python/branches/p3yk/Lib/encodings/cp437.py python/branches/p3yk/Lib/encodings/cp500.py python/branches/p3yk/Lib/encodings/cp737.py python/branches/p3yk/Lib/encodings/cp775.py python/branches/p3yk/Lib/encodings/cp850.py python/branches/p3yk/Lib/encodings/cp852.py python/branches/p3yk/Lib/encodings/cp855.py python/branches/p3yk/Lib/encodings/cp856.py python/branches/p3yk/Lib/encodings/cp857.py python/branches/p3yk/Lib/encodings/cp860.py python/branches/p3yk/Lib/encodings/cp861.py python/branches/p3yk/Lib/encodings/cp862.py python/branches/p3yk/Lib/encodings/cp863.py python/branches/p3yk/Lib/encodings/cp864.py python/branches/p3yk/Lib/encodings/cp865.py python/branches/p3yk/Lib/encodings/cp866.py python/branches/p3yk/Lib/encodings/cp869.py python/branches/p3yk/Lib/encodings/cp874.py python/branches/p3yk/Lib/encodings/cp875.py python/branches/p3yk/Lib/encodings/hex_codec.py python/branches/p3yk/Lib/encodings/hp_roman8.py python/branches/p3yk/Lib/encodings/idna.py python/branches/p3yk/Lib/encodings/iso8859_1.py python/branches/p3yk/Lib/encodings/iso8859_10.py python/branches/p3yk/Lib/encodings/iso8859_11.py python/branches/p3yk/Lib/encodings/iso8859_13.py python/branches/p3yk/Lib/encodings/iso8859_14.py python/branches/p3yk/Lib/encodings/iso8859_15.py python/branches/p3yk/Lib/encodings/iso8859_16.py python/branches/p3yk/Lib/encodings/iso8859_2.py python/branches/p3yk/Lib/encodings/iso8859_3.py python/branches/p3yk/Lib/encodings/iso8859_4.py python/branches/p3yk/Lib/encodings/iso8859_5.py python/branches/p3yk/Lib/encodings/iso8859_6.py python/branches/p3yk/Lib/encodings/iso8859_7.py python/branches/p3yk/Lib/encodings/iso8859_8.py python/branches/p3yk/Lib/encodings/iso8859_9.py python/branches/p3yk/Lib/encodings/koi8_r.py python/branches/p3yk/Lib/encodings/koi8_u.py python/branches/p3yk/Lib/encodings/latin_1.py python/branches/p3yk/Lib/encodings/mac_arabic.py python/branches/p3yk/Lib/encodings/mac_centeuro.py python/branches/p3yk/Lib/encodings/mac_croatian.py python/branches/p3yk/Lib/encodings/mac_cyrillic.py python/branches/p3yk/Lib/encodings/mac_farsi.py python/branches/p3yk/Lib/encodings/mac_greek.py python/branches/p3yk/Lib/encodings/mac_iceland.py python/branches/p3yk/Lib/encodings/mac_latin2.py python/branches/p3yk/Lib/encodings/mac_roman.py python/branches/p3yk/Lib/encodings/mac_romanian.py python/branches/p3yk/Lib/encodings/mac_turkish.py python/branches/p3yk/Lib/encodings/mbcs.py python/branches/p3yk/Lib/encodings/palmos.py python/branches/p3yk/Lib/encodings/ptcp154.py python/branches/p3yk/Lib/encodings/punycode.py python/branches/p3yk/Lib/encodings/quopri_codec.py python/branches/p3yk/Lib/encodings/raw_unicode_escape.py python/branches/p3yk/Lib/encodings/rot_13.py python/branches/p3yk/Lib/encodings/string_escape.py python/branches/p3yk/Lib/encodings/tis_620.py python/branches/p3yk/Lib/encodings/undefined.py python/branches/p3yk/Lib/encodings/unicode_escape.py python/branches/p3yk/Lib/encodings/unicode_internal.py python/branches/p3yk/Lib/encodings/utf_16.py python/branches/p3yk/Lib/encodings/utf_16_be.py python/branches/p3yk/Lib/encodings/utf_16_le.py python/branches/p3yk/Lib/encodings/utf_7.py python/branches/p3yk/Lib/encodings/utf_8.py python/branches/p3yk/Lib/encodings/utf_8_sig.py python/branches/p3yk/Lib/encodings/uu_codec.py python/branches/p3yk/Lib/encodings/zlib_codec.py python/branches/p3yk/Lib/logging/__init__.py python/branches/p3yk/Lib/test/regrtest.py python/branches/p3yk/Lib/test/test_StringIO.py python/branches/p3yk/Lib/test/test___all__.py python/branches/p3yk/Lib/test/test_codecs.py python/branches/p3yk/Makefile.pre.in python/branches/p3yk/Modules/_ctypes/_ctypes.c python/branches/p3yk/Modules/_ctypes/cfield.c python/branches/p3yk/Modules/_ctypes/ctypes.h python/branches/p3yk/Modules/_testcapimodule.c python/branches/p3yk/Modules/cStringIO.c python/branches/p3yk/Modules/main.c python/branches/p3yk/Modules/xxmodule.c python/branches/p3yk/Objects/obmalloc.c python/branches/p3yk/Python/codecs.c python/branches/p3yk/Tools/buildbot/clean.bat python/branches/p3yk/Tools/unicode/Makefile python/branches/p3yk/Tools/unicode/gencodec.py Log: Merge part of the trunk changes into the p3yk branch. This merges from 43030 (branch-creation time) up to 43067. 43068 and 43069 contain a little swapping action between re.py and sre.py, and this mightily confuses svn merge, so later changes are going in separately. This merge should break no additional tests. The last-merged revision is going in a 'last_merge' property on '.' (the branch directory.) Arbitrarily chosen, really; if there's a BCP for this, I couldn't find it, but we can easily change it afterwards ;) Modified: python/branches/p3yk/Doc/lib/libcodecs.tex ============================================================================== --- python/branches/p3yk/Doc/lib/libcodecs.tex (original) +++ python/branches/p3yk/Doc/lib/libcodecs.tex Fri Apr 21 11:43:23 2006 @@ -24,8 +24,19 @@ \begin{funcdesc}{register}{search_function} Register a codec search function. Search functions are expected to take one argument, the encoding name in all lower case letters, and -return a tuple of functions \code{(\var{encoder}, \var{decoder}, \var{stream_reader}, -\var{stream_writer})} taking the following arguments: +return a \class{CodecInfo} object having the following attributes: + +\begin{itemize} + \item \code{name} The name of the encoding; + \item \code{encoder} The stateless encoding function; + \item \code{decoder} The stateless decoding function; + \item \code{incrementalencoder} An incremental encoder class or factory function; + \item \code{incrementaldecoder} An incremental decoder class or factory function; + \item \code{streamwriter} A stream writer class or factory function; + \item \code{streamreader} A stream reader class or factory function. +\end{itemize} + +The various functions or classes take the following arguments: \var{encoder} and \var{decoder}: These must be functions or methods which have the same interface as the @@ -33,7 +44,17 @@ Codec Interface). The functions/methods are expected to work in a stateless mode. - \var{stream_reader} and \var{stream_writer}: These have to be + \var{incrementalencoder} and \var{incrementalencoder}: These have to be + factory functions providing the following interface: + + \code{factory(\var{errors}='strict')} + + The factory functions must return objects providing the interfaces + defined by the base classes \class{IncrementalEncoder} and + \class{IncrementalEncoder}, respectively. Incremental codecs can maintain + state. + + \var{streamreader} and \var{streamwriter}: These have to be factory functions providing the following interface: \code{factory(\var{stream}, \var{errors}='strict')} @@ -58,13 +79,13 @@ \end{funcdesc} \begin{funcdesc}{lookup}{encoding} -Looks up a codec tuple in the Python codec registry and returns the -function tuple as defined above. +Looks up the codec info in the Python codec registry and returns a +\class{CodecInfo} object as defined above. Encodings are first looked up in the registry's cache. If not found, -the list of registered search functions is scanned. If no codecs tuple -is found, a \exception{LookupError} is raised. Otherwise, the codecs -tuple is stored in the cache and returned to the caller. +the list of registered search functions is scanned. If no \class{CodecInfo} +object is found, a \exception{LookupError} is raised. Otherwise, the +\class{CodecInfo} object is stored in the cache and returned to the caller. \end{funcdesc} To simplify access to the various codecs, the module provides these @@ -85,6 +106,22 @@ Raises a \exception{LookupError} in case the encoding cannot be found. \end{funcdesc} +\begin{funcdesc}{getincrementalencoder}{encoding} +Lookup up the codec for the given encoding and return its incremental encoder +class or factory function. + +Raises a \exception{LookupError} in case the encoding cannot be found or the +codec doesn't support an incremental encoder. +\end{funcdesc} + +\begin{funcdesc}{getincrementaldecoder}{encoding} +Lookup up the codec for the given encoding and return its incremental decoder +class or factory function. + +Raises a \exception{LookupError} in case the encoding cannot be found or the +codec doesn't support an incremental decoder. +\end{funcdesc} + \begin{funcdesc}{getreader}{encoding} Lookup up the codec for the given encoding and return its StreamReader class or factory function. @@ -188,6 +225,18 @@ an encoding error occurs. \end{funcdesc} +\begin{funcdesc}{iterencode}{iterable, encoding\optional{, errors}} +Uses an incremental encoder to iteratively encode the input provided by +\var{iterable}. This function is a generator. \var{errors} (as well as +any other keyword argument) is passed through to the incremental encoder. +\end{funcdesc} + +\begin{funcdesc}{iterdecode}{iterable, encoding\optional{, errors}} +Uses an incremental decoder to iteratively decode the input provided by +\var{iterable}. This function is a generator. \var{errors} (as well as +any other keyword argument) is passed through to the incremental encoder. +\end{funcdesc} + The module also provides the following constants which are useful for reading and writing to platform dependent files: @@ -292,6 +341,109 @@ empty object of the output object type in this situation. \end{methoddesc} +The \class{IncrementalEncoder} and \class{IncrementalDecoder} classes provide +the basic interface for incremental encoding and decoding. Encoding/decoding the +input isn't done with one call to the stateless encoder/decoder function, +but with multiple calls to the \method{encode}/\method{decode} method of the +incremental encoder/decoder. The incremental encoder/decoder keeps track of +the encoding/decoding process during method calls. + +The joined output of calls to the \method{encode}/\method{decode} method is the +same as if the all single inputs where joined into one, and this input was +encoded/decoded with the stateless encoder/decoder. + + +\subsubsection{IncrementalEncoder Objects \label{incremental-encoder-objects}} + +The \class{IncrementalEncoder} class is used for encoding an input in multiple +steps. It defines the following methods which every incremental encoder must +define in order to be compatible to the Python codec registry. + +\begin{classdesc}{IncrementalEncoder}{\optional{errors}} + Constructor for a \class{IncrementalEncoder} instance. + + All incremental encoders must provide this constructor interface. They are + free to add additional keyword arguments, but only the ones defined + here are used by the Python codec registry. + + The \class{IncrementalEncoder} may implement different error handling + schemes by providing the \var{errors} keyword argument. These + parameters are predefined: + + \begin{itemize} + \item \code{'strict'} Raise \exception{ValueError} (or a subclass); + this is the default. + \item \code{'ignore'} Ignore the character and continue with the next. + \item \code{'replace'} Replace with a suitable replacement character + \item \code{'xmlcharrefreplace'} Replace with the appropriate XML + character reference + \item \code{'backslashreplace'} Replace with backslashed escape sequences. + \end{itemize} + + The \var{errors} argument will be assigned to an attribute of the + same name. Assigning to this attribute makes it possible to switch + between different error handling strategies during the lifetime + of the \class{IncrementalEncoder} object. + + The set of allowed values for the \var{errors} argument can + be extended with \function{register_error()}. +\end{classdesc} + +\begin{methoddesc}{encode}{object\optional{, final}} + Encodes \var{object} (taking the current state of the encoder into account) + and returns the resulting encoded object. If this is the last call to + \method{encode} \var{final} must be true (the default is false). +\end{methoddesc} + +\begin{methoddesc}{reset}{} + Reset the encoder to the initial state. +\end{methoddesc} + + +\subsubsection{IncrementalDecoder Objects \label{incremental-decoder-objects}} + +The \class{IncrementalDecoder} class is used for decoding an input in multiple +steps. It defines the following methods which every incremental decoder must +define in order to be compatible to the Python codec registry. + +\begin{classdesc}{IncrementalDecoder}{\optional{errors}} + Constructor for a \class{IncrementalDecoder} instance. + + All incremental decoders must provide this constructor interface. They are + free to add additional keyword arguments, but only the ones defined + here are used by the Python codec registry. + + The \class{IncrementalDecoder} may implement different error handling + schemes by providing the \var{errors} keyword argument. These + parameters are predefined: + + \begin{itemize} + \item \code{'strict'} Raise \exception{ValueError} (or a subclass); + this is the default. + \item \code{'ignore'} Ignore the character and continue with the next. + \item \code{'replace'} Replace with a suitable replacement character. + \end{itemize} + + The \var{errors} argument will be assigned to an attribute of the + same name. Assigning to this attribute makes it possible to switch + between different error handling strategies during the lifetime + of the \class{IncrementalEncoder} object. + + The set of allowed values for the \var{errors} argument can + be extended with \function{register_error()}. +\end{classdesc} + +\begin{methoddesc}{decode}{object\optional{, final}} + Decodes \var{object} (taking the current state of the decoder into account) + and returns the resulting decoded object. If this is the last call to + \method{decode} \var{final} must be true (the default is false). +\end{methoddesc} + +\begin{methoddesc}{reset}{} + Reset the decoder to the initial state. +\end{methoddesc} + + The \class{StreamWriter} and \class{StreamReader} classes provide generic working interfaces which can be used to implement new encodings submodules very easily. See \module{encodings.utf_8} for an Modified: python/branches/p3yk/Doc/whatsnew/whatsnew25.tex ============================================================================== --- python/branches/p3yk/Doc/whatsnew/whatsnew25.tex (original) +++ python/branches/p3yk/Doc/whatsnew/whatsnew25.tex Fri Apr 21 11:43:23 2006 @@ -210,6 +210,12 @@ %====================================================================== +\section{PEP 338: Executing Modules as Scripts} + +% XXX write this + + +%====================================================================== \section{PEP 341: Unified try/except/finally} % XXX write this Modified: python/branches/p3yk/Include/codecs.h ============================================================================== --- python/branches/p3yk/Include/codecs.h (original) +++ python/branches/p3yk/Include/codecs.h Fri Apr 21 11:43:23 2006 @@ -29,15 +29,15 @@ /* Codec register lookup API. - Looks up the given encoding and returns a tuple (encoder, decoder, - stream reader, stream writer) of functions which implement the - different aspects of processing the encoding. + Looks up the given encoding and returns a CodecInfo object with + function attributes which implement the different aspects of + processing the encoding. The encoding string is looked up converted to all lower-case characters. This makes encodings looked up through this mechanism effectively case-insensitive. - If no codec is found, a KeyError is set and NULL returned. + If no codec is found, a KeyError is set and NULL returned. As side effect, this tries to load the encodings package, if not yet done. This is part of the lazy load strategy for the encodings @@ -101,6 +101,20 @@ const char *encoding ); +/* Get a IncrementalEncoder object for the given encoding. */ + +PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder( + const char *encoding, + const char *errors + ); + +/* Get a IncrementalDecoder object function for the given encoding. */ + +PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder( + const char *encoding, + const char *errors + ); + /* Get a StreamReader factory function for the given encoding. */ PyAPI_FUNC(PyObject *) PyCodec_StreamReader( Modified: python/branches/p3yk/Lib/StringIO.py ============================================================================== --- python/branches/p3yk/Lib/StringIO.py (original) +++ python/branches/p3yk/Lib/StringIO.py Fri Apr 21 11:43:23 2006 @@ -72,8 +72,7 @@ method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit. """ - if self.closed: - raise StopIteration + _complain_ifclosed(self.closed) r = self.readline() if not r: raise StopIteration Modified: python/branches/p3yk/Lib/codecs.py ============================================================================== --- python/branches/p3yk/Lib/codecs.py (original) +++ python/branches/p3yk/Lib/codecs.py Fri Apr 21 11:43:23 2006 @@ -73,6 +73,23 @@ ### Codec base classes (defining the API) +class CodecInfo(tuple): + + def __new__(cls, encode, decode, streamreader=None, streamwriter=None, + incrementalencoder=None, incrementaldecoder=None, name=None): + self = tuple.__new__(cls, (encode, decode, streamreader, streamwriter)) + self.name = name + self.encode = encode + self.decode = decode + self.incrementalencoder = incrementalencoder + self.incrementaldecoder = incrementaldecoder + self.streamwriter = streamwriter + self.streamreader = streamreader + return self + + def __repr__(self): + return "<%s.%s object for encoding %s at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self)) + class Codec: """ Defines the interface for stateless encoders/decoders. @@ -137,6 +154,88 @@ """ raise NotImplementedError +class IncrementalEncoder(object): + """ + A IncrementalEncoder encodes an input in multiple steps. The input can be + passed piece by piece to the encode() method. The IncrementalEncoder remembers + the state of the Encoding process between calls to encode(). + """ + def __init__(self, errors='strict'): + """ + Creates a IncrementalEncoder instance. + + The IncrementalEncoder may use different error handling schemes by + providing the errors keyword argument. See the module docstring + for a list of possible values. + """ + self.errors = errors + self.buffer = "" + + def encode(self, input, final=False): + """ + Encodes input and returns the resulting object. + """ + raise NotImplementedError + + def reset(self): + """ + Resets the encoder to the initial state. + """ + +class IncrementalDecoder(object): + """ + An IncrementalDecoder decodes an input in multiple steps. The input can be + passed piece by piece to the decode() method. The IncrementalDecoder + remembers the state of the decoding process between calls to decode(). + """ + def __init__(self, errors='strict'): + """ + Creates a IncrementalDecoder instance. + + The IncrementalDecoder may use different error handling schemes by + providing the errors keyword argument. See the module docstring + for a list of possible values. + """ + self.errors = errors + + def decode(self, input, final=False): + """ + Decodes input and returns the resulting object. + """ + raise NotImplementedError + + def reset(self): + """ + Resets the decoder to the initial state. + """ + +class BufferedIncrementalDecoder(IncrementalDecoder): + """ + This subclass of IncrementalDecoder can be used as the baseclass for an + incremental decoder if the decoder must be able to handle incomplete byte + sequences. + """ + def __init__(self, errors='strict'): + IncrementalDecoder.__init__(self, errors) + self.buffer = "" # undecoded input that is kept between calls to decode() + + def _buffer_decode(self, input, errors, final): + # Overwrite this method in subclasses: It must decode input + # and return an (output, length consumed) tuple + raise NotImplementedError + + def decode(self, input, final=False): + # decode input (taking the buffer into account) + data = self.buffer + input + (result, consumed) = self._buffer_decode(data, self.errors, final) + # keep undecoded input until the next call + self.buffer = data[consumed:] + return result + + def reset(self): + IncrementalDecoder.reset(self) + self.bytebuffer = "" + # # The StreamWriter and StreamReader class provide generic working # interfaces which can be used to implement new encoding submodules @@ -666,8 +765,8 @@ file = __builtin__.open(filename, mode, buffering) if encoding is None: return file - (e, d, sr, sw) = lookup(encoding) - srw = StreamReaderWriter(file, sr, sw, errors) + info = lookup(encoding) + srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors) # Add attributes to simplify introspection srw.encoding = encoding return srw @@ -699,11 +798,9 @@ """ if file_encoding is None: file_encoding = data_encoding - encode, decode = lookup(data_encoding)[:2] - Reader, Writer = lookup(file_encoding)[2:] - sr = StreamRecoder(file, - encode, decode, Reader, Writer, - errors) + info = lookup(data_encoding) + sr = StreamRecoder(file, info.encode, info.decode, + info.streamreader, info.streamwriter, errors) # Add attributes to simplify introspection sr.data_encoding = data_encoding sr.file_encoding = file_encoding @@ -719,7 +816,7 @@ Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[0] + return lookup(encoding).encode def getdecoder(encoding): @@ -729,7 +826,35 @@ Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[1] + return lookup(encoding).decode + +def getincrementalencoder(encoding): + + """ Lookup up the codec for the given encoding and return + its IncrementalEncoder class or factory function. + + Raises a LookupError in case the encoding cannot be found + or the codecs doesn't provide an incremental encoder. + + """ + encoder = lookup(encoding).incrementalencoder + if encoder is None: + raise LookupError(encoding) + return encoder + +def getincrementaldecoder(encoding): + + """ Lookup up the codec for the given encoding and return + its IncrementalDecoder class or factory function. + + Raises a LookupError in case the encoding cannot be found + or the codecs doesn't provide an incremental decoder. + + """ + decoder = lookup(encoding).incrementaldecoder + if decoder is None: + raise LookupError(encoding) + return decoder def getreader(encoding): @@ -739,7 +864,7 @@ Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[2] + return lookup(encoding).streamreader def getwriter(encoding): @@ -749,7 +874,43 @@ Raises a LookupError in case the encoding cannot be found. """ - return lookup(encoding)[3] + return lookup(encoding).streamwriter + +def iterencode(iterator, encoding, errors='strict', **kwargs): + """ + Encoding iterator. + + Encodes the input strings from the iterator using a IncrementalEncoder. + + errors and kwargs are passed through to the IncrementalEncoder + constructor. + """ + encoder = getincrementalencoder(encoding)(errors, **kwargs) + for input in iterator: + output = encoder.encode(input) + if output: + yield output + output = encoder.encode("", True) + if output: + yield output + +def iterdecode(iterator, encoding, errors='strict', **kwargs): + """ + Decoding iterator. + + Decodes the input strings from the iterator using a IncrementalDecoder. + + errors and kwargs are passed through to the IncrementalDecoder + constructor. + """ + decoder = getincrementaldecoder(encoding)(errors, **kwargs) + for input in iterator: + output = decoder.decode(input) + if output: + yield output + output = decoder.decode("", True) + if output: + yield output ### Helpers for charmap-based codecs Modified: python/branches/p3yk/Lib/encodings/__init__.py ============================================================================== --- python/branches/p3yk/Lib/encodings/__init__.py (original) +++ python/branches/p3yk/Lib/encodings/__init__.py Fri Apr 21 11:43:23 2006 @@ -9,9 +9,10 @@ Each codec module must export the following interface: - * getregentry() -> (encoder, decoder, stream_reader, stream_writer) - The getregentry() API must return callable objects which adhere to - the Python Codec Interface Standard. + * getregentry() -> codecs.CodecInfo object + The getregentry() API must a CodecInfo object with encoder, decoder, + incrementalencoder, incrementaldecoder, streamwriter and streamreader + atttributes which adhere to the Python Codec Interface Standard. In addition, a module may optionally also define the following APIs which are then used by the package's codec search function: @@ -113,16 +114,24 @@ return None # Now ask the module for the registry entry - entry = tuple(getregentry()) - if len(entry) != 4: - raise CodecRegistryError,\ - 'module "%s" (%s) failed to register' % \ - (mod.__name__, mod.__file__) - for obj in entry: - if not callable(obj): + entry = getregentry() + if not isinstance(entry, codecs.CodecInfo): + if not 4 <= len(entry) <= 7: raise CodecRegistryError,\ - 'incompatible codecs in module "%s" (%s)' % \ + 'module "%s" (%s) failed to register' % \ (mod.__name__, mod.__file__) + if not callable(entry[0]) or \ + not callable(entry[1]) or \ + (entry[2] is not None and not callable(entry[2])) or \ + (entry[3] is not None and not callable(entry[3])) or \ + (len(entry) > 4 and entry[4] is not None and not callable(entry[4])) or \ + (len(entry) > 5 and entry[5] is not None and not callable(entry[5])): + raise CodecRegistryError,\ + 'incompatible codecs in module "%s" (%s)' % \ + (mod.__name__, mod.__file__) + if len(entry)<7 or entry[6] is None: + entry += (None,)*(6-len(entry)) + (mod.__name__.split(".", 1)[1],) + entry = codecs.CodecInfo(*entry) # Cache the codec registry entry _cache[encoding] = entry Modified: python/branches/p3yk/Lib/encodings/ascii.py ============================================================================== --- python/branches/p3yk/Lib/encodings/ascii.py (original) +++ python/branches/p3yk/Lib/encodings/ascii.py Fri Apr 21 11:43:23 2006 @@ -17,6 +17,14 @@ encode = codecs.ascii_encode decode = codecs.ascii_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.ascii_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.ascii_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -31,5 +39,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='ascii', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/base64_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/base64_codec.py (original) +++ python/branches/p3yk/Lib/encodings/base64_codec.py Fri Apr 21 11:43:23 2006 @@ -49,6 +49,16 @@ def decode(self, input,errors='strict'): return base64_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return base64.encodestring(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return base64.decodestring(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -58,5 +68,12 @@ ### encodings module API def getregentry(): - - return (base64_encode,base64_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='base64', + encode=base64_encode, + decode=base64_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/bz2_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/bz2_codec.py (original) +++ python/branches/p3yk/Lib/encodings/bz2_codec.py Fri Apr 21 11:43:23 2006 @@ -51,6 +51,16 @@ def decode(self, input, errors='strict'): return bz2_decode(input, errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return bz2.compress(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return bz2.decompress(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -60,5 +70,12 @@ ### encodings module API def getregentry(): - - return (bz2_encode,bz2_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name="bz2", + encode=bz2_encode, + decode=bz2_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/charmap.py ============================================================================== --- python/branches/p3yk/Lib/encodings/charmap.py (original) +++ python/branches/p3yk/Lib/encodings/charmap.py Fri Apr 21 11:43:23 2006 @@ -21,30 +21,49 @@ encode = codecs.charmap_encode decode = codecs.charmap_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict', mapping=None): + codecs.IncrementalEncoder.__init__(self, errors) + self.mapping = mapping + + def encode(self, input, final=False): + return codecs.charmap_encode(input, self.errors, self.mapping)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def __init__(self, errors='strict', mapping=None): + codecs.IncrementalDecoder.__init__(self, errors) + self.mapping = mapping + + def decode(self, input, final=False): + return codecs.charmap_decode(input, self.errors, self.mapping)[0] + class StreamWriter(Codec,codecs.StreamWriter): def __init__(self,stream,errors='strict',mapping=None): - codecs.StreamWriter.__init__(self,stream,errors) self.mapping = mapping def encode(self,input,errors='strict'): - return Codec.encode(input,errors,self.mapping) class StreamReader(Codec,codecs.StreamReader): def __init__(self,stream,errors='strict',mapping=None): - codecs.StreamReader.__init__(self,stream,errors) self.mapping = mapping def decode(self,input,errors='strict'): - return Codec.decode(input,errors,self.mapping) ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='charmap', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/cp037.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp037.py (original) +++ python/branches/p3yk/Lib/encodings/cp037.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT' with gencodec.py. +""" Python Character Mapping Codec cp037 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP037.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp037', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1006.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1006.py (original) +++ python/branches/p3yk/Lib/encodings/cp1006.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP1006.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1006 generated from 'MAPPINGS/VENDORS/MISC/CP1006.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1006', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1026.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1026.py (original) +++ python/branches/p3yk/Lib/encodings/cp1026.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1026 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP1026.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1026', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1140.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1140.py (original) +++ python/branches/p3yk/Lib/encodings/cp1140.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/CP1140.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1140 generated from 'python-mappings/CP1140.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1140', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1250.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1250.py (original) +++ python/branches/p3yk/Lib/encodings/cp1250.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1250 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1250', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1251.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1251.py (original) +++ python/branches/p3yk/Lib/encodings/cp1251.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1251 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1251', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1252.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1252.py (original) +++ python/branches/p3yk/Lib/encodings/cp1252.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1252 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1252', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1253.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1253.py (original) +++ python/branches/p3yk/Lib/encodings/cp1253.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1253 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1253.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1253', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1254.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1254.py (original) +++ python/branches/p3yk/Lib/encodings/cp1254.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1254 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1254.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1254', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1255.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1255.py (original) +++ python/branches/p3yk/Lib/encodings/cp1255.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1255 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1255', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1256.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1256.py (original) +++ python/branches/p3yk/Lib/encodings/cp1256.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1256 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1256', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1257.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1257.py (original) +++ python/branches/p3yk/Lib/encodings/cp1257.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1257 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1257', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp1258.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp1258.py (original) +++ python/branches/p3yk/Lib/encodings/cp1258.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT' with gencodec.py. +""" Python Character Mapping Codec cp1258 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1258.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp1258', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp424.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp424.py (original) +++ python/branches/p3yk/Lib/encodings/cp424.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP424.TXT' with gencodec.py. +""" Python Character Mapping Codec cp424 generated from 'MAPPINGS/VENDORS/MISC/CP424.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp424', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp437.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp437.py (original) +++ python/branches/p3yk/Lib/encodings/cp437.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP437.TXT' with gencodec.py. +""" Python Character Mapping Codec cp437 generated from 'VENDORS/MICSFT/PC/CP437.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp437', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp500.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp500.py (original) +++ python/branches/p3yk/Lib/encodings/cp500.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT' with gencodec.py. +""" Python Character Mapping Codec cp500 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP500.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp500', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp737.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp737.py (original) +++ python/branches/p3yk/Lib/encodings/cp737.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP737.TXT' with gencodec.py. +""" Python Character Mapping Codec cp737 generated from 'VENDORS/MICSFT/PC/CP737.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp737', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp775.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp775.py (original) +++ python/branches/p3yk/Lib/encodings/cp775.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'VENDORS/MICSFT/PC/CP775.TXT' with gencodec.py. +""" Python Character Mapping Codec cp775 generated from 'VENDORS/MICSFT/PC/CP775.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,9 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) - + return codecs.CodecInfo( + name='cp775', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map decoding_map = codecs.make_identity_dict(range(256)) Modified: python/branches/p3yk/Lib/encodings/cp850.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp850.py (original) +++ python/branches/p3yk/Lib/encodings/cp850.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp850', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp852.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp852.py (original) +++ python/branches/p3yk/Lib/encodings/cp852.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp852', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp855.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp855.py (original) +++ python/branches/p3yk/Lib/encodings/cp855.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp855', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp856.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp856.py (original) +++ python/branches/p3yk/Lib/encodings/cp856.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/CP856.TXT' with gencodec.py. +""" Python Character Mapping Codec cp856 generated from 'MAPPINGS/VENDORS/MISC/CP856.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp856', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp857.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp857.py (original) +++ python/branches/p3yk/Lib/encodings/cp857.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp857', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp860.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp860.py (original) +++ python/branches/p3yk/Lib/encodings/cp860.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp860', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp861.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp861.py (original) +++ python/branches/p3yk/Lib/encodings/cp861.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp861', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp862.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp862.py (original) +++ python/branches/p3yk/Lib/encodings/cp862.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp862', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp863.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp863.py (original) +++ python/branches/p3yk/Lib/encodings/cp863.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp863', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp864.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp864.py (original) +++ python/branches/p3yk/Lib/encodings/cp864.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp864', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp865.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp865.py (original) +++ python/branches/p3yk/Lib/encodings/cp865.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp865', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp866.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp866.py (original) +++ python/branches/p3yk/Lib/encodings/cp866.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp866', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp869.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp869.py (original) +++ python/branches/p3yk/Lib/encodings/cp869.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp869', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/cp874.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp874.py (original) +++ python/branches/p3yk/Lib/encodings/cp874.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP874.TXT' with gencodec.py. +""" Python Character Mapping Codec cp874 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP874.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp874', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/cp875.py ============================================================================== --- python/branches/p3yk/Lib/encodings/cp875.py (original) +++ python/branches/p3yk/Lib/encodings/cp875.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT' with gencodec.py. +""" Python Character Mapping Codec cp875 generated from 'MAPPINGS/VENDORS/MICSFT/EBCDIC/CP875.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='cp875', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/hex_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/hex_codec.py (original) +++ python/branches/p3yk/Lib/encodings/hex_codec.py Fri Apr 21 11:43:23 2006 @@ -49,6 +49,16 @@ def decode(self, input,errors='strict'): return hex_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return binascii.b2a_hex(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return binascii.a2b_hex(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -58,5 +68,12 @@ ### encodings module API def getregentry(): - - return (hex_encode,hex_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='hex', + encode=hex_encode, + decode=hex_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/hp_roman8.py ============================================================================== --- python/branches/p3yk/Lib/encodings/hp_roman8.py (original) +++ python/branches/p3yk/Lib/encodings/hp_roman8.py Fri Apr 21 11:43:23 2006 @@ -14,13 +14,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_map) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='hp-roman8', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/idna.py ============================================================================== --- python/branches/p3yk/Lib/encodings/idna.py (original) +++ python/branches/p3yk/Lib/encodings/idna.py Fri Apr 21 11:43:23 2006 @@ -194,6 +194,14 @@ return u".".join(result)+trailing_dot, len(input) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return Codec().encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return Codec().decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -203,5 +211,12 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='idna', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/iso8859_1.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_1.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_1.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-1.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_1 generated from 'MAPPINGS/ISO8859/8859-1.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-1', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_10.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_10.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_10.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-10.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_10 generated from 'MAPPINGS/ISO8859/8859-10.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-10', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_11.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_11.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_11.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-11.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_11 generated from 'MAPPINGS/ISO8859/8859-11.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-11', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_13.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_13.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_13.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-13.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_13 generated from 'MAPPINGS/ISO8859/8859-13.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-13', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_14.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_14.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_14.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-14.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_14 generated from 'MAPPINGS/ISO8859/8859-14.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-14', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_15.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_15.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_15.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-15.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_15 generated from 'MAPPINGS/ISO8859/8859-15.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-15', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_16.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_16.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_16.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-16.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_16 generated from 'MAPPINGS/ISO8859/8859-16.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-16', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_2.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_2.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_2.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-2.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_2 generated from 'MAPPINGS/ISO8859/8859-2.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-2', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_3.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_3.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_3.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-3.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_3 generated from 'MAPPINGS/ISO8859/8859-3.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-3', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_4.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_4.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_4.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-4.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_4 generated from 'MAPPINGS/ISO8859/8859-4.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-4', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_5.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_5.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_5.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-5.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_5 generated from 'MAPPINGS/ISO8859/8859-5.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-5', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_6.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_6.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_6.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-6.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_6 generated from 'MAPPINGS/ISO8859/8859-6.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-6', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_7.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_7.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_7.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-7.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_7 generated from 'MAPPINGS/ISO8859/8859-7.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-7', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_8.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_8.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_8.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-8.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_8 generated from 'MAPPINGS/ISO8859/8859-8.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-8', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/iso8859_9.py ============================================================================== --- python/branches/p3yk/Lib/encodings/iso8859_9.py (original) +++ python/branches/p3yk/Lib/encodings/iso8859_9.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/ISO8859/8859-9.TXT' with gencodec.py. +""" Python Character Mapping Codec iso8859_9 generated from 'MAPPINGS/ISO8859/8859-9.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-9', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/koi8_r.py ============================================================================== --- python/branches/p3yk/Lib/encodings/koi8_r.py (original) +++ python/branches/p3yk/Lib/encodings/koi8_r.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/MISC/KOI8-R.TXT' with gencodec.py. +""" Python Character Mapping Codec koi8_r generated from 'MAPPINGS/VENDORS/MISC/KOI8-R.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='koi8-r', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/koi8_u.py ============================================================================== --- python/branches/p3yk/Lib/encodings/koi8_u.py (original) +++ python/branches/p3yk/Lib/encodings/koi8_u.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/KOI8-U.TXT' with gencodec.py. +""" Python Character Mapping Codec koi8_u generated from 'python-mappings/KOI8-U.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='koi8-u', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/latin_1.py ============================================================================== --- python/branches/p3yk/Lib/encodings/latin_1.py (original) +++ python/branches/p3yk/Lib/encodings/latin_1.py Fri Apr 21 11:43:23 2006 @@ -17,6 +17,14 @@ encode = codecs.latin_1_encode decode = codecs.latin_1_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.latin_1_encode(input,self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.latin_1_decode(input,self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -31,5 +39,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='iso8859-1', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/mac_arabic.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_arabic.py (original) +++ python/branches/p3yk/Lib/encodings/mac_arabic.py Fri Apr 21 11:43:23 2006 @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-arabic', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/mac_centeuro.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_centeuro.py (original) +++ python/branches/p3yk/Lib/encodings/mac_centeuro.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CENTEURO.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_centeuro generated from 'MAPPINGS/VENDORS/APPLE/CENTEURO.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-centeuro', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_croatian.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_croatian.py (original) +++ python/branches/p3yk/Lib/encodings/mac_croatian.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CROATIAN.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_croatian generated from 'MAPPINGS/VENDORS/APPLE/CROATIAN.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-croatian', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_cyrillic.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_cyrillic.py (original) +++ python/branches/p3yk/Lib/encodings/mac_cyrillic.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_cyrillic generated from 'MAPPINGS/VENDORS/APPLE/CYRILLIC.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-cyrillic', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_farsi.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_farsi.py (original) +++ python/branches/p3yk/Lib/encodings/mac_farsi.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/FARSI.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_farsi generated from 'MAPPINGS/VENDORS/APPLE/FARSI.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-farsi', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_greek.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_greek.py (original) +++ python/branches/p3yk/Lib/encodings/mac_greek.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/GREEK.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_greek generated from 'MAPPINGS/VENDORS/APPLE/GREEK.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-greek', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_iceland.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_iceland.py (original) +++ python/branches/p3yk/Lib/encodings/mac_iceland.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ICELAND.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_iceland generated from 'MAPPINGS/VENDORS/APPLE/ICELAND.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-iceland', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_latin2.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_latin2.py (original) +++ python/branches/p3yk/Lib/encodings/mac_latin2.py Fri Apr 21 11:43:23 2006 @@ -14,13 +14,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_map) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-latin2', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/mac_roman.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_roman.py (original) +++ python/branches/p3yk/Lib/encodings/mac_roman.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ROMAN.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_roman generated from 'MAPPINGS/VENDORS/APPLE/ROMAN.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-roman', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_romanian.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_romanian.py (original) +++ python/branches/p3yk/Lib/encodings/mac_romanian.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/ROMANIAN.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_romanian generated from 'MAPPINGS/VENDORS/APPLE/ROMANIAN.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-romanian', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mac_turkish.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mac_turkish.py (original) +++ python/branches/p3yk/Lib/encodings/mac_turkish.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'MAPPINGS/VENDORS/APPLE/TURKISH.TXT' with gencodec.py. +""" Python Character Mapping Codec mac_turkish generated from 'MAPPINGS/VENDORS/APPLE/TURKISH.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mac-turkish', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/mbcs.py ============================================================================== --- python/branches/p3yk/Lib/encodings/mbcs.py (original) +++ python/branches/p3yk/Lib/encodings/mbcs.py Fri Apr 21 11:43:23 2006 @@ -18,6 +18,13 @@ encode = codecs.mbcs_encode decode = codecs.mbcs_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.mbcs_encode(input,self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.mbcs_decode(input,self.errors)[0] class StreamWriter(Codec,codecs.StreamWriter): pass @@ -32,5 +39,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='mbcs', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/palmos.py ============================================================================== --- python/branches/p3yk/Lib/encodings/palmos.py (original) +++ python/branches/p3yk/Lib/encodings/palmos.py Fri Apr 21 11:43:23 2006 @@ -15,6 +15,14 @@ def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_map) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -24,7 +32,15 @@ ### encodings module API def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='palmos', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/ptcp154.py ============================================================================== --- python/branches/p3yk/Lib/encodings/ptcp154.py (original) +++ python/branches/p3yk/Lib/encodings/ptcp154.py Fri Apr 21 11:43:23 2006 @@ -14,13 +14,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_map) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='ptcp154', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/punycode.py ============================================================================== --- python/branches/p3yk/Lib/encodings/punycode.py (original) +++ python/branches/p3yk/Lib/encodings/punycode.py Fri Apr 21 11:43:23 2006 @@ -197,18 +197,27 @@ ### Codec APIs class Codec(codecs.Codec): - def encode(self,input,errors='strict'): + def encode(self,input,errors='strict'): res = punycode_encode(input) return res, len(input) def decode(self,input,errors='strict'): - if errors not in ('strict', 'replace', 'ignore'): raise UnicodeError, "Unsupported error handling "+errors res = punycode_decode(input, errors) return res, len(input) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return punycode_encode(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + if errors not in ('strict', 'replace', 'ignore'): + raise UnicodeError, "Unsupported error handling "+errors + return punycode_decode(input, errors) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -218,5 +227,12 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='punycode', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/quopri_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/quopri_codec.py (original) +++ python/branches/p3yk/Lib/encodings/quopri_codec.py Fri Apr 21 11:43:23 2006 @@ -46,6 +46,14 @@ def decode(self, input,errors='strict'): return quopri_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return quopri_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return quopri_decode(input, self.errors)[0] + class StreamWriter(Codec, codecs.StreamWriter): pass @@ -55,4 +63,12 @@ # encodings module API def getregentry(): - return (quopri_encode, quopri_decode, StreamReader, StreamWriter) + return codecs.CodecInfo( + name='quopri', + encode=quopri_encode, + decode=quopri_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/raw_unicode_escape.py ============================================================================== --- python/branches/p3yk/Lib/encodings/raw_unicode_escape.py (original) +++ python/branches/p3yk/Lib/encodings/raw_unicode_escape.py Fri Apr 21 11:43:23 2006 @@ -17,6 +17,14 @@ encode = codecs.raw_unicode_escape_encode decode = codecs.raw_unicode_escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.raw_unicode_escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.raw_unicode_escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='raw-unicode-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/rot_13.py ============================================================================== --- python/branches/p3yk/Lib/encodings/rot_13.py (original) +++ python/branches/p3yk/Lib/encodings/rot_13.py Fri Apr 21 11:43:23 2006 @@ -14,13 +14,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_map) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_map)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,8 +36,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='rot-13', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) ### Decoding Map Modified: python/branches/p3yk/Lib/encodings/string_escape.py ============================================================================== --- python/branches/p3yk/Lib/encodings/string_escape.py (original) +++ python/branches/p3yk/Lib/encodings/string_escape.py Fri Apr 21 11:43:23 2006 @@ -12,6 +12,14 @@ encode = codecs.escape_encode decode = codecs.escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -19,5 +27,12 @@ pass def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='string-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/tis_620.py ============================================================================== --- python/branches/p3yk/Lib/encodings/tis_620.py (original) +++ python/branches/p3yk/Lib/encodings/tis_620.py Fri Apr 21 11:43:23 2006 @@ -1,4 +1,4 @@ -""" Python Character Mapping Codec generated from 'python-mappings/TIS-620.TXT' with gencodec.py. +""" Python Character Mapping Codec tis_620 generated from 'python-mappings/TIS-620.TXT' with gencodec.py. """#" @@ -9,13 +9,19 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): - return codecs.charmap_decode(input,errors,decoding_table) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_table)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -25,8 +31,15 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='tis-620', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) ### Decoding Table Modified: python/branches/p3yk/Lib/encodings/undefined.py ============================================================================== --- python/branches/p3yk/Lib/encodings/undefined.py (original) +++ python/branches/p3yk/Lib/encodings/undefined.py Fri Apr 21 11:43:23 2006 @@ -16,10 +16,18 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - raise UnicodeError, "undefined encoding" + raise UnicodeError("undefined encoding") def decode(self,input,errors='strict'): - raise UnicodeError, "undefined encoding" + raise UnicodeError("undefined encoding") + +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + raise UnicodeError("undefined encoding") + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + raise UnicodeError("undefined encoding") class StreamWriter(Codec,codecs.StreamWriter): pass @@ -30,5 +38,12 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='undefined', + encode=Codec().encode, + decode=Codec().decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/unicode_escape.py ============================================================================== --- python/branches/p3yk/Lib/encodings/unicode_escape.py (original) +++ python/branches/p3yk/Lib/encodings/unicode_escape.py Fri Apr 21 11:43:23 2006 @@ -17,6 +17,14 @@ encode = codecs.unicode_escape_encode decode = codecs.unicode_escape_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.unicode_escape_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.unicode_escape_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='unicode-escape', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/unicode_internal.py ============================================================================== --- python/branches/p3yk/Lib/encodings/unicode_internal.py (original) +++ python/branches/p3yk/Lib/encodings/unicode_internal.py Fri Apr 21 11:43:23 2006 @@ -17,6 +17,14 @@ encode = codecs.unicode_internal_encode decode = codecs.unicode_internal_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.unicode_internal_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return codecs.unicode_internal_decode(input, self.errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -26,5 +34,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='unicode-internal', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamwriter=StreamWriter, + streamreader=StreamReader, + ) Modified: python/branches/p3yk/Lib/encodings/utf_16.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_16.py (original) +++ python/branches/p3yk/Lib/encodings/utf_16.py Fri Apr 21 11:43:23 2006 @@ -15,6 +15,47 @@ def decode(input, errors='strict'): return codecs.utf_16_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + codecs.IncrementalEncoder.__init__(self, errors) + self.encoder = None + + def encode(self, input, final=False): + if self.encoder is None: + result = codecs.utf_16_encode(input, self.errors)[0] + if sys.byteorder == 'little': + self.encoder = codecs.utf_16_le_encode + else: + self.encoder = codecs.utf_16_be_encode + return result + return self.encoder(input, self.errors)[0] + + def reset(self): + codecs.IncrementalEncoder.reset(self) + self.encoder = None + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) + self.decoder = None + + def _buffer_decode(self, input, errors, final): + if self.decoder is None: + (output, consumed, byteorder) = \ + codecs.utf_16_ex_decode(input, errors, 0, final) + if byteorder == -1: + self.decoder = codecs.utf_16_le_decode + elif byteorder == 1: + self.decoder = codecs.utf_16_be_decode + elif consumed >= 2: + raise UnicodeError("UTF-16 stream does not start with BOM") + return (output, consumed) + return self.decoder(input, self.errors, final) + + def reset(self): + codecs.BufferedIncrementalDecoder.reset(self) + self.decoder = None + class StreamWriter(codecs.StreamWriter): def __init__(self, stream, errors='strict'): self.bom_written = False @@ -52,5 +93,12 @@ ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/utf_16_be.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_16_be.py (original) +++ python/branches/p3yk/Lib/encodings/utf_16_be.py Fri Apr 21 11:43:23 2006 @@ -15,6 +15,13 @@ def decode(input, errors='strict'): return codecs.utf_16_be_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_16_be_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_16_be_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_16_be_encode @@ -24,5 +31,12 @@ ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16-be', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/utf_16_le.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_16_le.py (original) +++ python/branches/p3yk/Lib/encodings/utf_16_le.py Fri Apr 21 11:43:23 2006 @@ -15,15 +15,28 @@ def decode(input, errors='strict'): return codecs.utf_16_le_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_16_le_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_16_le_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_16_le_encode class StreamReader(codecs.StreamReader): decode = codecs.utf_16_le_decode - ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-16-le', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/utf_7.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_7.py (original) +++ python/branches/p3yk/Lib/encodings/utf_7.py Fri Apr 21 11:43:23 2006 @@ -13,6 +13,14 @@ encode = codecs.utf_7_encode decode = codecs.utf_7_decode +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_7_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def _buffer_decode(self, input, errors, final): + return codecs.utf_7_decode(input, self.errors) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -22,5 +30,12 @@ ### encodings module API def getregentry(): - - return (Codec.encode,Codec.decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-7', + encode=Codec.encode, + decode=Codec.decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/utf_8.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_8.py (original) +++ python/branches/p3yk/Lib/encodings/utf_8.py Fri Apr 21 11:43:23 2006 @@ -15,6 +15,13 @@ def decode(input, errors='strict'): return codecs.utf_8_decode(input, errors, True) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.utf_8_encode(input, self.errors)[0] + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + _buffer_decode = codecs.utf_8_decode + class StreamWriter(codecs.StreamWriter): encode = codecs.utf_8_encode @@ -24,5 +31,12 @@ ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-8', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/utf_8_sig.py ============================================================================== --- python/branches/p3yk/Lib/encodings/utf_8_sig.py (original) +++ python/branches/p3yk/Lib/encodings/utf_8_sig.py Fri Apr 21 11:43:23 2006 @@ -22,6 +22,42 @@ (output, consumed) = codecs.utf_8_decode(input, errors, True) return (output, consumed+prefix) +class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + codecs.IncrementalEncoder.__init__(self, errors) + self.first = True + + def encode(self, input, final=False): + if self.first: + self.first = False + return codecs.BOM_UTF8 + codecs.utf_8_encode(input, errors)[0] + else: + return codecs.utf_8_encode(input, errors)[0] + + def reset(self): + codecs.IncrementalEncoder.reset(self) + self.first = True + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) + self.first = True + + def _buffer_decode(self, input, errors, final): + if self.first and codecs.BOM_UTF8.startswith(input): # might be a BOM + if len(input) < 3: + # not enough data to decide if this really is a BOM + # => try again on the next call + return (u"", 0) + (output, consumed) = codecs.utf_8_decode(input[3:], errors, final) + self.first = False + return (output, consumed+3) + return codecs.utf_8_decode(input, errors, final) + + def reset(self): + codecs.BufferedIncrementalDecoder.reset(self) + self.first = True + class StreamWriter(codecs.StreamWriter): def reset(self): codecs.StreamWriter.reset(self) @@ -53,5 +89,12 @@ ### encodings module API def getregentry(): - - return (encode,decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='utf-8-sig', + encode=encode, + decode=decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/uu_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/uu_codec.py (original) +++ python/branches/p3yk/Lib/encodings/uu_codec.py Fri Apr 21 11:43:23 2006 @@ -96,9 +96,18 @@ def encode(self,input,errors='strict'): return uu_encode(input,errors) + def decode(self,input,errors='strict'): return uu_decode(input,errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return uu_encode(input, errors)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + return uu_decode(input, errors)[0] + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -108,5 +117,12 @@ ### encodings module API def getregentry(): - - return (uu_encode,uu_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='uu', + encode=uu_encode, + decode=uu_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/encodings/zlib_codec.py ============================================================================== --- python/branches/p3yk/Lib/encodings/zlib_codec.py (original) +++ python/branches/p3yk/Lib/encodings/zlib_codec.py Fri Apr 21 11:43:23 2006 @@ -50,6 +50,16 @@ def decode(self, input, errors='strict'): return zlib_decode(input, errors) +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + assert self.errors == 'strict' + return zlib.compress(input) + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False): + assert self.errors == 'strict' + return zlib.decompress(input) + class StreamWriter(Codec,codecs.StreamWriter): pass @@ -59,5 +69,12 @@ ### encodings module API def getregentry(): - - return (zlib_encode,zlib_decode,StreamReader,StreamWriter) + return codecs.CodecInfo( + name='zlib', + encode=zlib_encode, + decode=zlib_decode, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, + ) Modified: python/branches/p3yk/Lib/logging/__init__.py ============================================================================== --- python/branches/p3yk/Lib/logging/__init__.py (original) +++ python/branches/p3yk/Lib/logging/__init__.py Fri Apr 21 11:43:23 2006 @@ -1058,13 +1058,16 @@ file name, line number and function name. """ f = currentframe().f_back - while 1: + rv = "(unknown file)", 0, "(unknown function)" + while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename == _srcfile: f = f.f_back continue - return filename, f.f_lineno, co.co_name + rv = (filename, f.f_lineno, co.co_name) + break + return rv def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None): """ Modified: python/branches/p3yk/Lib/test/regrtest.py ============================================================================== --- python/branches/p3yk/Lib/test/regrtest.py (original) +++ python/branches/p3yk/Lib/test/regrtest.py Fri Apr 21 11:43:23 2006 @@ -1136,9 +1136,6 @@ s = _expectations[sys.platform] self.expected = set(s.split()) - # this isn't a regularly run unit test, it is always skipped - self.expected.add('test_hashlib_speed') - if not os.path.supports_unicode_filenames: self.expected.add('test_pep277') Modified: python/branches/p3yk/Lib/test/test_StringIO.py ============================================================================== --- python/branches/p3yk/Lib/test/test_StringIO.py (original) +++ python/branches/p3yk/Lib/test/test_StringIO.py Fri Apr 21 11:43:23 2006 @@ -75,6 +75,13 @@ f.close() self.assertEqual(f.closed, True) + def test_isatty(self): + f = self.MODULE.StringIO() + self.assertRaises(TypeError, f.isatty, None) + self.assertEqual(f.isatty(), False) + f.close() + self.assertRaises(ValueError, f.isatty) + def test_iterator(self): eq = self.assertEqual unless = self.failUnless @@ -87,6 +94,8 @@ eq(line, self._line + '\n') i += 1 eq(i, 5) + self._fp.close() + self.assertRaises(ValueError, self._fp.next) class TestStringIO(TestGenericStringIO): MODULE = StringIO Modified: python/branches/p3yk/Lib/test/test___all__.py ============================================================================== --- python/branches/p3yk/Lib/test/test___all__.py (original) +++ python/branches/p3yk/Lib/test/test___all__.py Fri Apr 21 11:43:23 2006 @@ -5,8 +5,6 @@ import sys import warnings -warnings.filterwarnings("ignore", ".* 'pre' .*", DeprecationWarning, - r'pre$') warnings.filterwarnings("ignore", ".* regsub .*", DeprecationWarning, r'^regsub$') warnings.filterwarnings("ignore", @@ -122,7 +120,6 @@ self.check_all("poplib") self.check_all("posixpath") self.check_all("pprint") - self.check_all("pre") # deprecated self.check_all("profile") self.check_all("pstats") self.check_all("pty") Modified: python/branches/p3yk/Lib/test/test_codecs.py ============================================================================== --- python/branches/p3yk/Lib/test/test_codecs.py (original) +++ python/branches/p3yk/Lib/test/test_codecs.py Fri Apr 21 11:43:23 2006 @@ -41,6 +41,33 @@ self.assertEqual(r.bytebuffer, "") self.assertEqual(r.charbuffer, u"") + # do the check again, this time using a incremental decoder + d = codecs.getincrementaldecoder(self.encoding)() + result = u"" + for (c, partialresult) in zip(input.encode(self.encoding), partialresults): + result += d.decode(c) + self.assertEqual(result, partialresult) + # check that there's nothing left in the buffers + self.assertEqual(d.decode("", True), u"") + self.assertEqual(d.buffer, "") + + # Check whether the rest method works properly + d.reset() + result = u"" + for (c, partialresult) in zip(input.encode(self.encoding), partialresults): + result += d.decode(c) + self.assertEqual(result, partialresult) + # check that there's nothing left in the buffers + self.assertEqual(d.decode("", True), u"") + self.assertEqual(d.buffer, "") + + # check iterdecode() + encoded = input.encode(self.encoding) + self.assertEqual( + input, + u"".join(codecs.iterdecode(encoded, self.encoding)) + ) + def test_readline(self): def getreader(input): stream = StringIO.StringIO(input.encode(self.encoding)) @@ -977,6 +1004,12 @@ def test_basics(self): s = u"abc123" # all codecs should be able to encode these for encoding in all_unicode_encodings: + name = codecs.lookup(encoding).name + if encoding.endswith("_codec"): + name += "_codec" + elif encoding == "latin_1": + name = "latin_1" + self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) (bytes, size) = codecs.getencoder(encoding)(s) if encoding != "unicode_internal": self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding)) @@ -999,6 +1032,30 @@ decodedresult += reader.read() self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + # check incremental decoder/encoder and iterencode()/iterdecode() + try: + encoder = codecs.getincrementalencoder(encoding)() + except LookupError: # no IncrementalEncoder + pass + else: + # check incremental decoder/encoder + encodedresult = "" + for c in s: + encodedresult += encoder.encode(c) + decoder = codecs.getincrementaldecoder(encoding)() + decodedresult = u"" + for c in encodedresult: + decodedresult += decoder.decode(c) + self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding)) + + # check iterencode()/iterdecode() + result = u"".join(codecs.iterdecode(codecs.iterencode(s, encoding), encoding)) + self.assertEqual(result, s, "%r != %r (encoding=%r)" % (result, s, encoding)) + + # check iterencode()/iterdecode() with empty string + result = u"".join(codecs.iterdecode(codecs.iterencode(u"", encoding), encoding)) + self.assertEqual(result, u"") + def test_seek(self): # all codecs should be able to encode these s = u"%s\n%s\n" % (100*u"abc123", 100*u"def456") Deleted: /python/branches/p3yk/Lib/test/test_hashlib_speed.py ============================================================================== --- /python/branches/p3yk/Lib/test/test_hashlib_speed.py Fri Apr 21 11:43:23 2006 +++ (empty file) @@ -1,92 +0,0 @@ - -import sys, time -import hashlib -from test import test_support - - -def creatorFunc(): - raise RuntimeError, "eek, creatorFunc not overridden" - - -def test_scaled_msg(scale, name): - - iterations = 106201/scale * 20 - longStr = 'Z'*scale - - localCF = creatorFunc - start = time.time() - for f in xrange(iterations): - x = localCF(longStr).digest() - end = time.time() - - print ('%2.2f' % (end-start)), "seconds", iterations, "x", len(longStr), "bytes", name - -def test_create(): - start = time.time() - for f in xrange(20000): - d = creatorFunc() - end = time.time() - - print ('%2.2f' % (end-start)), "seconds", '[20000 creations]' - -def test_zero(): - start = time.time() - for f in xrange(20000): - x = creatorFunc().digest() - end = time.time() - - print ('%2.2f' % (end-start)), "seconds", '[20000 "" digests]' - - - -### this 'test' is not normally run. skip it if the test runner finds it -if __name__ != '__main__': - raise test_support.TestSkipped, "not a unit test (stand alone benchmark)" - -hName = sys.argv[1] - -# -# setup our creatorFunc to test the requested hash -# -if hName in ('_md5', '_sha'): - exec 'import '+hName - exec 'creatorFunc = '+hName+'.new' - print "testing speed of old", hName, "legacy interface" -elif hName == '_hashlib' and len(sys.argv) > 3: - import _hashlib - exec 'creatorFunc = _hashlib.%s' % sys.argv[2] - print "testing speed of _hashlib.%s" % sys.argv[2], getattr(_hashlib, sys.argv[2]) -elif hName == '_hashlib' and len(sys.argv) == 3: - import _hashlib - exec 'creatorFunc = lambda x=_hashlib.new : x(%r)' % sys.argv[2] - print "testing speed of _hashlib.new(%r)" % sys.argv[2] -elif hasattr(hashlib, hName) and callable(getattr(hashlib, hName)): - creatorFunc = getattr(hashlib, hName) - print "testing speed of hashlib."+hName, getattr(hashlib, hName) -else: - exec "creatorFunc = lambda x=hashlib.new : x(%r)" % hName - print "testing speed of hashlib.new(%r)" % hName - -try: - test_create() -except ValueError: - print - print "pass argument(s) naming the hash to run a speed test on:" - print " '_md5' and '_sha' test the legacy builtin md5 and sha" - print " '_hashlib' 'openssl_hName' 'fast' tests the builtin _hashlib" - print " '_hashlib' 'hName' tests builtin _hashlib.new(shaFOO)" - print " 'hName' tests the hashlib.hName() implementation if it exists" - print " otherwise it uses hashlib.new(hName)." - print - raise - -test_zero() -test_scaled_msg(scale=106201, name='[huge data]') -test_scaled_msg(scale=10620, name='[large data]') -test_scaled_msg(scale=1062, name='[medium data]') -test_scaled_msg(scale=424, name='[4*small data]') -test_scaled_msg(scale=336, name='[3*small data]') -test_scaled_msg(scale=212, name='[2*small data]') -test_scaled_msg(scale=106, name='[small data]') -test_scaled_msg(scale=creatorFunc().digest_size, name='[digest_size data]') -test_scaled_msg(scale=10, name='[tiny data]') Modified: python/branches/p3yk/Makefile.pre.in ============================================================================== --- python/branches/p3yk/Makefile.pre.in (original) +++ python/branches/p3yk/Makefile.pre.in Fri Apr 21 11:43:23 2006 @@ -974,6 +974,8 @@ find . -name '*.o' -exec rm -f {} ';' find . -name '*.s[ol]' -exec rm -f {} ';' find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' + find $(srcdir) -name 'fficonfig.h' -exec rm -f {} ';' + find $(srcdir) -name 'fficonfig.py' -exec rm -f {} ';' clobber: clean -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ Modified: python/branches/p3yk/Modules/_ctypes/_ctypes.c ============================================================================== --- python/branches/p3yk/Modules/_ctypes/_ctypes.c (original) +++ python/branches/p3yk/Modules/_ctypes/_ctypes.c Fri Apr 21 11:43:23 2006 @@ -3674,7 +3674,11 @@ if (cache == NULL) return NULL; } +#if (PY_VERSION_HEX < 0x02050000) + key = Py_BuildValue("(Oi)", itemtype, length); +#else key = Py_BuildValue("(On)", itemtype, length); +#endif if (!key) return NULL; result = PyDict_GetItem(cache, key); @@ -3698,7 +3702,11 @@ #endif result = PyObject_CallFunction((PyObject *)&ArrayType_Type, +#if (PY_VERSION_HEX < 0x02050000) + "s(O){s:i,s:O}", +#else "s(O){s:n,s:O}", +#endif name, &Array_Type, "_length_", Modified: python/branches/p3yk/Modules/_ctypes/cfield.c ============================================================================== --- python/branches/p3yk/Modules/_ctypes/cfield.c (original) +++ python/branches/p3yk/Modules/_ctypes/cfield.c Fri Apr 21 11:43:23 2006 @@ -250,11 +250,21 @@ name = ((PyTypeObject *)self->proto)->tp_name; if (bits) - result = PyString_FromFormat("", - name, (int)self->offset, size, bits); + result = PyString_FromFormat( +#if (PY_VERSION_HEX < 0x02050000) + "", +#else + "", +#endif + name, self->offset, size, bits); else - result = PyString_FromFormat("", - name, (int)self->offset, size); + result = PyString_FromFormat( +#if (PY_VERSION_HEX < 0x02050000) + "", +#else + "", +#endif + name, self->offset, size); return result; } Modified: python/branches/p3yk/Modules/_ctypes/ctypes.h ============================================================================== --- python/branches/p3yk/Modules/_ctypes/ctypes.h (original) +++ python/branches/p3yk/Modules/_ctypes/ctypes.h Fri Apr 21 11:43:23 2006 @@ -1,5 +1,18 @@ /******************************************************************/ +#if (PY_VERSION_HEX < 0x02050000) +typedef int Py_ssize_t; +#define lenfunc inquiry +#define readbufferproc getreadbufferproc +#define writebufferproc getwritebufferproc +#define segcountproc getsegcountproc +#define charbufferproc getcharbufferproc +#define ssizeargfunc intargfunc +#define ssizessizeargfunc intintargfunc +#define ssizeobjargproc intobjargproc +#define ssizessizeobjargproc intintobjargproc +#endif + #ifndef MS_WIN32 #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) Modified: python/branches/p3yk/Modules/_testcapimodule.c ============================================================================== --- python/branches/p3yk/Modules/_testcapimodule.c (original) +++ python/branches/p3yk/Modules/_testcapimodule.c Fri Apr 21 11:43:23 2006 @@ -522,6 +522,18 @@ return Py_None; } +/* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */ + +static PyObject * +test_null_strings(PyObject *self) +{ + PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL); + PyObject *tuple = PyTuple_Pack(2, o1, o2); + Py_XDECREF(o1); + Py_XDECREF(o2); + return tuple; +} + static PyObject * raise_exception(PyObject *self, PyObject *args) { @@ -597,6 +609,7 @@ {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, {"test_long_numbits", (PyCFunction)test_long_numbits, METH_NOARGS}, {"test_k_code", (PyCFunction)test_k_code, METH_NOARGS}, + {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, {"getargs_b", (PyCFunction)getargs_b, METH_VARARGS}, {"getargs_B", (PyCFunction)getargs_B, METH_VARARGS}, Modified: python/branches/p3yk/Modules/cStringIO.c ============================================================================== --- python/branches/p3yk/Modules/cStringIO.c (original) +++ python/branches/p3yk/Modules/cStringIO.c Fri Apr 21 11:43:23 2006 @@ -144,7 +144,8 @@ static PyObject * IO_isatty(IOobject *self, PyObject *unused) { - Py_INCREF(Py_False); + if (!IO__opencheck(self)) return NULL; + Py_INCREF(Py_False); return Py_False; } Modified: python/branches/p3yk/Modules/main.c ============================================================================== --- python/branches/p3yk/Modules/main.c (original) +++ python/branches/p3yk/Modules/main.c Fri Apr 21 11:43:23 2006 @@ -130,27 +130,42 @@ } } -/* Get the path to a top-level module */ -static struct filedescr * FindModule(const char *module, - FILE **fp, char **filename) -{ - struct filedescr *fdescr = NULL; - *fp = NULL; - *filename = malloc(MAXPATHLEN); - - if (*filename == NULL) - return NULL; - /* Find the actual module source code */ - fdescr = _PyImport_FindModule(module, NULL, - *filename, MAXPATHLEN, fp, NULL); - - if (fdescr == NULL) { - free(*filename); - *filename = NULL; +static int RunModule(char *module) +{ + PyObject *runpy, *runmodule, *runargs, *result; + runpy = PyImport_ImportModule("runpy"); + if (runpy == NULL) { + fprintf(stderr, "Could not import runpy module\n"); + return -1; + } + runmodule = PyObject_GetAttrString(runpy, "run_module"); + if (runmodule == NULL) { + fprintf(stderr, "Could not access runpy.run_module\n"); + Py_DECREF(runpy); + return -1; + } + runargs = Py_BuildValue("sOsO", module, + Py_None, "__main__", Py_True); + if (runargs == NULL) { + fprintf(stderr, + "Could not create arguments for runpy.run_module\n"); + Py_DECREF(runpy); + Py_DECREF(runmodule); + return -1; + } + result = PyObject_Call(runmodule, runargs, NULL); + if (result == NULL) { + PyErr_Print(); + } + Py_DECREF(runpy); + Py_DECREF(runmodule); + Py_DECREF(runargs); + if (result == NULL) { + return -1; } - - return fdescr; + Py_DECREF(result); + return 0; } /* Main program */ @@ -410,28 +425,9 @@ } if (module != NULL) { - /* Backup _PyOS_optind and find the real file */ - struct filedescr *fdescr = NULL; + /* Backup _PyOS_optind and force sys.arv[0] = module */ _PyOS_optind--; - if ((fdescr = FindModule(module, &fp, &filename))) { - argv[_PyOS_optind] = filename; - } else { - fprintf(stderr, "%s: module %s not found\n", - argv[0], module); - return 2; - } - if (!fp) { - fprintf(stderr, - "%s: module %s has no associated file\n", - argv[0], module); - return 2; - } - if (!_PyImport_IsScript(fdescr)) { - fprintf(stderr, - "%s: module %s not usable as script\n (%s)\n", - argv[0], module, filename); - return 2; - } + argv[_PyOS_optind] = module; } PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind); @@ -450,9 +446,8 @@ sts = PyRun_SimpleStringFlags(command, &cf) != 0; free(command); } else if (module) { - sts = PyRun_AnyFileExFlags(fp, filename, 1, &cf) != 0; + sts = RunModule(module); free(module); - free(filename); } else { if (filename == NULL && stdin_is_interactive) { Modified: python/branches/p3yk/Modules/xxmodule.c ============================================================================== --- python/branches/p3yk/Modules/xxmodule.c (original) +++ python/branches/p3yk/Modules/xxmodule.c Fri Apr 21 11:43:23 2006 @@ -197,18 +197,6 @@ return Py_None; } -/* Example passing NULLs to PyObject_Str(NULL) and PyObject_Unicode(NULL). */ - -static PyObject * -xx_null(PyObject *self, PyObject *noargs) -{ - PyObject *o1 = PyObject_Str(NULL), *o2 = PyObject_Unicode(NULL); - PyObject *tuple = PyTuple_Pack(2, o1, o2); - Py_XDECREF(o1); - Py_XDECREF(o2); - return tuple; -} - /* Test bad format character */ static PyObject * @@ -343,8 +331,6 @@ PyDoc_STR("new() -> new Xx object")}, {"bug", xx_bug, METH_VARARGS, PyDoc_STR("bug(o) -> None")}, - {"null", xx_null, METH_NOARGS, - PyDoc_STR("null(o) -> ('NULL', u'NULL')")}, {NULL, NULL} /* sentinel */ }; Modified: python/branches/p3yk/Objects/obmalloc.c ============================================================================== --- python/branches/p3yk/Objects/obmalloc.c (original) +++ python/branches/p3yk/Objects/obmalloc.c Fri Apr 21 11:43:23 2006 @@ -217,16 +217,16 @@ * I don't care if these are defined in or elsewhere. Axiom. */ #undef uchar -#define uchar unsigned char /* assuming == 8 bits */ +#define uchar unsigned char /* assuming == 8 bits */ #undef uint -#define uint unsigned int /* assuming >= 16 bits */ +#define uint unsigned int /* assuming >= 16 bits */ #undef ulong -#define ulong unsigned long /* assuming >= 32 bits */ +#define ulong unsigned long /* assuming >= 32 bits */ #undef uptr -#define uptr Py_uintptr_t +#define uptr Py_uintptr_t /* When you say memory, my mind reasons in terms of (pointers to) blocks */ typedef uchar block; @@ -246,6 +246,47 @@ typedef struct pool_header *poolp; +/* Record keeping for arenas. */ +struct arena_object { + /* The address of the arena, as returned by malloc. Note that 0 + * will never be returned by a successful malloc, and is used + * here to mark an arena_object that doesn't correspond to an + * allocated arena. + */ + uptr address; + + /* Pool-aligned pointer to the next pool to be carved off. */ + block* pool_address; + + /* The number of available pools in the arena: free pools + never- + * allocated pools. + */ + uint nfreepools; + + /* The total number of pools in the arena, whether or not available. */ + uint ntotalpools; + + /* Singly-linked list of available pools. */ + struct pool_header* freepools; + + /* Whenever this arena_object is not associated with an allocated + * arena, the nextarena member is used to link all unassociated + * arena_objects in the singly-linked `unused_arena_objects` list. + * The prevarena member is unused in this case. + * + * When this arena_object is associated with an allocated arena + * with at least one available pool, both members are used in the + * doubly-linked `usable_arenas` list, which is maintained in + * increasing order of `nfreepools` values. + * + * Else this arena_object is associated with an allocated arena + * all of whose pools are in use. `nextarena` and `prevarena` + * are both meaningless in this case. + */ + struct arena_object* nextarena; + struct arena_object* prevarena; +}; + #undef ROUNDUP #define ROUNDUP(x) (((x) + ALIGNMENT_MASK) & ~ALIGNMENT_MASK) #define POOL_OVERHEAD ROUNDUP(sizeof(struct pool_header)) @@ -277,8 +318,9 @@ usedpools[0] corresponds to blocks of size 8, usedpools[2] to blocks of size 16, and so on: index 2*i <-> blocks of size (i+1)< 8 */ }; -/* - * Free (cached) pools +/*========================================================================== +Arena management. + +`arenas` is a vector of arena_objects. It contains maxarenas entries, some of +which may not be currently used (== they're arena_objects that aren't +currently associated with an allocated arena). Note that arenas proper are +separately malloc'ed. + +Prior to Python 2.5, arenas were never free()'ed. Starting with Python 2.5, +we do try to free() arenas, and use some mild heuristic strategies to increase +the likelihood that arenas eventually can be freed. + +unused_arena_objects + + This is a singly-linked list of the arena_objects that are currently not + being used (no arena is associated with them). Objects are taken off the + head of the list in new_arena(), and are pushed on the head of the list in + PyObject_Free() when the arena is empty. Key invariant: an arena_object + is on this list if and only if its .address member is 0. + +usable_arenas + + This is a doubly-linked list of the arena_objects associated with arenas + that have pools available. These pools are either waiting to be reused, + or have not been used before. The list is sorted to have the most- + allocated arenas first (ascending order based on the nfreepools member). + This means that the next allocation will come from a heavily used arena, + which gives the nearly empty arenas a chance to be returned to the system. + In my unscientific tests this dramatically improved the number of arenas + that could be freed. + +Note that an arena_object associated with an arena all of whose pools are +currently in use isn't on either list. +*/ + +/* Array of objects used to track chunks of memory (arenas). */ +static struct arena_object* arenas = NULL; +/* Number of slots currently allocated in the `arenas` vector. */ +static uint maxarenas = 0; + +/* The head of the singly-linked, NULL-terminated list of available + * arena_objects. */ -static poolp freepools = NULL; /* free list for cached pools */ +static struct arena_object* unused_arena_objects = NULL; -/*==========================================================================*/ -/* Arena management. */ +/* The head of the doubly-linked, NULL-terminated at each end, list of + * arena_objects associated with arenas that have pools available. + */ +static struct arena_object* usable_arenas = NULL; -/* arenas is a vector of arena base addresses, in order of allocation time. - * arenas currently contains narenas entries, and has space allocated - * for at most maxarenas entries. - * - * CAUTION: See the long comment block about thread safety in new_arena(): - * the code currently relies in deep ways on that this vector only grows, - * and only grows by appending at the end. For now we never return an arena - * to the OS. +/* How many arena_objects do we initially allocate? + * 16 = can allocate 16 arenas = 16 * ARENA_SIZE = 4MB before growing the + * `arenas` vector. */ -static uptr *volatile arenas = NULL; /* the pointer itself is volatile */ -static volatile uint narenas = 0; -static uint maxarenas = 0; +#define INITIAL_ARENA_OBJECTS 16 -/* Number of pools still available to be allocated in the current arena. */ -static uint nfreepools = 0; +/* Number of arenas allocated that haven't been free()'d. */ +static ulong narenas_currently_allocated = 0; -/* Free space start address in current arena. This is pool-aligned. */ -static block *arenabase = NULL; +#ifdef PYMALLOC_DEBUG +/* Total number of times malloc() called to allocate an arena. */ +static ulong ntimes_arena_allocated = 0; +/* High water mark (max value ever seen) for narenas_currently_allocated. */ +static ulong narenas_highwater = 0; +#endif -/* Allocate a new arena and return its base address. If we run out of - * memory, return NULL. +/* Allocate a new arena. If we run out of memory, return NULL. Else + * allocate a new arena, and return the address of an arena_object + * describing the new arena. It's expected that the caller will set + * `usable_arenas` to the return value. */ -static block * +static struct arena_object* new_arena(void) { + struct arena_object* arenaobj; uint excess; /* number of bytes above pool alignment */ - block *bp = (block *)malloc(ARENA_SIZE); - if (bp == NULL) - return NULL; #ifdef PYMALLOC_DEBUG if (Py_GETENV("PYTHONMALLOCSTATS")) _PyObject_DebugMallocStats(); #endif + if (unused_arena_objects == NULL) { + uint i; + uint numarenas; + size_t nbytes; - /* arenabase <- first pool-aligned address in the arena - nfreepools <- number of whole pools that fit after alignment */ - arenabase = bp; - nfreepools = ARENA_SIZE / POOL_SIZE; - assert(POOL_SIZE * nfreepools == ARENA_SIZE); - excess = (uint) ((Py_uintptr_t)bp & POOL_SIZE_MASK); - if (excess != 0) { - --nfreepools; - arenabase += POOL_SIZE - excess; - } + /* Double the number of arena objects on each allocation. + * Note that it's possible for `numarenas` to overflow. + */ + numarenas = maxarenas ? maxarenas << 1 : INITIAL_ARENA_OBJECTS; + if (numarenas <= maxarenas) + return NULL; /* overflow */ + nbytes = numarenas * sizeof(*arenas); + if (nbytes / sizeof(*arenas) != numarenas) + return NULL; /* overflow */ + arenaobj = realloc(arenas, nbytes); + if (arenaobj == NULL) + return NULL; + arenas = arenaobj; + + /* We might need to fix pointers that were copied. However, + * new_arena only gets called when all the pages in the + * previous arenas are full. Thus, there are *no* pointers + * into the old array. Thus, we don't have to worry about + * invalid pointers. Just to be sure, some asserts: + */ + assert(usable_arenas == NULL); + assert(unused_arena_objects == NULL); - /* Make room for a new entry in the arenas vector. */ - if (arenas == NULL) { - assert(narenas == 0 && maxarenas == 0); - arenas = (uptr *)malloc(16 * sizeof(*arenas)); - if (arenas == NULL) - goto error; - maxarenas = 16; + /* Put the new arenas on the unused_arena_objects list. */ + for (i = maxarenas; i < numarenas; ++i) { + arenas[i].address = 0; /* mark as unassociated */ + arenas[i].nextarena = i < numarenas - 1 ? + &arenas[i+1] : NULL; + } + + /* Update globals. */ + unused_arena_objects = &arenas[maxarenas]; + maxarenas = numarenas; } - else if (narenas == maxarenas) { - /* Grow arenas. - * - * Exceedingly subtle: Someone may be calling the pymalloc - * free via PyMem_{DEL, Del, FREE, Free} without holding the - *.GIL. Someone else may simultaneously be calling the - * pymalloc malloc while holding the GIL via, e.g., - * PyObject_New. Now the pymalloc free may index into arenas - * for an address check, while the pymalloc malloc calls - * new_arena and we end up here to grow a new arena *and* - * grow the arenas vector. If the value for arenas pymalloc - * free picks up "vanishes" during this resize, anything may - * happen, and it would be an incredibly rare bug. Therefore - * the code here takes great pains to make sure that, at every - * moment, arenas always points to an intact vector of - * addresses. It doesn't matter whether arenas points to a - * wholly up-to-date vector when pymalloc free checks it in - * this case, because the only legal (and that even this is - * legal is debatable) way to call PyMem_{Del, etc} while not - * holding the GIL is if the memory being released is not - * object memory, i.e. if the address check in pymalloc free - * is supposed to fail. Having an incomplete vector can't - * make a supposed-to-fail case succeed by mistake (it could - * only make a supposed-to-succeed case fail by mistake). - * - * In addition, without a lock we can't know for sure when - * an old vector is no longer referenced, so we simply let - * old vectors leak. - * - * And on top of that, since narenas and arenas can't be - * changed as-a-pair atomically without a lock, we're also - * careful to declare them volatile and ensure that we change - * arenas first. This prevents another thread from picking - * up an narenas value too large for the arenas value it - * reads up (arenas never shrinks). - * - * Read the above 50 times before changing anything in this - * block. + + /* Take the next available arena object off the head of the list. */ + assert(unused_arena_objects != NULL); + arenaobj = unused_arena_objects; + unused_arena_objects = arenaobj->nextarena; + assert(arenaobj->address == 0); + arenaobj->address = (uptr)malloc(ARENA_SIZE); + if (arenaobj->address == 0) { + /* The allocation failed: return NULL after putting the + * arenaobj back. */ - uptr *p; - uint newmax = maxarenas << 1; - if (newmax <= maxarenas) /* overflow */ - goto error; - p = (uptr *)malloc(newmax * sizeof(*arenas)); - if (p == NULL) - goto error; - memcpy(p, arenas, narenas * sizeof(*arenas)); - arenas = p; /* old arenas deliberately leaked */ - maxarenas = newmax; + arenaobj->nextarena = unused_arena_objects; + unused_arena_objects = arenaobj; + return NULL; } - /* Append the new arena address to arenas. */ - assert(narenas < maxarenas); - arenas[narenas] = (uptr)bp; - ++narenas; /* can't overflow, since narenas < maxarenas before */ - return bp; + ++narenas_currently_allocated; +#ifdef PYMALLOC_DEBUG + ++ntimes_arena_allocated; + if (narenas_currently_allocated > narenas_highwater) + narenas_highwater = narenas_currently_allocated; +#endif + arenaobj->freepools = NULL; + /* pool_address <- first pool-aligned address in the arena + nfreepools <- number of whole pools that fit after alignment */ + arenaobj->pool_address = (block*)arenaobj->address; + arenaobj->nfreepools = ARENA_SIZE / POOL_SIZE; + assert(POOL_SIZE * arenaobj->nfreepools == ARENA_SIZE); + excess = (uint)(arenaobj->address & POOL_SIZE_MASK); + if (excess != 0) { + --arenaobj->nfreepools; + arenaobj->pool_address += POOL_SIZE - excess; + } + arenaobj->ntotalpools = arenaobj->nfreepools; -error: - free(bp); - nfreepools = 0; - return NULL; + return arenaobj; } -/* Return true if and only if P is an address that was allocated by - * pymalloc. I must be the index into arenas that the address claims - * to come from. - * - * Tricky: Letting B be the arena base address in arenas[I], P belongs to the - * arena if and only if - * B <= P < B + ARENA_SIZE - * Subtracting B throughout, this is true iff - * 0 <= P-B < ARENA_SIZE - * By using unsigned arithmetic, the "0 <=" half of the test can be skipped. - * - * Obscure: A PyMem "free memory" function can call the pymalloc free or - * realloc before the first arena has been allocated. arenas is still - * NULL in that case. We're relying on that narenas is also 0 in that case, - * so the (I) < narenas must be false, saving us from trying to index into - * a NULL arenas. - */ -#define Py_ADDRESS_IN_RANGE(P, POOL) \ - ((POOL)->arenaindex < narenas && \ - (uptr)(P) - arenas[(POOL)->arenaindex] < (uptr)ARENA_SIZE) +/* +Py_ADDRESS_IN_RANGE(P, POOL) + +Return true if and only if P is an address that was allocated by pymalloc. +POOL must be the pool address associated with P, i.e., POOL = POOL_ADDR(P) +(the caller is asked to compute this because the macro expands POOL more than +once, and for efficiency it's best for the caller to assign POOL_ADDR(P) to a +variable and pass the latter to the macro; because Py_ADDRESS_IN_RANGE is +called on every alloc/realloc/free, micro-efficiency is important here). + +Tricky: Let B be the arena base address associated with the pool, B = +arenas[(POOL)->arenaindex].address. Then P belongs to the arena if and only if + + B <= P < B + ARENA_SIZE + +Subtracting B throughout, this is true iff + + 0 <= P-B < ARENA_SIZE + +By using unsigned arithmetic, the "0 <=" half of the test can be skipped. + +Obscure: A PyMem "free memory" function can call the pymalloc free or realloc +before the first arena has been allocated. `arenas` is still NULL in that +case. We're relying on that maxarenas is also 0 in that case, so that +(POOL)->arenaindex < maxarenas must be false, saving us from trying to index +into a NULL arenas. + +Details: given P and POOL, the arena_object corresponding to P is AO = +arenas[(POOL)->arenaindex]. Suppose obmalloc controls P. Then (barring wild +stores, etc), POOL is the correct address of P's pool, AO.address is the +correct base address of the pool's arena, and P must be within ARENA_SIZE of +AO.address. In addition, AO.address is not 0 (no arena can start at address 0 +(NULL)). Therefore Py_ADDRESS_IN_RANGE correctly reports that obmalloc +controls P. + +Now suppose obmalloc does not control P (e.g., P was obtained via a direct +call to the system malloc() or realloc()). (POOL)->arenaindex may be anything +in this case -- it may even be uninitialized trash. If the trash arenaindex +is >= maxarenas, the macro correctly concludes at once that obmalloc doesn't +control P. + +Else arenaindex is < maxarena, and AO is read up. If AO corresponds to an +allocated arena, obmalloc controls all the memory in slice AO.address : +AO.address+ARENA_SIZE. By case assumption, P is not controlled by obmalloc, +so P doesn't lie in that slice, so the macro correctly reports that P is not +controlled by obmalloc. + +Finally, if P is not controlled by obmalloc and AO corresponds to an unused +arena_object (one not currently associated with an allocated arena), +AO.address is 0, and the second test in the macro reduces to: + + P < ARENA_SIZE + +If P >= ARENA_SIZE (extremely likely), the macro again correctly concludes +that P is not controlled by obmalloc. However, if P < ARENA_SIZE, this part +of the test still passes, and the third clause (AO.address != 0) is necessary +to get the correct result: AO.address is 0 in this case, so the macro +correctly reports that P is not controlled by obmalloc (despite that P lies in +slice AO.address : AO.address + ARENA_SIZE). + +Note: The third (AO.address != 0) clause was added in Python 2.5. Before +2.5, arenas were never free()'ed, and an arenaindex < maxarena always +corresponded to a currently-allocated arena, so the "P is not controlled by +obmalloc, AO corresponds to an unused arena_object, and P < ARENA_SIZE" case +was impossible. + +Note that the logic is excruciating, and reading up possibly uninitialized +memory when P is not controlled by obmalloc (to get at (POOL)->arenaindex) +creates problems for some memory debuggers. The overwhelming advantage is +that this test determines whether an arbitrary address is controlled by +obmalloc in a small constant time, independent of the number of arenas +obmalloc controls. Since this test is needed at every entry point, it's +extremely desirable that it be this fast. +*/ +#define Py_ADDRESS_IN_RANGE(P, POOL) \ + ((POOL)->arenaindex < maxarenas && \ + (uptr)(P) - arenas[(POOL)->arenaindex].address < (uptr)ARENA_SIZE && \ + arenas[(POOL)->arenaindex].address != 0) + /* This is only useful when running memory debuggers such as * Purify or Valgrind. Uncomment to use. @@ -599,7 +733,7 @@ /* * Most frequent paths first */ - size = (uint )(nbytes - 1) >> ALIGNMENT_SHIFT; + size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT; pool = usedpools[size + size]; if (pool != pool->nextpool) { /* @@ -614,22 +748,18 @@ return (void *)bp; } /* - * Reached the end of the free list, try to extend it + * Reached the end of the free list, try to extend it. */ if (pool->nextoffset <= pool->maxnextoffset) { - /* - * There is room for another block - */ - pool->freeblock = (block *)pool + + /* There is room for another block. */ + pool->freeblock = (block*)pool + pool->nextoffset; pool->nextoffset += INDEX2SIZE(size); *(block **)(pool->freeblock) = NULL; UNLOCK(); return (void *)bp; } - /* - * Pool is full, unlink from used pools - */ + /* Pool is full, unlink from used pools. */ next = pool->nextpool; pool = pool->prevpool; next->prevpool = pool; @@ -637,19 +767,68 @@ UNLOCK(); return (void *)bp; } - /* - * Try to get a cached free pool + + /* There isn't a pool of the right size class immediately + * available: use a free pool. */ - pool = freepools; + if (usable_arenas == NULL) { + /* No arena has a free pool: allocate a new arena. */ +#ifdef WITH_MEMORY_LIMITS + if (narenas_currently_allocated >= MAX_ARENAS) { + UNLOCK(); + goto redirect; + } +#endif + usable_arenas = new_arena(); + if (usable_arenas == NULL) { + UNLOCK(); + goto redirect; + } + usable_arenas->nextarena = + usable_arenas->prevarena = NULL; + } + assert(usable_arenas->address != 0); + + /* Try to get a cached free pool. */ + pool = usable_arenas->freepools; if (pool != NULL) { - /* - * Unlink from cached pools + /* Unlink from cached pools. */ + usable_arenas->freepools = pool->nextpool; + + /* This arena already had the smallest nfreepools + * value, so decreasing nfreepools doesn't change + * that, and we don't need to rearrange the + * usable_arenas list. However, if the arena has + * become wholly allocated, we need to remove its + * arena_object from usable_arenas. */ - freepools = pool->nextpool; + --usable_arenas->nfreepools; + if (usable_arenas->nfreepools == 0) { + /* Wholly allocated: remove. */ + assert(usable_arenas->freepools == NULL); + assert(usable_arenas->nextarena == NULL || + usable_arenas->nextarena->prevarena == + usable_arenas); + + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) { + usable_arenas->prevarena = NULL; + assert(usable_arenas->address != 0); + } + } + else { + /* nfreepools > 0: it must be that freepools + * isn't NULL, or that we haven't yet carved + * off all the arena's pools for the first + * time. + */ + assert(usable_arenas->freepools != NULL || + usable_arenas->pool_address <= + (block*)usable_arenas->address + + ARENA_SIZE - POOL_SIZE); + } init_pool: - /* - * Frontlink to used pools - */ + /* Frontlink to used pools. */ next = usedpools[size + size]; /* == prev */ pool->nextpool = next; pool->prevpool = next; @@ -657,8 +836,7 @@ next->prevpool = pool; pool->ref.count = 1; if (pool->szidx == size) { - /* - * Luckily, this pool last contained blocks + /* Luckily, this pool last contained blocks * of the same size class, so its header * and free list are already initialized. */ @@ -682,39 +860,38 @@ UNLOCK(); return (void *)bp; } - /* - * Allocate new pool - */ - if (nfreepools) { - commit_pool: - --nfreepools; - pool = (poolp)arenabase; - arenabase += POOL_SIZE; - pool->arenaindex = narenas - 1; - pool->szidx = DUMMY_SIZE_IDX; - goto init_pool; - } - /* - * Allocate new arena - */ -#ifdef WITH_MEMORY_LIMITS - if (!(narenas < MAX_ARENAS)) { - UNLOCK(); - goto redirect; + + /* Carve off a new pool. */ + assert(usable_arenas->nfreepools > 0); + assert(usable_arenas->freepools == NULL); + pool = (poolp)usable_arenas->pool_address; + assert((block*)pool <= (block*)usable_arenas->address + + ARENA_SIZE - POOL_SIZE); + pool->arenaindex = usable_arenas - arenas; + assert(&arenas[pool->arenaindex] == usable_arenas); + pool->szidx = DUMMY_SIZE_IDX; + usable_arenas->pool_address += POOL_SIZE; + --usable_arenas->nfreepools; + + if (usable_arenas->nfreepools == 0) { + assert(usable_arenas->nextarena == NULL || + usable_arenas->nextarena->prevarena == + usable_arenas); + /* Unlink the arena: it is completely allocated. */ + usable_arenas = usable_arenas->nextarena; + if (usable_arenas != NULL) { + usable_arenas->prevarena = NULL; + assert(usable_arenas->address != 0); + } } -#endif - bp = new_arena(); - if (bp != NULL) - goto commit_pool; - UNLOCK(); - goto redirect; + + goto init_pool; } /* The small block allocator ends here. */ redirect: - /* - * Redirect the original request to the underlying (libc) allocator. + /* Redirect the original request to the underlying (libc) allocator. * We jump here on bigger requests, on error in the code above (as a * last chance to serve the request) or when the max memory limit * has been reached. @@ -742,8 +919,7 @@ if (Py_ADDRESS_IN_RANGE(p, pool)) { /* We allocated this address. */ LOCK(); - /* - * Link p to the start of the pool's freeblock list. Since + /* Link p to the start of the pool's freeblock list. Since * the pool had at least the p block outstanding, the pool * wasn't empty (so it's already in a usedpools[] list, or * was full and is in no list -- it's not in the freeblocks @@ -753,8 +929,10 @@ *(block **)p = lastfree = pool->freeblock; pool->freeblock = (block *)p; if (lastfree) { - /* - * freeblock wasn't NULL, so the pool wasn't full, + struct arena_object* ao; + uint nf; /* ao->nfreepools */ + + /* freeblock wasn't NULL, so the pool wasn't full, * and the pool is in a usedpools[] list. */ if (--pool->ref.count != 0) { @@ -762,8 +940,7 @@ UNLOCK(); return; } - /* - * Pool is now empty: unlink from usedpools, and + /* Pool is now empty: unlink from usedpools, and * link to the front of freepools. This ensures that * previously freed pools will be allocated later * (being not referenced, they are perhaps paged out). @@ -772,16 +949,147 @@ prev = pool->prevpool; next->prevpool = prev; prev->nextpool = next; - /* Link to freepools. This is a singly-linked list, - * and pool->prevpool isn't used there. + + /* Link the pool to freepools. This is a singly-linked + * list, and pool->prevpool isn't used there. */ - pool->nextpool = freepools; - freepools = pool; + ao = &arenas[pool->arenaindex]; + pool->nextpool = ao->freepools; + ao->freepools = pool; + nf = ++ao->nfreepools; + + /* All the rest is arena management. We just freed + * a pool, and there are 4 cases for arena mgmt: + * 1. If all the pools are free, return the arena to + * the system free(). + * 2. If this is the only free pool in the arena, + * add the arena back to the `usable_arenas` list. + * 3. If the "next" arena has a smaller count of free + * pools, we have to "slide this arena right" to + * restore that usable_arenas is sorted in order of + * nfreepools. + * 4. Else there's nothing more to do. + */ + if (nf == ao->ntotalpools) { + /* Case 1. First unlink ao from usable_arenas. + */ + assert(ao->prevarena == NULL || + ao->prevarena->address != 0); + assert(ao ->nextarena == NULL || + ao->nextarena->address != 0); + + /* Fix the pointer in the prevarena, or the + * usable_arenas pointer. + */ + if (ao->prevarena == NULL) { + usable_arenas = ao->nextarena; + assert(usable_arenas == NULL || + usable_arenas->address != 0); + } + else { + assert(ao->prevarena->nextarena == ao); + ao->prevarena->nextarena = + ao->nextarena; + } + /* Fix the pointer in the nextarena. */ + if (ao->nextarena != NULL) { + assert(ao->nextarena->prevarena == ao); + ao->nextarena->prevarena = + ao->prevarena; + } + /* Record that this arena_object slot is + * available to be reused. + */ + ao->nextarena = unused_arena_objects; + unused_arena_objects = ao; + + /* Free the entire arena. */ + free((void *)ao->address); + ao->address = 0; /* mark unassociated */ + --narenas_currently_allocated; + + UNLOCK(); + return; + } + if (nf == 1) { + /* Case 2. Put ao at the head of + * usable_arenas. Note that because + * ao->nfreepools was 0 before, ao isn't + * currently on the usable_arenas list. + */ + ao->nextarena = usable_arenas; + ao->prevarena = NULL; + if (usable_arenas) + usable_arenas->prevarena = ao; + usable_arenas = ao; + assert(usable_arenas->address != 0); + + UNLOCK(); + return; + } + /* If this arena is now out of order, we need to keep + * the list sorted. The list is kept sorted so that + * the "most full" arenas are used first, which allows + * the nearly empty arenas to be completely freed. In + * a few un-scientific tests, it seems like this + * approach allowed a lot more memory to be freed. + */ + if (ao->nextarena == NULL || + nf <= ao->nextarena->nfreepools) { + /* Case 4. Nothing to do. */ + UNLOCK(); + return; + } + /* Case 3: We have to move the arena towards the end + * of the list, because it has more free pools than + * the arena to its right. + * First unlink ao from usable_arenas. + */ + if (ao->prevarena != NULL) { + /* ao isn't at the head of the list */ + assert(ao->prevarena->nextarena == ao); + ao->prevarena->nextarena = ao->nextarena; + } + else { + /* ao is at the head of the list */ + assert(usable_arenas == ao); + usable_arenas = ao->nextarena; + } + ao->nextarena->prevarena = ao->prevarena; + + /* Locate the new insertion point by iterating over + * the list, using our nextarena pointer. + */ + while (ao->nextarena != NULL && + nf > ao->nextarena->nfreepools) { + ao->prevarena = ao->nextarena; + ao->nextarena = ao->nextarena->nextarena; + } + + /* Insert ao at this point. */ + assert(ao->nextarena == NULL || + ao->prevarena == ao->nextarena->prevarena); + assert(ao->prevarena->nextarena == ao->nextarena); + + ao->prevarena->nextarena = ao; + if (ao->nextarena != NULL) + ao->nextarena->prevarena = ao; + + /* Verify that the swaps worked. */ + assert(ao->nextarena == NULL || + nf <= ao->nextarena->nfreepools); + assert(ao->prevarena == NULL || + nf > ao->prevarena->nfreepools); + assert(ao->nextarena == NULL || + ao->nextarena->prevarena == ao); + assert((usable_arenas == ao && + ao->prevarena == NULL) || + ao->prevarena->nextarena == ao); + UNLOCK(); return; } - /* - * Pool was full, so doesn't currently live in any list: + /* Pool was full, so doesn't currently live in any list: * link it to the front of the appropriate usedpools[] list. * This mimics LRU pool usage for new allocations and * targets optimal filling when several pools contain @@ -1302,6 +1610,8 @@ * full pools. */ ulong quantization = 0; + /* # of arenas actually allocated. */ + ulong narenas = 0; /* running total -- should equal narenas * ARENA_SIZE */ ulong total; char buf[128]; @@ -1316,36 +1626,38 @@ * to march over all the arenas. If we're lucky, most of the memory * will be living in full pools -- would be a shame to miss them. */ - for (i = 0; i < narenas; ++i) { + for (i = 0; i < maxarenas; ++i) { uint poolsinarena; uint j; - uptr base = arenas[i]; + uptr base = arenas[i].address; + + /* Skip arenas which are not allocated. */ + if (arenas[i].address == (uptr)NULL) + continue; + narenas += 1; + + poolsinarena = arenas[i].ntotalpools; + numfreepools += arenas[i].nfreepools; /* round up to pool alignment */ - poolsinarena = ARENA_SIZE / POOL_SIZE; if (base & (uptr)POOL_SIZE_MASK) { - --poolsinarena; arena_alignment += POOL_SIZE; base &= ~(uptr)POOL_SIZE_MASK; base += POOL_SIZE; } - if (i == narenas - 1) { - /* current arena may have raw memory at the end */ - numfreepools += nfreepools; - poolsinarena -= nfreepools; - } - /* visit every pool in the arena */ - for (j = 0; j < poolsinarena; ++j, base += POOL_SIZE) { + assert(base <= (uptr) arenas[i].pool_address); + for (j = 0; + base < (uptr) arenas[i].pool_address; + ++j, base += POOL_SIZE) { poolp p = (poolp)base; const uint sz = p->szidx; uint freeblocks; if (p->ref.count == 0) { /* currently unused */ - ++numfreepools; - assert(pool_is_in_list(p, freepools)); + assert(pool_is_in_list(p, arenas[i].freepools)); continue; } ++numpools[sz]; @@ -1358,6 +1670,7 @@ #endif } } + assert(narenas == narenas_currently_allocated); fputc('\n', stderr); fputs("class size num pools blocks in use avail blocks\n" @@ -1383,9 +1696,14 @@ fputc('\n', stderr); (void)printone("# times object malloc called", serialno); + (void)printone("# arenas allocated total", ntimes_arena_allocated); + (void)printone("# arenas reclaimed", ntimes_arena_allocated - narenas); + (void)printone("# arenas highwater mark", narenas_highwater); + (void)printone("# arenas allocated current", narenas); + PyOS_snprintf(buf, sizeof(buf), - "%u arenas * %d bytes/arena", narenas, ARENA_SIZE); - (void)printone(buf, (ulong)narenas * ARENA_SIZE); + "%lu arenas * %d bytes/arena", narenas, ARENA_SIZE); + (void)printone(buf, narenas * ARENA_SIZE); fputc('\n', stderr); @@ -1405,12 +1723,14 @@ #endif /* PYMALLOC_DEBUG */ #ifdef Py_USING_MEMORY_DEBUGGER -/* Make this function last so gcc won't inline it - since the definition is after the reference. */ +/* Make this function last so gcc won't inline it since the definition is + * after the reference. + */ int Py_ADDRESS_IN_RANGE(void *P, poolp pool) { - return ((pool->arenaindex) < narenas && - (uptr)(P) - arenas[pool->arenaindex] < (uptr)ARENA_SIZE); + return pool->arenaindex < maxarenas && + (uptr)P - arenas[pool->arenaindex].address < (uptr)ARENA_SIZE && + arenas[pool->arenaindex].address != 0; } #endif Modified: python/branches/p3yk/Python/codecs.c ============================================================================== --- python/branches/p3yk/Python/codecs.c (original) +++ python/branches/p3yk/Python/codecs.c Fri Apr 21 11:43:23 2006 @@ -260,6 +260,56 @@ return NULL; } +PyObject *PyCodec_IncrementalEncoder(const char *encoding, + const char *errors) +{ + PyObject *codecs, *ret, *encoder; + + codecs = _PyCodec_Lookup(encoding); + if (codecs == NULL) + goto onError; + encoder = PyObject_GetAttrString(codecs, "incrementalencoder"); + if (encoder == NULL) { + Py_DECREF(codecs); + return NULL; + } + if (errors) + ret = PyObject_CallFunction(encoder, "O", errors); + else + ret = PyObject_CallFunction(encoder, NULL); + Py_DECREF(encoder); + Py_DECREF(codecs); + return ret; + + onError: + return NULL; +} + +PyObject *PyCodec_IncrementalDecoder(const char *encoding, + const char *errors) +{ + PyObject *codecs, *ret, *decoder; + + codecs = _PyCodec_Lookup(encoding); + if (codecs == NULL) + goto onError; + decoder = PyObject_GetAttrString(codecs, "incrementaldecoder"); + if (decoder == NULL) { + Py_DECREF(codecs); + return NULL; + } + if (errors) + ret = PyObject_CallFunction(decoder, "O", errors); + else + ret = PyObject_CallFunction(decoder, NULL); + Py_DECREF(decoder); + Py_DECREF(codecs); + return ret; + + onError: + return NULL; +} + PyObject *PyCodec_StreamReader(const char *encoding, PyObject *stream, const char *errors) Modified: python/branches/p3yk/Tools/buildbot/clean.bat ============================================================================== --- python/branches/p3yk/Tools/buildbot/clean.bat (original) +++ python/branches/p3yk/Tools/buildbot/clean.bat Fri Apr 21 11:43:23 2006 @@ -1,3 +1,6 @@ @rem Used by the buildbot "clean" step. call "%VS71COMNTOOLS%vsvars32.bat" -devenv.com /clean Debug PCbuild\pcbuild.sln +cd PCbuild + at echo Deleting .pyc/.pyo files ... +python_d.exe rmpyc.py +devenv.com /clean Debug pcbuild.sln Modified: python/branches/p3yk/Tools/unicode/Makefile ============================================================================== --- python/branches/p3yk/Tools/unicode/Makefile (original) +++ python/branches/p3yk/Tools/unicode/Makefile Fri Apr 21 11:43:23 2006 @@ -44,11 +44,11 @@ $(RM) -f build/readme.* iso: build/ - $(PYTHON) gencodec.py MAPPINGS/ISO8859/ build/iso + $(PYTHON) gencodec.py MAPPINGS/ISO8859/ build/ iso $(RM) -f build/isoreadme.* apple: build/ - $(PYTHON) gencodec.py MAPPINGS/VENDORS/APPLE/ build/mac_ + $(PYTHON) gencodec.py MAPPINGS/VENDORS/APPLE/ build/ mac_ $(RM) build/mac_dingbats.* $(RM) build/mac_japanese.* $(RM) build/mac_chin* Modified: python/branches/p3yk/Tools/unicode/gencodec.py ============================================================================== --- python/branches/p3yk/Tools/unicode/gencodec.py (original) +++ python/branches/p3yk/Tools/unicode/gencodec.py Fri Apr 21 11:43:23 2006 @@ -248,7 +248,7 @@ append(')') return l -def codegen(name, map, comments=1): +def codegen(name, map, encodingname, comments=1): """ Returns Python source for the given map. @@ -272,7 +272,7 @@ l = [ '''\ -""" Python Character Mapping Codec generated from '%s' with gencodec.py. +""" Python Character Mapping Codec %s generated from '%s' with gencodec.py. """#" @@ -283,11 +283,9 @@ class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) - def decode(self,input,errors='strict'): -''' % name + def decode(self,input,errors='strict'):''' % (encodingname, name) ] if decoding_table_code: l.append('''\ @@ -297,6 +295,20 @@ return codecs.charmap_decode(input,errors,decoding_map)''') l.append(''' +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input, final=False): + return codecs.charmap_encode(input,self.errors,encoding_map)[0] + +class IncrementalDecoder(codecs.IncrementalDecoder): + def decode(self, input, final=False):''') + if decoding_table_code: + l.append('''\ + return codecs.charmap_decode(input,self.errors,decoding_table)[0]''') + else: + l.append('''\ + return codecs.charmap_decode(input,self.errors,decoding_map)[0]''') + + l.append(''' class StreamWriter(Codec,codecs.StreamWriter): pass @@ -306,9 +318,16 @@ ### encodings module API def getregentry(): - - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) -''') + return codecs.CodecInfo(( + name=%r, + Codec().encode, + Codec().decode, + streamwriter=StreamWriter, + streamreader=StreamReader, + incrementalencoder=IncrementalEncoder, + incrementaldecoder=IncrementalDecoder, + )) +''' % encodingname.replace('_', '-')) # Add decoding table or map (with preference to the table) if not decoding_table_code: @@ -331,11 +350,11 @@ # Final new-line l.append('\n') - return '\n'.join(l) + return '\n'.join(l).expandtabs() -def pymap(name,map,pyfile,comments=1): +def pymap(name,map,pyfile,encodingname,comments=1): - code = codegen(name,map,comments) + code = codegen(name,map,encodingname,comments) f = open(pyfile,'w') f.write(code) f.close() @@ -349,7 +368,7 @@ marshal.dump(d,f) f.close() -def convertdir(dir,prefix='',comments=1): +def convertdir(dir, dirprefix='', nameprefix='', comments=1): mapnames = os.listdir(dir) for mapname in mapnames: @@ -360,38 +379,40 @@ name = name.replace('-','_') name = name.split('.')[0] name = name.lower() + name = nameprefix + name codefile = name + '.py' marshalfile = name + '.mapping' print 'converting %s to %s and %s' % (mapname, - prefix + codefile, - prefix + marshalfile) + dirprefix + codefile, + dirprefix + marshalfile) try: map = readmap(os.path.join(dir,mapname)) if not map: print '* map is empty; skipping' else: - pymap(mappathname, map, prefix + codefile,comments) - marshalmap(mappathname, map, prefix + marshalfile) + pymap(mappathname, map, dirprefix + codefile,name,comments) + marshalmap(mappathname, map, dirprefix + marshalfile) except ValueError, why: print '* conversion failed: %s' % why raise -def rewritepythondir(dir,prefix='',comments=1): +def rewritepythondir(dir, dirprefix='', comments=1): mapnames = os.listdir(dir) for mapname in mapnames: if not mapname.endswith('.mapping'): continue - codefile = mapname[:-len('.mapping')] + '.py' + name = mapname[:-len('.mapping')] + codefile = name + '.py' print 'converting %s to %s' % (mapname, - prefix + codefile) + dirprefix + codefile) try: map = marshal.load(open(os.path.join(dir,mapname), 'rb')) if not map: print '* map is empty; skipping' else: - pymap(mapname, map, prefix + codefile,comments) + pymap(mapname, map, dirprefix + codefile,name,comments) except ValueError, why: print '* conversion failed: %s' % why From python-3000-checkins at python.org Fri Apr 21 13:28:18 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 13:28:18 +0200 (CEST) Subject: [Python-3000-checkins] r45599 - in python/branches/p3yk: Objects/typeobject.c Tools/msi/msi.py Message-ID: <20060421112818.2CB051E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 13:28:17 2006 New Revision: 45599 Modified: python/branches/p3yk/ (props changed) python/branches/p3yk/Objects/typeobject.c python/branches/p3yk/Tools/msi/msi.py Log: Merge trunk up to 45598. Modified: python/branches/p3yk/Objects/typeobject.c ============================================================================== --- python/branches/p3yk/Objects/typeobject.c (original) +++ python/branches/p3yk/Objects/typeobject.c Fri Apr 21 13:28:17 2006 @@ -4183,10 +4183,10 @@ if (value == NULL) res = call_method(self, "__delitem__", &delitem_str, - "(i)", index); + "(n)", index); else res = call_method(self, "__setitem__", &setitem_str, - "(iO)", index, value); + "(nO)", index, value); if (res == NULL) return -1; Py_DECREF(res); @@ -4201,10 +4201,10 @@ if (value == NULL) res = call_method(self, "__delslice__", &delslice_str, - "(ii)", i, j); + "(nn)", i, j); else res = call_method(self, "__setslice__", &setslice_str, - "(iiO)", i, j, value); + "(nnO)", i, j, value); if (res == NULL) return -1; Py_DECREF(res); Modified: python/branches/p3yk/Tools/msi/msi.py ============================================================================== --- python/branches/p3yk/Tools/msi/msi.py (original) +++ python/branches/p3yk/Tools/msi/msi.py Fri Apr 21 13:28:17 2006 @@ -908,6 +908,12 @@ if files: # Add an entry to the RemoveFile table to remove bytecode files. lib.remove_pyc() + if dir.endswith('.egg-info'): + lib.add_file('entry_points.txt') + lib.add_file('PKG-INFO') + lib.add_file('top_level.txt') + lib.add_file('zip-safe') + continue if dir=='test' and parent.physical=='Lib': lib.add_file("185test.db") lib.add_file("audiotest.au") @@ -930,9 +936,12 @@ if dir=="Icons": lib.glob("*.gif") lib.add_file("idle.icns") - if dir=="command": + if dir=="command" and parent.physical=="distutils": lib.add_file("wininst-6.exe") lib.add_file("wininst-7.1.exe") + if dir=="setuptools": + lib.add_file("cli.exe") + lib.add_file("gui.exe") if dir=="data" and parent.physical=="test" and parent.basedir.physical=="email": # This should contain all non-.svn files listed in subversion for f in os.listdir(lib.absolute): From python-3000-checkins at python.org Fri Apr 21 13:30:52 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 13:30:52 +0200 (CEST) Subject: [Python-3000-checkins] r45600 - python/branches/p3yk/Lib/test/test_decimal.py Message-ID: <20060421113052.BCA3C1E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 13:30:52 2006 New Revision: 45600 Modified: python/branches/p3yk/Lib/test/test_decimal.py Log: Fix merge glitch. Modified: python/branches/p3yk/Lib/test/test_decimal.py ============================================================================== --- python/branches/p3yk/Lib/test/test_decimal.py (original) +++ python/branches/p3yk/Lib/test/test_decimal.py Fri Apr 21 13:30:52 2006 @@ -511,7 +511,7 @@ ('+', '__add__', '__radd__'), ('-', '__sub__', '__rsub__'), ('*', '__mul__', '__rmul__'), - ('/', '__truediv__', '__rtruediv__') + ('/', '__truediv__', '__rtruediv__'), ('%', '__mod__', '__rmod__'), ('//', '__floordiv__', '__rfloordiv__'), ('**', '__pow__', '__rpow__') From python-3000-checkins at python.org Fri Apr 21 13:36:14 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 13:36:14 +0200 (CEST) Subject: [Python-3000-checkins] r45601 - python/branches/p3yk/Lib/test/test_getargs2.py Message-ID: <20060421113614.D48381E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 13:36:13 2006 New Revision: 45601 Modified: python/branches/p3yk/Lib/test/test_getargs2.py Log: Fix newly merged test for p3ykness. Modified: python/branches/p3yk/Lib/test/test_getargs2.py ============================================================================== --- python/branches/p3yk/Lib/test/test_getargs2.py (original) +++ python/branches/p3yk/Lib/test/test_getargs2.py Fri Apr 21 13:36:13 2006 @@ -186,7 +186,7 @@ from _testcapi import getargs_n # n returns 'Py_ssize_t', and does range checking # (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX) - self.failUnlessEqual(3, getargs_n(3.14)) + self.assertRaises(TypeError, getargs_n, 3.14) self.failUnlessEqual(99, getargs_n(Long())) self.failUnlessEqual(99, getargs_n(Int())) From python-3000-checkins at python.org Fri Apr 21 15:45:01 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 21 Apr 2006 15:45:01 +0200 (CEST) Subject: [Python-3000-checkins] r45611 - python/branches/p3yk/Lib/xmlrpclib.py Message-ID: <20060421134501.7EA201E400B@bag.python.org> Author: guido.van.rossum Date: Fri Apr 21 15:45:00 2006 New Revision: 45611 Modified: python/branches/p3yk/Lib/xmlrpclib.py Log: Fix the unit tests by adding dispatch tables for DateTime and Binary. I'm not convinced this is the right thing to do... InstanceType makes no sense any longer. Modified: python/branches/p3yk/Lib/xmlrpclib.py ============================================================================== --- python/branches/p3yk/Lib/xmlrpclib.py (original) +++ python/branches/p3yk/Lib/xmlrpclib.py Fri Apr 21 15:45:00 2006 @@ -749,6 +749,8 @@ # store instance attributes as a struct (really?) self.dump_struct(value.__dict__, write) dispatch[InstanceType] = dump_instance + dispatch[DateTime] = dump_instance + dispatch[Binary] = dump_instance ## # XML-RPC unmarshaller. From python-3000-checkins at python.org Fri Apr 21 15:52:57 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 21 Apr 2006 15:52:57 +0200 (CEST) Subject: [Python-3000-checkins] r45613 - python/branches/p3yk/Lib/xmlcore/sax/xmlreader.py Message-ID: <20060421135257.215161E400B@bag.python.org> Author: guido.van.rossum Date: Fri Apr 21 15:52:56 2006 New Revision: 45613 Modified: python/branches/p3yk/Lib/xmlcore/sax/xmlreader.py Log: Fix relative import. This fixes test_sax.py. Modified: python/branches/p3yk/Lib/xmlcore/sax/xmlreader.py ============================================================================== --- python/branches/p3yk/Lib/xmlcore/sax/xmlreader.py (original) +++ python/branches/p3yk/Lib/xmlcore/sax/xmlreader.py Fri Apr 21 15:52:56 2006 @@ -113,7 +113,7 @@ XMLReader.__init__(self) def parse(self, source): - import saxutils + from . import saxutils source = saxutils.prepare_input_source(source) self.prepareParser(source) From python-3000-checkins at python.org Fri Apr 21 16:02:59 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 16:02:59 +0200 (CEST) Subject: [Python-3000-checkins] r45615 - python/branches/p3yk/Python/Python-ast.c Message-ID: <20060421140259.ADD7E1E400B@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 16:02:59 2006 New Revision: 45615 Modified: python/branches/p3yk/Python/Python-ast.c Log: Commit regenerated Python-ast.c. Modified: python/branches/p3yk/Python/Python-ast.c ============================================================================== --- python/branches/p3yk/Python/Python-ast.c (original) +++ python/branches/p3yk/Python/Python-ast.c Fri Apr 21 16:02:59 2006 @@ -3048,7 +3048,7 @@ if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return; - if (PyModule_AddStringConstant(m, "__version__", "42753") < 0) + if (PyModule_AddStringConstant(m, "__version__", "45597") < 0) return; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) From python-3000-checkins at python.org Fri Apr 21 17:44:21 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 21 Apr 2006 17:44:21 +0200 (CEST) Subject: [Python-3000-checkins] r45617 - in python/branches/p3yk/Lib/plat-mac/lib-scriptpackages: CodeWarrior/CodeWarrior_suite.py CodeWarrior/__init__.py Explorer/__init__.py Finder/Containers_and_folders.py Finder/Files.py Finder/Finder_Basics.py Finder/__init__.py Netscape/__init__.py StdSuites/__init__.py SystemEvents/Disk_Folder_File_Suite.py SystemEvents/Folder_Actions_Suite.py SystemEvents/Login_Items_Suite.py SystemEvents/Power_Suite.py SystemEvents/Processes_Suite.py SystemEvents/System_Events_Suite.py SystemEvents/Text_Suite.py SystemEvents/__init__.py Terminal/Terminal_Suite.py Terminal/Text_Suite.py Terminal/__init__.py _builtinSuites/__init__.py Message-ID: <20060421154421.A83591E400B@bag.python.org> Author: guido.van.rossum Date: Fri Apr 21 17:44:20 2006 New Revision: 45617 Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/CodeWarrior_suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Explorer/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Containers_and_folders.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Files.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Finder_Basics.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Netscape/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Disk_Folder_File_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Folder_Actions_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Login_Items_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Power_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/System_Events_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Text_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Terminal_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Text_Suite.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/__init__.py python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/_builtinSuites/__init__.py Log: Fix test_scriptpackage with pure will power. I really don't know why I bother; these are all generated files. But I don't recall how to regenerate them nor how to fix the generator. The hardest part was fixing two mutual recursive imports; somehow changing "import foo" into "from . import foo" where foo and bar import each other AND both are imported from __init__.py caused things to break. Bah. Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/CodeWarrior_suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/CodeWarrior_suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/CodeWarrior_suite.py Fri Apr 21 17:44:20 2006 @@ -454,7 +454,7 @@ } single_class_browser._privelemdict = { } -import Standard_Suite +from . import Standard_Suite single_class_hierarchy._superclassnames = ['document'] single_class_hierarchy._privpropdict = { 'inherits' : _Prop_inherits, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/CodeWarrior/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,10 +3,10 @@ """ import aetools Error = aetools.Error -import CodeWarrior_suite -import Standard_Suite -import Metrowerks_Shell_Suite -import Required +from . import CodeWarrior_suite +from . import Standard_Suite +from . import Metrowerks_Shell_Suite +from . import Required _code_to_module = { @@ -25,10 +25,10 @@ 'reqd' : ('CodeWarrior.Required', 'Required'), } -from CodeWarrior_suite import * -from Standard_Suite import * -from Metrowerks_Shell_Suite import * -from Required import * +from CodeWarrior.CodeWarrior_suite import * +from CodeWarrior.Standard_Suite import * +from CodeWarrior.Metrowerks_Shell_Suite import * +from CodeWarrior.Required import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Explorer/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Explorer/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Explorer/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,12 +3,12 @@ """ import aetools Error = aetools.Error -import Standard_Suite -import URL_Suite -import Netscape_Suite -import Microsoft_Internet_Explorer -import Web_Browser_Suite -import Required_Suite +from . import Standard_Suite +from . import URL_Suite +from . import Netscape_Suite +from . import Microsoft_Internet_Explorer +from . import Web_Browser_Suite +from . import Required_Suite _code_to_module = { @@ -31,12 +31,12 @@ 'reqd' : ('Explorer.Required_Suite', 'Required_Suite'), } -from Standard_Suite import * -from URL_Suite import * -from Netscape_Suite import * -from Microsoft_Internet_Explorer import * -from Web_Browser_Suite import * -from Required_Suite import * +from Explorer.Standard_Suite import * +from Explorer.URL_Suite import * +from Explorer.Netscape_Suite import * +from Explorer.Microsoft_Internet_Explorer import * +from Explorer.Web_Browser_Suite import * +from Explorer.Required_Suite import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Containers_and_folders.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Containers_and_folders.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Containers_and_folders.py Fri Apr 21 17:44:20 2006 @@ -148,8 +148,8 @@ # element 'inlf' as ['indx', 'name'] # element 'pack' as ['indx', 'name'] disk._superclassnames = ['container'] -import Files -import Finder_items +from . import Files +from . import Finder_items disk._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'capacity' : _Prop_capacity, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Files.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Files.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Files.py Fri Apr 21 17:44:20 2006 @@ -148,7 +148,7 @@ } document_file._privelemdict = { } -import Finder_items +from . import Finder_items file._superclassnames = ['item'] file._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Finder_Basics.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Finder_Basics.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/Finder_Basics.py Fri Apr 21 17:44:20 2006 @@ -141,10 +141,10 @@ # element 'lwnd' as ['indx', 'name'] # element 'pack' as ['indx', 'name'] application._superclassnames = [] -import Files -import Window_classes -import Containers_and_folders -import Finder_items +from . import Files +from . import Window_classes +from . import Containers_and_folders +from . import Finder_items application._privpropdict = { 'Finder_preferences' : _Prop_Finder_preferences, 'clipboard' : _Prop_clipboard, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Finder/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,15 +3,15 @@ """ import aetools Error = aetools.Error -import Standard_Suite -import Legacy_suite -import Containers_and_folders -import Files -import Finder_Basics -import Finder_items -import Window_classes -import Type_Definitions -import Enumerations +from . import Standard_Suite +from . import Legacy_suite +from . import Containers_and_folders +from . import Files +from . import Finder_Basics +from . import Finder_items +from . import Window_classes +from . import Type_Definitions +from . import Enumerations _code_to_module = { @@ -40,15 +40,15 @@ 'tpnm' : ('Finder.Enumerations', 'Enumerations'), } -from Standard_Suite import * -from Legacy_suite import * -from Containers_and_folders import * -from Files import * -from Finder_Basics import * -from Finder_items import * -from Window_classes import * -from Type_Definitions import * -from Enumerations import * +from Finder.Standard_Suite import * +from Finder.Legacy_suite import * +from Finder.Containers_and_folders import * +from Finder.Files import * +from Finder.Finder_Basics import * +from Finder.Finder_items import * +from Finder.Window_classes import * +from Finder.Type_Definitions import * +from Finder.Enumerations import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Netscape/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Netscape/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Netscape/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,13 +3,13 @@ """ import aetools Error = aetools.Error -import Standard_Suite -import Standard_URL_suite -import Mozilla_suite -import Text -import WorldWideWeb_suite -import PowerPlant -import Required_suite +from . import Standard_Suite +from . import Standard_URL_suite +from . import Mozilla_suite +from . import Text +from . import WorldWideWeb_suite +from . import PowerPlant +from . import Required_suite _code_to_module = { @@ -34,13 +34,13 @@ 'reqd' : ('Netscape.Required_suite', 'Required_suite'), } -from Standard_Suite import * -from Standard_URL_suite import * -from Mozilla_suite import * -from Text import * -from WorldWideWeb_suite import * -from PowerPlant import * -from Required_suite import * +from Netscape.Standard_Suite import * +from Netscape.Standard_URL_suite import * +from Netscape.Mozilla_suite import * +from Netscape.Text import * +from Netscape.WorldWideWeb_suite import * +from Netscape.PowerPlant import * +from Netscape.Required_suite import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/StdSuites/__init__.py Fri Apr 21 17:44:20 2006 @@ -4,15 +4,15 @@ """ import aetools Error = aetools.Error -import Text_Suite -import AppleScript_Suite -import Standard_Suite -import Macintosh_Connectivity_Clas -import QuickDraw_Graphics_Suite -import QuickDraw_Graphics_Suppleme -import Required_Suite -import Table_Suite -import Type_Names_Suite +from . import Text_Suite +from . import AppleScript_Suite +from . import Standard_Suite +from . import Macintosh_Connectivity_Clas +from . import QuickDraw_Graphics_Suite +from . import QuickDraw_Graphics_Suppleme +from . import Required_Suite +from . import Table_Suite +from . import Type_Names_Suite _code_to_module = { @@ -41,15 +41,15 @@ 'tpnm' : ('StdSuites.Type_Names_Suite', 'Type_Names_Suite'), } -from Text_Suite import * -from AppleScript_Suite import * -from Standard_Suite import * -from Macintosh_Connectivity_Clas import * -from QuickDraw_Graphics_Suite import * -from QuickDraw_Graphics_Suppleme import * -from Required_Suite import * -from Table_Suite import * -from Type_Names_Suite import * +from StdSuites.Text_Suite import * +from StdSuites.AppleScript_Suite import * +from StdSuites.Standard_Suite import * +from StdSuites.Macintosh_Connectivity_Clas import * +from StdSuites.QuickDraw_Graphics_Suite import * +from StdSuites.QuickDraw_Graphics_Suppleme import * +from StdSuites.Required_Suite import * +from StdSuites.Table_Suite import * +from StdSuites.Type_Names_Suite import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Disk_Folder_File_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Disk_Folder_File_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Disk_Folder_File_Suite.py Fri Apr 21 17:44:20 2006 @@ -5,6 +5,11 @@ AETE/AEUT resource version 1/0, language 0, script 0 """ +# Crutch for recursive import +import sys +import SystemEvents +SystemEvents.Disk_Folder_File_Suite = sys.modules[__name__] + import aetools import MacOS @@ -210,10 +215,10 @@ files = file application._superclassnames = [] -import Standard_Suite -import Folder_Actions_Suite -import Login_Items_Suite -import Processes_Suite +from . import Standard_Suite +from . import Folder_Actions_Suite +from . import Login_Items_Suite +from . import Processes_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'folder_actions_enabled' : _Prop_folder_actions_enabled, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Folder_Actions_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Folder_Actions_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Folder_Actions_Suite.py Fri Apr 21 17:44:20 2006 @@ -5,6 +5,11 @@ AETE/AEUT resource version 1/0, language 0, script 0 """ +# Crutch for recursive import +import sys +import SystemEvents +SystemEvents.Folder_Actions_Suite = sys.modules[__name__] + import aetools import MacOS @@ -208,10 +213,11 @@ scripts = script application._superclassnames = [] -import Disk_Folder_File_Suite -import Standard_Suite -import Login_Items_Suite -import Processes_Suite +import sys +from . import Disk_Folder_File_Suite +from . import Standard_Suite +from . import Login_Items_Suite +from . import Processes_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'folder_actions_enabled' : _Prop_folder_actions_enabled, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Login_Items_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Login_Items_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Login_Items_Suite.py Fri Apr 21 17:44:20 2006 @@ -40,7 +40,7 @@ want = 'utxt' login_items = login_item -import Standard_Suite +from . import Standard_Suite login_item._superclassnames = ['item'] login_item._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Power_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Power_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Power_Suite.py Fri Apr 21 17:44:20 2006 @@ -105,11 +105,11 @@ applications = application application._superclassnames = [] -import Disk_Folder_File_Suite -import Standard_Suite -import Folder_Actions_Suite -import Login_Items_Suite -import Processes_Suite +from . import Disk_Folder_File_Suite +from . import Standard_Suite +from . import Folder_Actions_Suite +from . import Login_Items_Suite +from . import Processes_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'folder_actions_enabled' : _Prop_folder_actions_enabled, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Processes_Suite.py Fri Apr 21 17:44:20 2006 @@ -121,10 +121,10 @@ processes = process application._superclassnames = [] -import Disk_Folder_File_Suite -import Standard_Suite -import Folder_Actions_Suite -import Login_Items_Suite +from . import Disk_Folder_File_Suite +from . import Standard_Suite +from . import Folder_Actions_Suite +from . import Login_Items_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'folder_actions_enabled' : _Prop_folder_actions_enabled, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/System_Events_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/System_Events_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/System_Events_Suite.py Fri Apr 21 17:44:20 2006 @@ -65,11 +65,11 @@ applications = application application._superclassnames = [] -import Disk_Folder_File_Suite -import Standard_Suite -import Folder_Actions_Suite -import Login_Items_Suite -import Processes_Suite +from . import Disk_Folder_File_Suite +from . import Standard_Suite +from . import Folder_Actions_Suite +from . import Login_Items_Suite +from . import Processes_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'folder_actions_enabled' : _Prop_folder_actions_enabled, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Text_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Text_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/Text_Suite.py Fri Apr 21 17:44:20 2006 @@ -101,7 +101,7 @@ 'paragraph' : paragraph, 'word' : word, } -import Standard_Suite +from . import Standard_Suite attribute_run._superclassnames = ['item'] attribute_run._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/SystemEvents/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,14 +3,14 @@ """ import aetools Error = aetools.Error -import Standard_Suite -import Text_Suite -import Disk_Folder_File_Suite -import Folder_Actions_Suite -import Login_Items_Suite -import Power_Suite -import Processes_Suite -import System_Events_Suite +from . import Standard_Suite +from . import Text_Suite +from . import Disk_Folder_File_Suite +from . import Folder_Actions_Suite +from . import Login_Items_Suite +from . import Power_Suite +from . import Processes_Suite +from . import System_Events_Suite _code_to_module = { @@ -37,14 +37,14 @@ 'sevs' : ('SystemEvents.System_Events_Suite', 'System_Events_Suite'), } -from Standard_Suite import * -from Text_Suite import * -from Disk_Folder_File_Suite import * -from Folder_Actions_Suite import * -from Login_Items_Suite import * -from Power_Suite import * -from Processes_Suite import * -from System_Events_Suite import * +from SystemEvents.Standard_Suite import * +from SystemEvents.Text_Suite import * +from SystemEvents.Disk_Folder_File_Suite import * +from SystemEvents.Folder_Actions_Suite import * +from SystemEvents.Login_Items_Suite import * +from SystemEvents.Power_Suite import * +from SystemEvents.Processes_Suite import * +from SystemEvents.System_Events_Suite import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Terminal_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Terminal_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Terminal_Suite.py Fri Apr 21 17:44:20 2006 @@ -173,7 +173,7 @@ windows = window application._superclassnames = [] -import Standard_Suite +from . import Standard_Suite application._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, 'properties' : _Prop_properties, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Text_Suite.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Text_Suite.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/Text_Suite.py Fri Apr 21 17:44:20 2006 @@ -101,7 +101,7 @@ 'paragraph' : paragraph, 'word' : word, } -import Standard_Suite +from . import Standard_Suite attribute_run._superclassnames = ['item'] attribute_run._privpropdict = { '_3c_Inheritance_3e_' : _Prop__3c_Inheritance_3e_, Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/Terminal/__init__.py Fri Apr 21 17:44:20 2006 @@ -3,9 +3,9 @@ """ import aetools Error = aetools.Error -import Standard_Suite -import Text_Suite -import Terminal_Suite +from . import Standard_Suite +from . import Text_Suite +from . import Terminal_Suite _code_to_module = { @@ -22,9 +22,9 @@ 'trmx' : ('Terminal.Terminal_Suite', 'Terminal_Suite'), } -from Standard_Suite import * -from Text_Suite import * -from Terminal_Suite import * +from Terminal.Standard_Suite import * +from Terminal.Text_Suite import * +from Terminal.Terminal_Suite import * def getbaseclasses(v): if not getattr(v, '_propdict', None): Modified: python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/_builtinSuites/__init__.py ============================================================================== --- python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/_builtinSuites/__init__.py (original) +++ python/branches/p3yk/Lib/plat-mac/lib-scriptpackages/_builtinSuites/__init__.py Fri Apr 21 17:44:20 2006 @@ -5,7 +5,7 @@ in the Standard suite. """ import aetools -import builtin_Suite +from . import builtin_Suite _code_to_module = { @@ -20,7 +20,7 @@ 'core' : ('_builtinSuites.builtin_Suite', 'builtin_Suite'), } -from builtin_Suite import * +from _builtinSuites.builtin_Suite import * class _builtinSuites(builtin_Suite_Events, aetools.TalkTo): From python-3000-checkins at python.org Fri Apr 21 18:21:44 2006 From: python-3000-checkins at python.org (hyeshik.chang) Date: Fri, 21 Apr 2006 18:21:44 +0200 (CEST) Subject: [Python-3000-checkins] r45619 - python/branches/p3yk/Modules/cjkcodecs/multibytecodec.c Message-ID: <20060421162144.7BBFC1E4010@bag.python.org> Author: hyeshik.chang Date: Fri Apr 21 18:21:44 2006 New Revision: 45619 Modified: python/branches/p3yk/Modules/cjkcodecs/multibytecodec.c Log: Add empty __init__ methods for stateful multibytecodec instances. This resolves a problem found by Thomas Wouters: http://mail.python.org/pipermail/python-dev/2006-April/064051.html Modified: python/branches/p3yk/Modules/cjkcodecs/multibytecodec.c ============================================================================== --- python/branches/p3yk/Modules/cjkcodecs/multibytecodec.c (original) +++ python/branches/p3yk/Modules/cjkcodecs/multibytecodec.c Fri Apr 21 18:21:44 2006 @@ -927,6 +927,12 @@ } static int +mbiencoder_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static int mbiencoder_traverse(MultibyteIncrementalEncoderObject *self, visitproc visit, void *arg) { @@ -982,7 +988,7 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + mbiencoder_init, /* tp_init */ 0, /* tp_alloc */ mbiencoder_new, /* tp_new */ }; @@ -1122,6 +1128,12 @@ } static int +mbidecoder_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static int mbidecoder_traverse(MultibyteIncrementalDecoderObject *self, visitproc visit, void *arg) { @@ -1177,7 +1189,7 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + mbidecoder_init, /* tp_init */ 0, /* tp_alloc */ mbidecoder_new, /* tp_new */ }; @@ -1427,6 +1439,12 @@ } static int +mbstreamreader_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static int mbstreamreader_traverse(MultibyteStreamReaderObject *self, visitproc visit, void *arg) { @@ -1484,7 +1502,7 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + mbstreamreader_init, /* tp_init */ 0, /* tp_alloc */ mbstreamreader_new, /* tp_new */ }; @@ -1632,6 +1650,12 @@ } static int +mbstreamwriter_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + return 0; +} + +static int mbstreamwriter_traverse(MultibyteStreamWriterObject *self, visitproc visit, void *arg) { @@ -1706,7 +1730,7 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + mbstreamwriter_init, /* tp_init */ 0, /* tp_alloc */ mbstreamwriter_new, /* tp_new */ }; From python-3000-checkins at python.org Fri Apr 21 18:44:08 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Fri, 21 Apr 2006 18:44:08 +0200 (CEST) Subject: [Python-3000-checkins] r45623 - in python/branches/p3yk: Doc/howto/unicode.rst Doc/lib/libcodecs.tex Doc/whatsnew/whatsnew25.tex Lib/SimpleXMLRPCServer.py Objects/stringobject.c PCbuild/_bsddb.vcproj PCbuild/_ctypes.vcproj PCbuild/_ctypes_test.vcproj PCbuild/_elementtree.vcproj PCbuild/_msi.vcproj PCbuild/_socket.vcproj PCbuild/_sqlite3.vcproj PCbuild/_testcapi.vcproj PCbuild/_tkinter.vcproj PCbuild/bz2.vcproj PCbuild/pyexpat.vcproj PCbuild/python.vcproj PCbuild/pythoncore.vcproj PCbuild/pythonw.vcproj PCbuild/readme.txt PCbuild/select.vcproj PCbuild/unicodedata.vcproj PCbuild/winsound.vcproj Message-ID: <20060421164408.70EA71E4010@bag.python.org> Author: thomas.wouters Date: Fri Apr 21 18:44:05 2006 New Revision: 45623 Modified: python/branches/p3yk/ (props changed) python/branches/p3yk/Doc/howto/unicode.rst python/branches/p3yk/Doc/lib/libcodecs.tex python/branches/p3yk/Doc/whatsnew/whatsnew25.tex python/branches/p3yk/Lib/SimpleXMLRPCServer.py python/branches/p3yk/Objects/stringobject.c python/branches/p3yk/PCbuild/_bsddb.vcproj python/branches/p3yk/PCbuild/_ctypes.vcproj python/branches/p3yk/PCbuild/_ctypes_test.vcproj python/branches/p3yk/PCbuild/_elementtree.vcproj python/branches/p3yk/PCbuild/_msi.vcproj python/branches/p3yk/PCbuild/_socket.vcproj python/branches/p3yk/PCbuild/_sqlite3.vcproj python/branches/p3yk/PCbuild/_testcapi.vcproj python/branches/p3yk/PCbuild/_tkinter.vcproj python/branches/p3yk/PCbuild/bz2.vcproj python/branches/p3yk/PCbuild/pyexpat.vcproj python/branches/p3yk/PCbuild/python.vcproj python/branches/p3yk/PCbuild/pythoncore.vcproj python/branches/p3yk/PCbuild/pythonw.vcproj python/branches/p3yk/PCbuild/readme.txt python/branches/p3yk/PCbuild/select.vcproj python/branches/p3yk/PCbuild/unicodedata.vcproj python/branches/p3yk/PCbuild/winsound.vcproj Log: Merge with trunk up to revision 45620. Modified: python/branches/p3yk/Doc/howto/unicode.rst ============================================================================== --- python/branches/p3yk/Doc/howto/unicode.rst (original) +++ python/branches/p3yk/Doc/howto/unicode.rst Fri Apr 21 18:44:05 2006 @@ -733,6 +733,7 @@ .. comment Additional topic: building Python w/ UCS2 or UCS4 support .. comment Describe obscure -U switch somewhere? +.. comment Describe use of codecs.StreamRecoder and StreamReaderWriter .. comment Original outline: Modified: python/branches/p3yk/Doc/lib/libcodecs.tex ============================================================================== --- python/branches/p3yk/Doc/lib/libcodecs.tex (original) +++ python/branches/p3yk/Doc/lib/libcodecs.tex Fri Apr 21 18:44:05 2006 @@ -93,21 +93,21 @@ lookup: \begin{funcdesc}{getencoder}{encoding} -Lookup up the codec for the given encoding and return its encoder +Look up the codec for the given encoding and return its encoder function. Raises a \exception{LookupError} in case the encoding cannot be found. \end{funcdesc} \begin{funcdesc}{getdecoder}{encoding} -Lookup up the codec for the given encoding and return its decoder +Look up the codec for the given encoding and return its decoder function. Raises a \exception{LookupError} in case the encoding cannot be found. \end{funcdesc} \begin{funcdesc}{getincrementalencoder}{encoding} -Lookup up the codec for the given encoding and return its incremental encoder +Look up the codec for the given encoding and return its incremental encoder class or factory function. Raises a \exception{LookupError} in case the encoding cannot be found or the @@ -116,7 +116,7 @@ \end{funcdesc} \begin{funcdesc}{getincrementaldecoder}{encoding} -Lookup up the codec for the given encoding and return its incremental decoder +Look up the codec for the given encoding and return its incremental decoder class or factory function. Raises a \exception{LookupError} in case the encoding cannot be found or the @@ -125,14 +125,14 @@ \end{funcdesc} \begin{funcdesc}{getreader}{encoding} -Lookup up the codec for the given encoding and return its StreamReader +Look up the codec for the given encoding and return its StreamReader class or factory function. Raises a \exception{LookupError} in case the encoding cannot be found. \end{funcdesc} \begin{funcdesc}{getwriter}{encoding} -Lookup up the codec for the given encoding and return its StreamWriter +Look up the codec for the given encoding and return its StreamWriter class or factory function. Raises a \exception{LookupError} in case the encoding cannot be found. @@ -353,7 +353,7 @@ the encoding/decoding process during method calls. The joined output of calls to the \method{encode}/\method{decode} method is the -same as if the all single inputs where joined into one, and this input was +same as if all the single inputs were joined into one, and this input was encoded/decoded with the stateless encoder/decoder. @@ -363,7 +363,7 @@ The \class{IncrementalEncoder} class is used for encoding an input in multiple steps. It defines the following methods which every incremental encoder must -define in order to be compatible to the Python codec registry. +define in order to be compatible with the Python codec registry. \begin{classdesc}{IncrementalEncoder}{\optional{errors}} Constructor for a \class{IncrementalEncoder} instance. @@ -410,7 +410,7 @@ The \class{IncrementalDecoder} class is used for decoding an input in multiple steps. It defines the following methods which every incremental decoder must -define in order to be compatible to the Python codec registry. +define in order to be compatible with the Python codec registry. \begin{classdesc}{IncrementalDecoder}{\optional{errors}} Constructor for a \class{IncrementalDecoder} instance. @@ -456,15 +456,15 @@ The \class{StreamWriter} and \class{StreamReader} classes provide generic working interfaces which can be used to implement new -encodings submodules very easily. See \module{encodings.utf_8} for an -example on how this is done. +encoding submodules very easily. See \module{encodings.utf_8} for an +example of how this is done. \subsubsection{StreamWriter Objects \label{stream-writer-objects}} The \class{StreamWriter} class is a subclass of \class{Codec} and defines the following methods which every stream writer must define in -order to be compatible to the Python codec registry. +order to be compatible with the Python codec registry. \begin{classdesc}{StreamWriter}{stream\optional{, errors}} Constructor for a \class{StreamWriter} instance. @@ -473,7 +473,7 @@ free to add additional keyword arguments, but only the ones defined here are used by the Python codec registry. - \var{stream} must be a file-like object open for writing (binary) + \var{stream} must be a file-like object open for writing binary data. The \class{StreamWriter} may implement different error handling @@ -512,19 +512,19 @@ Flushes and resets the codec buffers used for keeping state. Calling this method should ensure that the data on the output is put - into a clean state, that allows appending of new fresh data without + into a clean state that allows appending of new fresh data without having to rescan the whole stream to recover state. \end{methoddesc} In addition to the above methods, the \class{StreamWriter} must also -inherit all other methods and attribute from the underlying stream. +inherit all other methods and attributes from the underlying stream. \subsubsection{StreamReader Objects \label{stream-reader-objects}} The \class{StreamReader} class is a subclass of \class{Codec} and defines the following methods which every stream reader must define in -order to be compatible to the Python codec registry. +order to be compatible with the Python codec registry. \begin{classdesc}{StreamReader}{stream\optional{, errors}} Constructor for a \class{StreamReader} instance. @@ -589,20 +589,20 @@ \var{size}, if given, is passed as size argument to the stream's \method{readline()} method. - If \var{keepends} is false lineends will be stripped from the + If \var{keepends} is false line-endings will be stripped from the lines returned. \versionchanged[\var{keepends} argument added]{2.4} \end{methoddesc} \begin{methoddesc}{readlines}{\optional{sizehint\optional{, keepends}}} - Read all lines available on the input stream and return them as list + Read all lines available on the input stream and return them as a list of lines. - Line breaks are implemented using the codec's decoder method and are + Line-endings are implemented using the codec's decoder method and are included in the list entries if \var{keepends} is true. - \var{sizehint}, if given, is passed as \var{size} argument to the + \var{sizehint}, if given, is passed as the \var{size} argument to the stream's \method{read()} method. \end{methoddesc} @@ -614,7 +614,7 @@ \end{methoddesc} In addition to the above methods, the \class{StreamReader} must also -inherit all other methods and attribute from the underlying stream. +inherit all other methods and attributes from the underlying stream. The next two base classes are included for convenience. They are not needed by the codec registry, but may provide useful in practice. @@ -640,7 +640,7 @@ \class{StreamReaderWriter} instances define the combined interfaces of \class{StreamReader} and \class{StreamWriter} classes. They inherit -all other methods and attribute from the underlying stream. +all other methods and attributes from the underlying stream. \subsubsection{StreamRecoder Objects \label{stream-recoder-objects}} @@ -666,14 +666,14 @@ \var{stream} must be a file-like object. \var{encode}, \var{decode} must adhere to the \class{Codec} - interface, \var{Reader}, \var{Writer} must be factory functions or + interface. \var{Reader}, \var{Writer} must be factory functions or classes providing objects of the \class{StreamReader} and \class{StreamWriter} interface respectively. \var{encode} and \var{decode} are needed for the frontend translation, \var{Reader} and \var{Writer} for the backend translation. The intermediate format used is determined by the two - sets of codecs, e.g. the Unicode codecs will use Unicode as + sets of codecs, e.g. the Unicode codecs will use Unicode as the intermediate encoding. Error handling is done in the same way as defined for the @@ -682,7 +682,7 @@ \class{StreamRecoder} instances define the combined interfaces of \class{StreamReader} and \class{StreamWriter} classes. They inherit -all other methods and attribute from the underlying stream. +all other methods and attributes from the underlying stream. \subsection{Encodings and Unicode\label{encodings-overview}} @@ -695,7 +695,7 @@ memory, CPU endianness and how these arrays are stored as bytes become an issue. Transforming a unicode object into a sequence of bytes is called encoding and recreating the unicode object from the sequence of -bytes is known as decoding. There are many different methods how this +bytes is known as decoding. There are many different methods for how this transformation can be done (these methods are also called encodings). The simplest method is to map the codepoints 0-255 to the bytes \code{0x0}-\code{0xff}. This means that a unicode object that contains @@ -742,7 +742,7 @@ it's a normal character that will be decoded like any other. There's another encoding that is able to encoding the full range of -Unicode characters: UTF-8. UTF-8 is an 8bit encoding, which means +Unicode characters: UTF-8. UTF-8 is an 8-bit encoding, which means there are no issues with byte order in UTF-8. Each byte in a UTF-8 byte sequence consists of two parts: Marker bits (the most significant bits) and payload bits. The marker bits are a sequence of zero to six @@ -762,7 +762,7 @@ The least significant bit of the Unicode character is the rightmost x bit. -As UTF-8 is an 8bit encoding no BOM is required and any \code{U+FEFF} +As UTF-8 is an 8-bit encoding no BOM is required and any \code{U+FEFF} character in the decoded Unicode string (even if it's the first character) is treated as a \samp{ZERO WIDTH NO-BREAK SPACE}. @@ -775,7 +775,7 @@ variant of UTF-8 (that Python 2.5 calls \code{"utf-8-sig"}) for its Notepad program: Before any of the Unicode characters is written to the file, a UTF-8 encoded BOM (which looks like this as a byte sequence: \code{0xef}, -\code{0xbb}, \code{0xbf}) is written. As it's rather improbably that any +\code{0xbb}, \code{0xbf}) is written. As it's rather improbable that any charmap encoded file starts with these byte values (which would e.g. map to LATIN SMALL LETTER I WITH DIAERESIS \\ @@ -794,8 +794,8 @@ \subsection{Standard Encodings\label{standard-encodings}} -Python comes with a number of codecs builtin, either implemented as C -functions, or with dictionaries as mapping tables. The following table +Python comes with a number of codecs built-in, either implemented as C +functions or with dictionaries as mapping tables. The following table lists the codecs by name, together with a few common aliases, and the languages for which the encoding is likely used. Neither the list of aliases nor the list of languages is meant to be exhaustive. Notice @@ -1337,7 +1337,7 @@ UTF-8 codec with BOM signature} \declaremodule{standard}{encodings.utf-8-sig} % XXX utf_8_sig gives TeX errors \modulesynopsis{UTF-8 codec with BOM signature} -\moduleauthor{Walter D\"orwald} +\moduleauthor{Walter D\"orwald}{} \versionadded{2.5} Modified: python/branches/p3yk/Doc/whatsnew/whatsnew25.tex ============================================================================== --- python/branches/p3yk/Doc/whatsnew/whatsnew25.tex (original) +++ python/branches/p3yk/Doc/whatsnew/whatsnew25.tex Fri Apr 21 18:44:05 2006 @@ -4,7 +4,6 @@ % The easy_install stuff % Describe the pkgutil module -% Stateful codec changes % Fix XXX comments % Count up the patches and bugs @@ -35,7 +34,7 @@ %====================================================================== -\section{PEP 243: Uploading Modules to PyPI} +\section{PEP 243: Uploading Modules to PyPI\label{pep-243}} PEP 243 describes an HTTP-based protocol for submitting software packages to a central archive. The Python package index at @@ -61,7 +60,7 @@ %====================================================================== -\section{PEP 308: Conditional Expressions} +\section{PEP 308: Conditional Expressions\label{pep-308}} For a long time, people have been requesting a way to write conditional expressions, expressions that return value A or value B @@ -152,7 +151,7 @@ %====================================================================== -\section{PEP 309: Partial Function Application} +\section{PEP 309: Partial Function Application\label{pep-309}} The \module{functional} module is intended to contain tools for functional-style programming. Currently it only contains a @@ -214,7 +213,7 @@ %====================================================================== -\section{PEP 314: Metadata for Python Software Packages v1.1} +\section{PEP 314: Metadata for Python Software Packages v1.1\label{pep-314}} Some simple dependency support was added to Distutils. The \function{setup()} function now has \code{requires}, \code{provides}, @@ -248,7 +247,7 @@ %====================================================================== -\section{PEP 328: Absolute and Relative Imports} +\section{PEP 328: Absolute and Relative Imports\label{pep-328}} The simpler part of PEP 328 was implemented in Python 2.4: parentheses could now be used to enclose the names imported from a module using @@ -342,7 +341,7 @@ %====================================================================== -\section{PEP 338: Executing Modules as Scripts} +\section{PEP 338: Executing Modules as Scripts\label{pep-338}} The \programopt{-m} switch added in Python 2.4 to execute a module as a script gained a few more abilities. Instead of being implemented in @@ -366,7 +365,7 @@ %====================================================================== -\section{PEP 341: Unified try/except/finally} +\section{PEP 341: Unified try/except/finally\label{pep-341}} Until Python 2.5, the \keyword{try} statement came in two flavours. You could use a \keyword{finally} block to ensure that code @@ -412,7 +411,7 @@ %====================================================================== -\section{PEP 342: New Generator Features\label{section-generators}} +\section{PEP 342: New Generator Features\label{pep-342}} Python 2.5 adds a simple way to pass values \emph{into} a generator. As introduced in Python 2.3, generators only produce output; once a @@ -578,9 +577,9 @@ %====================================================================== -\section{PEP 343: The 'with' statement} +\section{PEP 343: The 'with' statement\label{pep-343}} -The \keyword{with} statement allows a clearer version of code that +The '\keyword{with}' statement allows a clearer version of code that uses \code{try...finally} blocks to ensure that clean-up code is executed. @@ -589,7 +588,7 @@ and show how to write objects called ``context managers'' and ``contexts'' for use with this statement. -The \keyword{with} statement is a new control-flow structure whose +The '\keyword{with}' statement is a new control-flow structure whose basic structure is: \begin{verbatim} @@ -625,11 +624,11 @@ \end{verbatim} After this statement has executed, the file object in \var{f} will -have been automatically closed at this point, even if the 'for' loop +have been automatically closed, even if the 'for' loop raised an exception part-way through the block. The \module{threading} module's locks and condition variables -also support the \keyword{with} statement: +also support the '\keyword{with}' statement: \begin{verbatim} lock = threading.Lock() @@ -658,10 +657,10 @@ print v1.sqrt() \end{verbatim} -\subsection{Writing Context Managers} +\subsection{Writing Context Managers\label{context-managers}} -Under the hood, the \keyword{with} statement is fairly complicated. -Most people will only use \keyword{with} in company with +Under the hood, the '\keyword{with}' statement is fairly complicated. +Most people will only use '\keyword{with}' in company with existing objects that are documented to work as context managers, and don't need to know these details, so you can skip the following section if you like. Authors of new context managers will need to understand the @@ -678,7 +677,7 @@ return a context object. \item The context's \method{__enter__()} method is called. -The value returned is assigned to \var{VAR}. If no \code{as \var{VAR}} +The value returned is assigned to \var{VAR}. If no \code{'as \var{VAR}'} clause is present, the value is simply discarded. \item The code in \var{BLOCK} is executed. @@ -690,7 +689,7 @@ controls whether the exception is re-raised: any false value re-raises the exception, and \code{True} will result in suppressing it. You'll only rarely want to suppress the exception; the -author of the code containing the \keyword{with} statement will +author of the code containing the '\keyword{with}' statement will never realize anything went wrong. \item If \var{BLOCK} didn't raise an exception, @@ -761,7 +760,7 @@ to start a new transaction. In this example, the resulting cursor object would be a useful result, so the method will return it. The user can -then add \code{as cursor} to their \keyword{with} statement +then add \code{as cursor} to their '\keyword{with}' statement to bind the cursor to a variable name. \begin{verbatim} @@ -806,7 +805,7 @@ exactly one value. The code up to the \keyword{yield} will be executed as the \method{__enter__()} method, and the value yielded will be the method's return value that will get bound to the variable -in the \keyword{with} statement's \keyword{as} clause, if any. The +in the '\keyword{with}' statement's \keyword{as} clause, if any. The code after the \keyword{yield} will be executed in the \method{__exit__()} method. Any exception raised in the block will be raised by the \keyword{yield} statement. @@ -854,7 +853,7 @@ There's a \function{nested(\var{mgr1}, \var{mgr2}, ...)} manager that combines a number of context managers so you don't need to write -nested \keyword{with} statements. This example statement does two +nested '\keyword{with}' statements. This example statement does two things, starting a database transaction and acquiring a thread lock: \begin{verbatim} @@ -880,7 +879,7 @@ \seepep{343}{The ``with'' statement}{PEP written by Guido van~Rossum and Nick Coghlan; implemented by Mike Bland, Guido van~Rossum, and -Neal Norwitz. The PEP shows the code generated for a \keyword{with} +Neal Norwitz. The PEP shows the code generated for a '\keyword{with}' statement, which can be helpful in learning how context managers work.} @@ -891,7 +890,7 @@ %====================================================================== -\section{PEP 352: Exceptions as New-Style Classes} +\section{PEP 352: Exceptions as New-Style Classes\label{pep-352}} Exception classes can now be new-style classes, not just classic classes, and the built-in \exception{Exception} class and all the @@ -957,7 +956,7 @@ %====================================================================== -\section{PEP 353: Using ssize_t as the index type\label{section-353}} +\section{PEP 353: Using ssize_t as the index type\label{pep-353}} A wide-ranging change to Python's C API, using a new \ctype{Py_ssize_t} type definition instead of \ctype{int}, @@ -1019,7 +1018,7 @@ %====================================================================== -\section{PEP 357: The '__index__' method} +\section{PEP 357: The '__index__' method\label{pep-357}} The NumPy developers had a problem that could only be solved by adding a new special method, \method{__index__}. When using slice notation, @@ -1092,8 +1091,8 @@ \end{verbatim} \item The \function{min()} and \function{max()} built-in functions -gained a \code{key} keyword argument analogous to the \code{key} -argument for \method{sort()}. This argument supplies a function that +gained a \code{key} keyword parameter analogous to the \code{key} +argument for \method{sort()}. This parameter supplies a function that takes a single argument and is called for every value in the list; \function{min()}/\function{max()} will return the element with the smallest/largest return value from this function. @@ -1186,7 +1185,7 @@ %====================================================================== -\section{New, Improved, and Deprecated Modules} +\section{New, Improved, and Removed Modules} The standard library received many enhancements and bug fixes in Python 2.5. Here's a partial list of the most notable changes, sorted @@ -1196,13 +1195,23 @@ \begin{itemize} -% the cPickle module no longer accepts the deprecated None option in the -% args tuple returned by __reduce__(). - \item The \module{audioop} module now supports the a-LAW encoding, and the code for u-LAW encoding has been improved. (Contributed by Lars Immisch.) +\item The \module{codecs} module gained support for incremental +codecs. The \function{codec.lookup()} function now +returns a \class{CodecInfo} instance instead of a tuple. +\class{CodecInfo} instances behave like a 4-tuple to preserve backward +compatibility but also have the attributes \member{encode}, +\member{decode}, \member{incrementalencoder}, \member{incrementaldecoder}, +\member{streamwriter}, and \member{streamreader}. Incremental codecs +can receive input and produce output in multiple chunks; the output is +the same as if the entire input was fed to the non-incremental codec. +See the \module{codecs} module documentation for details. +(Designed and implemented by Walter D\"orwald.) +% Patch 1436130 + \item The \module{collections} module gained a new type, \class{defaultdict}, that subclasses the standard \class{dict} type. The new type mostly behaves like a dictionary but constructs a @@ -1244,7 +1253,7 @@ raising \exception{ValueError} if the value isn't found. \item New module: The \module{contextlib} module contains helper functions for use -with the new \keyword{with} statement. See +with the new '\keyword{with}' statement. See section~\ref{module-contextlib} for more about this module. (Contributed by Phillip J. Eby.) @@ -1257,6 +1266,11 @@ module's interface, will continue to be maintained in future versions of Python. (Contributed by Armin Rigo.) +Also, the \module{pstats} module used to analyze the data measured by +the profiler now supports directing the output to any file stream +by supplying a \var{stream} argument to the \class{Stats} constructor. +(Contributed by Skip Montanaro.) + \item The \module{csv} module, which parses files in comma-separated value format, received several enhancements and a number of bugfixes. You can now set the maximum size in bytes of a @@ -1302,7 +1316,7 @@ \item The \function{nsmallest()} and \function{nlargest()} functions in the \module{heapq} module -now support a \code{key} keyword argument similar to the one +now support a \code{key} keyword parameter similar to the one provided by the \function{min()}/\function{max()} functions and the \method{sort()} methods. For example: Example: @@ -1375,14 +1389,20 @@ (Contributed by Antti Louko and Diego Petten\`o.) % (Patch 1180695, 1212117) +\item The \module{pickle} and \module{cPickle} modules no +longer accept a return value of \code{None} from the +\method{__reduce__()} method; the method must return a tuple of +arguments instead. The ability to return \code{None} was deprecated +in Python 2.4, so this completes the removal of the feature. + \item The old \module{regex} and \module{regsub} modules, which have been deprecated ever since Python 2.0, have finally been deleted. Other deleted modules: \module{statcache}, \module{tzparse}, \module{whrandom}. -\item The \file{lib-old} directory, +\item Also deleted: the \file{lib-old} directory, which includes ancient modules such as \module{dircmp} and -\module{ni}, was also deleted. \file{lib-old} wasn't on the default +\module{ni}, was removed. \file{lib-old} wasn't on the default \code{sys.path}, so unless your programs explicitly added the directory to \code{sys.path}, this removal shouldn't affect your code. @@ -1824,7 +1844,7 @@ \item The largest change to the C API came from \pep{353}, which modifies the interpreter to use a \ctype{Py_ssize_t} type definition instead of \ctype{int}. See the earlier -section~\ref{section-353} for a discussion of this change. +section~\ref{pep-353} for a discussion of this change. \item The design of the bytecode compiler has changed a great deal, to no longer generate bytecode by traversing the parse tree. Instead @@ -1969,19 +1989,23 @@ characters but doesn't have an encoding declaration. In Python 2.4 this triggered a warning, not a syntax error. -\item The \module{pickle} module no longer uses the deprecated \var{bin} parameter. - \item Previously, the \member{gi_frame} attribute of a generator was always a frame object. Because of the \pep{342} changes -described in section~\ref{section-generators}, it's now possible +described in section~\ref{pep-342}, it's now possible for \member{gi_frame} to be \code{None}. + +\item Library: The \module{pickle} and \module{cPickle} modules no +longer accept a return value of \code{None} from the +\method{__reduce__()} method; the method must return a tuple of +arguments instead. The modules also no longer accept the deprecated +\var{bin} keyword parameter. + \item C API: Many functions now use \ctype{Py_ssize_t} -instead of \ctype{int} to allow processing more data -on 64-bit machines. Extension code may need to make -the same change to avoid warnings and to support 64-bit machines. -See the earlier -section~\ref{section-353} for a discussion of this change. +instead of \ctype{int} to allow processing more data on 64-bit +machines. Extension code may need to make the same change to avoid +warnings and to support 64-bit machines. See the earlier +section~\ref{pep-353} for a discussion of this change. \item C API: The obmalloc changes mean that Modified: python/branches/p3yk/Lib/SimpleXMLRPCServer.py ============================================================================== --- python/branches/p3yk/Lib/SimpleXMLRPCServer.py (original) +++ python/branches/p3yk/Lib/SimpleXMLRPCServer.py Fri Apr 21 18:44:05 2006 @@ -560,6 +560,7 @@ self.handle_xmlrpc(request_text) if __name__ == '__main__': + print 'Running XML-RPC server on port 8000' server = SimpleXMLRPCServer(("localhost", 8000)) server.register_function(pow) server.register_function(lambda x,y: x+y, 'add') Modified: python/branches/p3yk/Objects/stringobject.c ============================================================================== --- python/branches/p3yk/Objects/stringobject.c (original) +++ python/branches/p3yk/Objects/stringobject.c Fri Apr 21 18:44:05 2006 @@ -865,7 +865,7 @@ *p++ = quote; *p = '\0'; _PyString_Resize( - &v, (int) (p - PyString_AS_STRING(v))); + &v, (p - PyString_AS_STRING(v))); return v; } } Modified: python/branches/p3yk/PCbuild/_bsddb.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_bsddb.vcproj (original) +++ python/branches/p3yk/PCbuild/_bsddb.vcproj Fri Apr 21 18:44:05 2006 @@ -133,7 +133,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include;..\PC;"..\..\db-4.4.20\build_win32"" + AdditionalIncludeDirectories="..\Include;..\PC;"..\..\db-4.4.20\build_win32"" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -195,7 +195,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include;..\PC;"..\..\db-4.4.20\build_win32"" + AdditionalIncludeDirectories="..\Include;..\PC;"..\..\db-4.4.20\build_win32"" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_ctypes.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_ctypes.vcproj (original) +++ python/branches/p3yk/PCbuild/_ctypes.vcproj Fri Apr 21 18:44:05 2006 @@ -130,7 +130,7 @@ Name="VCCLCompilerTool" AdditionalOptions=" /USECL:MS_OPTERON" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC,..\Modules\_ctypes\libffi_msvc" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\_ctypes\libffi_msvc" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -189,7 +189,7 @@ Name="VCCLCompilerTool" AdditionalOptions=" /USECL:MS_ITANIUM" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC,..\Modules\_ctypes\libffi_msvc" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\_ctypes\libffi_msvc" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_ctypes_test.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_ctypes_test.vcproj (original) +++ python/branches/p3yk/PCbuild/_ctypes_test.vcproj Fri Apr 21 18:44:05 2006 @@ -126,7 +126,7 @@ Name="VCCLCompilerTool" AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="0" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS" MinimalRebuild="FALSE" BasicRuntimeChecks="0" @@ -181,7 +181,7 @@ Name="VCCLCompilerTool" AdditionalOptions=" /USECL:MS_OPTERON" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_elementtree.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_elementtree.vcproj (original) +++ python/branches/p3yk/PCbuild/_elementtree.vcproj Fri Apr 21 18:44:05 2006 @@ -132,7 +132,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC,..\Modules\expat" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\expat" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -193,7 +193,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC,..\Modules\expat" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\expat" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;USE_PYEXPAT_CAPI;XML_STATIC;HAVE_MEMMOVE" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_msi.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_msi.vcproj (original) +++ python/branches/p3yk/PCbuild/_msi.vcproj Fri Apr 21 18:44:05 2006 @@ -132,7 +132,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -192,7 +192,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_socket.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_socket.vcproj (original) +++ python/branches/p3yk/PCbuild/_socket.vcproj Fri Apr 21 18:44:05 2006 @@ -131,7 +131,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -192,7 +192,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_sqlite3.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_sqlite3.vcproj (original) +++ python/branches/p3yk/PCbuild/_sqlite3.vcproj Fri Apr 21 18:44:05 2006 @@ -134,7 +134,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include;..\PC;..\..\sqlite-source-3.3.4" + AdditionalIncludeDirectories="..\Include;..\PC;..\..\sqlite-source-3.3.4" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\"sqlite3\"" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -196,7 +196,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include;..\PC;..\..\sqlite-source-3.3.4" + AdditionalIncludeDirectories="..\Include;..\PC;..\..\sqlite-source-3.3.4" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;MODULE_NAME=\"sqlite3\"" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_testcapi.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_testcapi.vcproj (original) +++ python/branches/p3yk/PCbuild/_testcapi.vcproj Fri Apr 21 18:44:05 2006 @@ -129,7 +129,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -188,7 +188,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MMAP_EXPORTS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/_tkinter.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/_tkinter.vcproj (original) +++ python/branches/p3yk/PCbuild/_tkinter.vcproj Fri Apr 21 18:44:05 2006 @@ -133,7 +133,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\..\tcltk\include,..\Include,..\PC" + AdditionalIncludeDirectories="..\..\tcltk\include,..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;WITH_APPINIT" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -195,7 +195,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\..\tcltk\include,..\Include,..\PC" + AdditionalIncludeDirectories="..\..\tcltk\include,..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;WITH_APPINIT" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/bz2.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/bz2.vcproj (original) +++ python/branches/p3yk/PCbuild/bz2.vcproj Fri Apr 21 18:44:05 2006 @@ -140,7 +140,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC,..\..\bzip2-1.0.3" + AdditionalIncludeDirectories="..\Include,..\PC,..\..\bzip2-1.0.3" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -205,7 +205,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC,..\..\bzip2-1.0.3" + AdditionalIncludeDirectories="..\Include,..\PC,..\..\bzip2-1.0.3" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/pyexpat.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/pyexpat.vcproj (original) +++ python/branches/p3yk/PCbuild/pyexpat.vcproj Fri Apr 21 18:44:05 2006 @@ -131,7 +131,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC,..\Modules\expat" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\expat" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -192,7 +192,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC,..\Modules\expat" + AdditionalIncludeDirectories="..\Include,..\PC,..\Modules\expat" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;XML_NS;XML_DTD;BYTEORDER=1234;XML_CONTEXT_BYTES=1024;XML_STATIC;HAVE_MEMMOVE" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/python.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/python.vcproj (original) +++ python/branches/p3yk/PCbuild/python.vcproj Fri Apr 21 18:44:05 2006 @@ -140,7 +140,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM /VSEXTCOMP_VERBOSE" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -204,7 +204,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/pythoncore.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/pythoncore.vcproj (original) +++ python/branches/p3yk/PCbuild/pythoncore.vcproj Fri Apr 21 18:44:05 2006 @@ -147,7 +147,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -214,7 +214,7 @@ AdditionalOptions="/Zm200 /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;USE_DL_EXPORT" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/pythonw.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/pythonw.vcproj (original) +++ python/branches/p3yk/PCbuild/pythonw.vcproj Fri Apr 21 18:44:05 2006 @@ -133,7 +133,7 @@ AdditionalOptions=" /USECL:MS_ITANIUM" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl;{MSSDKPATH}\include\Win64\crt;{MSSDKPATH}\include\Win64\crt\sys;{MSSDKPATH}\include\Win64\mfc;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" @@ -195,7 +195,7 @@ AdditionalOptions=" /USECL:MS_OPTERON" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="{MSSDKPATH}\include\Win64\atl\amd64;{MSSDKPATH}\include\Win64\crt\amd64;{MSSDKPATH}\include\Win64\crt\amd64\sys;{MSSDKPATH}\include\Win64\mfc\amd64;..\Include,..\PC" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="TRUE" BasicRuntimeChecks="0" Modified: python/branches/p3yk/PCbuild/readme.txt ============================================================================== --- python/branches/p3yk/PCbuild/readme.txt (original) +++ python/branches/p3yk/PCbuild/readme.txt Fri Apr 21 18:44:05 2006 @@ -264,7 +264,7 @@ In addition, you need the Visual Studio plugin for external C compilers, from http://sf.net/projects/vsextcomp. The plugin will wrap cl.exe, to locate the proper target compiler, and convert compiler options -accordingly. +accordingly. The project files require atleast version 0.8. Building for AMD64 ------------------ Modified: python/branches/p3yk/PCbuild/select.vcproj ============================================================================== --- python/branches/p3yk/PCbuild/select.vcproj (original) +++ python/branches/p3yk/PCbuild/select.vcproj Fri Apr 21 18:44:05 2006 @@ -21,7 +21,7 @@ Name="VCCLCompilerTool" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="..\Include,..\PC,..\..\select113" + AdditionalIncludeDirectories="..\Include,..\PC" PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS" StringPooling="TRUE" RuntimeLibrary="2" @@ -77,7 +77,7 @@ Author: guido.van.rossum Date: Sat Apr 22 19:37:27 2006 New Revision: 45650 Removed: python/branches/p3yk/Lib/test/test_coercion.py Log: Delete test_coercion.py. Coercion is dead, so this test is useless. (Plus, it fails. :-) Deleted: /python/branches/p3yk/Lib/test/test_coercion.py ============================================================================== --- /python/branches/p3yk/Lib/test/test_coercion.py Sat Apr 22 19:37:27 2006 +++ (empty file) @@ -1,329 +0,0 @@ -import copy -import sys -import warnings -import unittest -from test.test_support import run_unittest - -# Fake a number that implements numeric methods through __coerce__ -class CoerceNumber: - def __init__(self, arg): - self.arg = arg - - def __repr__(self): - return '' % repr(self.arg) - - def __coerce__(self, other): - if isinstance(other, CoerceNumber): - return self.arg, other.arg - else: - return (self.arg, other) - -# New-style class version of CoerceNumber -class CoerceTo(object): - def __init__(self, arg): - self.arg = arg - def __coerce__(self, other): - if isinstance(other, CoerceTo): - return self.arg, other.arg - else: - return self.arg, other - - -# Fake a number that implements numeric ops through methods. -class MethodNumber: - def __init__(self,arg): - self.arg = arg - - def __repr__(self): - return '' % repr(self.arg) - - def __add__(self,other): - return self.arg + other - - def __radd__(self,other): - return other + self.arg - - def __sub__(self,other): - return self.arg - other - - def __rsub__(self,other): - return other - self.arg - - def __mul__(self,other): - return self.arg * other - - def __rmul__(self,other): - return other * self.arg - - def __truediv__(self,other): - return self.arg / other - - def __rtruediv__(self,other): - return other / self.arg - - def __truediv__(self,other): - return self.arg / other - - def __rtruediv__(self,other): - return other / self.arg - - def __floordiv__(self,other): - return self.arg // other - - def __rfloordiv__(self,other): - return other // self.arg - - def __pow__(self,other): - return self.arg ** other - - def __rpow__(self,other): - return other ** self.arg - - def __mod__(self,other): - return self.arg % other - - def __rmod__(self,other): - return other % self.arg - - def __cmp__(self, other): - return cmp(self.arg, other) - - -candidates = [2, 2L, 4.0, 2+0j, [1], (2,), None, - MethodNumber(2), CoerceNumber(2)] - -infix_binops = [ '+', '-', '*', '**', '%', '//', '/' ] - -TE = TypeError -# b = both normal and augmented give same result list -# s = single result lists for normal and augmented -# e = equals other results -# result lists: ['+', '-', '*', '**', '%', '//', ('classic /', 'new /')] -# ^^^^^^^^^^^^^^^^^^^^^^ -# 2-tuple if results differ -# else only one value -infix_results = { - # 2 - (0,0): ('b', [4, 0, 4, 4, 0, 1, (1, 1.0)]), - (0,1): ('e', (0,0)), - (0,2): ('b', [6.0, -2.0, 8.0, 16.0, 2.0, 0.0, 0.5]), - (0,3): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]), - (0,4): ('b', [TE, TE, [1, 1], TE, TE, TE, TE]), - (0,5): ('b', [TE, TE, (2, 2), TE, TE, TE, TE]), - (0,6): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (0,7): ('e', (0,0)), - (0,8): ('e', (0,0)), - - # 2L - (1,0): ('e', (0,0)), - (1,1): ('e', (0,1)), - (1,2): ('e', (0,2)), - (1,3): ('e', (0,3)), - (1,4): ('e', (0,4)), - (1,5): ('e', (0,5)), - (1,6): ('e', (0,6)), - (1,7): ('e', (0,7)), - (1,8): ('e', (0,8)), - - # 4.0 - (2,0): ('b', [6.0, 2.0, 8.0, 16.0, 0.0, 2.0, 2.0]), - (2,1): ('e', (2,0)), - (2,2): ('b', [8.0, 0.0, 16.0, 256.0, 0.0, 1.0, 1.0]), - (2,3): ('b', [6+0j, 2+0j, 8+0j, 16+0j, 0+0j, 2+0j, 2+0j]), - (2,4): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (2,5): ('e', (2,4)), - (2,6): ('e', (2,4)), - (2,7): ('e', (2,0)), - (2,8): ('e', (2,0)), - - # (2+0j) - (3,0): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]), - (3,1): ('e', (3,0)), - (3,2): ('b', [6+0j, -2+0j, 8+0j, 16+0j, 2+0j, 0+0j, 0.5+0j]), - (3,3): ('b', [4+0j, 0+0j, 4+0j, 4+0j, 0+0j, 1+0j, 1+0j]), - (3,4): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (3,5): ('e', (3,4)), - (3,6): ('e', (3,4)), - (3,7): ('e', (3,0)), - (3,8): ('e', (3,0)), - - # [1] - (4,0): ('b', [TE, TE, [1, 1], TE, TE, TE, TE]), - (4,1): ('e', (4,0)), - (4,2): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (4,3): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (4,4): ('b', [[1, 1], TE, TE, TE, TE, TE, TE]), - (4,5): ('s', [TE, TE, TE, TE, TE, TE, TE], [[1, 2], TE, TE, TE, TE, TE, TE]), - (4,6): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (4,7): ('e', (4,0)), - (4,8): ('e', (4,0)), - - # (2,) - (5,0): ('b', [TE, TE, (2, 2), TE, TE, TE, TE]), - (5,1): ('e', (5,0)), - (5,2): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (5,3): ('e', (5,2)), - (5,4): ('e', (5,2)), - (5,5): ('b', [(2, 2), TE, TE, TE, TE, TE, TE]), - (5,6): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (5,7): ('e', (5,0)), - (5,8): ('e', (5,0)), - - # None - (6,0): ('b', [TE, TE, TE, TE, TE, TE, TE]), - (6,1): ('e', (6,0)), - (6,2): ('e', (6,0)), - (6,3): ('e', (6,0)), - (6,4): ('e', (6,0)), - (6,5): ('e', (6,0)), - (6,6): ('e', (6,0)), - (6,7): ('e', (6,0)), - (6,8): ('e', (6,0)), - - # MethodNumber(2) - (7,0): ('e', (0,0)), - (7,1): ('e', (0,1)), - (7,2): ('e', (0,2)), - (7,3): ('e', (0,3)), - (7,4): ('e', (0,4)), - (7,5): ('e', (0,5)), - (7,6): ('e', (0,6)), - (7,7): ('e', (0,7)), - (7,8): ('e', (0,8)), - - # CoerceNumber(2) - (8,0): ('e', (0,0)), - (8,1): ('e', (0,1)), - (8,2): ('e', (0,2)), - (8,3): ('e', (0,3)), - (8,4): ('e', (0,4)), - (8,5): ('e', (0,5)), - (8,6): ('e', (0,6)), - (8,7): ('e', (0,7)), - (8,8): ('e', (0,8)), -} - -def process_infix_results(): - for key in sorted(infix_results): - val = infix_results[key] - if val[0] == 'e': - infix_results[key] = infix_results[val[1]] - else: - if val[0] == 's': - res = (val[1], val[2]) - elif val[0] == 'b': - res = (val[1], val[1]) - for i in range(1): - if isinstance(res[i][6], tuple): - if 1/2 == 0: - # testing with classic (floor) division - res[i][6] = res[i][6][0] - else: - # testing with -Qnew - res[i][6] = res[i][6][1] - infix_results[key] = res - - - -process_infix_results() -# now infix_results has two lists of results for every pairing. - -prefix_binops = [ 'divmod' ] -prefix_results = [ - [(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)], - [(1L,0L), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1L,0L)], - [(2.0,0.0), (2.0,0.0), (1.0,0.0), ((2+0j),0j), TE, TE, TE, TE, (2.0,0.0)], - [((1+0j),0j), ((1+0j),0j), (0j,(2+0j)), ((1+0j),0j), TE, TE, TE, TE, ((1+0j),0j)], - [TE, TE, TE, TE, TE, TE, TE, TE, TE], - [TE, TE, TE, TE, TE, TE, TE, TE, TE], - [TE, TE, TE, TE, TE, TE, TE, TE, TE], - [TE, TE, TE, TE, TE, TE, TE, TE, TE], - [(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)] -] - -def format_float(value): - if abs(value) < 0.01: - return '0.0' - else: - return '%.1f' % value - -# avoid testing platform fp quirks -def format_result(value): - if isinstance(value, complex): - return '(%s + %sj)' % (format_float(value.real), - format_float(value.imag)) - elif isinstance(value, float): - return format_float(value) - return str(value) - -class CoercionTest(unittest.TestCase): - def test_infix_binops(self): - for ia, a in enumerate(candidates): - for ib, b in enumerate(candidates): - results = infix_results[(ia, ib)] - for op, res, ires in zip(infix_binops, results[0], results[1]): - if res is TE: - self.assertRaises(TypeError, eval, - 'a %s b' % op, {'a': a, 'b': b}) - else: - self.assertEquals(format_result(res), - format_result(eval('a %s b' % op)), - '%s %s %s == %s failed' % (a, op, b, res)) - try: - z = copy.copy(a) - except copy.Error: - z = a # assume it has no inplace ops - if ires is TE: - try: - exec 'z %s= b' % op - except TypeError: - pass - else: - self.fail("TypeError not raised") - else: - exec('z %s= b' % op) - self.assertEquals(ires, z) - - def test_prefix_binops(self): - for ia, a in enumerate(candidates): - for ib, b in enumerate(candidates): - for op in prefix_binops: - res = prefix_results[ia][ib] - if res is TE: - self.assertRaises(TypeError, eval, - '%s(a, b)' % op, {'a': a, 'b': b}) - else: - self.assertEquals(format_result(res), - format_result(eval('%s(a, b)' % op)), - '%s(%s, %s) == %s failed' % (op, a, b, res)) - - def test_cmptypes(self): - # Built-in tp_compare slots expect their arguments to have the - # same type, but a user-defined __coerce__ doesn't have to obey. - # SF #980352 - evil_coercer = CoerceTo(42) - # Make sure these don't crash any more - self.assertNotEquals(cmp(u'fish', evil_coercer), 0) - self.assertNotEquals(cmp(slice(1), evil_coercer), 0) - # ...but that this still works - class WackyComparer(object): - def __cmp__(slf, other): - self.assert_(other == 42, 'expected evil_coercer, got %r' % other) - return 0 - self.assertEquals(cmp(WackyComparer(), evil_coercer), 0) - # ...and classic classes too, since that code path is a little different - class ClassicWackyComparer: - def __cmp__(slf, other): - self.assert_(other == 42, 'expected evil_coercer, got %r' % other) - return 0 - self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 0) - -def test_main(): - warnings.filterwarnings("ignore", - r'complex divmod\(\), // and % are deprecated', - DeprecationWarning, - r'test.test_coercion$') - run_unittest(CoercionTest) - -if __name__ == "__main__": - test_main() From python-3000-checkins at python.org Sun Apr 23 01:28:06 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sun, 23 Apr 2006 01:28:06 +0200 (CEST) Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk: Include/Python.h Include/bytesobject.h Lib/test/test_bytes.py Makefile.pre.in Objects/bytesobject.c Objects/object.c Python/bltinmodule.c Message-ID: <20060422232806.351AE1E400B@bag.python.org> Author: guido.van.rossum Date: Sun Apr 23 01:28:04 2006 New Revision: 45652 Added: python/branches/p3yk/Include/bytesobject.h (contents, props changed) python/branches/p3yk/Lib/test/test_bytes.py (contents, props changed) python/branches/p3yk/Objects/bytesobject.c (contents, props changed) Modified: python/branches/p3yk/Include/Python.h python/branches/p3yk/Makefile.pre.in python/branches/p3yk/Objects/object.c python/branches/p3yk/Python/bltinmodule.c Log: Here is a bytes type. It's very minimal but it's a start. Modified: python/branches/p3yk/Include/Python.h ============================================================================== --- python/branches/p3yk/Include/Python.h (original) +++ python/branches/p3yk/Include/Python.h Sun Apr 23 01:28:04 2006 @@ -78,6 +78,7 @@ #include "pydebug.h" +#include "bytesobject.h" #include "unicodeobject.h" #include "intobject.h" #include "boolobject.h" Added: python/branches/p3yk/Include/bytesobject.h ============================================================================== --- (empty file) +++ python/branches/p3yk/Include/bytesobject.h Sun Apr 23 01:28:04 2006 @@ -0,0 +1,47 @@ +/* Bytes object interface */ + +#ifndef Py_BYTESOBJECT_H +#define Py_BYTESOBJECT_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Type PyBytesObject represents a mutable array of bytes. + * The Python API is that of a sequence; + * the bytes are mapped to ints in [0, 256). + * Bytes are not characters; they may be used to encode characters. + * The only way to go between bytes and str/unicode is via encoding + * and decoding. + * For the concenience of C programmers, the bytes type is considered + * to contain a char pointer, not an unsigned char pointer. + */ + +/* Object layout */ +typedef struct { + PyObject_VAR_HEAD + char *ob_sval; +} PyBytesObject; + +/* Type object */ +PyAPI_DATA(PyTypeObject) PyBytes_Type; + +/* Type check macros */ +#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type) +#define PyBytes_CheckExact(self) ((self)->ob_type == &PyBytes_Type) + +/* Direct API functions */ +PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); +PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); +PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); +PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t); + +/* Macros, trading safety for speed */ +#define PyBytes_AS_STRING(self) (((PyBytesObject *)(self))->ob_sval) +#define PyBytes_GET_SIZE(self) (((PyBytesObject *)(self))->ob_size) + +#ifdef __cplusplus +} +#endif +#endif /* !Py_BYTESOBJECT_H */ Added: python/branches/p3yk/Lib/test/test_bytes.py ============================================================================== --- (empty file) +++ python/branches/p3yk/Lib/test/test_bytes.py Sun Apr 23 01:28:04 2006 @@ -0,0 +1,109 @@ +"""Unit tests for the bytes type.""" + +import sys +import unittest +import test.test_support + + +class BytesTest(unittest.TestCase): + + def test_basics(self): + b = bytes() + self.assertEqual(type(b), bytes) + self.assertEqual(b.__class__, bytes) + + def test_empty_sequence(self): + b = bytes() + self.assertEqual(len(b), 0) + self.assertRaises(IndexError, lambda: b[0]) + self.assertRaises(IndexError, lambda: b[1]) + self.assertRaises(IndexError, lambda: b[sys.maxint]) + self.assertRaises(IndexError, lambda: b[sys.maxint+1]) + self.assertRaises(IndexError, lambda: b[10**100]) + self.assertRaises(IndexError, lambda: b[-1]) + self.assertRaises(IndexError, lambda: b[-2]) + self.assertRaises(IndexError, lambda: b[-sys.maxint]) + self.assertRaises(IndexError, lambda: b[-sys.maxint-1]) + self.assertRaises(IndexError, lambda: b[-sys.maxint-2]) + self.assertRaises(IndexError, lambda: b[-10**100]) + + def test_from_list(self): + ints = list(range(256)) + b = bytes(i for i in ints) + self.assertEqual(len(b), 256) + self.assertEqual(list(b), ints) + + def test_from_index(self): + class C: + def __init__(self, i=0): + self.i = i + def __index__(self): + return self.i + b = bytes([C(), C(1), C(254), C(255)]) + self.assertEqual(list(b), [0, 1, 254, 255]) + self.assertRaises(ValueError, lambda: bytes([C(-1)])) + self.assertRaises(ValueError, lambda: bytes([C(256)])) + + def test_constructor_type_errors(self): + class C: + pass + self.assertRaises(TypeError, lambda: bytes(["0"])) + self.assertRaises(TypeError, lambda: bytes([0.0])) + self.assertRaises(TypeError, lambda: bytes([None])) + self.assertRaises(TypeError, lambda: bytes([C()])) + + def test_constructor_value_errors(self): + self.assertRaises(ValueError, lambda: bytes([-1])) + self.assertRaises(ValueError, lambda: bytes([-sys.maxint])) + self.assertRaises(ValueError, lambda: bytes([-sys.maxint-1])) + self.assertRaises(ValueError, lambda: bytes([-sys.maxint-2])) + self.assertRaises(ValueError, lambda: bytes([-10**100])) + self.assertRaises(ValueError, lambda: bytes([256])) + self.assertRaises(ValueError, lambda: bytes([257])) + self.assertRaises(ValueError, lambda: bytes([sys.maxint])) + self.assertRaises(ValueError, lambda: bytes([sys.maxint+1])) + self.assertRaises(ValueError, lambda: bytes([10**100])) + + def test_repr(self): + self.assertEqual(repr(bytes()), "bytes()") + self.assertEqual(repr(bytes([0])), "bytes([0x00])") + self.assertEqual(repr(bytes([0, 1, 254, 255])), "bytes([0x00, 0x01, 0xfe, 0xff])") + + def test_compare(self): + b1 = bytes([1, 2, 3]) + b2 = bytes([1, 2, 3]) + b3 = bytes([1, 3]) + + self.failUnless(b1 == b2) + self.failUnless(b2 != b3) + self.failUnless(b1 <= b2) + self.failUnless(b1 <= b3) + self.failUnless(b1 < b3) + self.failUnless(b1 >= b2) + self.failUnless(b3 >= b2) + self.failUnless(b3 > b2) + + self.failIf(b1 != b2) + self.failIf(b2 == b3) + self.failIf(b1 > b2) + self.failIf(b1 > b3) + self.failIf(b1 >= b3) + self.failIf(b1 < b2) + self.failIf(b3 < b2) + self.failIf(b3 <= b2) + + def test_nohash(self): + self.assertRaises(TypeError, hash, bytes()) + + def test_doc(self): + self.failUnless(bytes.__doc__ != None) + self.failUnless(bytes.__doc__.startswith("bytes(")) + + +def test_main(): + test.test_support.run_unittest(XrangeTest) + + +if __name__ == "__main__": + ##test_main() + unittest.main() Modified: python/branches/p3yk/Makefile.pre.in ============================================================================== --- python/branches/p3yk/Makefile.pre.in (original) +++ python/branches/p3yk/Makefile.pre.in Sun Apr 23 01:28:04 2006 @@ -278,6 +278,7 @@ Objects/abstract.o \ Objects/boolobject.o \ Objects/bufferobject.o \ + Objects/bytesobject.o \ Objects/cellobject.o \ Objects/classobject.o \ Objects/cobject.o \ @@ -494,6 +495,7 @@ Include/abstract.h \ Include/boolobject.h \ Include/bufferobject.h \ + Include/bytesobject.h \ Include/ceval.h \ Include/classobject.h \ Include/cobject.h \ Added: python/branches/p3yk/Objects/bytesobject.c ============================================================================== --- (empty file) +++ python/branches/p3yk/Objects/bytesobject.c Sun Apr 23 01:28:04 2006 @@ -0,0 +1,373 @@ +/* Bytes object implementation */ + +/* XXX TO DO: optimizations */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" + +/* Direct API functions */ + +PyObject * +PyBytes_FromStringAndSize(const char *sval, Py_ssize_t size) +{ + PyBytesObject *new; + + if (size != 0) { + assert(sval != NULL); + assert(size > 0); + } + + new = PyObject_New(PyBytesObject, &PyBytes_Type); + if (new == NULL) + return NULL; + + if (size > 0) { + new->ob_sval = PyMem_Malloc(size); + if (new->ob_sval == NULL) { + Py_DECREF(new); + return NULL; + } + memcpy(new->ob_sval, sval, size); + new->ob_size = size; + } + + return (PyObject *)new; +} + +Py_ssize_t +PyBytes_Size(PyObject *self) +{ + assert(self != NULL); + assert(PyBytes_Check(self)); + + return ((PyBytesObject *)self)->ob_size; +} + +char * +PyBytes_AsString(PyObject *self) +{ + assert(self != NULL); + assert(PyBytes_Check(self)); + + return ((PyBytesObject *)self)->ob_sval; +} + +int +PyBytes_Resize(PyObject *self, Py_ssize_t size) +{ + void *sval; + + assert(self != NULL); + assert(PyBytes_Check(self)); + assert(size >= 0); + + sval = PyMem_Realloc(((PyBytesObject *)self)->ob_sval, size); + if (sval == NULL) { + PyErr_NoMemory(); + return -1; + } + + ((PyBytesObject *)self)->ob_sval = sval; + ((PyBytesObject *)self)->ob_size = size; + + return 0; +} + +/* Functions stuffed into the type object */ + +static Py_ssize_t +bytes_length(PyBytesObject *self) +{ + return self->ob_size; +} + +static PyObject * +bytes_getitem(PyBytesObject *self, Py_ssize_t i) +{ + if (i < 0) + i += self->ob_size; + if (i < 0 || i >= self->ob_size) { + PyErr_SetString(PyExc_IndexError, "bytes index out of range"); + return NULL; + } + return PyInt_FromLong((unsigned char)(self->ob_sval[i])); +} + +static long +bytes_nohash(PyObject *self) +{ + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); + return -1; +} + +static int +bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"sequence", 0}; + PyObject *arg = NULL; + PyObject *it; /* iter(arg) */ + PyObject *(*iternext)(PyObject *); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bytes", kwlist, &arg)) + return -1; + + /* Verify list invariants established by PyType_GenericAlloc() */ + if (self->ob_size != 0) { + assert(self->ob_sval != NULL); + assert(self->ob_size > 0); + } + + /* Empty previous contents */ + if (PyBytes_Resize((PyObject *)self, 0) < 0) + return -1; + + /* Quick check if we're done */ + if (arg == 0) + return 0; + + /* XXX Optimize this if the arguments is a list, tuple, or bytes */ + + /* Get the iterator */ + it = PyObject_GetIter(arg); + if (it == NULL) + return 0; + iternext = *it->ob_type->tp_iternext; + + /* Run the iterator to exhaustion */ + for (;;) { + PyObject *item; + Py_ssize_t value; + + /* Get the next item */ + item = iternext(it); + if (item == NULL) { + if (PyErr_Occurred()) { + if (!PyErr_ExceptionMatches(PyExc_StopIteration)) + goto error; + PyErr_Clear(); + } + break; + } + + /* Interpret it as an int (__index__) */ + value = PyNumber_Index(item); + if (value == -1 && PyErr_Occurred()) + goto error; + + /* Range check */ + if (value < 0 || value >= 256) { + PyErr_SetString(PyExc_ValueError, "bytes must be in range(0, 256)"); + goto error; + } + + /* Append the byte */ + /* XXX Speed this up */ + if (PyBytes_Resize((PyObject *)self, self->ob_size+1) < 0) + goto error; + self->ob_sval[self->ob_size-1] = value; + } + + /* Clean up and return success */ + Py_DECREF(it); + return 0; + + error: + /* Error handling when it != NULL */ + Py_DECREF(it); + return -1; +} + +static PyObject * +bytes_repr(PyBytesObject *self) +{ + PyObject *list; + PyObject *str; + PyObject *result; + int err; + int i; + + if (self->ob_size == 0) + return PyString_FromString("bytes()"); + + list = PyList_New(0); + if (list == NULL) + return NULL; + + str = PyString_FromString("bytes(["); + if (str == NULL) + goto error; + + err = PyList_Append(list, str); + Py_DECREF(str); + if (err < 0) + goto error; + + for (i = 0; i < self->ob_size; i++) { + char buffer[20]; + sprintf(buffer, ", 0x%02x", (unsigned char) (self->ob_sval[i])); + str = PyString_FromString((i == 0) ? buffer+2 : buffer); + if (str == NULL) + goto error; + err = PyList_Append(list, str); + Py_DECREF(str); + if (err < 0) + goto error; + } + + str = PyString_FromString("])"); + if (str == NULL) + goto error; + + err = PyList_Append(list, str); + Py_DECREF(str); + if (err < 0) + goto error; + + str = PyString_FromString(""); + if (str == NULL) + goto error; + + result = _PyString_Join(str, list); + Py_DECREF(str); + Py_DECREF(list); + return result; + + error: + /* Error handling when list != NULL */ + Py_DECREF(list); + return NULL; +} + +static PyObject * +bytes_richcompare(PyBytesObject *self, PyBytesObject *other, int op) +{ + PyObject *res; + int minsize; + int cmp; + + if (!PyBytes_Check(self) || !PyBytes_Check(other)) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + + if (self->ob_size != other->ob_size && (op == Py_EQ || op == Py_NE)) { + /* Shortcut: if the lengths differ, the objects differ */ + cmp = (op == Py_NE); + } + else { + minsize = self->ob_size; + if (other->ob_size < minsize) + minsize = other->ob_size; + + cmp = memcmp(self->ob_sval, other->ob_sval, minsize); + /* In ISO C, memcmp() guarantees to use unsigned bytes! */ + + if (cmp == 0) { + if (self->ob_size < other->ob_size) + cmp = -1; + else if (self->ob_size > other->ob_size) + cmp = 1; + } + + switch (op) { + case Py_LT: cmp = cmp < 0; break; + case Py_LE: cmp = cmp <= 0; break; + case Py_EQ: cmp = cmp == 0; break; + case Py_NE: cmp = cmp != 0; break; + case Py_GT: cmp = cmp > 0; break; + case Py_GE: cmp = cmp >= 0; break; + } + } + + res = cmp ? Py_True : Py_False; + Py_INCREF(res); + return res; +} + +static void +bytes_dealloc(PyBytesObject *self) +{ + if (self->ob_sval != 0) { + PyMem_Free(self->ob_sval); + } + self->ob_type->tp_free((PyObject *)self); +} + +static PySequenceMethods bytes_as_sequence = { + (lenfunc)bytes_length, /*sq_length*/ + (binaryfunc)0, /*sq_concat*/ + (ssizeargfunc)0, /*sq_repeat*/ + (ssizeargfunc)bytes_getitem, /*sq_item*/ + (ssizessizeargfunc)0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + (objobjproc)0, /*sq_contains*/ +}; + +static PyMappingMethods bytes_as_mapping = { + (lenfunc)bytes_length, + (binaryfunc)0, + 0, +}; + +static PyBufferProcs bytes_as_buffer = { +/* + (readbufferproc)bytes_buffer_getreadbuf, + (writebufferproc)bytes_buffer_getwritebuf, + (segcountproc)bytes_buffer_getsegcount, + (charbufferproc)bytes_buffer_getcharbuf, +*/ +}; + +static PyMethodDef +bytes_methods[] = { + {NULL, NULL} +}; + +PyDoc_STRVAR(bytes_doc, +"bytes([iterable]) -> new array of bytes.\n\ +\n\ +If an argument is given it must be an iterable yielding ints in range(256)."); + +PyTypeObject PyBytes_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "bytes", + sizeof(PyBytesObject), + 0, + (destructor)bytes_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)bytes_repr, /* tp_repr */ + 0, /* tp_as_number */ + &bytes_as_sequence, /* tp_as_sequence */ + &bytes_as_mapping, /* tp_as_mapping */ + bytes_nohash, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + &bytes_as_buffer, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ /* bytes is 'final' or 'sealed' */ + bytes_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)bytes_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + bytes_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)bytes_init, /* tp_init */ + PyType_GenericAlloc, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + PyObject_Del, /* tp_free */ +}; Modified: python/branches/p3yk/Objects/object.c ============================================================================== --- python/branches/p3yk/Objects/object.c (original) +++ python/branches/p3yk/Objects/object.c Sun Apr 23 01:28:04 2006 @@ -1881,6 +1881,9 @@ if (PyType_Ready(&PyBool_Type) < 0) Py_FatalError("Can't initialize 'bool'"); + if (PyType_Ready(&PyBytes_Type) < 0) + Py_FatalError("Can't initialize 'bytes'"); + if (PyType_Ready(&PyString_Type) < 0) Py_FatalError("Can't initialize 'str'"); Modified: python/branches/p3yk/Python/bltinmodule.c ============================================================================== --- python/branches/p3yk/Python/bltinmodule.c (original) +++ python/branches/p3yk/Python/bltinmodule.c Sun Apr 23 01:28:04 2006 @@ -2139,6 +2139,7 @@ SETBUILTIN("basestring", &PyBaseString_Type); SETBUILTIN("bool", &PyBool_Type); SETBUILTIN("buffer", &PyBuffer_Type); + SETBUILTIN("bytes", &PyBytes_Type); SETBUILTIN("classmethod", &PyClassMethod_Type); #ifndef WITHOUT_COMPLEX SETBUILTIN("complex", &PyComplex_Type); From python-3000-checkins at python.org Sun Apr 23 02:19:59 2006 From: python-3000-checkins at python.org (thomas.wouters) Date: Sun, 23 Apr 2006 02:19:59 +0200 (CEST) Subject: [Python-3000-checkins] r45653 - python/branches/p3yk/Lib/test/test_bytes.py Message-ID: <20060423001959.11AD81E400B@bag.python.org> Author: thomas.wouters Date: Sun Apr 23 02:19:58 2006 New Revision: 45653 Modified: python/branches/p3yk/Lib/test/test_bytes.py Log: Fix test_main function so test_bytes can be run by regrtest.py. Modified: python/branches/p3yk/Lib/test/test_bytes.py ============================================================================== --- python/branches/p3yk/Lib/test/test_bytes.py (original) +++ python/branches/p3yk/Lib/test/test_bytes.py Sun Apr 23 02:19:58 2006 @@ -101,7 +101,7 @@ def test_main(): - test.test_support.run_unittest(XrangeTest) + test.test_support.run_unittest(BytesTest) if __name__ == "__main__": From thomas at python.org Sun Apr 23 02:25:53 2006 From: thomas at python.org (Thomas Wouters) Date: Sun, 23 Apr 2006 02:25:53 +0200 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk: Include/Python.h Include/bytesobject.h Lib/test/test_bytes.py Makefile.pre.in Objects/bytesobject.c Objects/object.c Python/bltinmodule.c In-Reply-To: <20060422232806.351AE1E400B@bag.python.org> References: <20060422232806.351AE1E400B@bag.python.org> Message-ID: <9e804ac0604221725h4a66cac2r14732aa0da82fb68@mail.gmail.com> Yay, progress :) On 4/23/06, guido.van.rossum wrote: > Here is a bytes type. It's very minimal but it's a start. It's a bit leaky, and I noticed a teensy buglet. Are you still working on it, or should I just check in fixes? + /* Get the iterator */ > + it = PyObject_GetIter(arg); > + if (it == NULL) > + return 0; Shouldn't this return -1? > > + /* Run the iterator to exhaustion */ > + for (;;) { > + PyObject *item; > + Py_ssize_t value; > + > + /* Get the next item */ > + item = iternext(it); You never DECREF the item the iterator gives you. (There was also a typo in the testsuite that only showed when running under regrtest, I checked that in already.) -- Thomas Wouters Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000-checkins/attachments/20060423/d76a4e8e/attachment.html From python-3000-checkins at python.org Sun Apr 23 09:43:55 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sun, 23 Apr 2006 09:43:55 +0200 (CEST) Subject: [Python-3000-checkins] r45656 - in python/branches/p3yk: Lib/test/test_bytes.py Objects/bytesobject.c Message-ID: <20060423074355.8E4221E4007@bag.python.org> Author: guido.van.rossum Date: Sun Apr 23 09:43:54 2006 New Revision: 45656 Modified: python/branches/p3yk/Lib/test/test_bytes.py python/branches/p3yk/Objects/bytesobject.c Log: Fix a leak and a buglet discovered by Thomas. Get rid of silly lambdas in the unit test suite. Add a TODO list to the unit test suite (TDD style). Modified: python/branches/p3yk/Lib/test/test_bytes.py ============================================================================== --- python/branches/p3yk/Lib/test/test_bytes.py (original) +++ python/branches/p3yk/Lib/test/test_bytes.py Sun Apr 23 09:43:54 2006 @@ -41,28 +41,29 @@ return self.i b = bytes([C(), C(1), C(254), C(255)]) self.assertEqual(list(b), [0, 1, 254, 255]) - self.assertRaises(ValueError, lambda: bytes([C(-1)])) - self.assertRaises(ValueError, lambda: bytes([C(256)])) + self.assertRaises(ValueError, bytes, [C(-1)]) + self.assertRaises(ValueError, bytes, [C(256)]) def test_constructor_type_errors(self): + self.assertRaises(TypeError, bytes, 0) class C: pass - self.assertRaises(TypeError, lambda: bytes(["0"])) - self.assertRaises(TypeError, lambda: bytes([0.0])) - self.assertRaises(TypeError, lambda: bytes([None])) - self.assertRaises(TypeError, lambda: bytes([C()])) + self.assertRaises(TypeError, bytes, ["0"]) + self.assertRaises(TypeError, bytes, [0.0]) + self.assertRaises(TypeError, bytes, [None]) + self.assertRaises(TypeError, bytes, [C()]) def test_constructor_value_errors(self): - self.assertRaises(ValueError, lambda: bytes([-1])) - self.assertRaises(ValueError, lambda: bytes([-sys.maxint])) - self.assertRaises(ValueError, lambda: bytes([-sys.maxint-1])) - self.assertRaises(ValueError, lambda: bytes([-sys.maxint-2])) - self.assertRaises(ValueError, lambda: bytes([-10**100])) - self.assertRaises(ValueError, lambda: bytes([256])) - self.assertRaises(ValueError, lambda: bytes([257])) - self.assertRaises(ValueError, lambda: bytes([sys.maxint])) - self.assertRaises(ValueError, lambda: bytes([sys.maxint+1])) - self.assertRaises(ValueError, lambda: bytes([10**100])) + self.assertRaises(ValueError, bytes, [-1]) + self.assertRaises(ValueError, bytes, [-sys.maxint]) + self.assertRaises(ValueError, bytes, [-sys.maxint-1]) + self.assertRaises(ValueError, bytes, [-sys.maxint-2]) + self.assertRaises(ValueError, bytes, [-10**100]) + self.assertRaises(ValueError, bytes, [256]) + self.assertRaises(ValueError, bytes, [257]) + self.assertRaises(ValueError, bytes, [sys.maxint]) + self.assertRaises(ValueError, bytes, [sys.maxint+1]) + self.assertRaises(ValueError, bytes, [10**100]) def test_repr(self): self.assertEqual(repr(bytes()), "bytes()") @@ -99,6 +100,37 @@ self.failUnless(bytes.__doc__ != None) self.failUnless(bytes.__doc__.startswith("bytes(")) + # XXX More stuff to test and build (TDD): + # constructor from str: bytes() == bytes(map(ord, ))? + # encoding constructor: bytes([, [, ]]) + # default encoding Latin-1? (Matching ord) + # slicing + # extended slicing? + # item assignment + # slice assignment + # extended slice assignment? + # __contains__ with simple int arg + # __contains__ with another bytes arg? + # find/index? (int or bytes arg?) + # count? (int arg) + # concatenation (+) + # repeat? + # extend? + # append? + # insert? + # pop? + # __reversed__? + # reverse? (inplace) + # NOT sort! + # __iter__? (optimization) + # __str__? (could return "".join(map(chr, self)) + # decode + # buffer API + # check that regexp searches work + # (I suppose re.sub() returns a string) + # file.readinto + # file.write + def test_main(): test.test_support.run_unittest(BytesTest) Modified: python/branches/p3yk/Objects/bytesobject.c ============================================================================== --- python/branches/p3yk/Objects/bytesobject.c (original) +++ python/branches/p3yk/Objects/bytesobject.c Sun Apr 23 09:43:54 2006 @@ -130,7 +130,7 @@ /* Get the iterator */ it = PyObject_GetIter(arg); if (it == NULL) - return 0; + return -1; iternext = *it->ob_type->tp_iternext; /* Run the iterator to exhaustion */ @@ -151,6 +151,7 @@ /* Interpret it as an int (__index__) */ value = PyNumber_Index(item); + Py_DECREF(item); if (value == -1 && PyErr_Occurred()) goto error; From python-3000-checkins at python.org Mon Apr 24 15:47:06 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Mon, 24 Apr 2006 15:47:06 +0200 (CEST) Subject: [Python-3000-checkins] r45689 - in python/branches/p3yk: Include/bytesobject.h Lib/test/test_bytes.py Lib/test/test_file.py Objects/bytesobject.c Objects/fileobject.c Message-ID: <20060424134706.EAF051E400A@bag.python.org> Author: guido.van.rossum Date: Mon Apr 24 15:47:05 2006 New Revision: 45689 Modified: python/branches/p3yk/Include/bytesobject.h python/branches/p3yk/Lib/test/test_bytes.py python/branches/p3yk/Lib/test/test_file.py python/branches/p3yk/Objects/bytesobject.c python/branches/p3yk/Objects/fileobject.c Log: Added much functionality to the bytes type. Change file.readinto() to require binary mode. Modified: python/branches/p3yk/Include/bytesobject.h ============================================================================== --- python/branches/p3yk/Include/bytesobject.h (original) +++ python/branches/p3yk/Include/bytesobject.h Mon Apr 24 15:47:05 2006 @@ -21,7 +21,7 @@ /* Object layout */ typedef struct { PyObject_VAR_HEAD - char *ob_sval; + char *ob_bytes; } PyBytesObject; /* Type object */ @@ -32,13 +32,14 @@ #define PyBytes_CheckExact(self) ((self)->ob_type == &PyBytes_Type) /* Direct API functions */ +PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t); /* Macros, trading safety for speed */ -#define PyBytes_AS_STRING(self) (((PyBytesObject *)(self))->ob_sval) +#define PyBytes_AS_STRING(self) (((PyBytesObject *)(self))->ob_bytes) #define PyBytes_GET_SIZE(self) (((PyBytesObject *)(self))->ob_size) #ifdef __cplusplus Modified: python/branches/p3yk/Lib/test/test_bytes.py ============================================================================== --- python/branches/p3yk/Lib/test/test_bytes.py (original) +++ python/branches/p3yk/Lib/test/test_bytes.py Mon Apr 24 15:47:05 2006 @@ -1,6 +1,9 @@ """Unit tests for the bytes type.""" +import os +import re import sys +import tempfile import unittest import test.test_support @@ -45,7 +48,7 @@ self.assertRaises(ValueError, bytes, [C(256)]) def test_constructor_type_errors(self): - self.assertRaises(TypeError, bytes, 0) + self.assertRaises(TypeError, bytes, 0.0) class C: pass self.assertRaises(TypeError, bytes, ["0"]) @@ -100,36 +103,233 @@ self.failUnless(bytes.__doc__ != None) self.failUnless(bytes.__doc__.startswith("bytes(")) - # XXX More stuff to test and build (TDD): - # constructor from str: bytes() == bytes(map(ord, ))? - # encoding constructor: bytes([, [, ]]) - # default encoding Latin-1? (Matching ord) - # slicing - # extended slicing? - # item assignment - # slice assignment - # extended slice assignment? - # __contains__ with simple int arg - # __contains__ with another bytes arg? - # find/index? (int or bytes arg?) - # count? (int arg) - # concatenation (+) - # repeat? - # extend? - # append? - # insert? - # pop? - # __reversed__? - # reverse? (inplace) - # NOT sort! + def test_buffer_api(self): + short_sample = "Hello world\n" + sample = short_sample + "x"*(20 - len(short_sample)) + tfn = tempfile.mktemp() + try: + # Prepare + with open(tfn, "wb") as f: + f.write(short_sample) + # Test readinto + with open(tfn, "rb") as f: + b = bytes([ord('x')]*20) + n = f.readinto(b) + self.assertEqual(n, len(short_sample)) + self.assertEqual(list(b), map(ord, sample)) + # Test writing in binary mode + with open(tfn, "wb") as f: + f.write(b) + with open(tfn, "rb") as f: + self.assertEqual(f.read(), sample) + # Test writing in text mode + with open(tfn, "w") as f: + f.write(b) + with open(tfn, "r") as f: + self.assertEqual(f.read(), sample) + # Can't use readinto in text mode + with open(tfn, "r") as f: + self.assertRaises(TypeError, f.readinto, b) + finally: + try: + os.remove(tfn) + except os.error: + pass + + def test_reversed(self): + input = map(ord, "Hello") + b = bytes(input) + output = list(reversed(b)) + input.reverse() + self.assertEqual(output, input) + + def test_getslice(self): + def by(s): + return bytes(map(ord, s)) + b = by("Hello, world") + + self.assertEqual(b[:5], by("Hello")) + self.assertEqual(b[1:5], by("ello")) + self.assertEqual(b[5:7], by(", ")) + self.assertEqual(b[7:], by("world")) + self.assertEqual(b[7:12], by("world")) + self.assertEqual(b[7:100], by("world")) + + self.assertEqual(b[:-7], by("Hello")) + self.assertEqual(b[-11:-7], by("ello")) + self.assertEqual(b[-7:-5], by(", ")) + self.assertEqual(b[-5:], by("world")) + self.assertEqual(b[-5:12], by("world")) + self.assertEqual(b[-5:100], by("world")) + self.assertEqual(b[-100:5], by("Hello")) + + def test_regexps(self): + def by(s): + return bytes(map(ord, s)) + b = by("Hello, world") + self.assertEqual(re.findall(r"\w+", b), [by("Hello"), by("world")]) + + def test_setitem(self): + b = bytes([1, 2, 3]) + b[1] = 100 + self.assertEqual(b, bytes([1, 100, 3])) + b[-1] = 200 + self.assertEqual(b, bytes([1, 100, 200])) + class C: + def __init__(self, i=0): + self.i = i + def __index__(self): + return self.i + b[0] = C(10) + self.assertEqual(b, bytes([10, 100, 200])) + try: + b[3] = 0 + self.fail("Didn't raise IndexError") + except IndexError: + pass + try: + b[-10] = 0 + self.fail("Didn't raise IndexError") + except IndexError: + pass + try: + b[0] = 256 + self.fail("Didn't raise ValueError") + except ValueError: + pass + try: + b[0] = C(-1) + self.fail("Didn't raise ValueError") + except ValueError: + pass + try: + b[0] = None + self.fail("Didn't raise TypeError") + except TypeError: + pass + + def test_delitem(self): + b = bytes(range(10)) + del b[0] + self.assertEqual(b, bytes(range(1, 10))) + del b[-1] + self.assertEqual(b, bytes(range(1, 9))) + del b[4] + self.assertEqual(b, bytes([1, 2, 3, 4, 6, 7, 8])) + + def test_setslice(self): + b = bytes(range(10)) + self.assertEqual(list(b), list(range(10))) + + b[0:5] = bytes([1, 1, 1, 1, 1]) + self.assertEqual(b, bytes([1, 1, 1, 1, 1, 5, 6, 7, 8, 9])) + + del b[0:-5] + self.assertEqual(b, bytes([5, 6, 7, 8, 9])) + + b[0:0] = bytes([0, 1, 2, 3, 4]) + self.assertEqual(b, bytes(range(10))) + + b[-7:-3] = bytes([100, 101]) + self.assertEqual(b, bytes([0, 1, 2, 100, 101, 7, 8, 9])) + + b[3:5] = [3, 4, 5, 6] + self.assertEqual(b, bytes(range(10))) + + def test_setslice_trap(self): + # This test verifies that we correctly handle assigning self + # to a slice of self (the old Lambert Meertens trap). + b = bytes(range(256)) + b[8:] = b + self.assertEqual(b, bytes(list(range(8)) + list(range(256)))) + + def test_encoding(self): + sample = u"Hello world\n\u1234\u5678\u9abc\udef0" + for enc in ("utf8", "utf16"): + b = bytes(sample, enc) + self.assertEqual(b, bytes(map(ord, sample.encode(enc)))) + self.assertRaises(UnicodeEncodeError, bytes, sample, "latin1") + b = bytes(sample, "latin1", "ignore") + self.assertEqual(b, bytes(sample[:-4])) + + def test_decode(self): + sample = u"Hello world\n\u1234\u5678\u9abc\def0\def0" + for enc in ("utf8", "utf16"): + b = bytes(sample, enc) + self.assertEqual(b.decode(enc), sample) + sample = u"Hello world\n\x80\x81\xfe\xff" + b = bytes(sample, "latin1") + self.assertRaises(UnicodeDecodeError, b.decode, "utf8") + self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n") + + def test_from_buffer(self): + sample = "Hello world\n\x80\x81\xfe\xff" + buf = buffer(sample) + b = bytes(buf) + self.assertEqual(b, bytes(map(ord, sample))) + + def test_to_str(self): + sample = "Hello world\n\x80\x81\xfe\xff" + b = bytes(sample) + self.assertEqual(str(b), sample) + + def test_from_int(self): + b = bytes(0) + self.assertEqual(b, bytes()) + b = bytes(10) + self.assertEqual(b, bytes([0]*10)) + b = bytes(10000) + self.assertEqual(b, bytes([0]*10000)) + + def test_concat(self): + b1 = bytes("abc") + b2 = bytes("def") + self.assertEqual(b1 + b2, bytes("abcdef")) + self.assertRaises(TypeError, lambda: b1 + "def") + self.assertRaises(TypeError, lambda: "abc" + b2) + + def test_repeat(self): + b = bytes("abc") + self.assertEqual(b * 3, bytes("abcabcabc")) + self.assertEqual(b * 0, bytes()) + self.assertEqual(b * -1, bytes()) + self.assertRaises(TypeError, lambda: b * 3.14) + self.assertRaises(TypeError, lambda: 3.14 * b) + self.assertRaises(MemoryError, lambda: b * sys.maxint) + self.assertEqual(bytes('x')*100, bytes('x'*100)) + + # Optimizations: # __iter__? (optimization) - # __str__? (could return "".join(map(chr, self)) - # decode - # buffer API - # check that regexp searches work - # (I suppose re.sub() returns a string) - # file.readinto - # file.write + # __reversed__? (optimization) + + # XXX Some list methods? + # extended slicing + # extended slice assignment + # extend (same as b[len(b):] = src) + # reverse (in-place) + # remove + # pop + # NOT sort! + # With int arg: + # __contains__ + # index + # count + # append + # insert + + # XXX Some string methods? (Those that don't use character properties) + # startswith + # endswidth + # find, rfind + # __contains__ (bytes arg) + # index, rindex (bytes arg) + # join + # replace + # translate + # split, rsplit + # lstrip, rstrip, strip?? + + # XXX pickle and marshal support? def test_main(): @@ -137,5 +337,5 @@ if __name__ == "__main__": - ##test_main() - unittest.main() + test_main() + ##unittest.main() Modified: python/branches/p3yk/Lib/test/test_file.py ============================================================================== --- python/branches/p3yk/Lib/test/test_file.py (original) +++ python/branches/p3yk/Lib/test/test_file.py Mon Apr 24 15:47:05 2006 @@ -67,6 +67,17 @@ f.close() verify(buf == a.tostring()[:n]) +# verify readinto refuses text files +a = array('c', 'x'*10) +f = open(TESTFN, 'r') +try: + f.readinto(a) + raise TestFailed("readinto shouldn't work in text mode") +except TypeError: + pass +finally: + f.close() + # verify writelines with integers f = open(TESTFN, 'wb') try: @@ -261,13 +272,13 @@ try: # Prepare the testfile - bag = open(TESTFN, "w") + bag = open(TESTFN, "wb") bag.write(filler * nchunks) bag.writelines(testlines) bag.close() # Test for appropriate errors mixing read* and iteration for methodname, args in methods: - f = open(TESTFN) + f = open(TESTFN, 'rb') if f.next() != filler: raise TestFailed, "Broken testfile" meth = getattr(f, methodname) @@ -286,7 +297,7 @@ # Each line in the bag o' ham is 4 bytes ("h", "a", "m", "\n"), so # 4096 lines of that should get us exactly on the buffer boundary for # any power-of-2 buffersize between 4 and 16384 (inclusive). - f = open(TESTFN) + f = open(TESTFN, 'rb') for i in range(nchunks): f.next() testline = testlines.pop(0) @@ -328,7 +339,7 @@ raise TestFailed("readlines() after next() with empty buffer " "failed. Got %r, expected %r" % (line, testline)) # Reading after iteration hit EOF shouldn't hurt either - f = open(TESTFN) + f = open(TESTFN, 'rb') try: for line in f: pass Modified: python/branches/p3yk/Objects/bytesobject.c ============================================================================== --- python/branches/p3yk/Objects/bytesobject.c (original) +++ python/branches/p3yk/Objects/bytesobject.c Mon Apr 24 15:47:05 2006 @@ -8,27 +8,34 @@ /* Direct API functions */ PyObject * -PyBytes_FromStringAndSize(const char *sval, Py_ssize_t size) +PyBytes_FromObject(PyObject *input) +{ + return PyObject_CallFunctionObjArgs((PyObject *)&PyBytes_Type, + input, NULL); +} + +PyObject * +PyBytes_FromStringAndSize(const char *bytes, Py_ssize_t size) { PyBytesObject *new; - if (size != 0) { - assert(sval != NULL); - assert(size > 0); - } + assert(size >= 0); new = PyObject_New(PyBytesObject, &PyBytes_Type); if (new == NULL) - return NULL; + return NULL; - if (size > 0) { - new->ob_sval = PyMem_Malloc(size); - if (new->ob_sval == NULL) { - Py_DECREF(new); - return NULL; - } - memcpy(new->ob_sval, sval, size); - new->ob_size = size; + new->ob_size = size; + if (size == 0) + new->ob_bytes = NULL; + else { + new->ob_bytes = PyMem_Malloc(size); + if (new->ob_bytes == NULL) { + Py_DECREF(new); + return NULL; + } + if (bytes != NULL) + memcpy(new->ob_bytes, bytes, size); } return (PyObject *)new; @@ -49,7 +56,7 @@ assert(self != NULL); assert(PyBytes_Check(self)); - return ((PyBytesObject *)self)->ob_sval; + return ((PyBytesObject *)self)->ob_bytes; } int @@ -61,13 +68,13 @@ assert(PyBytes_Check(self)); assert(size >= 0); - sval = PyMem_Realloc(((PyBytesObject *)self)->ob_sval, size); + sval = PyMem_Realloc(((PyBytesObject *)self)->ob_bytes, size); if (sval == NULL) { - PyErr_NoMemory(); - return -1; + PyErr_NoMemory(); + return -1; } - ((PyBytesObject *)self)->ob_sval = sval; + ((PyBytesObject *)self)->ob_bytes = sval; ((PyBytesObject *)self)->ob_size = size; return 0; @@ -82,15 +89,178 @@ } static PyObject * +bytes_concat(PyBytesObject *self, PyObject *other) +{ + PyBytesObject *result; + Py_ssize_t mysize; + Py_ssize_t size; + + if (!PyBytes_Check(other)) { + PyErr_Format(PyExc_TypeError, + "can't concat bytes to %.100s", other->ob_type->tp_name); + return NULL; + } + + mysize = self->ob_size; + size = mysize + ((PyBytesObject *)other)->ob_size; + if (size < 0) + return PyErr_NoMemory(); + result = (PyBytesObject *) PyBytes_FromStringAndSize(NULL, size); + if (result != NULL) { + memcpy(result->ob_bytes, self->ob_bytes, self->ob_size); + memcpy(result->ob_bytes + self->ob_size, + ((PyBytesObject *)other)->ob_bytes, + ((PyBytesObject *)other)->ob_size); + } + return (PyObject *)result; +} + +static PyObject * +bytes_repeat(PyBytesObject *self, Py_ssize_t count) +{ + PyBytesObject *result; + Py_ssize_t mysize; + Py_ssize_t size; + + if (count < 0) + count = 0; + mysize = self->ob_size; + size = mysize * count; + if (count != 0 && size / count != mysize) + return PyErr_NoMemory(); + result = (PyBytesObject *)PyBytes_FromStringAndSize(NULL, size); + if (result != NULL && size != 0) { + if (mysize == 1) + memset(result->ob_bytes, self->ob_bytes[0], size); + else { + int i; + for (i = 0; i < count; i++) + memcpy(result->ob_bytes + i*mysize, self->ob_bytes, mysize); + } + } + return (PyObject *)result; +} + +static PyObject * bytes_getitem(PyBytesObject *self, Py_ssize_t i) { if (i < 0) - i += self->ob_size; + i += self->ob_size; if (i < 0 || i >= self->ob_size) { - PyErr_SetString(PyExc_IndexError, "bytes index out of range"); - return NULL; + PyErr_SetString(PyExc_IndexError, "bytes index out of range"); + return NULL; } - return PyInt_FromLong((unsigned char)(self->ob_sval[i])); + return PyInt_FromLong((unsigned char)(self->ob_bytes[i])); +} + +static PyObject * +bytes_getslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi) +{ + if (lo < 0) + lo = 0; + if (hi > self->ob_size) + hi = self->ob_size; + if (lo >= hi) + lo = hi = 0; + return PyBytes_FromStringAndSize(self->ob_bytes + lo, hi - lo); +} + +static int +bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi, + PyObject *values) +{ + int avail; + int needed; + char *bytes; + + if (values == NULL) { + bytes = NULL; + needed = 0; + } + else if (values == (PyObject *)self || !PyBytes_Check(values)) { + /* Make a copy an call this function recursively */ + int err; + values = PyBytes_FromObject(values); + if (values == NULL) + return -1; + err = bytes_setslice(self, lo, hi, values); + Py_DECREF(values); + return err; + } + else { + assert(PyBytes_Check(values)); + bytes = ((PyBytesObject *)values)->ob_bytes; + needed = ((PyBytesObject *)values)->ob_size; + } + + if (lo < 0) + lo = 0; + if (hi > self->ob_size) + hi = self->ob_size; + + avail = hi - lo; + if (avail < 0) + lo = hi = avail = 0; + + if (avail != needed) { + if (avail > needed) { + /* + 0 lo hi old_size + | |<----avail----->|<-----tomove------>| + | |<-needed->|<-----tomove------>| + 0 lo new_hi new_size + */ + memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi, + self->ob_size - hi); + } + if (PyBytes_Resize((PyObject *)self, + self->ob_size + needed - avail) < 0) + return -1; + if (avail < needed) { + /* + 0 lo hi old_size + | |<-avail->|<-----tomove------>| + | |<----needed---->|<-----tomove------>| + 0 lo new_hi new_size + */ + memmove(self->ob_bytes + lo + needed, self->ob_bytes + hi, + self->ob_size - lo - needed); + } + } + + if (needed > 0) + memcpy(self->ob_bytes + lo, bytes, needed); + + return 0; +} + +static int +bytes_setitem(PyBytesObject *self, Py_ssize_t i, PyObject *value) +{ + Py_ssize_t ival; + + if (i < 0) + i += self->ob_size; + + if (i < 0 || i >= self->ob_size) { + PyErr_SetString(PyExc_IndexError, "bytes index out of range"); + return -1; + } + + if (value == NULL) + return bytes_setslice(self, i, i+1, NULL); + + ival = PyNumber_Index(value); + if (ival == -1 && PyErr_Occurred()) + return -1; + + if (ival < 0 || ival >= 256) { + PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); + return -1; + } + + self->ob_bytes[i] = ival; + return 0; } static long @@ -103,69 +273,138 @@ static int bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"sequence", 0}; + static char *kwlist[] = {"source", "encoding", "errors", 0}; PyObject *arg = NULL; - PyObject *it; /* iter(arg) */ + const char *encoding = NULL; + const char *errors = NULL; + Py_ssize_t count; + PyObject *it; PyObject *(*iternext)(PyObject *); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bytes", kwlist, &arg)) - return -1; - - /* Verify list invariants established by PyType_GenericAlloc() */ - if (self->ob_size != 0) { - assert(self->ob_sval != NULL); - assert(self->ob_size > 0); - } - - /* Empty previous contents */ + /* Empty previous contents (yes, do this first of all!) */ if (PyBytes_Resize((PyObject *)self, 0) < 0) - return -1; + return -1; - /* Quick check if we're done */ - if (arg == 0) - return 0; + /* Parse arguments */ + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:bytes", kwlist, + &arg, &encoding, &errors)) + return -1; + + /* Make a quick exit if no first argument */ + if (arg == NULL) { + if (encoding != NULL || errors != NULL) { + PyErr_SetString(PyExc_TypeError, + "encoding or errors without sequence argument"); + return -1; + } + return 0; + } + + if (PyUnicode_Check(arg)) { + /* Encode via the codec registry */ + PyObject *encoded; + char *bytes; + Py_ssize_t size; + if (encoding == NULL) + encoding = PyUnicode_GetDefaultEncoding(); + encoded = PyCodec_Encode(arg, encoding, errors); + if (encoded == NULL) + return -1; + if (!PyString_Check(encoded)) { + PyErr_Format(PyExc_TypeError, + "encoder did not return a string object (type=%.400s)", + encoded->ob_type->tp_name); + Py_DECREF(encoded); + return -1; + } + bytes = PyString_AS_STRING(encoded); + size = PyString_GET_SIZE(encoded); + if (PyBytes_Resize((PyObject *)self, size) < 0) { + Py_DECREF(encoded); + return -1; + } + memcpy(self->ob_bytes, bytes, size); + Py_DECREF(encoded); + return 0; + } + + /* If it's not unicode, there can't be encoding or errors */ + if (encoding != NULL || errors != NULL) { + PyErr_SetString(PyExc_TypeError, + "encoding or errors without a string argument"); + return -1; + } + + /* Is it an int? */ + count = PyNumber_Index(arg); + if (count == -1 && PyErr_Occurred()) + PyErr_Clear(); + else { + if (count < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); + return -1; + } + if (count > 0) { + if (PyBytes_Resize((PyObject *)self, count)) + return -1; + memset(self->ob_bytes, 0, count); + } + return 0; + } + + if (PyObject_CheckReadBuffer(arg)) { + const void *bytes; + Py_ssize_t size; + if (PyObject_AsReadBuffer(arg, &bytes, &size) < 0) + return -1; + if (PyBytes_Resize((PyObject *)self, size) < 0) + return -1; + memcpy(self->ob_bytes, bytes, size); + return 0; + } - /* XXX Optimize this if the arguments is a list, tuple, or bytes */ + /* XXX Optimize this if the arguments is a list, tuple */ /* Get the iterator */ it = PyObject_GetIter(arg); if (it == NULL) - return -1; + return -1; iternext = *it->ob_type->tp_iternext; /* Run the iterator to exhaustion */ for (;;) { - PyObject *item; - Py_ssize_t value; + PyObject *item; + Py_ssize_t value; - /* Get the next item */ - item = iternext(it); - if (item == NULL) { - if (PyErr_Occurred()) { - if (!PyErr_ExceptionMatches(PyExc_StopIteration)) - goto error; - PyErr_Clear(); - } - break; - } - - /* Interpret it as an int (__index__) */ - value = PyNumber_Index(item); - Py_DECREF(item); - if (value == -1 && PyErr_Occurred()) - goto error; - - /* Range check */ - if (value < 0 || value >= 256) { - PyErr_SetString(PyExc_ValueError, "bytes must be in range(0, 256)"); - goto error; - } - - /* Append the byte */ - /* XXX Speed this up */ - if (PyBytes_Resize((PyObject *)self, self->ob_size+1) < 0) - goto error; - self->ob_sval[self->ob_size-1] = value; + /* Get the next item */ + item = iternext(it); + if (item == NULL) { + if (PyErr_Occurred()) { + if (!PyErr_ExceptionMatches(PyExc_StopIteration)) + goto error; + PyErr_Clear(); + } + break; + } + + /* Interpret it as an int (__index__) */ + value = PyNumber_Index(item); + Py_DECREF(item); + if (value == -1 && PyErr_Occurred()) + goto error; + + /* Range check */ + if (value < 0 || value >= 256) { + PyErr_SetString(PyExc_ValueError, + "bytes must be in range(0, 256)"); + goto error; + } + + /* Append the byte */ + /* XXX Speed this up */ + if (PyBytes_Resize((PyObject *)self, self->ob_size+1) < 0) + goto error; + self->ob_bytes[self->ob_size-1] = value; } /* Clean up and return success */ @@ -188,45 +427,45 @@ int i; if (self->ob_size == 0) - return PyString_FromString("bytes()"); + return PyString_FromString("bytes()"); list = PyList_New(0); if (list == NULL) - return NULL; + return NULL; str = PyString_FromString("bytes(["); if (str == NULL) - goto error; + goto error; err = PyList_Append(list, str); Py_DECREF(str); if (err < 0) - goto error; + goto error; for (i = 0; i < self->ob_size; i++) { - char buffer[20]; - sprintf(buffer, ", 0x%02x", (unsigned char) (self->ob_sval[i])); - str = PyString_FromString((i == 0) ? buffer+2 : buffer); - if (str == NULL) - goto error; - err = PyList_Append(list, str); - Py_DECREF(str); - if (err < 0) - goto error; + char buffer[20]; + sprintf(buffer, ", 0x%02x", (unsigned char) (self->ob_bytes[i])); + str = PyString_FromString((i == 0) ? buffer+2 : buffer); + if (str == NULL) + goto error; + err = PyList_Append(list, str); + Py_DECREF(str); + if (err < 0) + goto error; } str = PyString_FromString("])"); if (str == NULL) - goto error; + goto error; err = PyList_Append(list, str); Py_DECREF(str); if (err < 0) - goto error; + goto error; str = PyString_FromString(""); if (str == NULL) - goto error; + goto error; result = _PyString_Join(str, list); Py_DECREF(str); @@ -240,6 +479,12 @@ } static PyObject * +bytes_str(PyBytesObject *self) +{ + return PyString_FromStringAndSize(self->ob_bytes, self->ob_size); +} + +static PyObject * bytes_richcompare(PyBytesObject *self, PyBytesObject *other, int op) { PyObject *res; @@ -247,37 +492,37 @@ int cmp; if (!PyBytes_Check(self) || !PyBytes_Check(other)) { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; } if (self->ob_size != other->ob_size && (op == Py_EQ || op == Py_NE)) { - /* Shortcut: if the lengths differ, the objects differ */ - cmp = (op == Py_NE); + /* Shortcut: if the lengths differ, the objects differ */ + cmp = (op == Py_NE); } else { - minsize = self->ob_size; - if (other->ob_size < minsize) - minsize = other->ob_size; - - cmp = memcmp(self->ob_sval, other->ob_sval, minsize); - /* In ISO C, memcmp() guarantees to use unsigned bytes! */ - - if (cmp == 0) { - if (self->ob_size < other->ob_size) - cmp = -1; - else if (self->ob_size > other->ob_size) - cmp = 1; - } - - switch (op) { - case Py_LT: cmp = cmp < 0; break; - case Py_LE: cmp = cmp <= 0; break; - case Py_EQ: cmp = cmp == 0; break; - case Py_NE: cmp = cmp != 0; break; - case Py_GT: cmp = cmp > 0; break; - case Py_GE: cmp = cmp >= 0; break; - } + minsize = self->ob_size; + if (other->ob_size < minsize) + minsize = other->ob_size; + + cmp = memcmp(self->ob_bytes, other->ob_bytes, minsize); + /* In ISO C, memcmp() guarantees to use unsigned bytes! */ + + if (cmp == 0) { + if (self->ob_size < other->ob_size) + cmp = -1; + else if (self->ob_size > other->ob_size) + cmp = 1; + } + + switch (op) { + case Py_LT: cmp = cmp < 0; break; + case Py_LE: cmp = cmp <= 0; break; + case Py_EQ: cmp = cmp == 0; break; + case Py_NE: cmp = cmp != 0; break; + case Py_GT: cmp = cmp > 0; break; + case Py_GE: cmp = cmp >= 0; break; + } } res = cmp ? Py_True : Py_False; @@ -288,41 +533,89 @@ static void bytes_dealloc(PyBytesObject *self) { - if (self->ob_sval != 0) { - PyMem_Free(self->ob_sval); + if (self->ob_bytes != 0) { + PyMem_Free(self->ob_bytes); } self->ob_type->tp_free((PyObject *)self); } +static Py_ssize_t +bytes_getbuffer(PyBytesObject *self, Py_ssize_t index, const void **ptr) +{ + if (index != 0) { + PyErr_SetString(PyExc_SystemError, + "accessing non-existent string segment"); + return -1; + } + *ptr = (void *)self->ob_bytes; + return self->ob_size; +} + +static Py_ssize_t +bytes_getsegcount(PyStringObject *self, Py_ssize_t *lenp) +{ + if (lenp) + *lenp = self->ob_size; + return 1; +} + +PyDoc_STRVAR(decode_doc, +"B.decode([encoding[,errors]]) -> unicode obect.\n\ +\n\ +Decodes B using the codec registered for encoding. encoding defaults\n\ +to the default encoding. errors may be given to set a different error\n\ +handling scheme. Default is 'strict' meaning that encoding errors raise\n\ +a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\ +as well as any other name registerd with codecs.register_error that is\n\ +able to handle UnicodeDecodeErrors."); + +static PyObject * +bytes_decode(PyObject *self, PyObject *args) +{ + const char *encoding = NULL; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors)) + return NULL; + if (encoding == NULL) + encoding = PyUnicode_GetDefaultEncoding(); + return PyCodec_Decode(self, encoding, errors); +} + static PySequenceMethods bytes_as_sequence = { - (lenfunc)bytes_length, /*sq_length*/ - (binaryfunc)0, /*sq_concat*/ - (ssizeargfunc)0, /*sq_repeat*/ - (ssizeargfunc)bytes_getitem, /*sq_item*/ - (ssizessizeargfunc)0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - (objobjproc)0, /*sq_contains*/ + (lenfunc)bytes_length, /*sq_length*/ + (binaryfunc)bytes_concat, /*sq_concat*/ + (ssizeargfunc)bytes_repeat, /*sq_repeat*/ + (ssizeargfunc)bytes_getitem, /*sq_item*/ + (ssizessizeargfunc)bytes_getslice, /*sq_slice*/ + (ssizeobjargproc)bytes_setitem, /*sq_ass_item*/ + (ssizessizeobjargproc)bytes_setslice, /* sq_ass_slice */ +#if 0 + (objobjproc)bytes_contains, /* sq_contains */ + (binaryfunc)bytes_inplace_concat, /* sq_inplace_concat */ + (ssizeargfunc)bytes_inplace_repeat, /* sq_inplace_repeat */ +#endif }; static PyMappingMethods bytes_as_mapping = { - (lenfunc)bytes_length, - (binaryfunc)0, - 0, + (lenfunc)bytes_length, + (binaryfunc)0, + 0, }; static PyBufferProcs bytes_as_buffer = { -/* - (readbufferproc)bytes_buffer_getreadbuf, - (writebufferproc)bytes_buffer_getwritebuf, - (segcountproc)bytes_buffer_getsegcount, - (charbufferproc)bytes_buffer_getcharbuf, -*/ + (readbufferproc)bytes_getbuffer, + (writebufferproc)bytes_getbuffer, + (segcountproc)bytes_getsegcount, + /* XXX Bytes are not characters! But we need to implement + bf_getcharbuffer() so we can be used as 't#' argument to codecs. */ + (charbufferproc)bytes_getbuffer, }; static PyMethodDef bytes_methods[] = { - {NULL, NULL} + {"decode", (PyCFunction)bytes_decode, METH_VARARGS, decode_doc}, + {NULL, NULL} }; PyDoc_STRVAR(bytes_doc, @@ -336,39 +629,40 @@ "bytes", sizeof(PyBytesObject), 0, - (destructor)bytes_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)bytes_repr, /* tp_repr */ - 0, /* tp_as_number */ - &bytes_as_sequence, /* tp_as_sequence */ - &bytes_as_mapping, /* tp_as_mapping */ - bytes_nohash, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - &bytes_as_buffer, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ /* bytes is 'final' or 'sealed' */ - bytes_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)bytes_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - bytes_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)bytes_init, /* tp_init */ - PyType_GenericAlloc, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ - PyObject_Del, /* tp_free */ + (destructor)bytes_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)bytes_repr, /* tp_repr */ + 0, /* tp_as_number */ + &bytes_as_sequence, /* tp_as_sequence */ + &bytes_as_mapping, /* tp_as_mapping */ + bytes_nohash, /* tp_hash */ + 0, /* tp_call */ + (reprfunc)bytes_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + &bytes_as_buffer, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ + /* bytes is 'final' or 'sealed' */ + bytes_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)bytes_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + bytes_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)bytes_init, /* tp_init */ + PyType_GenericAlloc, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + PyObject_Del, /* tp_free */ }; Modified: python/branches/p3yk/Objects/fileobject.c ============================================================================== --- python/branches/p3yk/Objects/fileobject.c (original) +++ python/branches/p3yk/Objects/fileobject.c Mon Apr 24 15:47:05 2006 @@ -880,6 +880,11 @@ if (f->f_fp == NULL) return err_closed(); + if (!f->f_binary) { + PyErr_SetString(PyExc_TypeError, + "readinto() requires binary mode"); + return NULL; + } /* refuse to mix with f.next() */ if (f->f_buf != NULL && (f->f_bufend - f->f_bufptr) > 0 && From python-3000-checkins at python.org Mon Apr 24 22:01:27 2006 From: python-3000-checkins at python.org (brett.cannon) Date: Mon, 24 Apr 2006 22:01:27 +0200 (CEST) Subject: [Python-3000-checkins] r45693 - python/branches/p3yk/Misc/Vim/vimrc Message-ID: <20060424200127.026D31E400A@bag.python.org> Author: brett.cannon Date: Mon Apr 24 22:01:24 2006 New Revision: 45693 Modified: python/branches/p3yk/Misc/Vim/vimrc Log: Change C code to use 4-space indents. Highlighting tab indents is off at the moment since that would be rather noisy, but should be turned on in the future when conversion to the new indentation style has been done. Modified: python/branches/p3yk/Misc/Vim/vimrc ============================================================================== --- python/branches/p3yk/Misc/Vim/vimrc (original) +++ python/branches/p3yk/Misc/Vim/vimrc Mon Apr 24 22:01:24 2006 @@ -19,9 +19,8 @@ " Number of spaces to use for an indent. " This will affect Ctrl-T and 'autoindent'. " Python: 4 spaces -" C: tab (8 spaces) -au BufRead,BufNewFile *.py,*pyw set shiftwidth=4 -au BufRead,BufNewFile *.c,*.h set shiftwidth=8 +" C: 4 spaces +au BufRead,BufNewFile *.py,*pyw,*.c,*.h set shiftwidth=4 " Number of spaces that a pre-existing tab is equal to. " For the amount of space used for a new tab use shiftwidth. @@ -32,16 +31,17 @@ " Replace tabs with the equivalent number of spaces. " Also have an autocmd for Makefiles since they require hard tabs. " Python: yes -" C: no +" C: yes " Makefile: no -au BufRead,BufNewFile *.py,*.pyw set expandtab -au BufRead,BufNewFile *.c,*.h set noexpandtab +au BufRead,BufNewFile *.py,*.pyw,*.c,*.h set expandtab au BufRead,BufNewFile Makefile* set noexpandtab " Use the below highlight group when displaying bad whitespace is desired highlight BadWhitespace ctermbg=red guibg=red " Display tabs at the beginning of a line in Python mode as bad +" Should be done for C code, but not until all code has been moved to 4-space +" indents. au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/ " Wrap text after a certain number of characters From nas at arctrix.com Sun Apr 23 02:24:04 2006 From: nas at arctrix.com (Neil Schemenauer) Date: Sat, 22 Apr 2006 18:24:04 -0600 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: <20060422232806.351AE1E400B@bag.python.org> References: <20060422232806.351AE1E400B@bag.python.org> Message-ID: <20060423002404.GA19097@mems-exchange.org> On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote: > +bytes_nohash(PyObject *self) > +{ > + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); > + return -1; > +} I think we might need to have a frozenbytes object too. Neil From guido at python.org Tue Apr 25 18:52:34 2006 From: guido at python.org (Guido van Rossum) Date: Tue, 25 Apr 2006 09:52:34 -0700 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: <20060423002404.GA19097@mems-exchange.org> References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> Message-ID: On 4/22/06, Neil Schemenauer wrote: > On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote: > > +bytes_nohash(PyObject *self) > > +{ > > + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); > > + return -1; > > +} > > I think we might need to have a frozenbytes object too. I believe YAGNI. Also, I'm not keen on all these frozen variants. Hands up who's ever used a frozen set or needed a frozen dict? -- --Guido van Rossum (home page: http://www.python.org/~guido/) From skip at pobox.com Tue Apr 25 20:10:36 2006 From: skip at pobox.com (skip at pobox.com) Date: Tue, 25 Apr 2006 13:10:36 -0500 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> Message-ID: <17486.26140.174778.987350@montanaro.dyndns.org> >> I think we might need to have a frozenbytes object too. Guido> I believe YAGNI. Also, I'm not keen on all these frozen variants. Guido> Hands up who's ever used a frozen set or needed a frozen dict? On the rare occasion where I've wanted to use a dict (for example) as a key in another dict, I've just used tuple(dict1.values()). In this context I've obviously only cared about shallow dicts. Idle thought alert: Would it be possible in principle to implement a freeze object which returns a proxy that prevents the proxied object from being modified, e.g.: def freeze(obj): return Freezer(obj) where the Freezer class is suitably powerful (knowing at least about all the various methods which can modify an object, maybe about some protocol to describe methods that can modify an object)? Now I know it could get messy (__setattr__, list.append, etc.), and like I said, this is just an idle thought, but still, if it was possible, you could freeze just about anything and not have to create special frozen varieties of every containiner type. Skip From nas at arctrix.com Tue Apr 25 20:19:33 2006 From: nas at arctrix.com (Neil Schemenauer) Date: Tue, 25 Apr 2006 12:19:33 -0600 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> Message-ID: <20060425181933.GA6245@mems-exchange.org> On Tue, Apr 25, 2006 at 09:52:34AM -0700, Guido van Rossum wrote: > On 4/22/06, Neil Schemenauer wrote: > > On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote: > > > +bytes_nohash(PyObject *self) > > > +{ > > > + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); > > > + return -1; > > > +} > > > > I think we might need to have a frozenbytes object too. > > I believe YAGNI. Also, I'm not keen on all these frozen variants. > Hands up who's ever used a frozen set or needed a frozen dict? Tuples work for those, I think. The use case I had in mind was a large mapping with binary data as the keys. If there was no frozenbytes object then I guess the most memory efficient way of representing the keys would be to use unicode strings. That's ugly. Is there some better way? Neil From guido at python.org Tue Apr 25 20:31:14 2006 From: guido at python.org (Guido van Rossum) Date: Tue, 25 Apr 2006 11:31:14 -0700 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: <17486.26140.174778.987350@montanaro.dyndns.org> References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> <17486.26140.174778.987350@montanaro.dyndns.org> Message-ID: On 4/25/06, skip at pobox.com wrote: > > >> I think we might need to have a frozenbytes object too. > > Guido> I believe YAGNI. Also, I'm not keen on all these frozen variants. > Guido> Hands up who's ever used a frozen set or needed a frozen dict? > > On the rare occasion where I've wanted to use a dict (for example) as a key > in another dict, I've just used tuple(dict1.values()). In this context I've > obviously only cared about shallow dicts. That doesn't quite work since two dicts with the same value could have different ordering (due to different insert/delete ordering). > Idle thought alert: > > Would it be possible in principle to implement a freeze object which returns > a proxy that prevents the proxied object from being modified, e.g.: > > def freeze(obj): > return Freezer(obj) > > where the Freezer class is suitably powerful (knowing at least about all the > various methods which can modify an object, maybe about some protocol to > describe methods that can modify an object)? > > Now I know it could get messy (__setattr__, list.append, etc.), and like I > said, this is just an idle thought, but still, if it was possible, you could > freeze just about anything and not have to create special frozen varieties > of every containiner type. It would require the freezer to know about the type of the underlying object. It also won't be able to prevent someone from reaching in directly and modifying it anyway. -- --Guido van Rossum (home page: http://www.python.org/~guido/) From guido at python.org Tue Apr 25 20:33:34 2006 From: guido at python.org (Guido van Rossum) Date: Tue, 25 Apr 2006 11:33:34 -0700 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: <20060425181933.GA6245@mems-exchange.org> References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> <20060425181933.GA6245@mems-exchange.org> Message-ID: On 4/25/06, Neil Schemenauer wrote: > On Tue, Apr 25, 2006 at 09:52:34AM -0700, Guido van Rossum wrote: > > On 4/22/06, Neil Schemenauer wrote: > > > On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote: > > > > +bytes_nohash(PyObject *self) > > > > +{ > > > > + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); > > > > + return -1; > > > > +} > > > > > > I think we might need to have a frozenbytes object too. > > > > I believe YAGNI. Also, I'm not keen on all these frozen variants. > > Hands up who's ever used a frozen set or needed a frozen dict? > > Tuples work for those, I think. No, unless you sort the data; you'd have to say tuple(sorted(d.items())) -- not pretty, and probably kind of slow. > The use case I had in mind was a > large mapping with binary data as the keys. If there was no > frozenbytes object then I guess the most memory efficient way of > representing the keys would be to use unicode strings. That's ugly. > Is there some better way? Have you ever encountered that use case in practice? (That's what I meant by YAGNI. :-) -- --Guido van Rossum (home page: http://www.python.org/~guido/) From walter at livinglogic.de Tue Apr 25 20:53:34 2006 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Tue, 25 Apr 2006 20:53:34 +0200 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> Message-ID: <444E702E.6040506@livinglogic.de> Guido van Rossum wrote: > On 4/22/06, Neil Schemenauer wrote: >> On Sun, Apr 23, 2006 at 01:28:06AM +0200, guido.van.rossum wrote: >>> +bytes_nohash(PyObject *self) >>> +{ >>> + PyErr_SetString(PyExc_TypeError, "bytes objects are unhashable"); >>> + return -1; >>> +} >> I think we might need to have a frozenbytes object too. > > I believe YAGNI. Also, I'm not keen on all these frozen variants. > Hands up who's ever used a frozen set or needed a frozen dict? When implementing a decorator that caches return values based on the function arguments it's useful (but of course a workaround can use tuple(sorted(kwargs.iteritems())): def cache(func): cache = {} def wrapper(*args, **kwargs): cacheargs = (args, tuple(sorted(kwargs.iteritems()))) try: return cache[cacheargs] except KeyError: result = func(*args, **kwargs) cache[cacheargs] = result return result return wrapper This can e.g. be used in CherryPy, where arguments are guaranteed to be strings. Servus, Walter From nas at arctrix.com Tue Apr 25 22:19:52 2006 From: nas at arctrix.com (Neil Schemenauer) Date: Tue, 25 Apr 2006 14:19:52 -0600 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: References: <20060422232806.351AE1E400B@bag.python.org> <20060423002404.GA19097@mems-exchange.org> <20060425181933.GA6245@mems-exchange.org> Message-ID: <20060425201951.GA6713@mems-exchange.org> On Tue, Apr 25, 2006 at 11:33:34AM -0700, Guido van Rossum wrote: > Have you ever encountered that use case in practice? (That's what I > meant by YAGNI. :-) Yes, I know what YAGNI means. The example that immediately comes to mind is ZODB and Durus. They use 8-byte binary strings to represent object IDs. Memory efficiency is important. Another example would be using a SHA-1 hash as a key. I don't recall if I have written such code but message digests are so common I don't think you can call YAGNI. Neil From fdrake at acm.org Tue Apr 25 22:30:39 2006 From: fdrake at acm.org (Fred L. Drake, Jr.) Date: Tue, 25 Apr 2006 16:30:39 -0400 Subject: [Python-3000-checkins] r45652 - in python/branches/p3yk In-Reply-To: <20060425201951.GA6713@mems-exchange.org> References: <20060422232806.351AE1E400B@bag.python.org> <20060425201951.GA6713@mems-exchange.org> Message-ID: <200604251630.39666.fdrake@acm.org> On Tuesday 25 April 2006 16:19, Neil Schemenauer wrote: > Yes, I know what YAGNI means. The example that immediately comes to > mind is ZODB and Durus. They use 8-byte binary strings to represent > object IDs. Memory efficiency is important. > > Another example would be using a SHA-1 hash as a key. I don't > recall if I have written such code but message digests are so common > I don't think you can call YAGNI. Yeah, we generally need both. These are important use cases for immutable binary data. It doesn't need a corresponding constructor in __builtin__ (IMO), but it's a common type to need. -Fred -- Fred L. Drake, Jr. From python-3000-checkins at python.org Fri Apr 28 00:54:27 2006 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 28 Apr 2006 00:54:27 +0200 (CEST) Subject: [Python-3000-checkins] r45769 - in python/branches/p3yk: Lib/test/test_bytes.py Objects/bytesobject.c Message-ID: <20060427225427.958B11E4006@bag.python.org> Author: guido.van.rossum Date: Fri Apr 28 00:54:26 2006 New Revision: 45769 Modified: python/branches/p3yk/Lib/test/test_bytes.py python/branches/p3yk/Objects/bytesobject.c Log: Implement bytes += bytes, bytes *= int, int in bytes, bytes in bytes. Modified: python/branches/p3yk/Lib/test/test_bytes.py ============================================================================== --- python/branches/p3yk/Lib/test/test_bytes.py (original) +++ python/branches/p3yk/Lib/test/test_bytes.py Fri Apr 28 00:54:26 2006 @@ -296,8 +296,57 @@ self.assertRaises(TypeError, lambda: b * 3.14) self.assertRaises(TypeError, lambda: 3.14 * b) self.assertRaises(MemoryError, lambda: b * sys.maxint) + + def test_repeat_1char(self): self.assertEqual(bytes('x')*100, bytes('x'*100)) + def test_iconcat(self): + b = bytes("abc") + b1 = b + b += bytes("def") + self.assertEqual(b, bytes("abcdef")) + self.assertEqual(b, b1) + self.failUnless(b is b1) + + def test_irepeat(self): + b = bytes("abc") + b1 = b + b *= 3 + self.assertEqual(b, bytes("abcabcabc")) + self.assertEqual(b, b1) + self.failUnless(b is b1) + + def test_irepeat_1char(self): + b = bytes("x") + b1 = b + b *= 100 + self.assertEqual(b, bytes("x"*100)) + self.assertEqual(b, b1) + self.failUnless(b is b1) + + def test_contains(self): + b = bytes("abc") + self.failUnless(ord('a') in b) + self.failUnless(long(ord('a')) in b) + self.failIf(200 in b) + self.failIf(200L in b) + self.assertRaises(ValueError, lambda: 300 in b) + self.assertRaises(ValueError, lambda: -1 in b) + self.assertRaises(TypeError, lambda: None in b) + self.assertRaises(TypeError, lambda: float(ord('a')) in b) + self.assertRaises(TypeError, lambda: "a" in b) + self.failUnless(bytes("") in b) + self.failUnless(bytes("a") in b) + self.failUnless(bytes("b") in b) + self.failUnless(bytes("c") in b) + self.failUnless(bytes("ab") in b) + self.failUnless(bytes("bc") in b) + self.failUnless(bytes("abc") in b) + self.failIf(bytes("ac") in b) + self.failIf(bytes("d") in b) + self.failIf(bytes("dab") in b) + self.failIf(bytes("abd") in b) + # Optimizations: # __iter__? (optimization) # __reversed__? (optimization) @@ -311,7 +360,6 @@ # pop # NOT sort! # With int arg: - # __contains__ # index # count # append @@ -321,7 +369,6 @@ # startswith # endswidth # find, rfind - # __contains__ (bytes arg) # index, rindex (bytes arg) # join # replace Modified: python/branches/p3yk/Objects/bytesobject.c ============================================================================== --- python/branches/p3yk/Objects/bytesobject.c (original) +++ python/branches/p3yk/Objects/bytesobject.c Fri Apr 28 00:54:26 2006 @@ -116,6 +116,31 @@ } static PyObject * +bytes_iconcat(PyBytesObject *self, PyObject *other) +{ + Py_ssize_t mysize; + Py_ssize_t osize; + Py_ssize_t size; + + if (!PyBytes_Check(other)) { + PyErr_Format(PyExc_TypeError, + "can't concat bytes to %.100s", other->ob_type->tp_name); + return NULL; + } + + mysize = self->ob_size; + osize = ((PyBytesObject *)other)->ob_size; + size = mysize + osize; + if (size < 0) + return PyErr_NoMemory(); + if (PyBytes_Resize((PyObject *)self, size) < 0) + return NULL; + memcpy(self->ob_bytes + mysize, ((PyBytesObject *)other)->ob_bytes, osize); + Py_INCREF(self); + return (PyObject *)self; +} + +static PyObject * bytes_repeat(PyBytesObject *self, Py_ssize_t count) { PyBytesObject *result; @@ -133,7 +158,7 @@ if (mysize == 1) memset(result->ob_bytes, self->ob_bytes[0], size); else { - int i; + Py_ssize_t i; for (i = 0; i < count; i++) memcpy(result->ob_bytes + i*mysize, self->ob_bytes, mysize); } @@ -142,6 +167,72 @@ } static PyObject * +bytes_irepeat(PyBytesObject *self, Py_ssize_t count) +{ + Py_ssize_t mysize; + Py_ssize_t size; + + if (count < 0) + count = 0; + mysize = self->ob_size; + size = mysize * count; + if (count != 0 && size / count != mysize) + return PyErr_NoMemory(); + if (PyBytes_Resize((PyObject *)self, size) < 0) + return NULL; + + if (mysize == 1) + memset(self->ob_bytes, self->ob_bytes[0], size); + else { + Py_ssize_t i; + for (i = 1; i < count; i++) + memcpy(self->ob_bytes + i*mysize, self->ob_bytes, mysize); + } + + Py_INCREF(self); + return (PyObject *)self; +} + +static int +bytes_substring(PyBytesObject *self, PyBytesObject *other) +{ + Py_ssize_t i; + + if (other->ob_size == 1) { + return memchr(self->ob_bytes, other->ob_bytes[0], + self->ob_size) != NULL; + } + if (other->ob_size == 0) + return 1; /* Edge case */ + for (i = 0; i + other->ob_size <= self->ob_size; i++) { + /* XXX Yeah, yeah, lots of optimizations possible... */ + if (memcmp(self->ob_bytes + i, other->ob_bytes, other->ob_size) == 0) + return 1; + } + return 0; +} + +static int +bytes_contains(PyBytesObject *self, PyObject *value) +{ + Py_ssize_t ival; + + if (PyBytes_Check(value)) + return bytes_substring(self, (PyBytesObject *)value); + + ival = PyNumber_Index(value); + if (ival == -1 && PyErr_Occurred()) + return -1; + + if (ival < 0 || ival >= 256) { + PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); + return -1; + } + + return memchr(self->ob_bytes, ival, self->ob_size) != NULL; +} + +static PyObject * bytes_getitem(PyBytesObject *self, Py_ssize_t i) { if (i < 0) @@ -590,11 +681,9 @@ (ssizessizeargfunc)bytes_getslice, /*sq_slice*/ (ssizeobjargproc)bytes_setitem, /*sq_ass_item*/ (ssizessizeobjargproc)bytes_setslice, /* sq_ass_slice */ -#if 0 (objobjproc)bytes_contains, /* sq_contains */ - (binaryfunc)bytes_inplace_concat, /* sq_inplace_concat */ - (ssizeargfunc)bytes_inplace_repeat, /* sq_inplace_repeat */ -#endif + (binaryfunc)bytes_iconcat, /* sq_inplace_concat */ + (ssizeargfunc)bytes_irepeat, /* sq_inplace_repeat */ }; static PyMappingMethods bytes_as_mapping = { From python-3000-checkins at python.org Sun Apr 30 04:31:57 2006 From: python-3000-checkins at python.org (neal.norwitz) Date: Sun, 30 Apr 2006 04:31:57 +0200 (CEST) Subject: [Python-3000-checkins] r45812 - python/branches/p3yk/Lib/test/test_compare.py Message-ID: <20060430023157.0C48A1E400C@bag.python.org> Author: neal.norwitz Date: Sun Apr 30 04:31:56 2006 New Revision: 45812 Modified: python/branches/p3yk/Lib/test/test_compare.py Log: __coerce__ is gone, there's nothing to test. This test now passes after removing refs to __coerce__. Modified: python/branches/p3yk/Lib/test/test_compare.py ============================================================================== --- python/branches/p3yk/Lib/test/test_compare.py (original) +++ python/branches/p3yk/Lib/test/test_compare.py Sun Apr 30 04:31:56 2006 @@ -6,19 +6,6 @@ def __repr__(self): return '' -class Coerce: - def __init__(self, arg): - self.arg = arg - - def __repr__(self): - return '' % self.arg - - def __coerce__(self, other): - if isinstance(other, Coerce): - return self.arg, other.arg - else: - return self.arg, other - class Cmp: def __init__(self,arg): self.arg = arg @@ -30,7 +17,7 @@ return cmp(self.arg, other) class ComparisonTest(unittest.TestCase): - set1 = [2, 2.0, 2L, 2+0j, Coerce(2), Cmp(2.0)] + set1 = [2, 2.0, 2L, 2+0j, Cmp(2.0)] set2 = [[1], (3,), None, Empty()] candidates = set1 + set2 From python-3000-checkins at python.org Sun Apr 30 04:32:45 2006 From: python-3000-checkins at python.org (neal.norwitz) Date: Sun, 30 Apr 2006 04:32:45 +0200 (CEST) Subject: [Python-3000-checkins] r45813 - python/branches/p3yk/Lib/xmlcore/etree/ElementInclude.py Message-ID: <20060430023245.AC7141E400C@bag.python.org> Author: neal.norwitz Date: Sun Apr 30 04:32:45 2006 New Revision: 45813 Modified: python/branches/p3yk/Lib/xmlcore/etree/ElementInclude.py Log: Some of the test cases were failing due to the busted (relative) import. This fixes some of the failures, but there are still more. Modified: python/branches/p3yk/Lib/xmlcore/etree/ElementInclude.py ============================================================================== --- python/branches/p3yk/Lib/xmlcore/etree/ElementInclude.py (original) +++ python/branches/p3yk/Lib/xmlcore/etree/ElementInclude.py Sun Apr 30 04:32:45 2006 @@ -49,7 +49,7 @@ ## import copy -import ElementTree +from . import ElementTree XINCLUDE = "{http://www.w3.org/2001/XInclude}"