[Python-3000-checkins] r58768 - in python/branches/py3k-pep3137: Lib/tarfile.py Lib/test/test_codeccallbacks.py Lib/test/test_collections.py Lib/test/test_unicode.py Lib/test/test_zipimport.py Modules/dbmmodule.c Modules/gdbmmodule.c
christian.heimes
python-3000-checkins at python.org
Fri Nov 2 12:05:47 CET 2007
Author: christian.heimes
Date: Fri Nov 2 12:05:47 2007
New Revision: 58768
Modified:
python/branches/py3k-pep3137/Lib/tarfile.py
python/branches/py3k-pep3137/Lib/test/test_codeccallbacks.py
python/branches/py3k-pep3137/Lib/test/test_collections.py
python/branches/py3k-pep3137/Lib/test/test_unicode.py
python/branches/py3k-pep3137/Lib/test/test_zipimport.py
python/branches/py3k-pep3137/Modules/dbmmodule.c
python/branches/py3k-pep3137/Modules/gdbmmodule.c
Log:
More fixes for bytes() vs. buffer()
Open question: Should UnicodeDecodeError accept bytes for self->object, too?
Modified: python/branches/py3k-pep3137/Lib/tarfile.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/tarfile.py (original)
+++ python/branches/py3k-pep3137/Lib/tarfile.py Fri Nov 2 12:05:47 2007
@@ -3,7 +3,7 @@
#-------------------------------------------------------------------
# tarfile.py
#-------------------------------------------------------------------
-# Copyright (C) 2002 Lars Gustäbel <lars at gustaebel.de>
+# Copyright (C) 2002 Lars Gust�bel <lars at gustaebel.de>
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person
@@ -34,10 +34,10 @@
# $Source$
version = "0.9.0"
-__author__ = "Lars Gustäbel (lars at gustaebel.de)"
+__author__ = "Lars Gust�bel (lars at gustaebel.de)"
__date__ = "$Date$"
__cvsid__ = "$Id$"
-__credits__ = "Gustavo Niemeyer, Niels Gustäbel, Richard Townsend."
+__credits__ = "Gustavo Niemeyer, Niels Gust�bel, Richard Townsend."
#---------
# Imports
@@ -224,7 +224,7 @@
# this could raise OverflowError.
n = struct.unpack("L", struct.pack("l", n))[0]
- s = b""
+ s = buffer()
for i in range(digits - 1):
s.insert(0, n & 0o377)
n >>= 8
Modified: python/branches/py3k-pep3137/Lib/test/test_codeccallbacks.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/test/test_codeccallbacks.py (original)
+++ python/branches/py3k-pep3137/Lib/test/test_codeccallbacks.py Fri Nov 2 12:05:47 2007
@@ -33,13 +33,13 @@
# A UnicodeDecodeError object without an end attribute
class NoEndUnicodeDecodeError(UnicodeDecodeError):
def __init__(self):
- UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
+ UnicodeDecodeError.__init__(self, "ascii", buffer(b""), 0, 1, "bad")
del self.end
# A UnicodeDecodeError object with a bad object attribute
class BadObjectUnicodeDecodeError(UnicodeDecodeError):
def __init__(self):
- UnicodeDecodeError.__init__(self, "ascii", b"", 0, 1, "bad")
+ UnicodeDecodeError.__init__(self, "ascii", buffer(b""), 0, 1, "bad")
self.object = []
# A UnicodeTranslateError object without a start attribute
@@ -181,7 +181,7 @@
# mapped through the encoding again. This means, that
# to be able to use e.g. the "replace" handler, the
# charmap has to have a mapping for "?".
- charmap = dict((ord(c), str8(2*c.upper(), 'ascii')) for c in "abcdefgh")
+ charmap = dict((ord(c), bytes(2*c.upper(), 'ascii')) for c in "abcdefgh")
sin = "abc"
sout = b"AABBCC"
self.assertEquals(codecs.charmap_encode(sin, "strict", charmap)[0], sout)
@@ -189,7 +189,7 @@
sin = "abcA"
self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap)
- charmap[ord("?")] = str8(b"XYZ")
+ charmap[ord("?")] = b"XYZ"
sin = "abcDEF"
sout = b"AABBCCXYZXYZXYZ"
self.assertEquals(codecs.charmap_encode(sin, "replace", charmap)[0], sout)
@@ -309,7 +309,7 @@
# check with one argument too much
self.assertRaises(TypeError, exctype, *(args + ["too much"]))
# check with one argument of the wrong type
- wrongargs = [ "spam", str8(b"eggs"), b"spam", 42, 1.0, None ]
+ wrongargs = [ "spam", b"eggs", b"spam", 42, 1.0, None ]
for i in range(len(args)):
for wrongarg in wrongargs:
if type(wrongarg) is type(args[i]):
@@ -363,12 +363,12 @@
def test_unicodedecodeerror(self):
self.check_exceptionobjectargs(
UnicodeDecodeError,
- ["ascii", b"g\xfcrk", 1, 2, "ouch"],
+ ["ascii", buffer(b"g\xfcrk"), 1, 2, "ouch"],
"'ascii' codec can't decode byte 0xfc in position 1: ouch"
)
self.check_exceptionobjectargs(
UnicodeDecodeError,
- ["ascii", b"g\xfcrk", 1, 3, "ouch"],
+ ["ascii", buffer(b"g\xfcrk"), 1, 3, "ouch"],
"'ascii' codec can't decode bytes in position 1-2: ouch"
)
@@ -442,7 +442,7 @@
)
self.assertEquals(
codecs.ignore_errors(
- UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
+ UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")),
("", 1)
)
self.assertEquals(
@@ -482,7 +482,7 @@
)
self.assertEquals(
codecs.replace_errors(
- UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")),
+ UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")),
("\ufffd", 1)
)
self.assertEquals(
@@ -508,7 +508,7 @@
self.assertRaises(
TypeError,
codecs.xmlcharrefreplace_errors,
- UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
+ UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")
)
self.assertRaises(
TypeError,
@@ -542,7 +542,7 @@
self.assertRaises(
TypeError,
codecs.backslashreplace_errors,
- UnicodeDecodeError("ascii", b"\xff", 0, 1, "ouch")
+ UnicodeDecodeError("ascii", buffer(b"\xff"), 0, 1, "ouch")
)
self.assertRaises(
TypeError,
Modified: python/branches/py3k-pep3137/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/test/test_collections.py (original)
+++ python/branches/py3k-pep3137/Lib/test/test_collections.py Fri Nov 2 12:05:47 2007
@@ -76,7 +76,7 @@
def test_Hashable(self):
# Check some non-hashables
- non_samples = [bytes(), list(), set(), dict()]
+ non_samples = [buffer(), list(), set(), dict()]
for x in non_samples:
self.failIf(isinstance(x, Hashable), repr(x))
self.failIf(issubclass(type(x), Hashable), repr(type(x)))
@@ -85,7 +85,7 @@
int(), float(), complex(),
str(),
tuple(), frozenset(),
- int, list, object, type,
+ int, list, object, type, bytes()
]
for x in samples:
self.failUnless(isinstance(x, Hashable), repr(x))
Modified: python/branches/py3k-pep3137/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/test/test_unicode.py (original)
+++ python/branches/py3k-pep3137/Lib/test/test_unicode.py Fri Nov 2 12:05:47 2007
@@ -202,9 +202,11 @@
self.checkequalnofix('one at two!three!', 'one!two!three!', 'replace', '!', '@', 1)
self.assertRaises(TypeError, 'replace'.replace, "r", 42)
- def test_str8_comparison(self):
- self.assertEqual('abc' == str8(b'abc'), False)
- self.assertEqual('abc' != str8(b'abc'), True)
+ def test_bytes_comparison(self):
+ self.assertEqual('abc' == b'abc', False)
+ self.assertEqual('abc' != b'abc', True)
+ self.assertEqual('abc' == buffer(b'abc'), False)
+ self.assertEqual('abc' != buffer(b'abc'), True)
def test_comparison(self):
# Comparisons:
Modified: python/branches/py3k-pep3137/Lib/test/test_zipimport.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/test/test_zipimport.py (original)
+++ python/branches/py3k-pep3137/Lib/test/test_zipimport.py Fri Nov 2 12:05:47 2007
@@ -153,7 +153,7 @@
def testBadMagic(self):
# make pyc magic word invalid, forcing loading from .py
- badmagic_pyc = bytes(test_pyc)
+ badmagic_pyc = buffer(test_pyc)
badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit
files = {TESTMOD + ".py": (NOW, test_src),
TESTMOD + pyc_ext: (NOW, badmagic_pyc)}
@@ -161,7 +161,7 @@
def testBadMagic2(self):
# make pyc magic word invalid, causing an ImportError
- badmagic_pyc = bytes(test_pyc)
+ badmagic_pyc = buffer(test_pyc)
badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit
files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)}
try:
@@ -172,7 +172,7 @@
self.fail("expected ImportError; import from bad pyc")
def testBadMTime(self):
- badtime_pyc = bytes(test_pyc)
+ badtime_pyc = buffer(test_pyc)
badtime_pyc[7] ^= 0x02 # flip the second bit -- not the first as that one
# isn't stored in the .py's mtime in the zip archive.
files = {TESTMOD + ".py": (NOW, test_src),
Modified: python/branches/py3k-pep3137/Modules/dbmmodule.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/dbmmodule.c (original)
+++ python/branches/py3k-pep3137/Modules/dbmmodule.c Fri Nov 2 12:05:47 2007
@@ -219,14 +219,14 @@
if (arg == NULL)
return -1;
}
- if (!PyBytes_Check(arg)) {
+ if (!PyString_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"dbm key must be string, not %.100s",
arg->ob_type->tp_name);
return -1;
}
- key.dptr = PyBytes_AS_STRING(arg);
- key.dsize = PyBytes_GET_SIZE(arg);
+ key.dptr = PyString_AS_STRING(arg);
+ key.dsize = PyString_GET_SIZE(arg);
val = dbm_fetch(dp->di_dbm, key);
return val.dptr != NULL;
}
Modified: python/branches/py3k-pep3137/Modules/gdbmmodule.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/gdbmmodule.c (original)
+++ python/branches/py3k-pep3137/Modules/gdbmmodule.c Fri Nov 2 12:05:47 2007
@@ -251,14 +251,14 @@
"GDBM object has already been closed");
return -1;
}
- if (!PyBytes_Check(arg)) {
+ if (!PyString_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"gdbm key must be bytes, not %.100s",
arg->ob_type->tp_name);
return -1;
}
- key.dptr = PyBytes_AsString(arg);
- key.dsize = PyBytes_Size(arg);
+ key.dptr = PyString_AS_STRING(arg);
+ key.dsize = PyString_GET_SIZE(arg);
return gdbm_exists(dp->di_dbm, key);
}
More information about the Python-3000-checkins
mailing list