[Python-3000-checkins] r58885 - in python/branches/py3k-pep3137: Lib/io.py Lib/plat-mac/aetypes.py Lib/plat-mac/plistlib.py Mac/Modules/ae/_AEmodule.c Modules/pyexpat.c Python/mactoolboxglue.c
guido.van.rossum
python-3000-checkins at python.org
Tue Nov 6 21:41:50 CET 2007
Author: guido.van.rossum
Date: Tue Nov 6 21:41:49 2007
New Revision: 58885
Modified:
python/branches/py3k-pep3137/Lib/io.py
python/branches/py3k-pep3137/Lib/plat-mac/aetypes.py
python/branches/py3k-pep3137/Lib/plat-mac/plistlib.py
python/branches/py3k-pep3137/Mac/Modules/ae/_AEmodule.c
python/branches/py3k-pep3137/Modules/pyexpat.c
python/branches/py3k-pep3137/Python/mactoolboxglue.c
Log:
Fix the remaining failing tests on OSX.
All str/bytes issues (in the must unexpected places :-).
Hail to Christian's -bb flag!
Modified: python/branches/py3k-pep3137/Lib/io.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/io.py (original)
+++ python/branches/py3k-pep3137/Lib/io.py Tue Nov 6 21:41:49 2007
@@ -662,7 +662,7 @@
self._pos = 0
def getvalue(self):
- return self._buffer
+ return bytes(self._buffer)
def read(self, n=None):
if n is None:
@@ -672,7 +672,7 @@
newpos = min(len(self._buffer), self._pos + n)
b = self._buffer[self._pos : newpos]
self._pos = newpos
- return b
+ return bytes(b)
def read1(self, n):
return self.read(n)
Modified: python/branches/py3k-pep3137/Lib/plat-mac/aetypes.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/plat-mac/aetypes.py (original)
+++ python/branches/py3k-pep3137/Lib/plat-mac/aetypes.py Tue Nov 6 21:41:49 2007
@@ -22,7 +22,18 @@
four_chars must contain only ASCII characters.
"""
- return ("%-4.4s" % str(four_chars)).encode("latin-1")
+ if isinstance(four_chars, (bytes, buffer)):
+ b = bytes(four_chars[:4])
+ n = len(b)
+ if n < 4:
+ b += b' ' * (4 - n)
+ return b
+ else:
+ s = str(four_chars)[:4]
+ n = len(s)
+ if n < 4:
+ s += ' ' * (4 - n)
+ return bytes(s, "latin-1") # MacRoman?
class Unknown:
"""An uninterpreted AE object"""
@@ -47,7 +58,7 @@
return "Enum(%r)" % (self.enum,)
def __str__(self):
- return self.enum.strip(b' ')
+ return self.enum.decode("latin-1").strip(" ")
def __aepack__(self):
return pack(self.enum, typeEnumeration)
@@ -559,7 +570,7 @@
return "selector for element %s of %s"%(self.__class__.__name__, str(self.fr))
template = """
-class %s(ComponentItem): want = '%s'
+class %s(ComponentItem): want = %r
"""
exec(template % ("Text", b'text'))
Modified: python/branches/py3k-pep3137/Lib/plat-mac/plistlib.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/plat-mac/plistlib.py (original)
+++ python/branches/py3k-pep3137/Lib/plat-mac/plistlib.py Tue Nov 6 21:41:49 2007
@@ -164,7 +164,7 @@
def simpleElement(self, element, value=None):
if value is not None:
- value = _escapeAndEncode(value)
+ value = _escape(value)
self.writeln("<%s>%s</%s>" % (element, value, element))
else:
self.writeln("<%s/>" % element)
@@ -207,7 +207,7 @@
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
-def _escapeAndEncode(text):
+def _escape(text):
m = _controlCharPat.search(text)
if m is not None:
raise ValueError("strings can't contains control characters; "
@@ -217,7 +217,7 @@
text = text.replace("&", "&") # escape '&'
text = text.replace("<", "<") # escape '<'
text = text.replace(">", ">") # escape '>'
- return text.encode("utf-8") # encode as UTF-8
+ return text
PLISTHEADER = b"""\
Modified: python/branches/py3k-pep3137/Mac/Modules/ae/_AEmodule.c
==============================================================================
--- python/branches/py3k-pep3137/Mac/Modules/ae/_AEmodule.c (original)
+++ python/branches/py3k-pep3137/Mac/Modules/ae/_AEmodule.c Tue Nov 6 21:41:49 2007
@@ -835,9 +835,9 @@
OSErr err;
size = AEGetDescDataSize(&self->ob_itself);
- if ( (res = PyBytes_FromStringAndSize(NULL, size)) == NULL )
+ if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
return NULL;
- if ( (ptr = PyBytes_AsString(res)) == NULL )
+ if ( (ptr = PyString_AS_STRING(res)) == NULL )
return NULL;
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
return PyMac_Error(err);
Modified: python/branches/py3k-pep3137/Modules/pyexpat.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/pyexpat.c (original)
+++ python/branches/py3k-pep3137/Modules/pyexpat.c Tue Nov 6 21:41:49 2007
@@ -858,6 +858,7 @@
PyObject *bytes = NULL;
PyObject *str = NULL;
int len = -1;
+ char *ptr;
if ((bytes = PyInt_FromLong(buf_size)) == NULL)
goto finally;
@@ -877,14 +878,17 @@
if (str == NULL)
goto finally;
- /* XXX what to do if it returns a Unicode string? */
- if (!PyBytes_Check(str)) {
+ if (PyString_Check(str))
+ ptr = PyString_AS_STRING(str);
+ else if (PyBytes_Check(str))
+ ptr = PyBytes_AS_STRING(str);
+ else {
PyErr_Format(PyExc_TypeError,
"read() did not return a bytes object (type=%.400s)",
Py_Type(str)->tp_name);
goto finally;
}
- len = PyBytes_GET_SIZE(str);
+ len = Py_Size(str);
if (len > buf_size) {
PyErr_Format(PyExc_ValueError,
"read() returned too much data: "
@@ -892,7 +896,7 @@
buf_size, len);
goto finally;
}
- memcpy(buf, PyBytes_AsString(str), len);
+ memcpy(buf, ptr, len);
finally:
Py_XDECREF(arg);
Py_XDECREF(str);
@@ -998,7 +1002,7 @@
= XML_GetInputContext(self->itself, &offset, &size);
if (buffer != NULL)
- return PyBytes_FromStringAndSize(buffer + offset,
+ return PyString_FromStringAndSize(buffer + offset,
size - offset);
else
Py_RETURN_NONE;
Modified: python/branches/py3k-pep3137/Python/mactoolboxglue.c
==============================================================================
--- python/branches/py3k-pep3137/Python/mactoolboxglue.c (original)
+++ python/branches/py3k-pep3137/Python/mactoolboxglue.c Tue Nov 6 21:41:49 2007
@@ -194,7 +194,7 @@
PyMac_BuildOSType(OSType t)
{
uint32_t tmp = htonl((uint32_t)t);
- return PyBytes_FromStringAndSize((char *)&tmp, 4);
+ return PyString_FromStringAndSize((char *)&tmp, 4);
}
/* Convert an NumVersion value to a 4-element tuple */
More information about the Python-3000-checkins
mailing list