[Python-3000-checkins] r58721 - in python/branches/py3k-pep3137: Include/fileobject.h Lib/BaseHTTPServer.py Lib/io.py Lib/plat-mac/ic.py Objects/fileobject.c Objects/object.c Python/pythonrun.c
guido.van.rossum
python-3000-checkins at python.org
Tue Oct 30 20:14:52 CET 2007
Author: guido.van.rossum
Date: Tue Oct 30 20:14:52 2007
New Revision: 58721
Modified:
python/branches/py3k-pep3137/ (props changed)
python/branches/py3k-pep3137/Include/fileobject.h
python/branches/py3k-pep3137/Lib/BaseHTTPServer.py
python/branches/py3k-pep3137/Lib/io.py
python/branches/py3k-pep3137/Lib/plat-mac/ic.py
python/branches/py3k-pep3137/Objects/fileobject.c
python/branches/py3k-pep3137/Objects/object.c
python/branches/py3k-pep3137/Python/pythonrun.c
Log:
Merged revisions 58713-58720 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r58714 | georg.brandl | 2007-10-30 10:42:20 -0700 (Tue, 30 Oct 2007) | 2 lines
Fix typo.
........
r58717 | bill.janssen | 2007-10-30 11:12:39 -0700 (Tue, 30 Oct 2007) | 1 line
remove ord() calls on what are now integers rather than characters
........
r58718 | bill.janssen | 2007-10-30 11:13:17 -0700 (Tue, 30 Oct 2007) | 1 line
make sure to write bytes instead of strings to underlying socket channel
........
r58719 | guido.van.rossum | 2007-10-30 11:34:07 -0700 (Tue, 30 Oct 2007) | 5 lines
Patch 1352 (continued in issue 1329) by Christian Heimes.
Before sys.stderr is set to the proper thing, set it to a really simple
file-like object that can print tracebacks using direct file descriptor I/O.
This is handy for debugging.
........
r58720 | guido.van.rossum | 2007-10-30 11:36:44 -0700 (Tue, 30 Oct 2007) | 2 lines
Minor correction to the stdprinter object.
........
Modified: python/branches/py3k-pep3137/Include/fileobject.h
==============================================================================
--- python/branches/py3k-pep3137/Include/fileobject.h (original)
+++ python/branches/py3k-pep3137/Include/fileobject.h Tue Oct 30 20:14:52 2007
@@ -21,6 +21,13 @@
*/
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
+/* Internal API
+
+ The std printer acts as a preliminary sys.stderr until the new io
+ infrastructure is in place. */
+PyAPI_FUNC(PyObject *) PyFile_NewStdPrinter(int);
+PyAPI_DATA(PyTypeObject) PyStdPrinter_Type;
+
#ifdef __cplusplus
}
#endif
Modified: python/branches/py3k-pep3137/Lib/BaseHTTPServer.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/BaseHTTPServer.py (original)
+++ python/branches/py3k-pep3137/Lib/BaseHTTPServer.py Tue Oct 30 20:14:52 2007
@@ -356,11 +356,11 @@
content = (self.error_message_format %
{'code': code, 'message': _quote_html(message), 'explain': explain})
self.send_response(code, message)
- self.send_header("Content-Type", "text/html")
+ self.send_header("Content-Type", "text/html;charset=utf-8")
self.send_header('Connection', 'close')
self.end_headers()
if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
- self.wfile.write(content)
+ self.wfile.write(content.encode('UTF-8', 'replace'))
error_message_format = DEFAULT_ERROR_MESSAGE
@@ -378,8 +378,8 @@
else:
message = ''
if self.request_version != 'HTTP/0.9':
- self.wfile.write("%s %d %s\r\n" %
- (self.protocol_version, code, message))
+ self.wfile.write(("%s %d %s\r\n" %
+ (self.protocol_version, code, message)).encode('ASCII', 'strict'))
# print (self.protocol_version, code, message)
self.send_header('Server', self.version_string())
self.send_header('Date', self.date_time_string())
@@ -387,7 +387,7 @@
def send_header(self, keyword, value):
"""Send a MIME header."""
if self.request_version != 'HTTP/0.9':
- self.wfile.write("%s: %s\r\n" % (keyword, value))
+ self.wfile.write(("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict'))
if keyword.lower() == 'connection':
if value.lower() == 'close':
@@ -398,7 +398,7 @@
def end_headers(self):
"""Send the blank line ending the MIME headers."""
if self.request_version != 'HTTP/0.9':
- self.wfile.write("\r\n")
+ self.wfile.write(b"\r\n")
def log_request(self, code='-', size='-'):
"""Log an accepted request.
Modified: python/branches/py3k-pep3137/Lib/io.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/io.py (original)
+++ python/branches/py3k-pep3137/Lib/io.py Tue Oct 30 20:14:52 2007
@@ -87,7 +87,7 @@
a filename is given.
(*) If a file descriptor is given, it is closed when the returned
- I/O object is closed, unless closefd=False is give.
+ I/O object is closed, unless closefd=False is given.
Mode strings characters:
'r': open for reading (default)
Modified: python/branches/py3k-pep3137/Lib/plat-mac/ic.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/plat-mac/ic.py (original)
+++ python/branches/py3k-pep3137/Lib/plat-mac/ic.py Tue Oct 30 20:14:52 2007
@@ -41,27 +41,27 @@
def _decode_default(data, key):
if len(data) == 0:
return data
- if ord(data[0]) == len(data)-1:
+ if data[0] == len(data)-1:
# Assume Pstring
return data[1:]
return ICOpaqueData(data)
def _decode_multistr(data, key):
- numstr = ord(data[0]) << 8 | ord(data[1])
+ numstr = data[0] << 8 | data[1]
rv = []
ptr = 2
for i in range(numstr):
- strlen = ord(data[ptr])
+ strlen = data[ptr]
str = data[ptr+1:ptr+strlen+1]
rv.append(str)
ptr = ptr + strlen + 1
return rv
def _decode_fontrecord(data, key):
- size = ord(data[0]) << 8 | ord(data[1])
- face = ord(data[2])
- namelen = ord(data[4])
+ size = data[0] << 8 | data[1]
+ face = data[2]
+ namelen = data[4]
return size, face, data[5:5+namelen]
def _decode_boolean(data, key):
@@ -74,7 +74,7 @@
return data[:256], data[256:]
def _decode_appspec(data, key):
- namelen = ord(data[4])
+ namelen = data[4]
return data[0:4], data[5:5+namelen]
def _code_default(data, key):
Modified: python/branches/py3k-pep3137/Objects/fileobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/fileobject.c (original)
+++ python/branches/py3k-pep3137/Objects/fileobject.c Tue Oct 30 20:14:52 2007
@@ -325,6 +325,126 @@
return buf;
}
+/* **************************** std printer **************************** */
+
+typedef struct {
+ PyObject_HEAD
+ int fd;
+} PyStdPrinter_Object;
+
+static PyObject *
+stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
+{
+ PyStdPrinter_Object *self;
+
+ assert(type != NULL && type->tp_alloc != NULL);
+
+ self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
+ if (self != NULL) {
+ self->fd = -1;
+ }
+
+ return (PyObject *) self;
+}
+
+PyObject *
+PyFile_NewStdPrinter(int fd)
+{
+ PyStdPrinter_Object *self;
+
+ if (fd != fileno(stdout) && fd != fileno(stderr)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ self = PyObject_New(PyStdPrinter_Object,
+ &PyStdPrinter_Type);
+ if (self != NULL) {
+ self->fd = fd;
+ }
+ return (PyObject*)self;
+}
+
+PyObject *
+stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
+{
+ char *c;
+ Py_ssize_t n;
+
+ if (self->fd < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "I/O operation on closed file");
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "s#", &c, &n)) {
+ return NULL;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ errno = 0;
+ n = write(self->fd, c, n);
+ Py_END_ALLOW_THREADS
+
+ if (n < 0) {
+ if (errno == EAGAIN)
+ Py_RETURN_NONE;
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+
+ return PyInt_FromSsize_t(n);
+}
+
+static PyMethodDef stdprinter_methods[] = {
+ {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""},
+ {NULL, NULL} /* sentinel */
+};
+
+PyTypeObject PyStdPrinter_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "stderrprinter", /* tp_name */
+ sizeof(PyStdPrinter_Object), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ stdprinter_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 */
+ 0, /* tp_init */
+ PyType_GenericAlloc, /* tp_alloc */
+ stdprinter_new, /* tp_new */
+ PyObject_Del, /* tp_free */
+};
+
+
#ifdef __cplusplus
}
#endif
Modified: python/branches/py3k-pep3137/Objects/object.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/object.c (original)
+++ python/branches/py3k-pep3137/Objects/object.c Tue Oct 30 20:14:52 2007
@@ -1595,6 +1595,9 @@
if (PyType_Ready(&PyCode_Type) < 0)
Py_FatalError("Can't initialize 'code'");
+
+ if (PyType_Ready(&PyStdPrinter_Type) < 0)
+ Py_FatalError("Can't initialize StdPrinter");
}
Modified: python/branches/py3k-pep3137/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-pep3137/Python/pythonrun.c (original)
+++ python/branches/py3k-pep3137/Python/pythonrun.c Tue Oct 30 20:14:52 2007
@@ -151,7 +151,7 @@
{
PyInterpreterState *interp;
PyThreadState *tstate;
- PyObject *bimod, *sysmod;
+ PyObject *bimod, *sysmod, *pstderr;
char *p;
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
char *codeset;
@@ -228,6 +228,13 @@
PyDict_SetItemString(interp->sysdict, "modules",
interp->modules);
+ /* Set up a preliminary stderr printer until we have enough
+ infrastructure for the io module in place. */
+ pstderr = PyFile_NewStdPrinter(fileno(stderr));
+ if (pstderr == NULL)
+ Py_FatalError("Py_Initialize: can't set preliminary stderr");
+ PySys_SetObject("stderr", pstderr);
+
_PyImport_Init();
/* initialize builtin exceptions */
More information about the Python-3000-checkins
mailing list