From python-3000-checkins at python.org Wed Aug 1 04:36:47 2007 From: python-3000-checkins at python.org (kurt.kaiser) Date: Wed, 1 Aug 2007 04:36:47 +0200 (CEST) Subject: [Python-3000-checkins] r56638 - python/branches/p3yk/Lib/idlelib/EditorWindow.py python/branches/p3yk/Lib/idlelib/PyShell.py python/branches/p3yk/Lib/idlelib/ScriptBinding.py Message-ID: <20070801023647.2E56E1E400D@bag.python.org> Author: kurt.kaiser Date: Wed Aug 1 04:36:45 2007 New Revision: 56638 Modified: python/branches/p3yk/Lib/idlelib/EditorWindow.py python/branches/p3yk/Lib/idlelib/PyShell.py python/branches/p3yk/Lib/idlelib/ScriptBinding.py Log: Refactor syntax error display in shell and edit windows; move colorize_syntax_error() to EditorWindow; update to py3k. Modified: python/branches/p3yk/Lib/idlelib/EditorWindow.py ============================================================================== --- python/branches/p3yk/Lib/idlelib/EditorWindow.py (original) +++ python/branches/p3yk/Lib/idlelib/EditorWindow.py Wed Aug 1 04:36:45 2007 @@ -1,6 +1,7 @@ import sys import os import re +import string import imp from itertools import count from Tkinter import * @@ -602,6 +603,19 @@ theme = idleConf.GetOption('main','Theme','name') self.text.config(idleConf.GetHighlight(theme, "normal")) + IDENTCHARS = string.ascii_letters + string.digits + "_" + + def colorize_syntax_error(self, text, pos): + text.tag_add("ERROR", pos) + char = text.get(pos) + if char and char in self.IDENTCHARS: + text.tag_add("ERROR", pos + " wordstart", pos) + if '\n' == text.get(pos): # error at line end + text.mark_set("insert", pos) + else: + text.mark_set("insert", pos + "+1c") + text.see(pos) + def ResetFont(self): "Update the text widgets' font if it is changed" # Called from configDialog.py @@ -1004,6 +1018,8 @@ "n" * newtabwidth) text.configure(tabs=pixels) +### begin autoindent code ### (configuration was moved to beginning of class) + # If ispythonsource and guess are true, guess a good value for # indentwidth based on file content (if possible), and if # indentwidth != tabwidth set usetabs false. Modified: python/branches/p3yk/Lib/idlelib/PyShell.py ============================================================================== --- python/branches/p3yk/Lib/idlelib/PyShell.py (original) +++ python/branches/p3yk/Lib/idlelib/PyShell.py Wed Aug 1 04:36:45 2007 @@ -3,7 +3,6 @@ import os import os.path import sys -import string import getopt import re import socket @@ -35,7 +34,6 @@ from . import RemoteDebugger from . import macosxSupport -IDENTCHARS = string.ascii_letters + string.digits + "_" LOCALHOST = '127.0.0.1' try: @@ -624,47 +622,30 @@ \n""" % (filename,)) def showsyntaxerror(self, filename=None): - """Extend base class method: Add Colorizing + """Override Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret. """ - text = self.tkconsole.text - stuff = self.unpackerror() - if stuff: - msg, lineno, offset, line = stuff - if lineno == 1: - pos = "iomark + %d chars" % (offset-1) - else: - pos = "iomark linestart + %d lines + %d chars" % \ - (lineno-1, offset-1) - text.tag_add("ERROR", pos) - text.see(pos) - char = text.get(pos) - if char and char in IDENTCHARS: - text.tag_add("ERROR", pos + " wordstart", pos) - self.tkconsole.resetoutput() - self.write("SyntaxError: %s\n" % str(msg)) - else: - self.tkconsole.resetoutput() - InteractiveInterpreter.showsyntaxerror(self, filename) - self.tkconsole.showprompt() - - def unpackerror(self): + tkconsole = self.tkconsole + text = tkconsole.text + text.tag_remove("ERROR", "1.0", "end") type, value, tb = sys.exc_info() - ok = type is SyntaxError - if ok: - try: - msg, (dummy_filename, lineno, offset, line) = value - if not offset: - offset = 0 - except: - ok = 0 - if ok: - return msg, lineno, offset, line + msg = value.msg or "" + lineno = value.lineno or 1 + offset = value.offset or 0 + if offset == 0: + lineno += 1 #mark end of offending line + if lineno == 1: + pos = "iomark + %d chars" % (offset-1) else: - return None + pos = "iomark linestart + %d lines + %d chars" % \ + (lineno-1, offset-1) + tkconsole.colorize_syntax_error(text, pos) + tkconsole.resetoutput() + self.write("SyntaxError: %s\n" % msg) + tkconsole.showprompt() def showtraceback(self): "Extend base class method to reset output properly" Modified: python/branches/p3yk/Lib/idlelib/ScriptBinding.py ============================================================================== --- python/branches/p3yk/Lib/idlelib/ScriptBinding.py (original) +++ python/branches/p3yk/Lib/idlelib/ScriptBinding.py Wed Aug 1 04:36:45 2007 @@ -23,12 +23,11 @@ import tabnanny import tokenize import tkMessageBox +from .EditorWindow import EditorWindow from . import PyShell from .configHandler import idleConf -IDENTCHARS = string.ascii_letters + string.digits + "_" - indent_message = """Error: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR @@ -83,7 +82,7 @@ self.shell = shell = self.flist.open_shell() saved_stream = shell.get_warning_stream() shell.set_warning_stream(shell.stderr) - f = open(filename, 'r') + f = file(filename, 'r') source = f.read() f.close() if '\r' in source: @@ -91,40 +90,25 @@ source = re.sub(r"\r", "\n", source) if source and source[-1] != '\n': source = source + '\n' - text = self.editwin.text + editwin = self.editwin + text = editwin.text text.tag_remove("ERROR", "1.0", "end") try: - try: - # If successful, return the compiled code - return compile(source, filename, "exec") - except (SyntaxError, OverflowError) as err: - try: - msg, (errorfilename, lineno, offset, line) = err.args - if not errorfilename: - err.args = msg, (filename, lineno, offset, line) - err.filename = filename - self.colorize_syntax_error(msg, lineno, offset) - except: - msg = str(err) - self.errorbox("Syntax error", - "There's an error in your program:\n" + msg) - return False + # If successful, return the compiled code + return compile(source, filename, "exec") + except (SyntaxError, OverflowError) as value: + msg = value.msg or "" + lineno = value.lineno or 1 + offset = value.offset or 0 + if offset == 0: + lineno += 1 #mark end of offending line + pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) + editwin.colorize_syntax_error(text, pos) + self.errorbox("SyntaxError", "%-20s" % msg) + return False finally: shell.set_warning_stream(saved_stream) - def colorize_syntax_error(self, msg, lineno, offset): - text = self.editwin.text - pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) - text.tag_add("ERROR", pos) - char = text.get(pos) - if char and char in IDENTCHARS: - text.tag_add("ERROR", pos + " wordstart", pos) - if '\n' == text.get(pos): # error at line end - text.mark_set("insert", pos) - else: - text.mark_set("insert", pos + "+1c") - text.see(pos) - def run_module_event(self, event): """Run the module after setting up the environment. @@ -199,10 +183,10 @@ icon=tkMessageBox.QUESTION, type=tkMessageBox.OKCANCEL, default=tkMessageBox.OK, - master=self.editwin.text) + parent=self.editwin.text) return mb.show() def errorbox(self, title, message): # XXX This should really be a function of EditorWindow... - tkMessageBox.showerror(title, message, master=self.editwin.text) + tkMessageBox.showerror(title, message, parent=self.editwin.text) self.editwin.text.focus_set() From python-3000-checkins at python.org Wed Aug 1 07:42:58 2007 From: python-3000-checkins at python.org (travis.oliphant) Date: Wed, 1 Aug 2007 07:42:58 +0200 (CEST) Subject: [Python-3000-checkins] r56639 - python/branches/py3k-buffer/Include/abstract.h python/branches/py3k-buffer/Include/memoryobject.h python/branches/py3k-buffer/Include/object.h python/branches/py3k-buffer/Include/pyerrors.h Message-ID: <20070801054258.0557E1E4015@bag.python.org> Author: travis.oliphant Date: Wed Aug 1 07:42:56 2007 New Revision: 56639 Added: python/branches/py3k-buffer/Include/memoryobject.h (contents, props changed) Modified: python/branches/py3k-buffer/Include/abstract.h python/branches/py3k-buffer/Include/object.h python/branches/py3k-buffer/Include/pyerrors.h Log: Layout the new buffer interface. Modified: python/branches/py3k-buffer/Include/abstract.h ============================================================================== --- python/branches/py3k-buffer/Include/abstract.h (original) +++ python/branches/py3k-buffer/Include/abstract.h Wed Aug 1 07:42:56 2007 @@ -475,6 +475,12 @@ This is the equivalent of the Python statement: del o[key]. */ + /* old buffer API + FIXME: usage of these should all be replaced in Python itself + but for backwards compatibility we will implement them. + Their usage without a corresponding "unlock" mechansim + may create issues (but they would already be there). */ + PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len); @@ -527,6 +533,110 @@ an exception set. */ + /* new buffer API */ + + PyAPI_FUNC(int) PyObject_CheckBuffer(PyObject *obj); + + /* Return 1 if the getbuffer function is available, otherwise + return 0 */ + + PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, PyBuffer *view, + int flags); + + /* This is a C-API version of the getbuffer function call. It checks + to make sure object has the required function pointer and issues the + call. Returns -1 and raises an error on failure and returns 0 on + success + */ + + PyAPI_FUNC(int) PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view); + + /* C-API version of the releasebuffer function call. It checks + to make sure the object has the required function pointer and + issues the call. Returns 0 on success and -1 (with an error + raised) on failure. This function always succeeds (as a NO-OP) + if there is no releasebuffer function for the object so that + it can always be called when the consumer is done with the buffer + */ + + PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *); + + /* Return the implied itemsize of the data-format area from a + struct-style description */ + + PyAPI_FUNC(int) PyObject_GetContiguous(PyObject *obj, void **buf, + Py_ssize_t *len, char **format, + char fortran); + + /* Return a contiguous chunk of memory representing the buffer + from an object. If a copy is made then return 1 (the + return variable should be checked so the memory can be + freed if needed after the caller is done with it). If no + copy was needed return 0. If an error occurred in probing + the buffer interface then return -1. + + The contiguous chunck of memory is pointed to by *buf and + the length of that memory is *len. The format of that + memory is returned in struct-string syntax in *format. + + If the object is multi-dimensional and if fortran is 'F', + the first dimension of the underlying array will vary the + fastest in the buffer. If fortran is 'C', then the last + dimension will vary the fastest (C-style contiguous). If + fortran is 'A', then it does not matter and you will get + whatever the object decides is more efficient. + + If a copy is made, then the memory *must be freed* by + calling PyMem_Free when the user of this sub-routine is + done with the memory + */ + + PyAPI_FUNC(int) PyObject_CopyToObject(PyObject *obj, void *buf, + Py_ssize_t len, char fortran); + + /* Copy len bytes of data from the contiguous chunk of memory + pointed to by buf into the buffer exported by obj. Return + 0 on success and return -1 and raise a PyBuffer_Error on + error (i.e. the object does not have a buffer interface or + it is not working). + + If fortran is 'F', then if the object is multi-dimensional, + then the data will be copied into the array in + Fortran-style (first dimension varies the fastest). If + fortran is 'C', then the data will be copied into the array + in C-style (last dimension varies the fastest). If fortran + is 'A', then it does not matter and the copy will be made + in whatever way is more efficient. + + */ + + PyAPI_FUNC(int) PyBuffer_IsContiguous(PyBuffer *view, char fortran); + + PyAPI_FUNC(int) PyBuffer_IsAligned(PyBuffer *view); + + PyAPI_FUNC(int) PyBuffer_FillContiguousStrides(int *ndims, + Py_ssize_t *shape, + int itemsize, + Py_ssize_t *strides, + char fortran); + + /* Fill the strides array with byte-strides of a contiguous + (Fortran-style if fortran is 'F' or C-style otherwise) + array of the given shape with the given number of bytes + per element. + */ + + PyAPI_FUNC(int) PyBuffer_FillInfo(PyBuffer *view, void *buf, + Py_ssize_t len, int readonly, + int flags); + + /* Fills in a buffer-info structure correctly for an exporter + that can only share a contiguous chunk of memory of + "unsigned bytes" of the given length. Returns 0 on success + and -1 (with raising an error) on error. + */ + + /* Iterators */ PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *); Added: python/branches/py3k-buffer/Include/memoryobject.h ============================================================================== --- (empty file) +++ python/branches/py3k-buffer/Include/memoryobject.h Wed Aug 1 07:42:56 2007 @@ -0,0 +1,35 @@ + +/* Memory object interface */ + +#ifndef Py_MEMORYOBJECT_H +#define Py_MEMORYOBJECT_H +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PyObject_HEAD + PyObject *base; + int ndims; + Py_ssize_t *starts; /* slice starts */ + Py_ssize_t *stops; /* slice stops */ + Py_ssize_t *steps; /* slice steps */ +} PyMemoryViewObject; + + +PyAPI_DATA(PyTypeObject) PyMemoryView_Type; + +#define PyMemory_Check(op) (Py_Type(op) == &PyMemoryView_Type) + +#define Py_END_OF_MEMORY (-1) + +PyAPI_FUNC(PyObject *) PyObject_GetMemoryView(PyObject *base); + +PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(PyBuffer *info); + /* create new if bufptr is NULL + will be a new bytesobject in base */ + +#ifdef __cplusplus +} +#endif +#endif /* !Py_BUFFEROBJECT_H */ Modified: python/branches/py3k-buffer/Include/object.h ============================================================================== --- python/branches/py3k-buffer/Include/object.h (original) +++ python/branches/py3k-buffer/Include/object.h Wed Aug 1 07:42:56 2007 @@ -140,11 +140,55 @@ typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *); -/* ssize_t-based buffer interface */ -typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **); -typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **); -typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *); -typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **); + +/* buffer interface */ +struct bufferinfo { + void *buf; + Py_ssize_t len; + int readonly; + const char *format; + int ndim; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + int itemsize; + void *internal; +} PyBuffer; + +typedef int (*getbufferproc)(PyObject *, PyBuffer *, int); +typedef int (*releasebufferproc)(PyObject *, PyBuffer *); + + /* Flags for getting buffers */ +#define PyBUF_SIMPLE 0 +#define PyBUF_REQ_WRITEABLE 0x0001 +#define PyBUF_REQ_LOCKDATA 0x0002 +#define PyBUF_REQ_FORMAT 0x0004 +#define PyBUF_REQ_ALIGNED (0x0008 | PyBUF_REQ_FORMAT) +#define PyBUF_ALW_ND 0x0010 +#define PyBUF_ALW_STRIDES (0x0020 | PyBUF_ALW_ND) +#define PyBUF_REQ_C_CONTIGUOUS (0x0040 | PyBUF_ALW_STRIDES) +#define PyBUF_REQ_F_CONTIGUOUS (0x0080 | PyBUF_ALW_STRIDES) +#define PyBUF_REQ_ANY_CONTIGUOUS (0x0200 | PyBUF_ALW_STRIDES) +#define PyBUF_ALW_INDIRECT (0x0400 | PyBUF_ALW_STRIDES) + +#define PyBUF_CONTIG (PyBUF_ALW_ND | PyBUF_REQ_WRITEABLE | PyBUF_REQ_ALIGNED) +#define PyBUF_CONTIG_RO (PyBUF_ALW_ND | PyBUF_REQ_ALIGNED) +#define PyBUF_CONTIG_LCK (PyBUF_ALW_ND | PyBUF_REQ_LOCKDATA | PyBUF_REQ_ALIGNED) + +#define PyBUF_STRIDED (PyBUF_ALW_STRIDES | PyBUF_REQ_WRITEABLE | PyBUF_REQ_ALIGNED) +#define PyBUF_STRIDED_RO (PyBUF_ALW_STRIDES | PyBUF_REQ_ALIGNED) +#define PyBUF_STRIDED_LCK (PyBUF_ALW_STRIDES | PyBUF_REQ_LOCKDATA | PyBUF_REQ_ALIGNED) + +#define PyBUF_RECORDS (PyBUF_ALW_STRIDES | PyBUF_REQ_WRITEABLE | PyBUF_REQ_FORMAT) +#define PyBUF_RECORDS_RO (PyBUF_ALW_STRIDES | PyBUF_REQ_FORMAT) +#define PyBUF_RECORDS_LCK (PyBUF_ALW_STRIDES | PyBUF_REQ_LOCKDATA | PyBUF_REQ_FORMAT) + +#define PyBUF_FULL (PyBUF_ALW_INDIRECT | PyBUF_REQ_WRITEABLE | PyBUF_REQ_FORMAT) +#define PyBUF_FULL_RO (PyBUF_ALW_INDIRECT | PyBUF_REQ_FORMAT) +#define PyBUF_FULL_LCK (PyBUF_ALW_INDIRECT | PyBUF_REQ_LOCKDATA | PyBUF_REQ_FORMAT) + + +/* End buffer interface */ typedef int (*objobjproc)(PyObject *, PyObject *); typedef int (*visitproc)(PyObject *, void *); @@ -218,14 +262,12 @@ objobjargproc mp_ass_subscript; } PyMappingMethods; + typedef struct { - readbufferproc bf_getreadbuffer; - writebufferproc bf_getwritebuffer; - segcountproc bf_getsegcount; - charbufferproc bf_getcharbuffer; + getbufferproc bf_getbuffer; + releasebufferproc bf_releasebuffer; } PyBufferProcs; - typedef void (*freefunc)(void *); typedef void (*destructor)(PyObject *); typedef int (*printfunc)(PyObject *, FILE *, int); Modified: python/branches/py3k-buffer/Include/pyerrors.h ============================================================================== --- python/branches/py3k-buffer/Include/pyerrors.h (original) +++ python/branches/py3k-buffer/Include/pyerrors.h Wed Aug 1 07:42:56 2007 @@ -138,6 +138,7 @@ PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; PyAPI_DATA(PyObject *) PyExc_ValueError; PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; +PyAPI_DATA(PyObject *) PyExc_BufferError; #ifdef MS_WINDOWS PyAPI_DATA(PyObject *) PyExc_WindowsError; #endif From python-3000-checkins at python.org Wed Aug 1 19:32:29 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Wed, 1 Aug 2007 19:32:29 +0200 (CEST) Subject: [Python-3000-checkins] r56648 - python/branches/py3k-struni/Lib/abc.py Message-ID: <20070801173229.25DBE1E4003@bag.python.org> Author: guido.van.rossum Date: Wed Aug 1 19:32:28 2007 New Revision: 56648 Modified: python/branches/py3k-struni/Lib/abc.py Log: Add @abstractproperty. Modified: python/branches/py3k-struni/Lib/abc.py ============================================================================== --- python/branches/py3k-struni/Lib/abc.py (original) +++ python/branches/py3k-struni/Lib/abc.py Wed Aug 1 19:32:28 2007 @@ -24,6 +24,31 @@ return funcobj +class abstractproperty(property): + """A decorator indicating abstract properties. + + Requires that the metaclass is ABCMeta or derived from it. A + class that has a metaclass derived from ABCMeta cannot be + instantiated unless all of its abstract properties are overridden. + + Usage: + + class C(metaclass=ABCMeta): + @abstractproperty + def my_abstract_property(self): + ... + + This defines a read-only property; you can also define a read-write + abstract property using the 'long' form of property declaration: + + class C(metaclass=ABCMeta): + def getx(self): ... + def setx(self, value): ... + x = abstractproperty(getx, setx) + """ + __isabstractmethod__ = True + + class _Abstract(object): """Helper class inserted into the bases by ABCMeta (using _fix_bases()). From python-3000-checkins at python.org Wed Aug 1 19:43:16 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Wed, 1 Aug 2007 19:43:16 +0200 (CEST) Subject: [Python-3000-checkins] r56649 - python/branches/py3k-struni/Objects/complexobject.c Message-ID: <20070801174316.A0EFB1E4008@bag.python.org> Author: guido.van.rossum Date: Wed Aug 1 19:43:15 2007 New Revision: 56649 Modified: python/branches/py3k-struni/Objects/complexobject.c Log: Kill div, mod and divmod on complex (already deprecated in 2.x). Add docstring for conjugate(). Patch by Jeffrey Yasskin. Modified: python/branches/py3k-struni/Objects/complexobject.c ============================================================================== --- python/branches/py3k-struni/Objects/complexobject.c (original) +++ python/branches/py3k-struni/Objects/complexobject.c Wed Aug 1 19:43:15 2007 @@ -466,57 +466,18 @@ static PyObject * complex_remainder(PyObject *v, PyObject *w) { - Py_complex div, mod; - Py_complex a, b; - TO_COMPLEX(v, a); - TO_COMPLEX(w, b); - - if (PyErr_Warn(PyExc_DeprecationWarning, - "complex divmod(), // and % are deprecated") < 0) - return NULL; - - errno = 0; - div = c_quot(a, b); /* The raw divisor value. */ - if (errno == EDOM) { - PyErr_SetString(PyExc_ZeroDivisionError, "complex remainder"); - return NULL; - } - div.real = floor(div.real); /* Use the floor of the real part. */ - div.imag = 0.0; - mod = c_diff(a, c_prod(b, div)); - - return PyComplex_FromCComplex(mod); + PyErr_SetString(PyExc_TypeError, + "can't mod complex numbers."); + return NULL; } static PyObject * complex_divmod(PyObject *v, PyObject *w) { - Py_complex div, mod; - PyObject *d, *m, *z; - Py_complex a, b; - TO_COMPLEX(v, a); - TO_COMPLEX(w, b); - - if (PyErr_Warn(PyExc_DeprecationWarning, - "complex divmod(), // and % are deprecated") < 0) - return NULL; - - errno = 0; - div = c_quot(a, b); /* The raw divisor value. */ - if (errno == EDOM) { - PyErr_SetString(PyExc_ZeroDivisionError, "complex divmod()"); - return NULL; - } - div.real = floor(div.real); /* Use the floor of the real part. */ - div.imag = 0.0; - mod = c_diff(a, c_prod(b, div)); - d = PyComplex_FromCComplex(div); - m = PyComplex_FromCComplex(mod); - z = PyTuple_Pack(2, d, m); - Py_XDECREF(d); - Py_XDECREF(m); - return z; + PyErr_SetString(PyExc_TypeError, + "can't take floor or mod of complex number."); + return NULL; } static PyObject * @@ -560,15 +521,8 @@ static PyObject * complex_int_div(PyObject *v, PyObject *w) { - PyObject *t, *r; - - t = complex_divmod(v, w); - if (t != NULL) { - r = PyTuple_GET_ITEM(t, 0); - Py_INCREF(r); - Py_DECREF(t); - return r; - } + PyErr_SetString(PyExc_TypeError, + "can't take floor of complex number."); return NULL; } @@ -665,6 +619,11 @@ return PyComplex_FromCComplex(c); } +PyDoc_STRVAR(complex_conjugate_doc, +"complex.conjugate() -> complex\n" +"\n" +"Returns the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); + static PyObject * complex_getnewargs(PyComplexObject *v) { @@ -672,7 +631,8 @@ } static PyMethodDef complex_methods[] = { - {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS}, + {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS, + complex_conjugate_doc}, {"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; From python-3000-checkins at python.org Wed Aug 1 19:52:24 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Wed, 1 Aug 2007 19:52:24 +0200 (CEST) Subject: [Python-3000-checkins] r56650 - in python/branches/py3k-struni/Lib: abc.py test/test_abc.py Message-ID: <20070801175224.3EE331E4005@bag.python.org> Author: guido.van.rossum Date: Wed Aug 1 19:52:23 2007 New Revision: 56650 Modified: python/branches/py3k-struni/Lib/abc.py python/branches/py3k-struni/Lib/test/test_abc.py Log: Tests for @abstractproperty by Jeffrey Yasskin. (The previous changes to abc.py were also by him). Put back a comment about using super() for properties (I didn't realize this worked). Modified: python/branches/py3k-struni/Lib/abc.py ============================================================================== --- python/branches/py3k-struni/Lib/abc.py (original) +++ python/branches/py3k-struni/Lib/abc.py Wed Aug 1 19:52:23 2007 @@ -30,6 +30,8 @@ Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract properties are overridden. + The abstract properties can be called using any of the the normal + 'super' call mechanisms. Usage: Modified: python/branches/py3k-struni/Lib/test/test_abc.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_abc.py (original) +++ python/branches/py3k-struni/Lib/test/test_abc.py Wed Aug 1 19:52:23 2007 @@ -19,26 +19,42 @@ def bar(self): pass self.assertEqual(hasattr(bar, "__isabstractmethod__"), False) - def test_abstractmethod_integration(self): + def test_abstractproperty_basics(self): + @abc.abstractproperty + def foo(self): pass + self.assertEqual(foo.__isabstractmethod__, True) + def bar(self): pass + self.assertEqual(hasattr(bar, "__isabstractmethod__"), False) + class C(metaclass=abc.ABCMeta): - @abc.abstractmethod - def foo(self): pass # abstract - def bar(self): pass # concrete - self.assertEqual(C.__abstractmethods__, {"foo"}) - self.assertRaises(TypeError, C) # because foo is abstract + @abc.abstractproperty + def foo(self): return 3 class D(C): - def bar(self): pass # concrete override of concrete - self.assertEqual(D.__abstractmethods__, {"foo"}) - self.assertRaises(TypeError, D) # because foo is still abstract - class E(D): - def foo(self): pass - self.assertEqual(E.__abstractmethods__, set()) - E() # now foo is concrete, too - class F(E): - @abc.abstractmethod - def bar(self): pass # abstract override of concrete - self.assertEqual(F.__abstractmethods__, {"bar"}) - self.assertRaises(TypeError, F) # because bar is abstract now + @property + def foo(self): return super().foo + self.assertEqual(D().foo, 3) + + def test_abstractmethod_integration(self): + for abstractthing in [abc.abstractmethod, abc.abstractproperty]: + class C(metaclass=abc.ABCMeta): + @abstractthing + def foo(self): pass # abstract + def bar(self): pass # concrete + self.assertEqual(C.__abstractmethods__, {"foo"}) + self.assertRaises(TypeError, C) # because foo is abstract + class D(C): + def bar(self): pass # concrete override of concrete + self.assertEqual(D.__abstractmethods__, {"foo"}) + self.assertRaises(TypeError, D) # because foo is still abstract + class E(D): + def foo(self): pass + self.assertEqual(E.__abstractmethods__, set()) + E() # now foo is concrete, too + class F(E): + @abstractthing + def bar(self): pass # abstract override of concrete + self.assertEqual(F.__abstractmethods__, {"bar"}) + self.assertRaises(TypeError, F) # because bar is abstract now def test_registration_basics(self): class A(metaclass=abc.ABCMeta): From python-3000-checkins at python.org Wed Aug 1 20:06:14 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Wed, 1 Aug 2007 20:06:14 +0200 (CEST) Subject: [Python-3000-checkins] r56651 - python/branches/py3k-struni/Lib/test/test_tokenize.py Message-ID: <20070801180614.8AF601E4007@bag.python.org> Author: guido.van.rossum Date: Wed Aug 1 20:06:13 2007 New Revision: 56651 Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py Log: When testing all stdlib modules, ignore test_pep263.py which is encoded in KOI8-R. Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_tokenize.py (original) +++ python/branches/py3k-struni/Lib/test/test_tokenize.py Wed Aug 1 20:06:13 2007 @@ -34,6 +34,7 @@ NEWLINE '\\n' (3, 26) (3, 27) DEDENT '' (4, 0) (4, 0) +' # Emacs hint There will be a bunch more tests of specific source patterns. @@ -184,6 +185,8 @@ testdir = os.path.dirname(f) or os.curdir testfiles = glob.glob(testdir + os.sep + 'test*.py') + # Exclude test_pep263 which is encoded in KOI8-R + testfiles = [t for t in testfiles if not t.endswith("pep263.py")] if not is_resource_enabled('compiler'): testfiles = random.sample(testfiles, 10) From python-3000-checkins at python.org Wed Aug 1 20:08:09 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Wed, 1 Aug 2007 20:08:09 +0200 (CEST) Subject: [Python-3000-checkins] r56652 - python/branches/py3k-struni/Objects/floatobject.c python/branches/py3k-struni/Objects/longobject.c Message-ID: <20070801180809.4DD4B1E400B@bag.python.org> Author: guido.van.rossum Date: Wed Aug 1 20:08:08 2007 New Revision: 56652 Modified: python/branches/py3k-struni/Objects/floatobject.c python/branches/py3k-struni/Objects/longobject.c Log: Changes to long and float by Jeffrey Jasskin to conform to PEP 3141. In particular, add trivial implementations of .real, .imag and .conjugate() to both, and add .numerator and .denominator to long. Also some small optimizations (e.g. remove long_pos in favor of long_long). Modified: python/branches/py3k-struni/Objects/floatobject.c ============================================================================== --- python/branches/py3k-struni/Objects/floatobject.c (original) +++ python/branches/py3k-struni/Objects/floatobject.c Wed Aug 1 20:08:08 2007 @@ -742,17 +742,6 @@ } static PyObject * -float_pos(PyFloatObject *v) -{ - if (PyFloat_CheckExact(v)) { - Py_INCREF(v); - return (PyObject *)v; - } - else - return PyFloat_FromDouble(v->ob_fval); -} - -static PyObject * float_abs(PyFloatObject *v) { return PyFloat_FromDouble(fabs(v->ob_fval)); @@ -989,7 +978,15 @@ "Overrides the automatic determination of C-level floating point type.\n" "This affects how floats are converted to and from binary strings."); +static PyObject * +float_getzero(PyObject *v, void *closure) +{ + return PyFloat_FromDouble(0.0); +} + static PyMethodDef float_methods[] = { + {"conjugate", (PyCFunction)float_float, METH_NOARGS, + "Returns self, the complex conjugate of any float."}, {"__getnewargs__", (PyCFunction)float_getnewargs, METH_NOARGS}, {"__getformat__", (PyCFunction)float_getformat, METH_O|METH_CLASS, float_getformat_doc}, @@ -998,6 +995,18 @@ {NULL, NULL} /* sentinel */ }; +static PyGetSetDef float_getset[] = { + {"real", + (getter)float_float, (setter)NULL, + "the real part of a complex number", + NULL}, + {"imag", + (getter)float_getzero, (setter)NULL, + "the imaginary part of a complex number", + NULL}, + {NULL} /* Sentinel */ +}; + PyDoc_STRVAR(float_doc, "float(x) -> floating point number\n\ \n\ @@ -1012,7 +1021,7 @@ float_divmod, /*nb_divmod*/ float_pow, /*nb_power*/ (unaryfunc)float_neg, /*nb_negative*/ - (unaryfunc)float_pos, /*nb_positive*/ + (unaryfunc)float_float, /*nb_positive*/ (unaryfunc)float_abs, /*nb_absolute*/ (inquiry)float_bool, /*nb_bool*/ 0, /*nb_invert*/ @@ -1073,7 +1082,7 @@ 0, /* tp_iternext */ float_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + float_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ Modified: python/branches/py3k-struni/Objects/longobject.c ============================================================================== --- python/branches/py3k-struni/Objects/longobject.c (original) +++ python/branches/py3k-struni/Objects/longobject.c Wed Aug 1 20:08:08 2007 @@ -1985,7 +1985,7 @@ /* forward */ static PyLongObject *x_divrem (PyLongObject *, PyLongObject *, PyLongObject **); -static PyObject *long_pos(PyLongObject *); +static PyObject *long_long(PyObject *v); static int long_divrem(PyLongObject *, PyLongObject *, PyLongObject **, PyLongObject **); @@ -3181,17 +3181,6 @@ } static PyObject * -long_pos(PyLongObject *v) -{ - if (PyLong_CheckExact(v)) { - Py_INCREF(v); - return (PyObject *)v; - } - else - return _PyLong_Copy(v); -} - -static PyObject * long_neg(PyLongObject *v) { PyLongObject *z; @@ -3209,7 +3198,7 @@ if (Py_Size(v) < 0) return long_neg(v); else - return long_pos(v); + return long_long((PyObject *)v); } static int @@ -3496,12 +3485,6 @@ } static PyObject * -long_int(PyObject *v) -{ - return long_long(v); -} - -static PyObject * long_float(PyObject *v) { double result; @@ -3607,11 +3590,38 @@ return Py_BuildValue("(N)", _PyLong_Copy(v)); } +static PyObject * +long_getN(PyLongObject *v, void *context) { + return PyLong_FromLong((intptr_t)context); +} + static PyMethodDef long_methods[] = { + {"conjugate", (PyCFunction)long_long, METH_NOARGS, + "Returns self, the complex conjugate of any int."}, {"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; +static PyGetSetDef long_getset[] = { + {"real", + (getter)long_long, (setter)NULL, + "the real part of a complex number", + NULL}, + {"imag", + (getter)long_getN, (setter)NULL, + "the imaginary part of a complex number", + (void*)0}, + {"numerator", + (getter)long_long, (setter)NULL, + "the numerator of a rational number in lowest terms", + NULL}, + {"denominator", + (getter)long_getN, (setter)NULL, + "the denominator of a rational number in lowest terms", + (void*)1}, + {NULL} /* Sentinel */ +}; + PyDoc_STRVAR(long_doc, "int(x[, base]) -> integer\n\ \n\ @@ -3629,7 +3639,7 @@ long_divmod, /*nb_divmod*/ long_pow, /*nb_power*/ (unaryfunc) long_neg, /*nb_negative*/ - (unaryfunc) long_pos, /*tp_positive*/ + (unaryfunc) long_long, /*tp_positive*/ (unaryfunc) long_abs, /*tp_absolute*/ (inquiry) long_bool, /*tp_bool*/ (unaryfunc) long_invert, /*nb_invert*/ @@ -3639,7 +3649,7 @@ long_xor, /*nb_xor*/ long_or, /*nb_or*/ 0, /*nb_coerce*/ - long_int, /*nb_int*/ + long_long, /*nb_int*/ long_long, /*nb_long*/ long_float, /*nb_float*/ 0, /*nb_oct*/ /* not used */ @@ -3694,7 +3704,7 @@ 0, /* tp_iternext */ long_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + long_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ From python-3000-checkins at python.org Thu Aug 2 09:53:40 2007 From: python-3000-checkins at python.org (georg.brandl) Date: Thu, 2 Aug 2007 09:53:40 +0200 (CEST) Subject: [Python-3000-checkins] r56659 - python/branches/py3k-struni/Doc/ref/ref3.tex Message-ID: <20070802075340.D61891E4003@bag.python.org> Author: georg.brandl Date: Thu Aug 2 09:53:40 2007 New Revision: 56659 Modified: python/branches/py3k-struni/Doc/ref/ref3.tex Log: Remove useless \withsubitem. Modified: python/branches/py3k-struni/Doc/ref/ref3.tex ============================================================================== --- python/branches/py3k-struni/Doc/ref/ref3.tex (original) +++ python/branches/py3k-struni/Doc/ref/ref3.tex Thu Aug 2 09:53:40 2007 @@ -1724,7 +1724,6 @@ \ttindex{__imul__()} \ttindex{__contains__()} \ttindex{__iter__()}} -\withsubitem{(numeric object method)} \begin{methoddesc}[container object]{__len__}{self} Called to implement the built-in function From python-3000-checkins at python.org Thu Aug 2 18:48:18 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Thu, 2 Aug 2007 18:48:18 +0200 (CEST) Subject: [Python-3000-checkins] r56672 - in python/branches/py3k-struni: Lib/test/test_metaclass.py Objects/typeobject.c Message-ID: <20070802164818.43BC01E400A@bag.python.org> Author: guido.van.rossum Date: Thu Aug 2 18:48:17 2007 New Revision: 56672 Modified: python/branches/py3k-struni/Lib/test/test_metaclass.py python/branches/py3k-struni/Objects/typeobject.c Log: Add a default __prepare__() method to 'type', so it can be called using super(). (See recent conversation on python-3000 with Talin and Phillip Eby about PEP 3115 chaining rules.) Modified: python/branches/py3k-struni/Lib/test/test_metaclass.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_metaclass.py (original) +++ python/branches/py3k-struni/Lib/test/test_metaclass.py Thu Aug 2 18:48:17 2007 @@ -207,6 +207,29 @@ kw: [('other', 'booh')] >>> +The default metaclass must define a __prepare__() method. + + >>> type.__prepare__() + {} + >>> + +Make sure it works with subclassing. + + >>> class M(type): + ... @classmethod + ... def __prepare__(cls, *args, **kwds): + ... d = super().__prepare__(*args, **kwds) + ... d["hello"] = 42 + ... return d + ... + >>> class C(metaclass=M): + ... print(hello) + ... + 42 + >>> print(C.hello) + 42 + >>> + """ __test__ = {'doctests' : doctests} Modified: python/branches/py3k-struni/Objects/typeobject.c ============================================================================== --- python/branches/py3k-struni/Objects/typeobject.c (original) +++ python/branches/py3k-struni/Objects/typeobject.c Thu Aug 2 18:48:17 2007 @@ -2200,11 +2200,21 @@ return list; } +static PyObject * +type_prepare(PyObject *self, PyObject *args, PyObject *kwds) +{ + return PyDict_New(); +} + static PyMethodDef type_methods[] = { {"mro", (PyCFunction)mro_external, METH_NOARGS, PyDoc_STR("mro() -> list\nreturn a type's method resolution order")}, {"__subclasses__", (PyCFunction)type_subclasses, METH_NOARGS, PyDoc_STR("__subclasses__() -> list of immediate subclasses")}, + {"__prepare__", (PyCFunction)type_prepare, + METH_VARARGS | METH_KEYWORDS | METH_CLASS, + PyDoc_STR("__prepare__() -> dict\n" + "used to create the namespace for the class statement")}, {0} }; From python-3000-checkins at python.org Fri Aug 3 07:20:26 2007 From: python-3000-checkins at python.org (neal.norwitz) Date: Fri, 3 Aug 2007 07:20:26 +0200 (CEST) Subject: [Python-3000-checkins] r56685 - in python/branches/p3yk: Demo/scripts/morse.py Demo/scripts/toaiff.py Doc/Makefile.deps Doc/lib/lib.tex Doc/lib/libaudioop.tex Doc/lib/libsun.tex Doc/lib/libsunaudio.tex Doc/lib/libundoc.tex Lib/audiodev.py Lib/plat-sunos5/SUNAUDIODEV.py Lib/test/README Lib/test/output/test_linuxaudiodev Lib/test/regrtest.py Lib/test/test___all__.py Lib/test/test_linuxaudiodev.py Lib/test/test_sunaudiodev.py Lib/test/test_sundry.py Lib/toaiff.py Makefile.pre.in Misc/BeOS-setup.py Misc/NEWS Misc/cheatsheet Modules/Setup.dist Modules/linuxaudiodev.c Modules/sunaudiodev.c PC/os2vacpp/makefile PC/os2vacpp/makefile.omk Tools/audiopy setup.py Message-ID: <20070803052026.107401E4005@bag.python.org> Author: neal.norwitz Date: Fri Aug 3 07:20:23 2007 New Revision: 56685 Added: python/branches/p3yk/Demo/scripts/toaiff.py - copied unchanged from r56683, python/branches/p3yk/Lib/toaiff.py Removed: python/branches/p3yk/Demo/scripts/morse.py python/branches/p3yk/Doc/lib/libsun.tex python/branches/p3yk/Doc/lib/libsunaudio.tex python/branches/p3yk/Lib/audiodev.py python/branches/p3yk/Lib/plat-sunos5/SUNAUDIODEV.py python/branches/p3yk/Lib/test/output/test_linuxaudiodev python/branches/p3yk/Lib/test/test_linuxaudiodev.py python/branches/p3yk/Lib/test/test_sunaudiodev.py python/branches/p3yk/Lib/toaiff.py python/branches/p3yk/Modules/linuxaudiodev.c python/branches/p3yk/Modules/sunaudiodev.c python/branches/p3yk/Tools/audiopy/ Modified: python/branches/p3yk/Doc/Makefile.deps python/branches/p3yk/Doc/lib/lib.tex python/branches/p3yk/Doc/lib/libaudioop.tex python/branches/p3yk/Doc/lib/libundoc.tex python/branches/p3yk/Lib/test/README python/branches/p3yk/Lib/test/regrtest.py python/branches/p3yk/Lib/test/test___all__.py python/branches/p3yk/Lib/test/test_sundry.py python/branches/p3yk/Makefile.pre.in python/branches/p3yk/Misc/BeOS-setup.py python/branches/p3yk/Misc/NEWS python/branches/p3yk/Misc/cheatsheet python/branches/p3yk/Modules/Setup.dist python/branches/p3yk/PC/os2vacpp/makefile python/branches/p3yk/PC/os2vacpp/makefile.omk python/branches/p3yk/setup.py Log: Remove several h/w and o/s specific modules that are undocumented, obsolete, and/or not widely used: linuxaudiodev.c, sunaudiodev.c Lib/plat-sunos5/SUNAUDIODEV.py Lib/audiodev.py Tools/audiopy/audiopy Move Lib/toaiff.py to Demo. See PEP 3108 for most of the details. Deleted: /python/branches/p3yk/Demo/scripts/morse.py ============================================================================== --- /python/branches/p3yk/Demo/scripts/morse.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,149 +0,0 @@ -# DAH should be three DOTs. -# Space between DOTs and DAHs should be one DOT. -# Space between two letters should be one DAH. -# Space between two words should be DOT DAH DAH. - -import sys, math, audiodev - -DOT = 30 -DAH = 3 * DOT -OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ... - -morsetab = { - 'A': '.-', 'a': '.-', - 'B': '-...', 'b': '-...', - 'C': '-.-.', 'c': '-.-.', - 'D': '-..', 'd': '-..', - 'E': '.', 'e': '.', - 'F': '..-.', 'f': '..-.', - 'G': '--.', 'g': '--.', - 'H': '....', 'h': '....', - 'I': '..', 'i': '..', - 'J': '.---', 'j': '.---', - 'K': '-.-', 'k': '-.-', - 'L': '.-..', 'l': '.-..', - 'M': '--', 'm': '--', - 'N': '-.', 'n': '-.', - 'O': '---', 'o': '---', - 'P': '.--.', 'p': '.--.', - 'Q': '--.-', 'q': '--.-', - 'R': '.-.', 'r': '.-.', - 'S': '...', 's': '...', - 'T': '-', 't': '-', - 'U': '..-', 'u': '..-', - 'V': '...-', 'v': '...-', - 'W': '.--', 'w': '.--', - 'X': '-..-', 'x': '-..-', - 'Y': '-.--', 'y': '-.--', - 'Z': '--..', 'z': '--..', - '0': '-----', - '1': '.----', - '2': '..---', - '3': '...--', - '4': '....-', - '5': '.....', - '6': '-....', - '7': '--...', - '8': '---..', - '9': '----.', - ',': '--..--', - '.': '.-.-.-', - '?': '..--..', - ';': '-.-.-.', - ':': '---...', - "'": '.----.', - '-': '-....-', - '/': '-..-.', - '(': '-.--.-', - ')': '-.--.-', - '_': '..--.-', - ' ': ' ' -} - -# If we play at 44.1 kHz (which we do), then if we produce one sine -# wave in 100 samples, we get a tone of 441 Hz. If we produce two -# sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz -# appears to be a nice one for playing morse code. -def mkwave(octave): - global sinewave, nowave - sinewave = '' - for i in range(100): - val = int(math.sin(math.pi * float(i) * octave / 50.0) * 30000) - sinewave = sinewave + chr((val >> 8) & 255) + chr(val & 255) - nowave = '\0' * 200 - -mkwave(OCTAVE) - -def main(): - import getopt, string - try: - opts, args = getopt.getopt(sys.argv[1:], 'o:p:') - except getopt.error: - sys.stderr.write('Usage ' + sys.argv[0] + - ' [ -o outfile ] [ args ] ...\n') - sys.exit(1) - dev = None - for o, a in opts: - if o == '-o': - import aifc - dev = aifc.open(a, 'w') - dev.setframerate(44100) - dev.setsampwidth(2) - dev.setnchannels(1) - if o == '-p': - mkwave(string.atoi(a)) - if not dev: - import audiodev - dev = audiodev.AudioDev() - dev.setoutrate(44100) - dev.setsampwidth(2) - dev.setnchannels(1) - dev.close = dev.stop - dev.writeframesraw = dev.writeframes - if args: - line = string.join(args) - else: - line = sys.stdin.readline() - while line: - mline = morse(line) - play(mline, dev) - if hasattr(dev, 'wait'): - dev.wait() - if not args: - line = sys.stdin.readline() - else: - line = '' - dev.close() - -# Convert a string to morse code with \001 between the characters in -# the string. -def morse(line): - res = '' - for c in line: - try: - res = res + morsetab[c] + '\001' - except KeyError: - pass - return res - -# Play a line of morse code. -def play(line, dev): - for c in line: - if c == '.': - sine(dev, DOT) - elif c == '-': - sine(dev, DAH) - else: # space - pause(dev, DAH + DOT) - pause(dev, DOT) - -def sine(dev, length): - for i in range(length): - dev.writeframesraw(sinewave) - -def pause(dev, length): - for i in range(length): - dev.writeframesraw(nowave) - -if __name__ == '__main__' or sys.argv[0] == __name__: - main() Modified: python/branches/p3yk/Doc/Makefile.deps ============================================================================== --- python/branches/p3yk/Doc/Makefile.deps (original) +++ python/branches/p3yk/Doc/Makefile.deps Fri Aug 3 07:20:23 2007 @@ -199,7 +199,6 @@ lib/libcrypto.tex \ lib/libhashlib.tex \ lib/libhmac.tex \ - lib/libsun.tex \ lib/libxdrlib.tex \ lib/libimghdr.tex \ lib/libformatter.tex \ @@ -259,7 +258,6 @@ lib/libsymbol.tex \ lib/libbinhex.tex \ lib/libuu.tex \ - lib/libsunaudio.tex \ lib/libfileinput.tex \ lib/libimaplib.tex \ lib/libpoplib.tex \ Modified: python/branches/p3yk/Doc/lib/lib.tex ============================================================================== --- python/branches/p3yk/Doc/lib/lib.tex (original) +++ python/branches/p3yk/Doc/lib/lib.tex Fri Aug 3 07:20:23 2007 @@ -416,10 +416,6 @@ % OTHER PLATFORM-SPECIFIC STUFF % ============= -\input{libsun} % SUNOS ONLY -\input{libsunaudio} -% XXX(nnorwitz): the modules below this comment should be kept. - \input{windows} % MS Windows ONLY \input{libmsilib} \input{libmsvcrt} @@ -430,9 +426,6 @@ \input{libundoc} %\chapter{Obsolete Modules} -%\input{libcmpcache} -%\input{libcmp} -%\input{libni} \chapter{Reporting Bugs} \input{reportingbugs} Modified: python/branches/p3yk/Doc/lib/libaudioop.tex ============================================================================== --- python/branches/p3yk/Doc/lib/libaudioop.tex (original) +++ python/branches/p3yk/Doc/lib/libaudioop.tex Fri Aug 3 07:20:23 2007 @@ -7,9 +7,8 @@ The \module{audioop} module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed -integer samples 8, 16 or 32 bits wide, stored in Python strings. This -is the same format as used by the \refmodule{al} and \refmodule{sunaudiodev} -modules. All scalar items are integers, unless specified otherwise. +integer samples 8, 16 or 32 bits wide, stored in Python strings. +All scalar items are integers, unless specified otherwise. % This para is mostly here to provide an excuse for the index entries... This module provides support for a-LAW, u-LAW and Intel/DVI ADPCM encodings. Deleted: /python/branches/p3yk/Doc/lib/libsun.tex ============================================================================== --- /python/branches/p3yk/Doc/lib/libsun.tex Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,7 +0,0 @@ -\chapter{SunOS Specific Services} -\label{sunos} - -The modules described in this chapter provide interfaces to features -that are unique to SunOS 5 (also known as Solaris version 2). - -\localmoduletable Deleted: /python/branches/p3yk/Doc/lib/libsunaudio.tex ============================================================================== --- /python/branches/p3yk/Doc/lib/libsunaudio.tex Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,146 +0,0 @@ -\section{\module{sunaudiodev} --- - Access to Sun audio hardware} - -\declaremodule{builtin}{sunaudiodev} - \platform{SunOS} -\modulesynopsis{Access to Sun audio hardware.} - - -This module allows you to access the Sun audio interface. The Sun -audio hardware is capable of recording and playing back audio data -in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A -full description can be found in the \manpage{audio}{7I} manual page. - -The module -\refmodule[sunaudiodev-constants]{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV} -defines constants which may be used with this module. - -This module defines the following variables and functions: - -\begin{excdesc}{error} -This exception is raised on all errors. The argument is a string -describing what went wrong. -\end{excdesc} - -\begin{funcdesc}{open}{mode} -This function opens the audio device and returns a Sun audio device -object. This object can then be used to do I/O on. The \var{mode} parameter -is one of \code{'r'} for record-only access, \code{'w'} for play-only -access, \code{'rw'} for both and \code{'control'} for access to the -control device. Since only one process is allowed to have the recorder -or player open at the same time it is a good idea to open the device -only for the activity needed. See \manpage{audio}{7I} for details. - -As per the manpage, this module first looks in the environment -variable \code{AUDIODEV} for the base audio device filename. If not -found, it falls back to \file{/dev/audio}. The control device is -calculated by appending ``ctl'' to the base audio device. -\end{funcdesc} - - -\subsection{Audio Device Objects \label{audio-device-objects}} - -The audio device objects are returned by \function{open()} define the -following methods (except \code{control} objects which only provide -\method{getinfo()}, \method{setinfo()}, \method{fileno()}, and -\method{drain()}): - -\begin{methoddesc}[audio device]{close}{} -This method explicitly closes the device. It is useful in situations -where deleting the object does not immediately close it since there -are other references to it. A closed device should not be used again. -\end{methoddesc} - -\begin{methoddesc}[audio device]{fileno}{} -Returns the file descriptor associated with the device. This can be -used to set up \code{SIGPOLL} notification, as described below. -\end{methoddesc} - -\begin{methoddesc}[audio device]{drain}{} -This method waits until all pending output is processed and then returns. -Calling this method is often not necessary: destroying the object will -automatically close the audio device and this will do an implicit drain. -\end{methoddesc} - -\begin{methoddesc}[audio device]{flush}{} -This method discards all pending output. It can be used avoid the -slow response to a user's stop request (due to buffering of up to one -second of sound). -\end{methoddesc} - -\begin{methoddesc}[audio device]{getinfo}{} -This method retrieves status information like input and output volume, -etc. and returns it in the form of -an audio status object. This object has no methods but it contains a -number of attributes describing the current device status. The names -and meanings of the attributes are described in -\code{} and in the \manpage{audio}{7I} -manual page. Member names -are slightly different from their C counterparts: a status object is -only a single structure. Members of the \cdata{play} substructure have -\samp{o_} prepended to their name and members of the \cdata{record} -structure have \samp{i_}. So, the C member \cdata{play.sample_rate} is -accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain} -and \cdata{monitor_gain} plainly as \member{monitor_gain}. -\end{methoddesc} - -\begin{methoddesc}[audio device]{ibufcount}{} -This method returns the number of samples that are buffered on the -recording side, i.e.\ the program will not block on a -\function{read()} call of so many samples. -\end{methoddesc} - -\begin{methoddesc}[audio device]{obufcount}{} -This method returns the number of samples buffered on the playback -side. Unfortunately, this number cannot be used to determine a number -of samples that can be written without blocking since the kernel -output queue length seems to be variable. -\end{methoddesc} - -\begin{methoddesc}[audio device]{read}{size} -This method reads \var{size} samples from the audio input and returns -them as a Python string. The function blocks until enough data is available. -\end{methoddesc} - -\begin{methoddesc}[audio device]{setinfo}{status} -This method sets the audio device status parameters. The \var{status} -parameter is an device status object as returned by \function{getinfo()} and -possibly modified by the program. -\end{methoddesc} - -\begin{methoddesc}[audio device]{write}{samples} -Write is passed a Python string containing audio samples to be played. -If there is enough buffer space free it will immediately return, -otherwise it will block. -\end{methoddesc} - -The audio device supports asynchronous notification of various events, -through the SIGPOLL signal. Here's an example of how you might enable -this in Python: - -\begin{verbatim} -def handle_sigpoll(signum, frame): - print 'I got a SIGPOLL update' - -import fcntl, signal, STROPTS - -signal.signal(signal.SIGPOLL, handle_sigpoll) -fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG) -\end{verbatim} - - -\section{\module{SUNAUDIODEV} --- - Constants used with \module{sunaudiodev}} - -\declaremodule[sunaudiodev-constants]{standard}{SUNAUDIODEV} - \platform{SunOS} -\modulesynopsis{Constants for use with \refmodule{sunaudiodev}.} - - -This is a companion module to -\refmodule{sunaudiodev}\refbimodindex{sunaudiodev} which defines -useful symbolic constants like \constant{MIN_GAIN}, -\constant{MAX_GAIN}, \constant{SPEAKER}, etc. The names of the -constants are the same names as used in the C include file -\code{}, with the leading string \samp{AUDIO_} -stripped. Modified: python/branches/p3yk/Doc/lib/libundoc.tex ============================================================================== --- python/branches/p3yk/Doc/lib/libundoc.tex (original) +++ python/branches/p3yk/Doc/lib/libundoc.tex Fri Aug 3 07:20:23 2007 @@ -52,19 +52,8 @@ \section{Multimedia} \begin{description} -\item[\module{audiodev}] ---- Platform-independent API for playing audio data. - -\item[\module{linuxaudiodev}] ---- Play audio data on the Linux audio device. Replaced in Python 2.3 - by the \module{ossaudiodev} module. - \item[\module{sunaudio}] --- Interpret Sun audio headers (may become obsolete or a tool/demo). - -\item[\module{toaiff}] ---- Convert "arbitrary" sound files to AIFF files; should probably - become a tool or demo. Requires the external program \program{sox}. \end{description} Deleted: /python/branches/p3yk/Lib/audiodev.py ============================================================================== --- /python/branches/p3yk/Lib/audiodev.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,257 +0,0 @@ -"""Classes for manipulating audio devices (currently only for Sun and SGI)""" - -__all__ = ["error","AudioDev"] - -class error(Exception): - pass - -class Play_Audio_sgi: - # Private instance variables -## if 0: access frameratelist, nchannelslist, sampwidthlist, oldparams, \ -## params, config, inited_outrate, inited_width, \ -## inited_nchannels, port, converter, classinited: private - - classinited = 0 - frameratelist = nchannelslist = sampwidthlist = None - - def initclass(self): - import AL - self.frameratelist = [ - (48000, AL.RATE_48000), - (44100, AL.RATE_44100), - (32000, AL.RATE_32000), - (22050, AL.RATE_22050), - (16000, AL.RATE_16000), - (11025, AL.RATE_11025), - ( 8000, AL.RATE_8000), - ] - self.nchannelslist = [ - (1, AL.MONO), - (2, AL.STEREO), - (4, AL.QUADRO), - ] - self.sampwidthlist = [ - (1, AL.SAMPLE_8), - (2, AL.SAMPLE_16), - (3, AL.SAMPLE_24), - ] - self.classinited = 1 - - def __init__(self): - import al, AL - if not self.classinited: - self.initclass() - self.oldparams = [] - self.params = [AL.OUTPUT_RATE, 0] - self.config = al.newconfig() - self.inited_outrate = 0 - self.inited_width = 0 - self.inited_nchannels = 0 - self.converter = None - self.port = None - return - - def __del__(self): - if self.port: - self.stop() - if self.oldparams: - import al, AL - al.setparams(AL.DEFAULT_DEVICE, self.oldparams) - self.oldparams = [] - - def wait(self): - if not self.port: - return - import time - while self.port.getfilled() > 0: - time.sleep(0.1) - self.stop() - - def stop(self): - if self.port: - self.port.closeport() - self.port = None - if self.oldparams: - import al, AL - al.setparams(AL.DEFAULT_DEVICE, self.oldparams) - self.oldparams = [] - - def setoutrate(self, rate): - for (raw, cooked) in self.frameratelist: - if rate == raw: - self.params[1] = cooked - self.inited_outrate = 1 - break - else: - raise error, 'bad output rate' - - def setsampwidth(self, width): - for (raw, cooked) in self.sampwidthlist: - if width == raw: - self.config.setwidth(cooked) - self.inited_width = 1 - break - else: - if width == 0: - import AL - self.inited_width = 0 - self.config.setwidth(AL.SAMPLE_16) - self.converter = self.ulaw2lin - else: - raise error, 'bad sample width' - - def setnchannels(self, nchannels): - for (raw, cooked) in self.nchannelslist: - if nchannels == raw: - self.config.setchannels(cooked) - self.inited_nchannels = 1 - break - else: - raise error, 'bad # of channels' - - def writeframes(self, data): - if not (self.inited_outrate and self.inited_nchannels): - raise error, 'params not specified' - if not self.port: - import al, AL - self.port = al.openport('Python', 'w', self.config) - self.oldparams = self.params[:] - al.getparams(AL.DEFAULT_DEVICE, self.oldparams) - al.setparams(AL.DEFAULT_DEVICE, self.params) - if self.converter: - data = self.converter(data) - self.port.writesamps(data) - - def getfilled(self): - if self.port: - return self.port.getfilled() - else: - return 0 - - def getfillable(self): - if self.port: - return self.port.getfillable() - else: - return self.config.getqueuesize() - - # private methods -## if 0: access *: private - - def ulaw2lin(self, data): - import audioop - return audioop.ulaw2lin(data, 2) - -class Play_Audio_sun: -## if 0: access outrate, sampwidth, nchannels, inited_outrate, inited_width, \ -## inited_nchannels, converter: private - - def __init__(self): - self.outrate = 0 - self.sampwidth = 0 - self.nchannels = 0 - self.inited_outrate = 0 - self.inited_width = 0 - self.inited_nchannels = 0 - self.converter = None - self.port = None - return - - def __del__(self): - self.stop() - - def setoutrate(self, rate): - self.outrate = rate - self.inited_outrate = 1 - - def setsampwidth(self, width): - self.sampwidth = width - self.inited_width = 1 - - def setnchannels(self, nchannels): - self.nchannels = nchannels - self.inited_nchannels = 1 - - def writeframes(self, data): - if not (self.inited_outrate and self.inited_width and self.inited_nchannels): - raise error, 'params not specified' - if not self.port: - import sunaudiodev, SUNAUDIODEV - self.port = sunaudiodev.open('w') - info = self.port.getinfo() - info.o_sample_rate = self.outrate - info.o_channels = self.nchannels - if self.sampwidth == 0: - info.o_precision = 8 - self.o_encoding = SUNAUDIODEV.ENCODING_ULAW - # XXX Hack, hack -- leave defaults - else: - info.o_precision = 8 * self.sampwidth - info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR - self.port.setinfo(info) - if self.converter: - data = self.converter(data) - self.port.write(data) - - def wait(self): - if not self.port: - return - self.port.drain() - self.stop() - - def stop(self): - if self.port: - self.port.flush() - self.port.close() - self.port = None - - def getfilled(self): - if self.port: - return self.port.obufcount() - else: - return 0 - -## # Nobody remembers what this method does, and it's broken. :-( -## def getfillable(self): -## return BUFFERSIZE - self.getfilled() - -def AudioDev(): - # Dynamically try to import and use a platform specific module. - try: - import al - except ImportError: - try: - import sunaudiodev - return Play_Audio_sun() - except ImportError: - try: - import Audio_mac - except ImportError: - raise error, 'no audio device' - else: - return Audio_mac.Play_Audio_mac() - else: - return Play_Audio_sgi() - -def test(fn = None): - import sys - if sys.argv[1:]: - fn = sys.argv[1] - else: - fn = 'f:just samples:just.aif' - import aifc - af = aifc.open(fn, 'r') - print(fn, af.getparams()) - p = AudioDev() - p.setoutrate(af.getframerate()) - p.setsampwidth(af.getsampwidth()) - p.setnchannels(af.getnchannels()) - BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels() - while 1: - data = af.readframes(BUFSIZ) - if not data: break - print(len(data)) - p.writeframes(data) - p.wait() - -if __name__ == '__main__': - test() Deleted: /python/branches/p3yk/Lib/plat-sunos5/SUNAUDIODEV.py ============================================================================== --- /python/branches/p3yk/Lib/plat-sunos5/SUNAUDIODEV.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,40 +0,0 @@ -# Symbolic constants for use with sunaudiodev module -# The names are the same as in audioio.h with the leading AUDIO_ -# removed. - -# Not all values are supported on all releases of SunOS. - -# Encoding types, for fields i_encoding and o_encoding - -ENCODING_NONE = 0 # no encoding assigned -ENCODING_ULAW = 1 # u-law encoding -ENCODING_ALAW = 2 # A-law encoding -ENCODING_LINEAR = 3 # Linear PCM encoding - -# Gain ranges for i_gain, o_gain and monitor_gain - -MIN_GAIN = 0 # minimum gain value -MAX_GAIN = 255 # maximum gain value - -# Balance values for i_balance and o_balance - -LEFT_BALANCE = 0 # left channel only -MID_BALANCE = 32 # equal left/right channel -RIGHT_BALANCE = 64 # right channel only -BALANCE_SHIFT = 3 - -# Port names for i_port and o_port - -PORT_A = 1 -PORT_B = 2 -PORT_C = 3 -PORT_D = 4 - -SPEAKER = 0x01 # output to built-in speaker -HEADPHONE = 0x02 # output to headphone jack -LINE_OUT = 0x04 # output to line out - -MICROPHONE = 0x01 # input from microphone -LINE_IN = 0x02 # input from line in -CD = 0x04 # input from on-board CD inputs -INTERNAL_CD_IN = CD # input from internal CDROM Modified: python/branches/p3yk/Lib/test/README ============================================================================== --- python/branches/p3yk/Lib/test/README (original) +++ python/branches/p3yk/Lib/test/README Fri Aug 3 07:20:23 2007 @@ -372,7 +372,7 @@ * ``findfile(file)`` - you can call this function to locate a file somewhere along sys.path or in the Lib/test tree - see - test_linuxaudiodev.py for an example of its use. + test_ossaudiodev.py for an example of its use. * ``fcmp(x,y)`` - you can call this function to compare two floating point numbers when you expect them to only be approximately equal Deleted: /python/branches/p3yk/Lib/test/output/test_linuxaudiodev ============================================================================== --- /python/branches/p3yk/Lib/test/output/test_linuxaudiodev Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,7 +0,0 @@ -test_linuxaudiodev -expected rate >= 0, not -1 -expected sample size >= 0, not -2 -nchannels must be 1 or 2, not 3 -unknown audio encoding: 177 -for linear unsigned 16-bit little-endian audio, expected sample size 16, not 8 -for linear unsigned 8-bit audio, expected sample size 8, not 16 Modified: python/branches/p3yk/Lib/test/regrtest.py ============================================================================== --- python/branches/p3yk/Lib/test/regrtest.py (original) +++ python/branches/p3yk/Lib/test/regrtest.py Fri Aug 3 07:20:23 2007 @@ -1106,8 +1106,6 @@ self.expected = set(s.split()) # expected to be skipped on every platform, even Linux - self.expected.add('test_linuxaudiodev') - if not os.path.supports_unicode_filenames: self.expected.add('test_pep277') @@ -1134,7 +1132,6 @@ self.expected.add(skip) if sys.platform != 'sunos5': - self.expected.add('test_sunaudiodev') self.expected.add('test_nis') self.valid = True 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 Aug 3 07:20:23 2007 @@ -39,7 +39,6 @@ self.check_all("StringIO") self.check_all("UserString") self.check_all("aifc") - self.check_all("audiodev") self.check_all("base64") self.check_all("bdb") self.check_all("binhex") @@ -135,7 +134,6 @@ self.check_all("textwrap") self.check_all("threading") self.check_all("timeit") - self.check_all("toaiff") self.check_all("tokenize") self.check_all("traceback") self.check_all("tty") Deleted: /python/branches/p3yk/Lib/test/test_linuxaudiodev.py ============================================================================== --- /python/branches/p3yk/Lib/test/test_linuxaudiodev.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,92 +0,0 @@ -from test import test_support -test_support.requires('audio') - -from test.test_support import verbose, findfile, TestFailed, TestSkipped - -import errno -import fcntl -import linuxaudiodev -import os -import sys -import select -import sunaudio -import time -import audioop - -SND_FORMAT_MULAW_8 = 1 - -def play_sound_file(path): - fp = open(path, 'r') - size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) - data = fp.read() - fp.close() - - if enc != SND_FORMAT_MULAW_8: - print("Expect .au file with 8-bit mu-law samples") - return - - try: - a = linuxaudiodev.open('w') - except linuxaudiodev.error as msg: - if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): - raise TestSkipped, msg - raise TestFailed, msg - - # convert the data to 16-bit signed - data = audioop.ulaw2lin(data, 2) - - # set the data format - if sys.byteorder == 'little': - fmt = linuxaudiodev.AFMT_S16_LE - else: - fmt = linuxaudiodev.AFMT_S16_BE - - # at least check that these methods can be invoked - a.bufsize() - a.obufcount() - a.obuffree() - a.getptr() - a.fileno() - - # set parameters based on .au file headers - a.setparameters(rate, 16, nchannels, fmt) - a.write(data) - a.flush() - a.close() - -def test_errors(): - a = linuxaudiodev.open("w") - size = 8 - fmt = linuxaudiodev.AFMT_U8 - rate = 8000 - nchannels = 1 - try: - a.setparameters(-1, size, nchannels, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, -2, nchannels, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, 3, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, nchannels, 177) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, 16, nchannels, fmt) - except ValueError as msg: - print(msg) - -def test(): - play_sound_file(findfile('audiotest.au')) - test_errors() - -test() Deleted: /python/branches/p3yk/Lib/test/test_sunaudiodev.py ============================================================================== --- /python/branches/p3yk/Lib/test/test_sunaudiodev.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,28 +0,0 @@ -from test.test_support import verbose, findfile, TestFailed, TestSkipped -import sunaudiodev -import os - -try: - audiodev = os.environ["AUDIODEV"] -except KeyError: - audiodev = "/dev/audio" - -if not os.path.exists(audiodev): - raise TestSkipped("no audio device found!") - -def play_sound_file(path): - fp = open(path, 'r') - data = fp.read() - fp.close() - try: - a = sunaudiodev.open('w') - except sunaudiodev.error as msg: - raise TestFailed, msg - else: - a.write(data) - a.close() - -def test(): - play_sound_file(findfile('audiotest.au')) - -test() Modified: python/branches/p3yk/Lib/test/test_sundry.py ============================================================================== --- python/branches/p3yk/Lib/test/test_sundry.py (original) +++ python/branches/p3yk/Lib/test/test_sundry.py Fri Aug 3 07:20:23 2007 @@ -13,7 +13,6 @@ import SimpleHTTPServer import SimpleXMLRPCServer import aifc - import audiodev import bdb import cgitb import cmd @@ -99,7 +98,6 @@ import tabnanny import telnetlib import timeit - import toaiff import token try: import tty # not available on Windows Deleted: /python/branches/p3yk/Lib/toaiff.py ============================================================================== --- /python/branches/p3yk/Lib/toaiff.py Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,107 +0,0 @@ -"""Convert "arbitrary" sound files to AIFF (Apple and SGI's audio format). - -Input may be compressed. -Uncompressed file type may be AIFF, WAV, VOC, 8SVX, NeXT/Sun, and others. -An exception is raised if the file is not of a recognized type. -Returned filename is either the input filename or a temporary filename; -in the latter case the caller must ensure that it is removed. -Other temporary files used are removed by the function. -""" - -import os -import tempfile -import pipes -import sndhdr - -__all__ = ["error", "toaiff"] - -table = {} - -t = pipes.Template() -t.append('sox -t au - -t aiff -r 8000 -', '--') -table['au'] = t - -# XXX The following is actually sub-optimal. -# XXX The HCOM sampling rate can be 22k, 22k/2, 22k/3 or 22k/4. -# XXX We must force the output sampling rate else the SGI won't play -# XXX files sampled at 5.5k or 7.333k; however this means that files -# XXX sampled at 11k are unnecessarily expanded. -# XXX Similar comments apply to some other file types. -t = pipes.Template() -t.append('sox -t hcom - -t aiff -r 22050 -', '--') -table['hcom'] = t - -t = pipes.Template() -t.append('sox -t voc - -t aiff -r 11025 -', '--') -table['voc'] = t - -t = pipes.Template() -t.append('sox -t wav - -t aiff -', '--') -table['wav'] = t - -t = pipes.Template() -t.append('sox -t 8svx - -t aiff -r 16000 -', '--') -table['8svx'] = t - -t = pipes.Template() -t.append('sox -t sndt - -t aiff -r 16000 -', '--') -table['sndt'] = t - -t = pipes.Template() -t.append('sox -t sndr - -t aiff -r 16000 -', '--') -table['sndr'] = t - -uncompress = pipes.Template() -uncompress.append('uncompress', '--') - - -class error(Exception): - pass - -def toaiff(filename): - temps = [] - ret = None - try: - ret = _toaiff(filename, temps) - finally: - for temp in temps[:]: - if temp != ret: - try: - os.unlink(temp) - except os.error: - pass - temps.remove(temp) - return ret - -def _toaiff(filename, temps): - if filename[-2:] == '.Z': - (fd, fname) = tempfile.mkstemp() - os.close(fd) - temps.append(fname) - sts = uncompress.copy(filename, fname) - if sts: - raise error, filename + ': uncompress failed' - else: - fname = filename - try: - ftype = sndhdr.whathdr(fname) - if ftype: - ftype = ftype[0] # All we're interested in - except IOError as msg: - if type(msg) == type(()) and len(msg) == 2 and \ - type(msg[0]) == type(0) and type(msg[1]) == type(''): - msg = msg[1] - if type(msg) != type(''): - msg = repr(msg) - raise error, filename + ': ' + msg - if ftype == 'aiff': - return fname - if ftype is None or not ftype in table: - raise error, '%s: unsupported audio file type %r' % (filename, ftype) - (fd, temp) = tempfile.mkstemp() - os.close(fd) - temps.append(temp) - sts = table[ftype].copy(fname, temp) - if sts: - raise error, filename + ': conversion to aiff failed' - return temp Modified: python/branches/p3yk/Makefile.pre.in ============================================================================== --- python/branches/p3yk/Makefile.pre.in (original) +++ python/branches/p3yk/Makefile.pre.in Fri Aug 3 07:20:23 2007 @@ -608,7 +608,7 @@ QUICKTESTOPTS= $(TESTOPTS) -x test_thread test_signal test_strftime \ test_unicodedata test_re test_sre test_select test_poll \ - test_linuxaudiodev test_struct test_sunaudiodev test_zlib + test_struct test_zlib quicktest: all platform -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -$(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS) Modified: python/branches/p3yk/Misc/BeOS-setup.py ============================================================================== --- python/branches/p3yk/Misc/BeOS-setup.py (original) +++ python/branches/p3yk/Misc/BeOS-setup.py Fri Aug 3 07:20:23 2007 @@ -445,15 +445,6 @@ define_macros = expat_defs, libraries = ['expat']) ) - # Platform-specific libraries - if platform == 'linux2': - # Linux-specific modules - exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) - - if platform == 'sunos5': - # SunOS specific modules - exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) - self.extensions.extend(exts) # Call the method for detecting whether _tkinter can be compiled Modified: python/branches/p3yk/Misc/NEWS ============================================================================== --- python/branches/p3yk/Misc/NEWS (original) +++ python/branches/p3yk/Misc/NEWS Fri Aug 3 07:20:23 2007 @@ -184,8 +184,12 @@ AST -> bytecode mechanism. - Removed these modules: - * Bastion, bsddb185, exceptions, md5, MimeWriter, mimify, popen2, rexec, - sets, sha, stringold, strop, timing, xmllib. + * audiodev, Bastion, bsddb185, exceptions, linuxaudiodev, + md5, MimeWriter, mimify, popen2, + rexec, sets, sha, stringold, strop, sunaudiodev, timing, xmllib. + +- Moved these modules to Tools/Demos: + * toaiff - Remove obsolete IRIX modules: al/AL, cd/CD, cddb, cdplayer, cl/CL, DEVICE, ERRNO, FILE, fl/FL, flp, fm, GET, gl/GL, GLWS, IN, imgfile, IOCTL, jpeg, Modified: python/branches/p3yk/Misc/cheatsheet ============================================================================== --- python/branches/p3yk/Misc/cheatsheet (original) +++ python/branches/p3yk/Misc/cheatsheet Fri Aug 3 07:20:23 2007 @@ -1808,7 +1808,6 @@ asynchat Support for 'chat' style protocols asyncore Asynchronous File I/O (in select style) atexit Register functions to be called at exit of Python interpreter. -audiodev Audio support for a few platforms. base64 Conversions to/from base64 RFC-MIME transport encoding . BaseHTTPServer Base class forhttp services. Bastion "Bastionification" utility (control access to instance vars) @@ -1871,7 +1870,6 @@ inspect Tool for probing live Python objects. keyword List of Python keywords. linecache Cache lines from files. -linuxaudiodev Lunix /dev/audio support. locale Support for number formatting using the current locale settings. logging Python logging facility. @@ -1946,7 +1944,6 @@ textwrap Object for wrapping and filling text. threading Proposed new higher-level threading interfaces threading_api (doc of the threading module) -toaiff Convert "arbitrary" sound files to AIFF files . token Tokens (from "token.h"). tokenize Compiles a regular expression that recognizes Python tokens. traceback Format and print Python stack traces. @@ -2042,10 +2039,6 @@ DEVICE More constants for gl imgfile Imglib image file interface -* Suns * - - sunaudiodev Access to sun audio interface - Workspace exploration and idiom hints Modified: python/branches/p3yk/Modules/Setup.dist ============================================================================== --- python/branches/p3yk/Modules/Setup.dist (original) +++ python/branches/p3yk/Modules/Setup.dist Fri Aug 3 07:20:23 2007 @@ -235,17 +235,6 @@ #_sha shamodule.c -# SunOS specific modules -- off by default: - -#sunaudiodev sunaudiodev.c - - -# A Linux specific module -- off by default; this may also work on -# some *BSDs. - -#linuxaudiodev linuxaudiodev.c - - # The _tkinter module. # # The command for _tkinter is long and site specific. Please Deleted: /python/branches/p3yk/Modules/linuxaudiodev.c ============================================================================== --- /python/branches/p3yk/Modules/linuxaudiodev.c Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,501 +0,0 @@ -/* Hey Emacs, this is -*-C-*- - ****************************************************************************** - * linuxaudiodev.c -- Linux audio device for python. - * - * Author : Peter Bosch - * Created On : Thu Mar 2 21:10:33 2000 - * Status : Unknown, Use with caution! - * - * Unless other notices are present in any part of this file - * explicitly claiming copyrights for other people and/or - * organizations, the contents of this file is fully copyright - * (C) 2000 Peter Bosch, all rights reserved. - ****************************************************************************** - */ - -#include "Python.h" -#include "structmember.h" - -#ifdef HAVE_FCNTL_H -#include -#else -#define O_RDONLY 00 -#define O_WRONLY 01 -#endif - - -#include -#if defined(linux) -#include - -#ifndef HAVE_STDINT_H -typedef unsigned long uint32_t; -#endif - -#elif defined(__FreeBSD__) -#include - -#ifndef SNDCTL_DSP_CHANNELS -#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS -#endif - -#endif - -typedef struct { - PyObject_HEAD - int x_fd; /* The open file */ - int x_mode; /* file mode */ - int x_icount; /* Input count */ - int x_ocount; /* Output count */ - uint32_t x_afmts; /* Audio formats supported by hardware*/ -} lad_t; - -/* XXX several format defined in soundcard.h are not supported, - including _NE (native endian) options and S32 options -*/ - -static struct { - int a_bps; - uint32_t a_fmt; - char *a_name; -} audio_types[] = { - { 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" }, - { 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" }, - { 8, AFMT_U8, "linear unsigned 8-bit audio" }, - { 8, AFMT_S8, "linear signed 8-bit audio" }, - { 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" }, - { 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" }, - { 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" }, - { 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" }, - { 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" }, -}; - -static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]); - -static PyTypeObject Ladtype; - -static PyObject *LinuxAudioError; - -static lad_t * -newladobject(PyObject *arg) -{ - lad_t *xp; - int fd, afmts, imode; - char *basedev = NULL; - char *mode = NULL; - - /* Two ways to call linuxaudiodev.open(): - open(device, mode) (for consistency with builtin open()) - open(mode) (for backwards compatibility) - because the *first* argument is optional, parsing args is - a wee bit tricky. */ - if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode)) - return NULL; - if (mode == NULL) { /* only one arg supplied */ - mode = basedev; - basedev = NULL; - } - - if (strcmp(mode, "r") == 0) - imode = O_RDONLY; - else if (strcmp(mode, "w") == 0) - imode = O_WRONLY; - else { - PyErr_SetString(LinuxAudioError, "mode should be 'r' or 'w'"); - return NULL; - } - - /* Open the correct device. The base device name comes from the - * AUDIODEV environment variable first, then /dev/dsp. The - * control device tacks "ctl" onto the base device name. - * - * Note that the only difference between /dev/audio and /dev/dsp - * is that the former uses logarithmic mu-law encoding and the - * latter uses 8-bit unsigned encoding. - */ - - if (basedev == NULL) { /* called with one arg */ - basedev = getenv("AUDIODEV"); - if (basedev == NULL) /* $AUDIODEV not set */ - basedev = "/dev/dsp"; - } - - if ((fd = open(basedev, imode)) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - if (imode == O_WRONLY && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - /* Create and initialize the object */ - if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) { - close(fd); - return NULL; - } - xp->x_fd = fd; - xp->x_mode = imode; - xp->x_icount = xp->x_ocount = 0; - xp->x_afmts = afmts; - return xp; -} - -static void -lad_dealloc(lad_t *xp) -{ - /* if already closed, don't reclose it */ - if (xp->x_fd != -1) - close(xp->x_fd); - PyObject_Del(xp); -} - -static PyObject * -lad_read(lad_t *self, PyObject *args) -{ - int size, count; - char *cp; - PyObject *rv; - - if (!PyArg_ParseTuple(args, "i:read", &size)) - return NULL; - rv = PyString_FromStringAndSize(NULL, size); - if (rv == NULL) - return NULL; - cp = PyString_AS_STRING(rv); - if ((count = read(self->x_fd, cp, size)) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - Py_DECREF(rv); - return NULL; - } - self->x_icount += count; - _PyString_Resize(&rv, count); - return rv; -} - -static PyObject * -lad_write(lad_t *self, PyObject *args) -{ - char *cp; - int rv, size; - fd_set write_set_fds; - struct timeval tv; - int select_retval; - - if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) - return NULL; - - /* use select to wait for audio device to be available */ - FD_ZERO(&write_set_fds); - FD_SET(self->x_fd, &write_set_fds); - tv.tv_sec = 4; /* timeout values */ - tv.tv_usec = 0; - - while (size > 0) { - select_retval = select(self->x_fd+1, NULL, &write_set_fds, NULL, &tv); - tv.tv_sec = 1; tv.tv_usec = 0; /* willing to wait this long next time*/ - if (select_retval) { - if ((rv = write(self->x_fd, cp, size)) == -1) { - if (errno != EAGAIN) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } else { - errno = 0; /* EAGAIN: buffer is full, try again */ - } - } else { - self->x_ocount += rv; - size -= rv; - cp += rv; - } - } else { - /* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */ - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -lad_close(lad_t *self, PyObject *unused) -{ - if (self->x_fd >= 0) { - close(self->x_fd); - self->x_fd = -1; - } - Py_RETURN_NONE; -} - -static PyObject * -lad_fileno(lad_t *self, PyObject *unused) -{ - return PyInt_FromLong(self->x_fd); -} - -static PyObject * -lad_setparameters(lad_t *self, PyObject *args) -{ - int rate, ssize, nchannels, n, fmt, emulate=0; - - if (!PyArg_ParseTuple(args, "iiii|i:setparameters", - &rate, &ssize, &nchannels, &fmt, &emulate)) - return NULL; - - if (rate < 0) { - PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", - rate); - return NULL; - } - if (ssize < 0) { - PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", - ssize); - return NULL; - } - if (nchannels != 1 && nchannels != 2) { - PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", - nchannels); - return NULL; - } - - for (n = 0; n < n_audio_types; n++) - if (fmt == audio_types[n].a_fmt) - break; - if (n == n_audio_types) { - PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); - return NULL; - } - if (audio_types[n].a_bps != ssize) { - PyErr_Format(PyExc_ValueError, - "for %s, expected sample size %d, not %d", - audio_types[n].a_name, audio_types[n].a_bps, ssize); - return NULL; - } - - if (emulate == 0) { - if ((self->x_afmts & audio_types[n].a_fmt) == 0) { - PyErr_Format(PyExc_ValueError, - "%s format not supported by device", - audio_types[n].a_name); - return NULL; - } - } - if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, - &audio_types[n].a_fmt) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -static int -_ssize(lad_t *self, int *nchannels, int *ssize) -{ - int fmt; - - fmt = 0; - if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0) - return -errno; - - switch (fmt) { - case AFMT_MU_LAW: - case AFMT_A_LAW: - case AFMT_U8: - case AFMT_S8: - *ssize = sizeof(char); - break; - case AFMT_S16_LE: - case AFMT_S16_BE: - case AFMT_U16_LE: - case AFMT_U16_BE: - *ssize = sizeof(short); - break; - case AFMT_MPEG: - case AFMT_IMA_ADPCM: - default: - return -EOPNOTSUPP; - } - if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) - return -errno; - return 0; -} - - -/* bufsize returns the size of the hardware audio buffer in number - of samples */ -static PyObject * -lad_bufsize(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); -} - -/* obufcount returns the number of samples that are available in the - hardware for playing */ -static PyObject * -lad_obufcount(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / - (ssize * nchannels)); -} - -/* obufcount returns the number of samples that can be played without - blocking */ -static PyObject * -lad_obuffree(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong(ai.bytes / (ssize * nchannels)); -} - -/* Flush the device */ -static PyObject * -lad_flush(lad_t *self, PyObject *unused) -{ - if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - Py_RETURN_NONE; -} - -static PyObject * -lad_getptr(lad_t *self, PyObject *unused) -{ - count_info info; - int req; - - if (self->x_mode == O_RDONLY) - req = SNDCTL_DSP_GETIPTR; - else - req = SNDCTL_DSP_GETOPTR; - if (ioctl(self->x_fd, req, &info) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); -} - -static PyMethodDef lad_methods[] = { - { "read", (PyCFunction)lad_read, METH_VARARGS }, - { "write", (PyCFunction)lad_write, METH_VARARGS }, - { "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS }, - { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS }, - { "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS }, - { "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS }, - { "flush", (PyCFunction)lad_flush, METH_NOARGS }, - { "close", (PyCFunction)lad_close, METH_NOARGS }, - { "fileno", (PyCFunction)lad_fileno, METH_NOARGS }, - { "getptr", (PyCFunction)lad_getptr, METH_NOARGS }, - { NULL, NULL} /* sentinel */ -}; - -static PyObject * -lad_getattr(lad_t *xp, char *name) -{ - return Py_FindMethod(lad_methods, (PyObject *)xp, name); -} - -static PyTypeObject Ladtype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "linuxaudiodev.linux_audio_device", /*tp_name*/ - sizeof(lad_t), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)lad_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)lad_getattr, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; - -static PyObject * -ladopen(PyObject *self, PyObject *args) -{ - return (PyObject *)newladobject(args); -} - -static PyMethodDef linuxaudiodev_methods[] = { - { "open", ladopen, METH_VARARGS }, - { 0, 0 }, -}; - -void -initlinuxaudiodev(void) -{ - PyObject *m; - - m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods); - if (m == NULL) - return; - - LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL); - if (LinuxAudioError) - PyModule_AddObject(m, "error", LinuxAudioError); - - if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1) - return; - - return; -} Deleted: /python/branches/p3yk/Modules/sunaudiodev.c ============================================================================== --- /python/branches/p3yk/Modules/sunaudiodev.c Fri Aug 3 07:20:23 2007 +++ (empty file) @@ -1,463 +0,0 @@ - -/* Sad objects */ - -#include "Python.h" -#include "structmember.h" - -#ifdef HAVE_SYS_AUDIOIO_H -#define SOLARIS -#endif - -#ifdef HAVE_FCNTL_H -#include -#endif - -#include -#include -#ifdef SOLARIS -#include -#else -#include -#endif - -/* #define offsetof(str,mem) ((int)(((str *)0)->mem)) */ - -typedef struct { - PyObject_HEAD - int x_fd; /* The open file */ - int x_icount; /* # samples read */ - int x_ocount; /* # samples written */ - int x_isctl; /* True if control device */ - -} sadobject; - -typedef struct { - PyObject_HEAD - audio_info_t ai; -} sadstatusobject; - -static PyTypeObject Sadtype; -static PyTypeObject Sadstatustype; -static sadstatusobject *sads_alloc(void); /* Forward */ - -static PyObject *SunAudioError; - -#define is_sadobject(v) (Py_Type(v) == &Sadtype) -#define is_sadstatusobject(v) (Py_Type(v) == &Sadstatustype) - - -static sadobject * -newsadobject(PyObject *args) -{ - sadobject *xp; - int fd; - char *mode; - int imode; - char* basedev; - char* ctldev; - char* opendev; - - /* Check arg for r/w/rw */ - if (!PyArg_ParseTuple(args, "s", &mode)) - return NULL; - if (strcmp(mode, "r") == 0) - imode = 0; - else if (strcmp(mode, "w") == 0) - imode = 1; - else if (strcmp(mode, "rw") == 0) - imode = 2; - else if (strcmp(mode, "control") == 0) - imode = -1; - else { - PyErr_SetString(SunAudioError, - "Mode should be one of 'r', 'w', 'rw' or 'control'"); - return NULL; - } - - /* Open the correct device. The base device name comes from the - * AUDIODEV environment variable first, then /dev/audio. The - * control device tacks "ctl" onto the base device name. - */ - basedev = getenv("AUDIODEV"); - if (!basedev) - basedev = "/dev/audio"; - ctldev = PyMem_NEW(char, strlen(basedev) + 4); - if (!ctldev) { - PyErr_NoMemory(); - return NULL; - } - strcpy(ctldev, basedev); - strcat(ctldev, "ctl"); - - if (imode < 0) { - opendev = ctldev; - fd = open(ctldev, 2); - } - else { - opendev = basedev; - fd = open(basedev, imode); - } - if (fd < 0) { - PyErr_SetFromErrnoWithFilename(SunAudioError, opendev); - PyMem_DEL(ctldev); - return NULL; - } - PyMem_DEL(ctldev); - - /* Create and initialize the object */ - xp = PyObject_New(sadobject, &Sadtype); - if (xp == NULL) { - close(fd); - return NULL; - } - xp->x_fd = fd; - xp->x_icount = xp->x_ocount = 0; - xp->x_isctl = (imode < 0); - - return xp; -} - -/* Sad methods */ - -static void -sad_dealloc(sadobject *xp) -{ - close(xp->x_fd); - PyObject_Del(xp); -} - -static PyObject * -sad_read(sadobject *self, PyObject *args) -{ - int size, count; - char *cp; - PyObject *rv; - - if (!PyArg_ParseTuple(args, "i:read", &size)) - return NULL; - rv = PyString_FromStringAndSize(NULL, size); - if (rv == NULL) - return NULL; - - if (!(cp = PyString_AsString(rv))) - goto finally; - - count = read(self->x_fd, cp, size); - if (count < 0) { - PyErr_SetFromErrno(SunAudioError); - goto finally; - } -#if 0 - /* TBD: why print this message if you can handle the condition? - * assume it's debugging info which we can just as well get rid - * of. in any case this message should *not* be using printf! - */ - if (count != size) - printf("sunaudio: funny read rv %d wtd %d\n", count, size); -#endif - self->x_icount += count; - return rv; - - finally: - Py_DECREF(rv); - return NULL; -} - -static PyObject * -sad_write(sadobject *self, PyObject *args) -{ - char *cp; - int count, size; - - if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) - return NULL; - - count = write(self->x_fd, cp, size); - if (count < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } -#if 0 - if (count != size) - printf("sunaudio: funny write rv %d wanted %d\n", count, size); -#endif - self->x_ocount += count; - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_getinfo(sadobject *self) -{ - sadstatusobject *rv; - - if (!(rv = sads_alloc())) - return NULL; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - Py_DECREF(rv); - return NULL; - } - return (PyObject *)rv; -} - -static PyObject * -sad_setinfo(sadobject *self, sadstatusobject *arg) -{ - if (!is_sadstatusobject(arg)) { - PyErr_SetString(PyExc_TypeError, - "Must be sun audio status object"); - return NULL; - } - if (ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_ibufcount(sadobject *self) -{ - audio_info_t ai; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - return PyInt_FromLong(ai.record.samples - self->x_icount); -} - -static PyObject * -sad_obufcount(sadobject *self) -{ - audio_info_t ai; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - /* x_ocount is in bytes, whereas play.samples is in frames */ - /* we want frames */ - return PyInt_FromLong(self->x_ocount / (ai.play.channels * - ai.play.precision / 8) - - ai.play.samples); -} - -static PyObject * -sad_drain(sadobject *self) -{ - if (ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -#ifdef SOLARIS -static PyObject * -sad_getdev(sadobject *self) -{ - struct audio_device ad; - - if (ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - return Py_BuildValue("(sss)", ad.name, ad.version, ad.config); -} -#endif - -static PyObject * -sad_flush(sadobject *self) -{ - if (ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_close(sadobject *self) -{ - - if (self->x_fd >= 0) { - close(self->x_fd); - self->x_fd = -1; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_fileno(sadobject *self) -{ - return PyInt_FromLong(self->x_fd); -} - - -static PyMethodDef sad_methods[] = { - { "read", (PyCFunction)sad_read, METH_VARARGS }, - { "write", (PyCFunction)sad_write, METH_VARARGS }, - { "ibufcount", (PyCFunction)sad_ibufcount, METH_NOARGS }, - { "obufcount", (PyCFunction)sad_obufcount, METH_NOARGS }, -#define CTL_METHODS 4 - { "getinfo", (PyCFunction)sad_getinfo, METH_NOARGS }, - { "setinfo", (PyCFunction)sad_setinfo, METH_O}, - { "drain", (PyCFunction)sad_drain, METH_NOARGS }, - { "flush", (PyCFunction)sad_flush, METH_NOARGS }, -#ifdef SOLARIS - { "getdev", (PyCFunction)sad_getdev, METH_NOARGS }, -#endif - { "close", (PyCFunction)sad_close, METH_NOARGS }, - { "fileno", (PyCFunction)sad_fileno, METH_NOARGS }, - {NULL, NULL} /* sentinel */ -}; - -static PyObject * -sad_getattr(sadobject *xp, char *name) -{ - if (xp->x_isctl) - return Py_FindMethod(sad_methods+CTL_METHODS, - (PyObject *)xp, name); - else - return Py_FindMethod(sad_methods, (PyObject *)xp, name); -} - -/* ----------------------------------------------------------------- */ - -static sadstatusobject * -sads_alloc(void) { - return PyObject_New(sadstatusobject, &Sadstatustype); -} - -static void -sads_dealloc(sadstatusobject *xp) -{ - PyMem_DEL(xp); -} - -#define OFF(x) offsetof(audio_info_t,x) -static struct memberlist sads_ml[] = { - { "i_sample_rate", T_UINT, OFF(record.sample_rate) }, - { "i_channels", T_UINT, OFF(record.channels) }, - { "i_precision", T_UINT, OFF(record.precision) }, - { "i_encoding", T_UINT, OFF(record.encoding) }, - { "i_gain", T_UINT, OFF(record.gain) }, - { "i_port", T_UINT, OFF(record.port) }, - { "i_samples", T_UINT, OFF(record.samples) }, - { "i_eof", T_UINT, OFF(record.eof) }, - { "i_pause", T_UBYTE, OFF(record.pause) }, - { "i_error", T_UBYTE, OFF(record.error) }, - { "i_waiting", T_UBYTE, OFF(record.waiting) }, - { "i_open", T_UBYTE, OFF(record.open) , RO}, - { "i_active", T_UBYTE, OFF(record.active) , RO}, -#ifdef SOLARIS - { "i_buffer_size", T_UINT, OFF(record.buffer_size) }, - { "i_balance", T_UBYTE, OFF(record.balance) }, - { "i_avail_ports", T_UINT, OFF(record.avail_ports) }, -#endif - - { "o_sample_rate", T_UINT, OFF(play.sample_rate) }, - { "o_channels", T_UINT, OFF(play.channels) }, - { "o_precision", T_UINT, OFF(play.precision) }, - { "o_encoding", T_UINT, OFF(play.encoding) }, - { "o_gain", T_UINT, OFF(play.gain) }, - { "o_port", T_UINT, OFF(play.port) }, - { "o_samples", T_UINT, OFF(play.samples) }, - { "o_eof", T_UINT, OFF(play.eof) }, - { "o_pause", T_UBYTE, OFF(play.pause) }, - { "o_error", T_UBYTE, OFF(play.error) }, - { "o_waiting", T_UBYTE, OFF(play.waiting) }, - { "o_open", T_UBYTE, OFF(play.open) , RO}, - { "o_active", T_UBYTE, OFF(play.active) , RO}, -#ifdef SOLARIS - { "o_buffer_size", T_UINT, OFF(play.buffer_size) }, - { "o_balance", T_UBYTE, OFF(play.balance) }, - { "o_avail_ports", T_UINT, OFF(play.avail_ports) }, -#endif - - { "monitor_gain", T_UINT, OFF(monitor_gain) }, - { NULL, 0, 0}, -}; - -static PyObject * -sads_getattr(sadstatusobject *xp, char *name) -{ - return PyMember_Get((char *)&xp->ai, sads_ml, name); -} - -static int -sads_setattr(sadstatusobject *xp, char *name, PyObject *v) -{ - - if (v == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete sun audio status attributes"); - return -1; - } - return PyMember_Set((char *)&xp->ai, sads_ml, name, v); -} - -/* ------------------------------------------------------------------- */ - - -static PyTypeObject Sadtype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "sunaudiodev.sun_audio_device", /*tp_name*/ - sizeof(sadobject), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)sad_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)sad_getattr, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; - -static PyTypeObject Sadstatustype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "sunaudiodev.sun_audio_device_status", /*tp_name*/ - sizeof(sadstatusobject), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)sads_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)sads_getattr, /*tp_getattr*/ - (setattrfunc)sads_setattr, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; -/* ------------------------------------------------------------------- */ - -static PyObject * -sadopen(PyObject *self, PyObject *args) -{ - return (PyObject *)newsadobject(args); -} - -static PyMethodDef sunaudiodev_methods[] = { - { "open", sadopen, METH_VARARGS }, - { 0, 0 }, -}; - -void -initsunaudiodev(void) -{ - PyObject *m, *d; - - m = Py_InitModule("sunaudiodev", sunaudiodev_methods); - if (m == NULL) - return; - d = PyModule_GetDict(m); - SunAudioError = PyErr_NewException("sunaudiodev.error", NULL, NULL); - if (SunAudioError) - PyDict_SetItemString(d, "error", SunAudioError); -} Modified: python/branches/p3yk/PC/os2vacpp/makefile ============================================================================== --- python/branches/p3yk/PC/os2vacpp/makefile (original) +++ python/branches/p3yk/PC/os2vacpp/makefile Fri Aug 3 07:20:23 2007 @@ -856,20 +856,6 @@ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\tupleobject.h -sunaudiodev.obj: $(PY_INCLUDE)\abstract.h $(OS2TCPIP)\Include\sys\ioctl.h $(PY_INCLUDE)\ceval.h \ - $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ - pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ - $(PY_INCLUDE)\floatobject.h $(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h \ - $(PY_INCLUDE)\intobject.h $(PY_INCLUDE)\intrcheck.h $(PY_INCLUDE)\listobject.h \ - $(PY_INCLUDE)\longobject.h $(PY_INCLUDE)\methodobject.h \ - $(PY_INCLUDE)\modsupport.h $(PY_INCLUDE)\moduleobject.h $(PY_INCLUDE)\mymalloc.h \ - $(PY_INCLUDE)\myproto.h $(PY_INCLUDE)\object.h $(PY_INCLUDE)\objimpl.h \ - $(PY_INCLUDE)\pydebug.h $(PY_INCLUDE)\pyerrors.h $(PY_INCLUDE)\pyfpe.h \ - $(PY_INCLUDE)\pystate.h $(PY_INCLUDE)\python.h $(PY_INCLUDE)\pythonrun.h \ - $(PY_INCLUDE)\rangeobject.h $(PY_INCLUDE)\sliceobject.h \ - $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\structmember.h \ - $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h - syslogmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ Modified: python/branches/p3yk/PC/os2vacpp/makefile.omk ============================================================================== --- python/branches/p3yk/PC/os2vacpp/makefile.omk (original) +++ python/branches/p3yk/PC/os2vacpp/makefile.omk Fri Aug 3 07:20:23 2007 @@ -171,8 +171,6 @@ # # Multimedia: # audioop.c -- Various Compute Operations on Audio Samples - # imageop.c -- Various Compute Operations on Video Samples - # sunaudiodev.c -- Wrapper of Sun Audio Device API # Database: # dbmmodule.c -- Wrapper of DBM Database API (Generic Flavor) @@ -627,15 +625,6 @@ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ stringobject.h sysmodule.h traceback.h tupleobject.h -sunaudiodev.obj: abstract.h c:\mptn\include\sys\ioctl.h ceval.h \ - classobject.h cobject.h complexobject.h pyconfig.h dictobject.h \ - fileobject.h floatobject.h funcobject.h import.h intobject.h \ - intrcheck.h listobject.h longobject.h methodobject.h modsupport.h \ - moduleobject.h mymalloc.h myproto.h object.h objimpl.h pydebug.h \ - pyerrors.h pyfpe.h pystate.h python.h pythonrun.h rangeobject.h \ - sliceobject.h stringobject.h structmember.h sysmodule.h \ - traceback.h tupleobject.h - syslogmodule.obj: abstract.h ceval.h classobject.h cobject.h \ complexobject.h pyconfig.h dictobject.h fileobject.h floatobject.h \ funcobject.h import.h intobject.h intrcheck.h listobject.h \ Modified: python/branches/p3yk/setup.py ============================================================================== --- python/branches/p3yk/setup.py (original) +++ python/branches/p3yk/setup.py Fri Aug 3 07:20:23 2007 @@ -1088,24 +1088,12 @@ exts.append(Extension('_fileio', ['_fileio.c'])) # Platform-specific libraries - if platform == 'linux2': - # Linux-specific modules - exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) - else: - missing.append('linuxaudiodev') - if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', 'freebsd7'): exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) else: missing.append('ossaudiodev') - if platform == 'sunos5': - # SunOS specific modules - exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) - else: - missing.append('sunaudiodev') - if platform == 'darwin' and ("--disable-toolbox-glue" not in sysconfig.get_config_var("CONFIG_ARGS")): From python-3000-checkins at python.org Fri Aug 3 07:21:48 2007 From: python-3000-checkins at python.org (neal.norwitz) Date: Fri, 3 Aug 2007 07:21:48 +0200 (CEST) Subject: [Python-3000-checkins] r56686 - python/branches/p3yk/Mac/Demo/sound/morse.py Message-ID: <20070803052148.B041C1E4005@bag.python.org> Author: neal.norwitz Date: Fri Aug 3 07:21:48 2007 New Revision: 56686 Removed: python/branches/p3yk/Mac/Demo/sound/morse.py Log: Missed one module that should have been removed since it relied on audiodev which was removed. Deleted: /python/branches/p3yk/Mac/Demo/sound/morse.py ============================================================================== --- /python/branches/p3yk/Mac/Demo/sound/morse.py Fri Aug 3 07:21:48 2007 +++ (empty file) @@ -1,180 +0,0 @@ -import sys, math, audiodev - -DOT = 30 -DAH = 80 -OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ... -SAMPWIDTH = 2 -FRAMERATE = 44100 -BASEFREQ = 441 -QSIZE = 20000 - -morsetab = { - 'A': '.-', 'a': '.-', - 'B': '-...', 'b': '-...', - 'C': '-.-.', 'c': '-.-.', - 'D': '-..', 'd': '-..', - 'E': '.', 'e': '.', - 'F': '..-.', 'f': '..-.', - 'G': '--.', 'g': '--.', - 'H': '....', 'h': '....', - 'I': '..', 'i': '..', - 'J': '.---', 'j': '.---', - 'K': '-.-', 'k': '-.-', - 'L': '.-..', 'l': '.-..', - 'M': '--', 'm': '--', - 'N': '-.', 'n': '-.', - 'O': '---', 'o': '---', - 'P': '.--.', 'p': '.--.', - 'Q': '--.-', 'q': '--.-', - 'R': '.-.', 'r': '.-.', - 'S': '...', 's': '...', - 'T': '-', 't': '-', - 'U': '..-', 'u': '..-', - 'V': '...-', 'v': '...-', - 'W': '.--', 'w': '.--', - 'X': '-..-', 'x': '-..-', - 'Y': '-.--', 'y': '-.--', - 'Z': '--..', 'z': '--..', - '0': '-----', - '1': '.----', - '2': '..---', - '3': '...--', - '4': '....-', - '5': '.....', - '6': '-....', - '7': '--...', - '8': '---..', - '9': '----.', - ',': '--..--', - '.': '.-.-.-', - '?': '..--..', - ';': '-.-.-.', - ':': '---...', - "'": '.----.', - '-': '-....-', - '/': '-..-.', - '(': '-.--.-', - ')': '-.--.-', - '_': '..--.-', - ' ': ' ' -} - -# If we play at 44.1 kHz (which we do), then if we produce one sine -# wave in 100 samples, we get a tone of 441 Hz. If we produce two -# sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz -# appears to be a nice one for playing morse code. -def mkwave(octave): - global sinewave, nowave - sinewave = '' - n = int(FRAMERATE / BASEFREQ) - for i in range(n): - val = int(math.sin(2 * math.pi * i * octave / n) * 0x7fff) - sample = chr((val >> 8) & 255) + chr(val & 255) - sinewave = sinewave + sample[:SAMPWIDTH] - nowave = '\0' * (n*SAMPWIDTH) - -mkwave(OCTAVE) - -class BufferedAudioDev: - def __init__(self, *args): - import audiodev - self._base = audiodev.AudioDev(*args) - self._buffer = [] - self._filled = 0 - self._addmethods(self._base, self._base.__class__) - def _addmethods(self, inst, cls): - for name in cls.__dict__.keys(): - if not hasattr(self, name): - try: - setattr(self, name, getattr(inst, name)) - except: - pass - for basecls in cls.__bases__: - self._addmethods(self, inst, basecls) - def writeframesraw(self, frames): - self._buffer.append(frames) - self._filled = self._filled + len(frames) - if self._filled >= QSIZE: - self.flush() - def wait(self): - self.flush() - self._base.wait() - def flush(self): - print 'flush: %d blocks, %d bytes' % (len(self._buffer), self._filled) - if self._buffer: - import string - self._base.writeframes(string.joinfields(self._buffer, '')) - self._buffer = [] - self._filled = 0 - -def main(args = sys.argv[1:]): - import getopt, string - try: - opts, args = getopt.getopt(args, 'o:p:') - except getopt.error: - sys.stderr.write('Usage ' + sys.argv[0] + - ' [ -o outfile ] [ args ] ...\n') - sys.exit(1) - dev = None - for o, a in opts: - if o == '-o': - import aifc - dev = aifc.open(a, 'w') - dev.setframerate(FRAMERATE) - dev.setsampwidth(SAMPWIDTH) - dev.setnchannels(1) - if o == '-p': - mkwave(string.atoi(a)) - if not dev: - dev = BufferedAudioDev() - dev.setoutrate(FRAMERATE) - dev.setsampwidth(SAMPWIDTH) - dev.setnchannels(1) - dev.close = dev.stop - if args: - line = string.join(args) - else: - line = sys.stdin.readline() - while line: - print line - mline = morse(line) - print mline - play(mline, dev) - if hasattr(dev, 'wait'): - dev.wait() - if not args: - line = sys.stdin.readline() - else: - line = '' - dev.close() - -# Convert a string to morse code with \001 between the characters in -# the string. -def morse(line): - res = '' - for c in line: - try: - res = res + morsetab[c] + '\001' - except KeyError: - pass - return res - -# Play a line of morse code. -def play(line, dev): - for c in line: - if c == '.': - sine(dev, DOT) - elif c == '-': - sine(dev, DAH) - else: - pause(dev, DAH) - pause(dev, DOT) - -def sine(dev, length): - dev.writeframesraw(sinewave*length) - -def pause(dev, length): - dev.writeframesraw(nowave*length) - -if __name__ == '__main__' or sys.argv[0] == __name__: - main() From python-3000-checkins at python.org Fri Aug 3 15:30:02 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 15:30:02 +0200 (CEST) Subject: [Python-3000-checkins] r56703 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070803133002.912571E4005@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 15:30:02 2007 New Revision: 56703 Modified: python/branches/py3k-struni/Lib/httplib.py Log: Fix status line parsing for http response. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Fri Aug 3 15:30:02 2007 @@ -264,7 +264,7 @@ except IOError: startofline = tell = None self.seekable = 0 - line = self.fp.readline() + line = str(self.fp.readline(), "iso-8859-1") if not line: self.status = 'EOF in headers' break @@ -317,6 +317,11 @@ # See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details. + # The bytes from the socket object are iso-8859-1 strings. + # See RFC 2616 sec 2.2 which notes an exception for MIME-encoded + # text following RFC 2047. The basic status line parsing only + # accepts iso-8859-1. + def __init__(self, sock, debuglevel=0, strict=0, method=None): self.fp = sock.makefile('rb', 0) self.debuglevel = debuglevel @@ -337,7 +342,7 @@ def _read_status(self): # Initialize with Simple-Response defaults - line = self.fp.readline() + line = str(self.fp.readline(), "iso-8859-1") if self.debuglevel > 0: print("reply:", repr(line)) if not line: From python-3000-checkins at python.org Fri Aug 3 15:45:25 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 15:45:25 +0200 (CEST) Subject: [Python-3000-checkins] r56704 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070803134525.2B0D41E4011@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 15:45:24 2007 New Revision: 56704 Modified: python/branches/py3k-struni/Lib/httplib.py Log: Make consistent use of "" for string literals in new classes. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Fri Aug 3 15:45:24 2007 @@ -323,7 +323,7 @@ # accepts iso-8859-1. def __init__(self, sock, debuglevel=0, strict=0, method=None): - self.fp = sock.makefile('rb', 0) + self.fp = sock.makefile("rb", 0) self.debuglevel = debuglevel self.strict = strict self._method = method @@ -359,7 +359,7 @@ # empty version will cause next test to fail and status # will be treated as 0.9 response. version = "" - if not version.startswith('HTTP/'): + if not version.startswith("HTTP/"): if self.strict: self.close() raise BadStatusLine(line) @@ -397,11 +397,11 @@ self.status = status self.reason = reason.strip() - if version == 'HTTP/1.0': + if version == "HTTP/1.0": self.version = 10 - elif version.startswith('HTTP/1.'): + elif version.startswith("HTTP/1."): self.version = 11 # use HTTP/1.1 code for HTTP/1.x where x>=1 - elif version == 'HTTP/0.9': + elif version == "HTTP/0.9": self.version = 9 else: raise UnknownProtocol(version) @@ -416,13 +416,13 @@ self.msg = HTTPMessage(self.fp, 0) if self.debuglevel > 0: for hdr in self.msg.headers: - print("header:", hdr, end=' ') + print("header:", hdr, end=" ") # don't let the msg keep an fp self.msg.fp = None # are we using the chunked-style of transfer encoding? - tr_enc = self.msg.getheader('transfer-encoding') + tr_enc = self.msg.getheader("transfer-encoding") if tr_enc and tr_enc.lower() == "chunked": self.chunked = 1 self.chunk_left = None @@ -434,7 +434,7 @@ # do we have a Content-Length? # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked" - length = self.msg.getheader('content-length') + length = self.msg.getheader("content-length") if length and not self.chunked: try: self.length = int(length) @@ -446,7 +446,7 @@ # does the body have a fixed length? (of zero) if (status == NO_CONTENT or status == NOT_MODIFIED or 100 <= status < 200 or # 1xx codes - self._method == 'HEAD'): + self._method == "HEAD"): self.length = 0 # if the connection remains open, and we aren't using chunked, and @@ -458,11 +458,11 @@ self.will_close = 1 def _check_close(self): - conn = self.msg.getheader('connection') + conn = self.msg.getheader("connection") if self.version == 11: # An HTTP/1.1 proxy is assumed to stay open unless # explicitly closed. - conn = self.msg.getheader('connection') + conn = self.msg.getheader("connection") if conn and "close" in conn.lower(): return True return False @@ -471,7 +471,7 @@ # connections, using rules different than HTTP/1.1. # For older HTTP, Keep-Alive indiciates persistent connection. - if self.msg.getheader('keep-alive'): + if self.msg.getheader("keep-alive"): return False # At least Akamai returns a "Connection: Keep-Alive" header, @@ -480,7 +480,7 @@ return False # Proxy-Connection is a netscape hack. - pconn = self.msg.getheader('proxy-connection') + pconn = self.msg.getheader("proxy-connection") if pconn and "keep-alive" in pconn.lower(): return False @@ -505,7 +505,7 @@ def read(self, amt=None): if self.fp is None: - return '' + return "" if self.chunked: return self._read_chunked(amt) @@ -537,14 +537,14 @@ def _read_chunked(self, amt): assert self.chunked != _UNKNOWN chunk_left = self.chunk_left - value = '' + value = "" # XXX This accumulates chunks by repeated string concatenation, # which is not efficient as the number or size of chunks gets big. while True: if chunk_left is None: line = self.fp.readline() - i = line.find(';') + i = line.find(";") if i >= 0: line = line[:i] # strip chunk-extensions chunk_left = int(line, 16) @@ -573,7 +573,7 @@ ### note: we shouldn't have any trailers! while True: line = self.fp.readline() - if line == '\r\n': + if line == "\r\n": break # we read everything; close the "file" @@ -602,7 +602,7 @@ raise IncompleteRead(s) s.append(chunk) amt -= len(chunk) - return ''.join(s) + return "".join(s) def getheader(self, name, default=None): if self.msg is None: From python-3000-checkins at python.org Fri Aug 3 19:06:46 2007 From: python-3000-checkins at python.org (collin.winter) Date: Fri, 3 Aug 2007 19:06:46 +0200 (CEST) Subject: [Python-3000-checkins] r56706 - in python/branches/py3k-struni/Tools: audiopy/audiopy bgen/bgen/bgenGenerator.py bgen/bgen/bgenGeneratorGroup.py bgen/bgen/scantools.py faqwiz/faqw.py faqwiz/faqwiz.py framer/framer/bases.py framer/framer/function.py framer/framer/member.py i18n/makelocalealias.py i18n/msgfmt.py i18n/pygettext.py modulator/Tkextra.py msi/msi.py msi/msilib.py pybench/pybench.py pynche/ColorDB.py pynche/Main.py pynche/Switchboard.py scripts/byext.py scripts/byteyears.py scripts/checkappend.py scripts/checkpyc.py scripts/cleanfuture.py scripts/combinerefs.py scripts/crlf.py scripts/cvsfiles.py scripts/dutree.py scripts/finddiv.py scripts/findlinksto.py scripts/findnocoding.py scripts/fixcid.py scripts/fixdiv.py scripts/fixheader.py scripts/fixnotice.py scripts/fixps.py scripts/ftpmirror.py scripts/google.py scripts/lfcr.py scripts/linktree.py scripts/lll.py scripts/logmerge.py scripts/mailerdaemon.py scripts/mkreal.py scripts/ndiff.py scripts/objgraph.py scripts/pdeps.py scripts/pysource.py scripts/rgrep.py scripts/suff.py scripts/texcheck.py scripts/texi2html.py scripts/treesync.py scripts/untabify.py scripts/which.py scripts/xxci.py unicode/comparecodecs.py unicode/gencodec.py unicode/listcodecs.py unicode/makeunicodedata.py unicode/mkstringprep.py versioncheck/checkversions.py versioncheck/pyversioncheck.py webchecker/wcgui.py webchecker/webchecker.py webchecker/websucker.py Message-ID: <20070803170646.341EF1E401C@bag.python.org> Author: collin.winter Date: Fri Aug 3 19:06:41 2007 New Revision: 56706 Modified: python/branches/py3k-struni/Tools/audiopy/audiopy python/branches/py3k-struni/Tools/bgen/bgen/bgenGenerator.py python/branches/py3k-struni/Tools/bgen/bgen/bgenGeneratorGroup.py python/branches/py3k-struni/Tools/bgen/bgen/scantools.py python/branches/py3k-struni/Tools/faqwiz/faqw.py python/branches/py3k-struni/Tools/faqwiz/faqwiz.py python/branches/py3k-struni/Tools/framer/framer/bases.py python/branches/py3k-struni/Tools/framer/framer/function.py python/branches/py3k-struni/Tools/framer/framer/member.py python/branches/py3k-struni/Tools/i18n/makelocalealias.py python/branches/py3k-struni/Tools/i18n/msgfmt.py python/branches/py3k-struni/Tools/i18n/pygettext.py python/branches/py3k-struni/Tools/modulator/Tkextra.py python/branches/py3k-struni/Tools/msi/msi.py python/branches/py3k-struni/Tools/msi/msilib.py python/branches/py3k-struni/Tools/pybench/pybench.py python/branches/py3k-struni/Tools/pynche/ColorDB.py python/branches/py3k-struni/Tools/pynche/Main.py python/branches/py3k-struni/Tools/pynche/Switchboard.py python/branches/py3k-struni/Tools/scripts/byext.py python/branches/py3k-struni/Tools/scripts/byteyears.py python/branches/py3k-struni/Tools/scripts/checkappend.py python/branches/py3k-struni/Tools/scripts/checkpyc.py python/branches/py3k-struni/Tools/scripts/cleanfuture.py python/branches/py3k-struni/Tools/scripts/combinerefs.py python/branches/py3k-struni/Tools/scripts/crlf.py python/branches/py3k-struni/Tools/scripts/cvsfiles.py python/branches/py3k-struni/Tools/scripts/dutree.py python/branches/py3k-struni/Tools/scripts/finddiv.py python/branches/py3k-struni/Tools/scripts/findlinksto.py python/branches/py3k-struni/Tools/scripts/findnocoding.py python/branches/py3k-struni/Tools/scripts/fixcid.py python/branches/py3k-struni/Tools/scripts/fixdiv.py python/branches/py3k-struni/Tools/scripts/fixheader.py python/branches/py3k-struni/Tools/scripts/fixnotice.py python/branches/py3k-struni/Tools/scripts/fixps.py python/branches/py3k-struni/Tools/scripts/ftpmirror.py python/branches/py3k-struni/Tools/scripts/google.py python/branches/py3k-struni/Tools/scripts/lfcr.py python/branches/py3k-struni/Tools/scripts/linktree.py python/branches/py3k-struni/Tools/scripts/lll.py python/branches/py3k-struni/Tools/scripts/logmerge.py python/branches/py3k-struni/Tools/scripts/mailerdaemon.py python/branches/py3k-struni/Tools/scripts/mkreal.py python/branches/py3k-struni/Tools/scripts/ndiff.py python/branches/py3k-struni/Tools/scripts/objgraph.py python/branches/py3k-struni/Tools/scripts/pdeps.py python/branches/py3k-struni/Tools/scripts/pysource.py python/branches/py3k-struni/Tools/scripts/rgrep.py python/branches/py3k-struni/Tools/scripts/suff.py python/branches/py3k-struni/Tools/scripts/texcheck.py python/branches/py3k-struni/Tools/scripts/texi2html.py python/branches/py3k-struni/Tools/scripts/treesync.py python/branches/py3k-struni/Tools/scripts/untabify.py python/branches/py3k-struni/Tools/scripts/which.py python/branches/py3k-struni/Tools/scripts/xxci.py python/branches/py3k-struni/Tools/unicode/comparecodecs.py python/branches/py3k-struni/Tools/unicode/gencodec.py python/branches/py3k-struni/Tools/unicode/listcodecs.py python/branches/py3k-struni/Tools/unicode/makeunicodedata.py python/branches/py3k-struni/Tools/unicode/mkstringprep.py python/branches/py3k-struni/Tools/versioncheck/checkversions.py python/branches/py3k-struni/Tools/versioncheck/pyversioncheck.py python/branches/py3k-struni/Tools/webchecker/wcgui.py python/branches/py3k-struni/Tools/webchecker/webchecker.py python/branches/py3k-struni/Tools/webchecker/websucker.py Log: Convert print statements to function calls in Tools/. Modified: python/branches/py3k-struni/Tools/audiopy/audiopy ============================================================================== --- python/branches/py3k-struni/Tools/audiopy/audiopy (original) +++ python/branches/py3k-struni/Tools/audiopy/audiopy Fri Aug 3 19:06:41 2007 @@ -401,9 +401,9 @@ def usage(code, msg=''): - print __doc__ % globals() + print(__doc__ % globals()) if msg: - print msg + print(msg) sys.exit(code) @@ -455,11 +455,11 @@ i = i + 1 continue elif arg in ('-v', '--version'): - print '''\ + print('''\ audiopy -- a program to control the Solaris audio device. Contact: Barry Warsaw Email: bwarsaw at python.org -Version: %s''' % __version__ +Version: %s''' % __version__) sys.exit(0) for long, short, io, mask in options: if arg in (long, short): Modified: python/branches/py3k-struni/Tools/bgen/bgen/bgenGenerator.py ============================================================================== --- python/branches/py3k-struni/Tools/bgen/bgen/bgenGenerator.py (original) +++ python/branches/py3k-struni/Tools/bgen/bgen/bgenGenerator.py Fri Aug 3 19:06:41 2007 @@ -16,7 +16,7 @@ class BaseFunctionGenerator: def __init__(self, name, condition=None, callname=None, modifiers=None): - if DEBUG: print "<--", name + if DEBUG: print("<--", name) self.name = name if callname: self.callname = callname @@ -36,7 +36,7 @@ def generate(self): if not self.checkgenerate(): return - if DEBUG: print "-->", self.name + if DEBUG: print("-->", self.name) if self.condition: Output() Output(self.condition) @@ -157,7 +157,7 @@ continue else: typeName = "?" - print "Nameless type", arg.type + print("Nameless type", arg.type) str = typeName + ' ' + arg.name if arg.mode in (InMode, InOutMode): @@ -294,7 +294,7 @@ (int, 'status', ErrorMode), ) eggs.setprefix("spam") - print "/* START */" + print("/* START */") eggs.generate() Modified: python/branches/py3k-struni/Tools/bgen/bgen/bgenGeneratorGroup.py ============================================================================== --- python/branches/py3k-struni/Tools/bgen/bgen/bgenGeneratorGroup.py (original) +++ python/branches/py3k-struni/Tools/bgen/bgen/bgenGeneratorGroup.py Fri Aug 3 19:06:41 2007 @@ -9,7 +9,7 @@ def add(self, g, dupcheck=0): if dupcheck: if g in self.generators: - print 'DUP', g.name + print('DUP', g.name) return g.setprefix(self.prefix) self.generators.append(g) @@ -33,7 +33,7 @@ group = GeneratorGroup("spam") eggs = FunctionGenerator(void, "eggs") group.add(eggs) - print "/* START */" + print("/* START */") group.generate() if __name__ == "__main__": Modified: python/branches/py3k-struni/Tools/bgen/bgen/scantools.py ============================================================================== --- python/branches/py3k-struni/Tools/bgen/bgen/scantools.py (original) +++ python/branches/py3k-struni/Tools/bgen/bgen/scantools.py Fri Aug 3 19:06:41 2007 @@ -162,11 +162,11 @@ def error(self, format, *args): if self.silent >= 0: - print format%args + print(format%args) def report(self, format, *args): if not self.silent: - print format%args + print(format%args) def writeinitialdefs(self): pass @@ -221,7 +221,7 @@ """ f = self.openrepairfile() if not f: return [] - print "Reading repair file", repr(f.name), "..." + print("Reading repair file", repr(f.name), "...") list = [] lineno = 0 while 1: @@ -237,31 +237,31 @@ words = [s.strip() for s in line.split(':')] if words == ['']: continue if len(words) <> 3: - print "Line", startlineno, - print ": bad line (not 3 colon-separated fields)" - print repr(line) + print("Line", startlineno, end=' ') + print(": bad line (not 3 colon-separated fields)") + print(repr(line)) continue [fpat, pat, rep] = words if not fpat: fpat = "*" if not pat: - print "Line", startlineno, - print "Empty pattern" - print repr(line) + print("Line", startlineno, end=' ') + print("Empty pattern") + print(repr(line)) continue patparts = [s.strip() for s in pat.split(',')] repparts = [s.strip() for s in rep.split(',')] patterns = [] for p in patparts: if not p: - print "Line", startlineno, - print "Empty pattern part" - print repr(line) + print("Line", startlineno, end=' ') + print("Empty pattern part") + print(repr(line)) continue pattern = p.split() if len(pattern) > 3: - print "Line", startlineno, - print "Pattern part has > 3 words" - print repr(line) + print("Line", startlineno, end=' ') + print("Pattern part has > 3 words") + print(repr(line)) pattern = pattern[:3] else: while len(pattern) < 3: @@ -270,15 +270,15 @@ replacements = [] for p in repparts: if not p: - print "Line", startlineno, - print "Empty replacement part" - print repr(line) + print("Line", startlineno, end=' ') + print("Empty replacement part") + print(repr(line)) continue replacement = p.split() if len(replacement) > 3: - print "Line", startlineno, - print "Pattern part has > 3 words" - print repr(line) + print("Line", startlineno, end=' ') + print("Pattern part has > 3 words") + print(repr(line)) replacement = replacement[:3] else: while len(replacement) < 3: @@ -294,8 +294,8 @@ try: return open(filename, "rU") except IOError as msg: - print repr(filename), ":", msg - print "Cannot open repair file -- assume no repair needed" + print(repr(filename), ":", msg) + print("Cannot open repair file -- assume no repair needed") return None def initfiles(self): Modified: python/branches/py3k-struni/Tools/faqwiz/faqw.py ============================================================================== --- python/branches/py3k-struni/Tools/faqwiz/faqw.py (original) +++ python/branches/py3k-struni/Tools/faqwiz/faqw.py Fri Aug 3 19:06:41 2007 @@ -28,6 +28,6 @@ sys.exit(n) except: t, v, tb = sys.exc_info() - print + print() import cgi cgi.print_exception(t, v, tb) Modified: python/branches/py3k-struni/Tools/faqwiz/faqwiz.py ============================================================================== --- python/branches/py3k-struni/Tools/faqwiz/faqwiz.py (original) +++ python/branches/py3k-struni/Tools/faqwiz/faqwiz.py Fri Aug 3 19:06:41 2007 @@ -158,8 +158,8 @@ then = now + COOKIE_LIFETIME gmt = time.gmtime(then) path = os.environ.get('SCRIPT_NAME', '/cgi-bin/') - print "Set-Cookie: %s=%s; path=%s;" % (name, value, path), - print time.strftime("expires=%a, %d-%b-%y %X GMT", gmt) + print("Set-Cookie: %s=%s; path=%s;" % (name, value, path), end=' ') + print(time.strftime("expires=%a, %d-%b-%y %X GMT", gmt)) class MagicDict: @@ -273,22 +273,22 @@ raw = 0 continue if raw: - print line + print(line) continue if not line.strip(): if pre: - print '' + print('') pre = 0 else: - print '

' + print('

') else: if not line[0].isspace(): if pre: - print '' + print('') pre = 0 else: if not pre: - print '

'
+                        print('
')
                         pre = 1
                 if '/' in line or '@' in line:
                     line = translate(line, pre)
@@ -296,16 +296,16 @@
                     line = escape(line)
                 if not pre and '*' in line:
                     line = emphasize(line)
-                print line
+                print(line)
         if pre:
-            print '
' + print('
') pre = 0 if edit: - print '

' + print('

') emit(ENTRY_FOOTER, self) if self.last_changed_date: emit(ENTRY_LOGINFO, self) - print '

' + print('

') class FaqDir: @@ -377,7 +377,7 @@ self.dir = FaqDir() def go(self): - print 'Content-type: text/html' + print('Content-type: text/html') req = self.ui.req or 'home' mname = 'do_%s' % req try: @@ -493,7 +493,7 @@ mtime = mtime = entry.getmtime() if mtime > latest: latest = mtime - print time.strftime(LAST_CHANGED, time.localtime(latest)) + print(time.strftime(LAST_CHANGED, time.localtime(latest))) emit(EXPLAIN_MARKS) def format_all(self, files, edit=1, headers=1): @@ -637,7 +637,7 @@ rev = line[9:].split() mami = revparse(rev) if not mami: - print line + print(line) else: emit(REVISIONLINK, entry, rev=rev, line=line) if mami[1] > 1: @@ -647,7 +647,7 @@ emit(DIFFLINK, entry, prev=rev, rev=headrev) else: headrev = rev - print + print() athead = 0 else: athead = 0 @@ -656,8 +656,8 @@ athead = 1 sys.stdout.write('


') else: - print line - print '' + print(line) + print('') def do_revision(self): entry = self.dir.open(self.ui.file) @@ -686,8 +686,8 @@ def shell(self, command): output = os.popen(command).read() sys.stdout.write('
')
-        print escape(output)
-        print '
' + print(escape(output)) + print('') def do_new(self): entry = self.dir.new(section=int(self.ui.section)) @@ -759,9 +759,9 @@ def cantcommit(self): self.prologue(T_CANTCOMMIT) - print CANTCOMMIT_HEAD + print(CANTCOMMIT_HEAD) self.errordetail() - print CANTCOMMIT_TAIL + print(CANTCOMMIT_TAIL) def errordetail(self): if PASSWORD and self.ui.password != PASSWORD: @@ -827,7 +827,7 @@ else: self.error(T_COMMITFAILED) emit(COMMITFAILED, sts=sts) - print '
%s
' % escape(output) + print('
%s
' % escape(output)) try: os.unlink(tf.name) Modified: python/branches/py3k-struni/Tools/framer/framer/bases.py ============================================================================== --- python/branches/py3k-struni/Tools/framer/framer/bases.py (original) +++ python/branches/py3k-struni/Tools/framer/framer/bases.py Fri Aug 3 19:06:41 2007 @@ -27,7 +27,7 @@ def dump_methoddef(self, f, functions, vars): def p(templ, vars=vars): # helper function to generate output - print >> f, templ % vars + print(templ % vars, file=f) if not functions: return @@ -77,12 +77,12 @@ def dump(self, f): def p(templ, vars=self.__vars): # helper function to generate output - print >> f, templ % vars + print(templ % vars, file=f) p(template.module_start) if self.__members: p(template.member_include) - print >> f + print(file=f) if self.__doc__: p(template.module_doc) @@ -111,10 +111,10 @@ # defined after initvars() so that __vars is defined def p(templ, vars=self.__vars): - print >> f, templ % vars + print(templ % vars, file=f) if self.struct is not None: - print >> f, unindent(self.struct, False) + print(unindent(self.struct, False), file=f) if self.__doc__: p(template.docstring) @@ -185,7 +185,7 @@ def dump_memberdef(self, f): def p(templ, vars=self.__vars): - print >> f, templ % vars + print(templ % vars, file=f) if not self.__members: return @@ -196,7 +196,7 @@ def dump_slots(self, f): def p(templ, vars=self.__vars): - print >> f, templ % vars + print(templ % vars, file=f) if self.struct: p(template.dealloc_func, {"name" : self.__slots[TP_DEALLOC]}) @@ -206,12 +206,12 @@ val = self.__slots.get(s, s.default) ntabs = 4 - (4 + len(val)) / 8 line = " %s,%s/* %s */" % (val, "\t" * ntabs, s.name) - print >> f, line + print(line, file=f) p(template.type_struct_end) def dump_init(self, f): def p(templ): - print >> f, templ % self.__vars + print(templ % self.__vars, file=f) p(template.type_init_type) p(template.module_add_type) Modified: python/branches/py3k-struni/Tools/framer/framer/function.py ============================================================================== --- python/branches/py3k-struni/Tools/framer/framer/function.py (original) +++ python/branches/py3k-struni/Tools/framer/framer/function.py Fri Aug 3 19:06:41 2007 @@ -96,7 +96,7 @@ def dump_decls(self, f): for a in self.args: - print >> f, " %s" % a.decl() + print(" %s" % a.decl(), file=f) def ArgumentList(func, method): code = func.func_code @@ -135,7 +135,7 @@ def p(templ, vars=None): # helper function to generate output if vars is None: vars = self.vars - print >> f, templ % vars + print(templ % vars, file=f) if self.__doc__: p(template.docstring) Modified: python/branches/py3k-struni/Tools/framer/framer/member.py ============================================================================== --- python/branches/py3k-struni/Tools/framer/framer/member.py (original) +++ python/branches/py3k-struni/Tools/framer/framer/member.py Fri Aug 3 19:06:41 2007 @@ -68,6 +68,6 @@ def dump(self, f): if self.doc is None: - print >> f, template.memberdef_def % self.vars + print(template.memberdef_def % self.vars, file=f) else: - print >> f, template.memberdef_def_doc % self.vars + print(template.memberdef_def_doc % self.vars, file=f) Modified: python/branches/py3k-struni/Tools/i18n/makelocalealias.py ============================================================================== --- python/branches/py3k-struni/Tools/i18n/makelocalealias.py (original) +++ python/branches/py3k-struni/Tools/i18n/makelocalealias.py Fri Aug 3 19:06:41 2007 @@ -49,7 +49,7 @@ items = data.items() items.sort() for k,v in items: - print ' %-40s%r,' % ('%r:' % k, v) + print(' %-40s%r,' % ('%r:' % k, v)) def print_differences(data, olddata): @@ -57,17 +57,17 @@ items.sort() for k, v in items: if not data.has_key(k): - print '# removed %r' % k + print('# removed %r' % k) elif olddata[k] != data[k]: - print '# updated %r -> %r to %r' % \ - (k, olddata[k], data[k]) + print('# updated %r -> %r to %r' % \ + (k, olddata[k], data[k])) # Additions are not mentioned if __name__ == '__main__': data = locale.locale_alias.copy() data.update(parse(LOCALE_ALIAS)) print_differences(data, locale.locale_alias) - print - print 'locale_alias = {' + print() + print('locale_alias = {') pprint(data) - print '}' + print('}') Modified: python/branches/py3k-struni/Tools/i18n/msgfmt.py ============================================================================== --- python/branches/py3k-struni/Tools/i18n/msgfmt.py (original) +++ python/branches/py3k-struni/Tools/i18n/msgfmt.py Fri Aug 3 19:06:41 2007 @@ -38,9 +38,9 @@ def usage(code, msg=''): - print >> sys.stderr, __doc__ + print(__doc__, file=sys.stderr) if msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(code) @@ -111,7 +111,7 @@ try: lines = open(infile).readlines() except IOError as msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(1) section = None @@ -154,9 +154,9 @@ elif section == STR: msgstr += l else: - print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \ - 'before:' - print >> sys.stderr, l + print('Syntax error on %s:%d' % (infile, lno), \ + 'before:', file=sys.stderr) + print(l, file=sys.stderr) sys.exit(1) # Add last entry if section == STR: @@ -168,7 +168,7 @@ try: open(outfile,"wb").write(output) except IOError as msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) @@ -185,14 +185,14 @@ if opt in ('-h', '--help'): usage(0) elif opt in ('-V', '--version'): - print >> sys.stderr, "msgfmt.py", __version__ + print("msgfmt.py", __version__, file=sys.stderr) sys.exit(0) elif opt in ('-o', '--output-file'): outfile = arg # do it if not args: - print >> sys.stderr, 'No input file given' - print >> sys.stderr, "Try `msgfmt --help' for more information." + print('No input file given', file=sys.stderr) + print("Try `msgfmt --help' for more information.", file=sys.stderr) return for filename in args: Modified: python/branches/py3k-struni/Tools/i18n/pygettext.py ============================================================================== --- python/branches/py3k-struni/Tools/i18n/pygettext.py (original) +++ python/branches/py3k-struni/Tools/i18n/pygettext.py Fri Aug 3 19:06:41 2007 @@ -197,9 +197,9 @@ def usage(code, msg=''): - print >> sys.stderr, __doc__ % globals() + print(__doc__ % globals(), file=sys.stderr) if msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(code) @@ -423,13 +423,13 @@ elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT, token.NEWLINE, tokenize.NL]: # warn if we see anything else than STRING or whitespace - print >> sys.stderr, _( + print(_( '*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"' ) % { 'token': tstring, 'file': self.__curfile, 'lineno': self.__lineno - } + }, file=sys.stderr) self.__state = self.__waiting def __addentry(self, msg, lineno=None, isdocstring=0): @@ -448,7 +448,7 @@ timestamp = time.strftime('%Y-%m-%d %H:%M+%Z') # The time stamp in the header doesn't have the same format as that # generated by xgettext... - print >> fp, pot_header % {'time': timestamp, 'version': __version__} + print(pot_header % {'time': timestamp, 'version': __version__}, file=fp) # Sort the entries. First sort each particular entry's keys, then # sort all the entries by their first item. reverse = {} @@ -477,8 +477,8 @@ elif options.locationstyle == options.SOLARIS: for filename, lineno in v: d = {'filename': filename, 'lineno': lineno} - print >>fp, _( - '# File: %(filename)s, line: %(lineno)d') % d + print(_( + '# File: %(filename)s, line: %(lineno)d') % d, file=fp) elif options.locationstyle == options.GNU: # fit as many locations on one line, as long as the # resulting line length doesn't exceeds 'options.width' @@ -489,14 +489,14 @@ if len(locline) + len(s) <= options.width: locline = locline + s else: - print >> fp, locline + print(locline, file=fp) locline = "#:" + s if len(locline) > 2: - print >> fp, locline + print(locline, file=fp) if isdocstring: - print >> fp, '#, docstring' - print >> fp, 'msgid', normalize(k) - print >> fp, 'msgstr ""\n' + print('#, docstring', file=fp) + print('msgid', normalize(k), file=fp) + print('msgstr ""\n', file=fp) @@ -570,7 +570,7 @@ elif opt in ('-v', '--verbose'): options.verbose = 1 elif opt in ('-V', '--version'): - print _('pygettext.py (xgettext for Python) %s') % __version__ + print(_('pygettext.py (xgettext for Python) %s') % __version__) sys.exit(0) elif opt in ('-w', '--width'): try: @@ -603,8 +603,8 @@ options.toexclude = fp.readlines() fp.close() except IOError: - print >> sys.stderr, _( - "Can't read --exclude-file: %s") % options.excludefilename + print(_( + "Can't read --exclude-file: %s") % options.excludefilename, file=sys.stderr) sys.exit(1) else: options.toexclude = [] @@ -623,12 +623,12 @@ for filename in args: if filename == '-': if options.verbose: - print _('Reading standard input') + print(_('Reading standard input')) fp = sys.stdin closep = 0 else: if options.verbose: - print _('Working on %s') % filename + print(_('Working on %s') % filename) fp = open(filename) closep = 1 try: @@ -636,8 +636,8 @@ try: tokenize.tokenize(fp.readline, eater) except tokenize.TokenError as e: - print >> sys.stderr, '%s: %s, line %d, column %d' % ( - e[0], filename, e[1][0], e[1][1]) + print('%s: %s, line %d, column %d' % ( + e[0], filename, e[1][0], e[1][1]), file=sys.stderr) finally: if closep: fp.close() Modified: python/branches/py3k-struni/Tools/modulator/Tkextra.py ============================================================================== --- python/branches/py3k-struni/Tools/modulator/Tkextra.py (original) +++ python/branches/py3k-struni/Tools/modulator/Tkextra.py Fri Aug 3 19:06:41 2007 @@ -198,7 +198,7 @@ '', -1, 'OK') - print 'pressed button', i + print('pressed button', i) i = dialog(mainWidget, 'File Modified', 'File "tcl.h" has been modified since ' @@ -209,13 +209,13 @@ 'Save File', 'Discard Changes', 'Return To Editor') - print 'pressed button', i - print message('Test of message') - print askyn('Test of yes/no') - print askync('Test of yes/no/cancel') - print askstr('Type a string:') - print strdialog(mainWidget, 'Question', 'Another string:', '', - 0, 'Save', 'Save as text') + print('pressed button', i) + print(message('Test of message')) + print(askyn('Test of yes/no')) + print(askync('Test of yes/no/cancel')) + print(askstr('Type a string:')) + print(strdialog(mainWidget, 'Question', 'Another string:', '', + 0, 'Save', 'Save as text')) def _test(): import sys Modified: python/branches/py3k-struni/Tools/msi/msi.py ============================================================================== --- python/branches/py3k-struni/Tools/msi/msi.py (original) +++ python/branches/py3k-struni/Tools/msi/msi.py Fri Aug 3 19:06:41 2007 @@ -114,7 +114,7 @@ dlltool = find_executable('dlltool') if not nm or not dlltool: - print warning % "nm and/or dlltool were not found" + print(warning % "nm and/or dlltool were not found") return False nm_command = '%s -Cs %s' % (nm, lib_file) @@ -123,23 +123,23 @@ export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match f = open(def_file,'w') - print >>f, "LIBRARY %s" % dll_file - print >>f, "EXPORTS" + print("LIBRARY %s" % dll_file, file=f) + print("EXPORTS", file=f) nm_pipe = os.popen(nm_command) for line in nm_pipe.readlines(): m = export_match(line) if m: - print >>f, m.group(1) + print(m.group(1), file=f) f.close() exit = nm_pipe.close() if exit: - print warning % "nm did not run successfully" + print(warning % "nm did not run successfully") return False if os.system(dlltool_command) != 0: - print warning % "dlltool did not run successfully" + print(warning % "dlltool did not run successfully") return False return True @@ -875,7 +875,7 @@ # Check if _ctypes.pyd exists have_ctypes = os.path.exists(srcdir+"/PCBuild/_ctypes.pyd") if not have_ctypes: - print "WARNING: _ctypes.pyd not found, ctypes will not be included" + print("WARNING: _ctypes.pyd not found, ctypes will not be included") extensions.remove("_ctypes.pyd") # Add all .py files in Lib, except lib-tk, test @@ -953,7 +953,7 @@ if f.endswith(".au") or f.endswith(".gif"): lib.add_file(f) else: - print "WARNING: New file %s in email/test/data" % f + print("WARNING: New file %s in email/test/data" % f) for f in os.listdir(lib.absolute): if os.path.isdir(os.path.join(lib.absolute, f)): pydirs.append((lib, f)) @@ -968,7 +968,7 @@ if f=="_tkinter.pyd": continue if not os.path.exists(srcdir+"/PCBuild/"+f): - print "WARNING: Missing extension", f + print("WARNING: Missing extension", f) continue dlls.append(f) lib.add_file(f) @@ -982,7 +982,7 @@ lib.add_file(srcdir+"/"+sqlite_dir+sqlite_arch+"/sqlite3.dll") if have_tcl: if not os.path.exists(srcdir+"/PCBuild/_tkinter.pyd"): - print "WARNING: Missing _tkinter.pyd" + print("WARNING: Missing _tkinter.pyd") else: lib.start_component("TkDLLs", tcltk) lib.add_file("_tkinter.pyd") @@ -994,7 +994,7 @@ for f in glob.glob1(srcdir+"/PCBuild", "*.pyd"): if f.endswith("_d.pyd"): continue # debug version if f in dlls: continue - print "WARNING: Unknown extension", f + print("WARNING: Unknown extension", f) # Add headers default_feature.set_current() Modified: python/branches/py3k-struni/Tools/msi/msilib.py ============================================================================== --- python/branches/py3k-struni/Tools/msi/msilib.py (original) +++ python/branches/py3k-struni/Tools/msi/msilib.py Fri Aug 3 19:06:41 2007 @@ -95,7 +95,7 @@ index -= 1 unk = type & ~knownbits if unk: - print "%s.%s unknown bits %x" % (self.name, name, unk) + print("%s.%s unknown bits %x" % (self.name, name, unk)) size = type & datasizemask dtype = type & typemask if dtype == type_string: @@ -114,7 +114,7 @@ tname="OBJECT" else: tname="unknown" - print "%s.%sunknown integer type %d" % (self.name, name, size) + print("%s.%sunknown integer type %d" % (self.name, name, size)) if type & type_nullable: flags = "" else: @@ -202,7 +202,7 @@ v = seqmsi.OpenView("SELECT * FROM _Tables"); v.Execute(None) f = open(destpath, "w") - print >>f, "import msilib,os;dirname=os.path.dirname(__file__)" + print("import msilib,os;dirname=os.path.dirname(__file__)", file=f) tables = [] while 1: r = v.Fetch() @@ -364,9 +364,9 @@ logical = self.gen_id(dir, file) self.index += 1 if full.find(" ")!=-1: - print >>self.file, '"%s" %s' % (full, logical) + print('"%s" %s' % (full, logical), file=self.file) else: - print >>self.file, '%s %s' % (full, logical) + print('%s %s' % (full, logical), file=self.file) return self.index, logical def commit(self, db): @@ -386,7 +386,7 @@ if not os.path.exists(cabarc):continue break else: - print "WARNING: cabarc.exe not found in registry" + print("WARNING: cabarc.exe not found in registry") cabarc = "cabarc.exe" cmd = r'"%s" -m lzx:21 n %s.cab @%s.txt' % (cabarc, self.name, self.name) p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, Modified: python/branches/py3k-struni/Tools/pybench/pybench.py ============================================================================== --- python/branches/py3k-struni/Tools/pybench/pybench.py (original) +++ python/branches/py3k-struni/Tools/pybench/pybench.py Fri Aug 3 19:06:41 2007 @@ -547,11 +547,11 @@ min_overhead * MILLI_SECONDS)) self.roundtimes.append(total_eff_time) if self.verbose: - print((' ' - ' ------------------------------')) - print((' ' + print(' ' + ' ------------------------------') + print(' ' ' Totals: %6.0fms' % - (total_eff_time * MILLI_SECONDS))) + (total_eff_time * MILLI_SECONDS)) print() else: print('* Round %i done in %.3f seconds.' % (i+1, @@ -595,8 +595,8 @@ def print_benchmark(self, hidenoise=0, limitnames=None): - print(('Test ' - ' minimum average operation overhead')) + print('Test ' + ' minimum average operation overhead') print('-' * LINE) tests = sorted(self.tests.items()) total_min_time = 0.0 @@ -619,20 +619,20 @@ op_avg * MICRO_SECONDS, min_overhead *MILLI_SECONDS)) print('-' * LINE) - print(('Totals: ' + print('Totals: ' ' %6.0fms %6.0fms' % (total_min_time * MILLI_SECONDS, total_avg_time * MILLI_SECONDS, - ))) + )) print() def print_comparison(self, compare_to, hidenoise=0, limitnames=None): # Check benchmark versions if compare_to.version != self.version: - print(('* Benchmark versions differ: ' + print('* Benchmark versions differ: ' 'cannot compare this benchmark to "%s" !' % - compare_to.name)) + compare_to.name) print() self.print_benchmark(hidenoise=hidenoise, limitnames=limitnames) @@ -640,10 +640,10 @@ # Print header compare_to.print_header('Comparing with') - print(('Test ' - ' minimum run-time average run-time')) - print((' ' - ' this other diff this other diff')) + print('Test ' + ' minimum run-time average run-time') + print(' ' + ' this other diff this other diff') print('-' * LINE) # Print test comparisons @@ -726,7 +726,7 @@ (other_total_avg_time * compare_to.warp) - 1.0) * PERCENT) else: avg_diff = 'n/a' - print(('Totals: ' + print('Totals: ' ' %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % (total_min_time * MILLI_SECONDS, (other_total_min_time * compare_to.warp/self.warp @@ -736,7 +736,7 @@ (other_total_avg_time * compare_to.warp/self.warp * MILLI_SECONDS), avg_diff - ))) + )) print() print('(this=%s, other=%s)' % (self.name, compare_to.name)) Modified: python/branches/py3k-struni/Tools/pynche/ColorDB.py ============================================================================== --- python/branches/py3k-struni/Tools/pynche/ColorDB.py (original) +++ python/branches/py3k-struni/Tools/pynche/ColorDB.py Fri Aug 3 19:06:41 2007 @@ -57,7 +57,7 @@ # get this compiled regular expression from derived class mo = self._re.match(line) if not mo: - print >> sys.stderr, 'Error in', fp.name, ' line', lineno + print('Error in', fp.name, ' line', lineno, file=sys.stderr) lineno += 1 continue # extract the red, green, blue, and name @@ -254,26 +254,26 @@ if __name__ == '__main__': colordb = get_colordb('/usr/openwin/lib/rgb.txt') if not colordb: - print 'No parseable color database found' + print('No parseable color database found') sys.exit(1) # on my system, this color matches exactly target = 'navy' red, green, blue = rgbtuple = colordb.find_byname(target) - print target, ':', red, green, blue, triplet_to_rrggbb(rgbtuple) + print(target, ':', red, green, blue, triplet_to_rrggbb(rgbtuple)) name, aliases = colordb.find_byrgb(rgbtuple) - print 'name:', name, 'aliases:', COMMASPACE.join(aliases) + print('name:', name, 'aliases:', COMMASPACE.join(aliases)) r, g, b = (1, 1, 128) # nearest to navy r, g, b = (145, 238, 144) # nearest to lightgreen r, g, b = (255, 251, 250) # snow - print 'finding nearest to', target, '...' + print('finding nearest to', target, '...') import time t0 = time.time() nearest = colordb.nearest(r, g, b) t1 = time.time() - print 'found nearest color', nearest, 'in', t1-t0, 'seconds' + print('found nearest color', nearest, 'in', t1-t0, 'seconds') # dump the database for n in colordb.unique_names(): r, g, b = colordb.find_byname(n) aliases = colordb.aliases_of(r, g, b) - print '%20s: (%3d/%3d/%3d) == %s' % (n, r, g, b, - SPACE.join(aliases[1:])) + print('%20s: (%3d/%3d/%3d) == %s' % (n, r, g, b, + SPACE.join(aliases[1:]))) Modified: python/branches/py3k-struni/Tools/pynche/Main.py ============================================================================== --- python/branches/py3k-struni/Tools/pynche/Main.py (original) +++ python/branches/py3k-struni/Tools/pynche/Main.py Fri Aug 3 19:06:41 2007 @@ -85,9 +85,9 @@ def usage(code, msg=''): - print docstring() + print(docstring()) if msg: - print msg + print(msg) sys.exit(code) @@ -111,7 +111,7 @@ # this to be escaped, which is a pain r, g, b = scan_color('#' + s) if r is None: - print 'Bad initial color, using gray50:', s + print('Bad initial color, using gray50:', s) r, g, b = scan_color('gray50') if r is None: usage(1, 'Cannot find an initial color to use') @@ -203,11 +203,11 @@ if opt in ('-h', '--help'): usage(0) elif opt in ('-v', '--version'): - print """\ + print("""\ Pynche -- The PYthon Natural Color and Hue Editor. Contact: %(AUTHNAME)s Email: %(AUTHEMAIL)s -Version: %(__version__)s""" % globals() +Version: %(__version__)s""" % globals()) sys.exit(0) elif opt in ('-d', '--database'): dbfile = arg Modified: python/branches/py3k-struni/Tools/pynche/Switchboard.py ============================================================================== --- python/branches/py3k-struni/Tools/pynche/Switchboard.py (original) +++ python/branches/py3k-struni/Tools/pynche/Switchboard.py Fri Aug 3 19:06:41 2007 @@ -65,8 +65,7 @@ fp = open(initfile) self.__optiondb = marshal.load(fp) if not isinstance(self.__optiondb, DictType): - print >> sys.stderr, \ - 'Problem reading options from file:', initfile + print('Problem reading options from file:', initfile, file=sys.stderr) self.__optiondb = {} except (IOError, EOFError, ValueError): pass @@ -119,8 +118,8 @@ try: fp = open(self.__initfile, 'w') except IOError: - print >> sys.stderr, 'Cannot write options to file:', \ - self.__initfile + print('Cannot write options to file:', \ + self.__initfile, file=sys.stderr) else: marshal.dump(self.__optiondb, fp) finally: Modified: python/branches/py3k-struni/Tools/scripts/byext.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/byext.py (original) +++ python/branches/py3k-struni/Tools/scripts/byext.py Fri Aug 3 19:06:41 2007 @@ -109,14 +109,14 @@ cols.insert(0, "ext") def printheader(): for col in cols: - print "%*s" % (colwidth[col], col), - print + print("%*s" % (colwidth[col], col), end=' ') + print() printheader() for ext in exts: for col in cols: value = self.stats[ext].get(col, "") - print "%*s" % (colwidth[col], value), - print + print("%*s" % (colwidth[col], value), end=' ') + print() printheader() # Another header at the bottom def main(): Modified: python/branches/py3k-struni/Tools/scripts/byteyears.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/byteyears.py (original) +++ python/branches/py3k-struni/Tools/scripts/byteyears.py Fri Aug 3 19:06:41 2007 @@ -52,8 +52,8 @@ size = st[ST_SIZE] age = now - anytime byteyears = float(size) * float(age) / secs_per_year - print filename.ljust(maxlen), - print repr(int(byteyears)).rjust(8) + print(filename.ljust(maxlen), end=' ') + print(repr(int(byteyears)).rjust(8)) sys.exit(status) Modified: python/branches/py3k-struni/Tools/scripts/checkappend.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/checkappend.py (original) +++ python/branches/py3k-struni/Tools/scripts/checkappend.py Fri Aug 3 19:06:41 2007 @@ -65,7 +65,7 @@ def check(file): if os.path.isdir(file) and not os.path.islink(file): if verbose: - print "%r: listing directory" % (file,) + print("%r: listing directory" % (file,)) names = os.listdir(file) for name in names: fullname = os.path.join(file, name) @@ -82,11 +82,11 @@ return if verbose > 1: - print "checking %r ..." % (file,) + print("checking %r ..." % (file,)) ok = AppendChecker(file, f).run() if verbose and ok: - print "%r: Clean bill of health." % (file,) + print("%r: Clean bill of health." % (file,)) [FIND_DOT, FIND_APPEND, @@ -149,8 +149,8 @@ state = FIND_DOT elif token == "," and self.level == 1: self.nerrors = self.nerrors + 1 - print "%s(%d):\n%s" % (self.fname, self.lineno, - self.line) + print("%s(%d):\n%s" % (self.fname, self.lineno, + self.line)) # don't gripe about this stmt again state = FIND_STMT Modified: python/branches/py3k-struni/Tools/scripts/checkpyc.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/checkpyc.py (original) +++ python/branches/py3k-struni/Tools/scripts/checkpyc.py Fri Aug 3 19:06:41 2007 @@ -17,15 +17,15 @@ silent = 1 MAGIC = imp.get_magic() if not silent: - print 'Using MAGIC word', repr(MAGIC) + print('Using MAGIC word', repr(MAGIC)) for dirname in sys.path: try: names = os.listdir(dirname) except os.error: - print 'Cannot list directory', repr(dirname) + print('Cannot list directory', repr(dirname)) continue if not silent: - print 'Checking ', repr(dirname), '...' + print('Checking ', repr(dirname), '...') names.sort() for name in names: if name[-3:] == '.py': @@ -33,29 +33,29 @@ try: st = os.stat(name) except os.error: - print 'Cannot stat', repr(name) + print('Cannot stat', repr(name)) continue if verbose: - print 'Check', repr(name), '...' + print('Check', repr(name), '...') name_c = name + 'c' try: f = open(name_c, 'r') except IOError: - print 'Cannot open', repr(name_c) + print('Cannot open', repr(name_c)) continue magic_str = f.read(4) mtime_str = f.read(4) f.close() if magic_str <> MAGIC: - print 'Bad MAGIC word in ".pyc" file', - print repr(name_c) + print('Bad MAGIC word in ".pyc" file', end=' ') + print(repr(name_c)) continue mtime = get_long(mtime_str) if mtime == 0 or mtime == -1: - print 'Bad ".pyc" file', repr(name_c) + print('Bad ".pyc" file', repr(name_c)) elif mtime <> st[ST_MTIME]: - print 'Out-of-date ".pyc" file', - print repr(name_c) + print('Out-of-date ".pyc" file', end=' ') + print(repr(name_c)) def get_long(s): if len(s) <> 4: Modified: python/branches/py3k-struni/Tools/scripts/cleanfuture.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/cleanfuture.py (original) +++ python/branches/py3k-struni/Tools/scripts/cleanfuture.py Fri Aug 3 19:06:41 2007 @@ -78,7 +78,7 @@ def check(file): if os.path.isdir(file) and not os.path.islink(file): if verbose: - print "listing directory", file + print("listing directory", file) names = os.listdir(file) for name in names: fullname = os.path.join(file, name) @@ -89,7 +89,7 @@ return if verbose: - print "checking", file, "...", + print("checking", file, "...", end=' ') try: f = open(file) except IOError as msg: @@ -103,33 +103,33 @@ f.close() if changed: if verbose: - print "changed." + print("changed.") if dryrun: - print "But this is a dry run, so leaving it alone." + print("But this is a dry run, so leaving it alone.") for s, e, line in changed: - print "%r lines %d-%d" % (file, s+1, e+1) + print("%r lines %d-%d" % (file, s+1, e+1)) for i in range(s, e+1): - print ff.lines[i], + print(ff.lines[i], end=' ') if line is None: - print "-- deleted" + print("-- deleted") else: - print "-- change to:" - print line, + print("-- change to:") + print(line, end=' ') if not dryrun: bak = file + ".bak" if os.path.exists(bak): os.remove(bak) os.rename(file, bak) if verbose: - print "renamed", file, "to", bak + print("renamed", file, "to", bak) g = open(file, "w") ff.write(g) g.close() if verbose: - print "wrote new", file + print("wrote new", file) else: if verbose: - print "unchanged." + print("unchanged.") class FutureFinder: Modified: python/branches/py3k-struni/Tools/scripts/combinerefs.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/combinerefs.py (original) +++ python/branches/py3k-struni/Tools/scripts/combinerefs.py Fri Aug 3 19:06:41 2007 @@ -102,7 +102,7 @@ addr, addr2rc[addr], addr2guts[addr] = m.groups() before += 1 else: - print '??? skipped:', line + print('??? skipped:', line) after = 0 for line in read(fi, crack, True): @@ -111,17 +111,17 @@ assert m addr, rc, guts = m.groups() # guts is type name here if addr not in addr2rc: - print '??? new object created while tearing down:', line.rstrip() + print('??? new object created while tearing down:', line.rstrip()) continue - print addr, + print(addr, end=' ') if rc == addr2rc[addr]: - print '[%s]' % rc, + print('[%s]' % rc, end=' ') else: - print '[%s->%s]' % (addr2rc[addr], rc), - print guts, addr2guts[addr] + print('[%s->%s]' % (addr2rc[addr], rc), end=' ') + print(guts, addr2guts[addr]) f.close() - print "%d objects before, %d after" % (before, after) + print("%d objects before, %d after" % (before, after)) if __name__ == '__main__': combine(sys.argv[1]) Modified: python/branches/py3k-struni/Tools/scripts/crlf.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/crlf.py (original) +++ python/branches/py3k-struni/Tools/scripts/crlf.py Fri Aug 3 19:06:41 2007 @@ -6,15 +6,15 @@ def main(): for filename in sys.argv[1:]: if os.path.isdir(filename): - print filename, "Directory!" + print(filename, "Directory!") continue data = open(filename, "rb").read() if '\0' in data: - print filename, "Binary!" + print(filename, "Binary!") continue newdata = data.replace("\r\n", "\n") if newdata != data: - print filename + print(filename) f = open(filename, "wb") f.write(newdata) f.close() Modified: python/branches/py3k-struni/Tools/scripts/cvsfiles.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/cvsfiles.py (original) +++ python/branches/py3k-struni/Tools/scripts/cvsfiles.py Fri Aug 3 19:06:41 2007 @@ -21,8 +21,8 @@ try: opts, args = getopt.getopt(sys.argv[1:], "n:") except getopt.error as msg: - print msg - print __doc__, + print(msg) + print(__doc__, end=' ') return 1 global cutofftime newerfile = None @@ -57,7 +57,7 @@ if cutofftime and getmtime(fullname) <= cutofftime: pass else: - print fullname + print(fullname) for sub in subdirs: process(sub) Modified: python/branches/py3k-struni/Tools/scripts/dutree.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/dutree.py (original) +++ python/branches/py3k-struni/Tools/scripts/dutree.py Fri Aug 3 19:06:41 2007 @@ -51,7 +51,7 @@ if tsub is None: psub = prefix else: - print prefix + repr(tsub).rjust(width) + ' ' + key + print(prefix + repr(tsub).rjust(width) + ' ' + key) psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1) if d.has_key(key): show(tsub, d[key][1], psub) Modified: python/branches/py3k-struni/Tools/scripts/finddiv.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/finddiv.py (original) +++ python/branches/py3k-struni/Tools/scripts/finddiv.py Fri Aug 3 19:06:41 2007 @@ -32,7 +32,7 @@ listnames = 0 for o, a in opts: if o == "-h": - print __doc__ + print(__doc__) return if o == "-l": listnames = 1 @@ -60,11 +60,11 @@ for type, token, (row, col), end, line in g: if token in ("/", "/="): if listnames: - print filename + print(filename) break if row != lastrow: lastrow = row - print "%s:%d:%s" % (filename, row, line), + print("%s:%d:%s" % (filename, row, line), end=' ') fp.close() def processdir(dir, listnames): Modified: python/branches/py3k-struni/Tools/scripts/findlinksto.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/findlinksto.py (original) +++ python/branches/py3k-struni/Tools/scripts/findlinksto.py Fri Aug 3 19:06:41 2007 @@ -16,8 +16,8 @@ raise getopt.GetoptError('not enough arguments', None) except getopt.GetoptError as msg: sys.stdout = sys.stderr - print msg - print 'usage: findlinksto pattern directory ...' + print(msg) + print('usage: findlinksto pattern directory ...') sys.exit(2) pat, dirs = args[0], args[1:] prog = re.compile(pat) @@ -29,13 +29,13 @@ names[:] = [] return if os.path.ismount(dirname): - print 'descend into', dirname + print('descend into', dirname) for name in names: name = os.path.join(dirname, name) try: linkto = os.readlink(name) if prog.search(linkto) is not None: - print name, '->', linkto + print(name, '->', linkto) except os.error: pass Modified: python/branches/py3k-struni/Tools/scripts/findnocoding.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/findnocoding.py (original) +++ python/branches/py3k-struni/Tools/scripts/findnocoding.py Fri Aug 3 19:06:41 2007 @@ -28,8 +28,8 @@ pysource = pysource() - print >>sys.stderr, ("The pysource module is not available; " - "no sophisticated Python source file search will be done.") + print("The pysource module is not available; " + "no sophisticated Python source file search will be done.", file=sys.stderr) decl_re = re.compile(r"coding[=:]\s*([-\w.]+)") @@ -79,8 +79,8 @@ try: opts, args = getopt.getopt(sys.argv[1:], 'cd') except getopt.error as msg: - print >>sys.stderr, msg - print >>sys.stderr, usage + print(msg, file=sys.stderr) + print(usage, file=sys.stderr) sys.exit(1) is_python = pysource.looks_like_python @@ -93,12 +93,12 @@ debug = True if not args: - print >>sys.stderr, usage + print(usage, file=sys.stderr) sys.exit(1) for fullpath in pysource.walk_python_files(args, is_python): if debug: - print "Testing for coding: %s" % fullpath + print("Testing for coding: %s" % fullpath) result = needs_declaration(fullpath) if result: - print fullpath + print(fullpath) Modified: python/branches/py3k-struni/Tools/scripts/fixcid.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/fixcid.py (original) +++ python/branches/py3k-struni/Tools/scripts/fixcid.py Fri Aug 3 19:06:41 2007 @@ -244,7 +244,7 @@ subst = Dict[found] if Program is InsideCommentProgram: if not Docomments: - print 'Found in comment:', found + print('Found in comment:', found) i = i + n continue if NotInComment.has_key(found): Modified: python/branches/py3k-struni/Tools/scripts/fixdiv.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/fixdiv.py (original) +++ python/branches/py3k-struni/Tools/scripts/fixdiv.py Fri Aug 3 19:06:41 2007 @@ -145,7 +145,7 @@ return 2 for o, a in opts: if o == "-h": - print __doc__ + print(__doc__) return if o == "-m": global multi_ok @@ -160,7 +160,7 @@ return 1 files = warnings.keys() if not files: - print "No classic division warnings read from", args[0] + print("No classic division warnings read from", args[0]) return files.sort() exit = None @@ -203,14 +203,14 @@ return warnings def process(filename, list): - print "-"*70 + print("-"*70) assert list # if this fails, readwarnings() is broken try: fp = open(filename) except IOError as msg: sys.stderr.write("can't open: %s\n" % msg) return 1 - print "Index:", filename + print("Index:", filename) f = FileContext(fp) list.sort() index = 0 # list[:index] has been processed, list[index:] is still to do @@ -248,10 +248,10 @@ lastrow = row assert rows if len(rows) == 1: - print "*** More than one / operator in line", rows[0] + print("*** More than one / operator in line", rows[0]) else: - print "*** More than one / operator per statement", - print "in lines %d-%d" % (rows[0], rows[-1]) + print("*** More than one / operator per statement", end=' ') + print("in lines %d-%d" % (rows[0], rows[-1])) intlong = [] floatcomplex = [] bad = [] @@ -269,24 +269,24 @@ lastrow = row line = chop(line) if line[col:col+1] != "/": - print "*** Can't find the / operator in line %d:" % row - print "*", line + print("*** Can't find the / operator in line %d:" % row) + print("*", line) continue if bad: - print "*** Bad warning for line %d:" % row, bad - print "*", line + print("*** Bad warning for line %d:" % row, bad) + print("*", line) elif intlong and not floatcomplex: - print "%dc%d" % (row, row) - print "<", line - print "---" - print ">", line[:col] + "/" + line[col:] + print("%dc%d" % (row, row)) + print("<", line) + print("---") + print(">", line[:col] + "/" + line[col:]) elif floatcomplex and not intlong: - print "True division / operator at line %d:" % row - print "=", line + print("True division / operator at line %d:" % row) + print("=", line) elif intlong and floatcomplex: - print "*** Ambiguous / operator (%s, %s) at line %d:" % ( - "|".join(intlong), "|".join(floatcomplex), row) - print "?", line + print("*** Ambiguous / operator (%s, %s) at line %d:" % ( + "|".join(intlong), "|".join(floatcomplex), row)) + print("?", line) fp.close() def reportphantomwarnings(warnings, f): @@ -301,15 +301,15 @@ for block in blocks: row = block[0] whats = "/".join(block[1:]) - print "*** Phantom %s warnings for line %d:" % (whats, row) + print("*** Phantom %s warnings for line %d:" % (whats, row)) f.report(row, mark="*") def report(slashes, message): lastrow = None for (row, col), line in slashes: if row != lastrow: - print "*** %s on line %d:" % (message, row) - print "*", chop(line) + print("*** %s on line %d:" % (message, row)) + print("*", chop(line)) lastrow = row class FileContext: @@ -354,7 +354,7 @@ line = self[first] except KeyError: line = "" - print mark, chop(line) + print(mark, chop(line)) def scanline(g): slashes = [] Modified: python/branches/py3k-struni/Tools/scripts/fixheader.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/fixheader.py (original) +++ python/branches/py3k-struni/Tools/scripts/fixheader.py Fri Aug 3 19:06:41 2007 @@ -32,18 +32,18 @@ magic = magic + c.upper() else: magic = magic + '_' sys.stdout = f - print '#ifndef', magic - print '#define', magic - print '#ifdef __cplusplus' - print 'extern "C" {' - print '#endif' - print + print('#ifndef', magic) + print('#define', magic) + print('#ifdef __cplusplus') + print('extern "C" {') + print('#endif') + print() f.write(data) - print - print '#ifdef __cplusplus' - print '}' - print '#endif' - print '#endif /*', '!'+magic, '*/' + print() + print('#ifdef __cplusplus') + print('}') + print('#endif') + print('#endif /*', '!'+magic, '*/') if __name__ == '__main__': main() Modified: python/branches/py3k-struni/Tools/scripts/fixnotice.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/fixnotice.py (original) +++ python/branches/py3k-struni/Tools/scripts/fixnotice.py Fri Aug 3 19:06:41 2007 @@ -50,9 +50,9 @@ def usage(code, msg=''): - print __doc__ % globals() + print(__doc__ % globals()) if msg: - print msg + print(msg) sys.exit(code) @@ -92,10 +92,10 @@ i = data.find(OLD_NOTICE) if i < 0: if VERBOSE: - print 'no change:', file + print('no change:', file) return elif DRYRUN or VERBOSE: - print ' change:', file + print(' change:', file) if DRYRUN: # Don't actually change the file return Modified: python/branches/py3k-struni/Tools/scripts/fixps.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/fixps.py (original) +++ python/branches/py3k-struni/Tools/scripts/fixps.py Fri Aug 3 19:06:41 2007 @@ -12,18 +12,18 @@ try: f = open(filename, 'r') except IOError as msg: - print filename, ': can\'t open :', msg + print(filename, ': can\'t open :', msg) continue line = f.readline() if not re.match('^#! */usr/local/bin/python', line): - print filename, ': not a /usr/local/bin/python script' + print(filename, ': not a /usr/local/bin/python script') f.close() continue rest = f.read() f.close() line = re.sub('/usr/local/bin/python', '/usr/bin/env python', line) - print filename, ':', repr(line) + print(filename, ':', repr(line)) f = open(filename, "w") f.write(line) f.write(rest) Modified: python/branches/py3k-struni/Tools/scripts/ftpmirror.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/ftpmirror.py (original) +++ python/branches/py3k-struni/Tools/scripts/ftpmirror.py Fri Aug 3 19:06:41 2007 @@ -29,8 +29,8 @@ # Print usage message and exit def usage(*args): sys.stdout = sys.stderr - for msg in args: print msg - print __doc__ + for msg in args: print(msg) + print(__doc__) sys.exit(2) verbose = 1 # 0 for -q, 2 for -v @@ -82,22 +82,22 @@ if args[3:]: usage('too many arguments') # f = ftplib.FTP() - if verbose: print "Connecting to '%s%s'..." % (host, - (port and ":%d"%port or "")) + if verbose: print("Connecting to '%s%s'..." % (host, + (port and ":%d"%port or ""))) f.connect(host,port) if not nologin: if verbose: - print 'Logging in as %r...' % (login or 'anonymous') + print('Logging in as %r...' % (login or 'anonymous')) f.login(login, passwd, account) - if verbose: print 'OK.' + if verbose: print('OK.') pwd = f.pwd() - if verbose > 1: print 'PWD =', repr(pwd) + if verbose > 1: print('PWD =', repr(pwd)) if remotedir: - if verbose > 1: print 'cwd(%s)' % repr(remotedir) + if verbose > 1: print('cwd(%s)' % repr(remotedir)) f.cwd(remotedir) - if verbose > 1: print 'OK.' + if verbose > 1: print('OK.') pwd = f.pwd() - if verbose > 1: print 'PWD =', repr(pwd) + if verbose > 1: print('PWD =', repr(pwd)) # mirrorsubdir(f, localdir) @@ -105,11 +105,11 @@ def mirrorsubdir(f, localdir): pwd = f.pwd() if localdir and not os.path.isdir(localdir): - if verbose: print 'Creating local directory', repr(localdir) + if verbose: print('Creating local directory', repr(localdir)) try: makedir(localdir) except os.error as msg: - print "Failed to establish local directory", repr(localdir) + print("Failed to establish local directory", repr(localdir)) return infofilename = os.path.join(localdir, '.mirrorinfo') try: @@ -119,15 +119,15 @@ try: info = eval(text) except (SyntaxError, NameError): - print 'Bad mirror info in', repr(infofilename) + print('Bad mirror info in', repr(infofilename)) info = {} subdirs = [] listing = [] - if verbose: print 'Listing remote directory %r...' % (pwd,) + if verbose: print('Listing remote directory %r...' % (pwd,)) f.retrlines('LIST', listing.append) filesfound = [] for line in listing: - if verbose > 1: print '-->', repr(line) + if verbose > 1: print('-->', repr(line)) if mac: # Mac listing has just filenames; # trailing / means subdirectory @@ -141,14 +141,14 @@ # Parse, assuming a UNIX listing words = line.split(None, 8) if len(words) < 6: - if verbose > 1: print 'Skipping short line' + if verbose > 1: print('Skipping short line') continue filename = words[-1].lstrip() i = filename.find(" -> ") if i >= 0: # words[0] had better start with 'l'... if verbose > 1: - print 'Found symbolic link %r' % (filename,) + print('Found symbolic link %r' % (filename,)) linkto = filename[i+4:] filename = filename[:i] infostuff = words[-5:-1] @@ -157,21 +157,21 @@ for pat in skippats: if fnmatch(filename, pat): if verbose > 1: - print 'Skip pattern', repr(pat), - print 'matches', repr(filename) + print('Skip pattern', repr(pat), end=' ') + print('matches', repr(filename)) skip = 1 break if skip: continue if mode[0] == 'd': if verbose > 1: - print 'Remembering subdirectory', repr(filename) + print('Remembering subdirectory', repr(filename)) subdirs.append(filename) continue filesfound.append(filename) if info.has_key(filename) and info[filename] == infostuff: if verbose > 1: - print 'Already have this version of',repr(filename) + print('Already have this version of',repr(filename)) continue fullname = os.path.join(localdir, filename) tempname = os.path.join(localdir, '@'+filename) @@ -187,20 +187,20 @@ pass if mode[0] == 'l': if verbose: - print "Creating symlink %r -> %r" % (filename, linkto) + print("Creating symlink %r -> %r" % (filename, linkto)) try: os.symlink(linkto, tempname) except IOError as msg: - print "Can't create %r: %s" % (tempname, msg) + print("Can't create %r: %s" % (tempname, msg)) continue else: try: fp = open(tempname, 'wb') except IOError as msg: - print "Can't create %r: %s" % (tempname, msg) + print("Can't create %r: %s" % (tempname, msg)) continue if verbose: - print 'Retrieving %r from %r as %r...' % (filename, pwd, fullname) + print('Retrieving %r from %r as %r...' % (filename, pwd, fullname)) if verbose: fp1 = LoggingFile(fp, 1024, sys.stdout) else: @@ -210,7 +210,7 @@ f.retrbinary('RETR ' + filename, fp1.write, 8*1024) except ftplib.error_perm as msg: - print msg + print(msg) t1 = time.time() bytes = fp.tell() fp.close() @@ -223,29 +223,29 @@ try: os.rename(tempname, fullname) except os.error as msg: - print "Can't rename %r to %r: %s" % (tempname, fullname, msg) + print("Can't rename %r to %r: %s" % (tempname, fullname, msg)) continue info[filename] = infostuff writedict(info, infofilename) if verbose and mode[0] != 'l': dt = t1 - t0 kbytes = bytes / 1024.0 - print int(round(kbytes)), - print 'Kbytes in', - print int(round(dt)), - print 'seconds', + print(int(round(kbytes)), end=' ') + print('Kbytes in', end=' ') + print(int(round(dt)), end=' ') + print('seconds', end=' ') if t1 > t0: - print '(~%d Kbytes/sec)' % \ - int(round(kbytes/dt),) - print + print('(~%d Kbytes/sec)' % \ + int(round(kbytes/dt),)) + print() # # Remove files from info that are no longer remote deletions = 0 for filename in info.keys(): if filename not in filesfound: if verbose: - print "Removing obsolete info entry for", - print repr(filename), "in", repr(localdir or ".") + print("Removing obsolete info entry for", end=' ') + print(repr(filename), "in", repr(localdir or ".")) del info[filename] deletions = deletions + 1 if deletions: @@ -264,8 +264,8 @@ for pat in skippats: if fnmatch(name, pat): if verbose > 1: - print 'Skip pattern', repr(pat), - print 'matches', repr(name) + print('Skip pattern', repr(pat), end=' ') + print('matches', repr(name)) skip = 1 break if skip: @@ -273,10 +273,10 @@ fullname = os.path.join(localdir, name) if not rmok: if verbose: - print 'Local file', repr(fullname), - print 'is no longer pertinent' + print('Local file', repr(fullname), end=' ') + print('is no longer pertinent') continue - if verbose: print 'Removing local file/dir', repr(fullname) + if verbose: print('Removing local file/dir', repr(fullname)) remove(fullname) # # Recursively mirror subdirectories @@ -284,28 +284,28 @@ if interactive: doit = askabout('subdirectory', subdir, pwd) if not doit: continue - if verbose: print 'Processing subdirectory', repr(subdir) + if verbose: print('Processing subdirectory', repr(subdir)) localsubdir = os.path.join(localdir, subdir) pwd = f.pwd() if verbose > 1: - print 'Remote directory now:', repr(pwd) - print 'Remote cwd', repr(subdir) + print('Remote directory now:', repr(pwd)) + print('Remote cwd', repr(subdir)) try: f.cwd(subdir) except ftplib.error_perm as msg: - print "Can't chdir to", repr(subdir), ":", repr(msg) + print("Can't chdir to", repr(subdir), ":", repr(msg)) else: - if verbose: print 'Mirroring as', repr(localsubdir) + if verbose: print('Mirroring as', repr(localsubdir)) mirrorsubdir(f, localsubdir) - if verbose > 1: print 'Remote cwd ..' + if verbose > 1: print('Remote cwd ..') f.cwd('..') newpwd = f.pwd() if newpwd != pwd: - print 'Ended up in wrong directory after cd + cd ..' - print 'Giving up now.' + print('Ended up in wrong directory after cd + cd ..') + print('Giving up now.') break else: - if verbose > 1: print 'OK.' + if verbose > 1: print('OK.') # Helper to remove a file or directory tree def remove(fullname): @@ -323,13 +323,13 @@ try: os.rmdir(fullname) except os.error as msg: - print "Can't remove local directory %r: %s" % (fullname, msg) + print("Can't remove local directory %r: %s" % (fullname, msg)) return 0 else: try: os.unlink(fullname) except os.error as msg: - print "Can't remove local file %r: %s" % (fullname, msg) + print("Can't remove local file %r: %s" % (fullname, msg)) return 0 return 1 @@ -366,7 +366,7 @@ return 1 if reply in ['', 'n', 'no', 'nop', 'nope']: return 0 - print 'Please answer yes or no.' + print('Please answer yes or no.') # Create a directory if it doesn't exist. Recursively create the # parent directory as well if needed. Modified: python/branches/py3k-struni/Tools/scripts/google.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/google.py (original) +++ python/branches/py3k-struni/Tools/scripts/google.py Fri Aug 3 19:06:41 2007 @@ -5,7 +5,7 @@ def main(): args = sys.argv[1:] if not args: - print "Usage: %s querystring" % sys.argv[0] + print("Usage: %s querystring" % sys.argv[0]) return list = [] for arg in args: Modified: python/branches/py3k-struni/Tools/scripts/lfcr.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/lfcr.py (original) +++ python/branches/py3k-struni/Tools/scripts/lfcr.py Fri Aug 3 19:06:41 2007 @@ -7,15 +7,15 @@ def main(): for filename in sys.argv[1:]: if os.path.isdir(filename): - print filename, "Directory!" + print(filename, "Directory!") continue data = open(filename, "rb").read() if '\0' in data: - print filename, "Binary!" + print(filename, "Binary!") continue newdata = re.sub("\r?\n", "\r\n", data) if newdata != data: - print filename + print(filename) f = open(filename, "wb") f.write(newdata) f.close() Modified: python/branches/py3k-struni/Tools/scripts/linktree.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/linktree.py (original) +++ python/branches/py3k-struni/Tools/scripts/linktree.py Fri Aug 3 19:06:41 2007 @@ -18,7 +18,7 @@ def main(): if not 3 <= len(sys.argv) <= 4: - print 'usage:', sys.argv[0], 'oldtree newtree [linkto]' + print('usage:', sys.argv[0], 'oldtree newtree [linkto]') return 2 oldtree, newtree = sys.argv[1], sys.argv[2] if len(sys.argv) > 3: @@ -28,46 +28,46 @@ link = LINK link_may_fail = 0 if not os.path.isdir(oldtree): - print oldtree + ': not a directory' + print(oldtree + ': not a directory') return 1 try: os.mkdir(newtree, 0o777) except os.error as msg: - print newtree + ': cannot mkdir:', msg + print(newtree + ': cannot mkdir:', msg) return 1 linkname = os.path.join(newtree, link) try: os.symlink(os.path.join(os.pardir, oldtree), linkname) except os.error as msg: if not link_may_fail: - print linkname + ': cannot symlink:', msg + print(linkname + ': cannot symlink:', msg) return 1 else: - print linkname + ': warning: cannot symlink:', msg + print(linkname + ': warning: cannot symlink:', msg) linknames(oldtree, newtree, link) return 0 def linknames(old, new, link): - if debug: print 'linknames', (old, new, link) + if debug: print('linknames', (old, new, link)) try: names = os.listdir(old) except os.error as msg: - print old + ': warning: cannot listdir:', msg + print(old + ': warning: cannot listdir:', msg) return for name in names: if name not in (os.curdir, os.pardir): oldname = os.path.join(old, name) linkname = os.path.join(link, name) newname = os.path.join(new, name) - if debug > 1: print oldname, newname, linkname + if debug > 1: print(oldname, newname, linkname) if os.path.isdir(oldname) and \ not os.path.islink(oldname): try: os.mkdir(newname, 0o777) ok = 1 except: - print newname + \ - ': warning: cannot mkdir:', msg + print(newname + \ + ': warning: cannot mkdir:', msg) ok = 0 if ok: linkname = os.path.join(os.pardir, Modified: python/branches/py3k-struni/Tools/scripts/lll.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/lll.py (original) +++ python/branches/py3k-struni/Tools/scripts/lll.py Fri Aug 3 19:06:41 2007 @@ -12,16 +12,16 @@ if name not in (os.curdir, os.pardir): full = os.path.join(dirname, name) if os.path.islink(full): - print name, '->', os.readlink(full) + print(name, '->', os.readlink(full)) def main(): args = sys.argv[1:] if not args: args = [os.curdir] first = 1 for arg in args: if len(args) > 1: - if not first: print + if not first: print() first = 0 - print arg + ':' + print(arg + ':') lll(arg) if __name__ == '__main__': Modified: python/branches/py3k-struni/Tools/scripts/logmerge.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/logmerge.py (original) +++ python/branches/py3k-struni/Tools/scripts/logmerge.py Fri Aug 3 19:06:41 2007 @@ -53,7 +53,7 @@ elif o == '-b': branch = a elif o == '-h': - print __doc__ + print(__doc__) sys.exit(0) database = [] while 1: @@ -169,9 +169,9 @@ for (date, working_file, rev, author, text) in database: if text != prevtext: if prev: - print sep2, + print(sep2, end=' ') for (p_date, p_working_file, p_rev, p_author) in prev: - print p_date, p_author, p_working_file, p_rev + print(p_date, p_author, p_working_file, p_rev) sys.stdout.writelines(prevtext) prev = [] prev.append((date, working_file, rev, author)) Modified: python/branches/py3k-struni/Tools/scripts/mailerdaemon.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/mailerdaemon.py (original) +++ python/branches/py3k-struni/Tools/scripts/mailerdaemon.py Fri Aug 3 19:06:41 2007 @@ -171,11 +171,11 @@ fp = open(fn) m = ErrorMessage(fp) sender = m.getaddr('From') - print '%s\t%-40s\t'%(fn, sender[1]), + print('%s\t%-40s\t'%(fn, sender[1]), end=' ') if m.is_warning(): fp.close() - print 'warning only' + print('warning only') nwarn = nwarn + 1 if modify: os.rename(fn, ','+fn) @@ -185,11 +185,11 @@ try: errors = m.get_errors() except Unparseable: - print '** Not parseable' + print('** Not parseable') nbad = nbad + 1 fp.close() continue - print len(errors), 'errors' + print(len(errors), 'errors') # Remember them for e in errors: @@ -211,16 +211,16 @@ os.rename(fn, ','+fn) ## os.unlink(fn) - print '--------------' - print nok, 'files parsed,',nwarn,'files warning-only,', - print nbad,'files unparseable' - print '--------------' + print('--------------') + print(nok, 'files parsed,',nwarn,'files warning-only,', end=' ') + print(nbad,'files unparseable') + print('--------------') list = [] for e in errordict.keys(): list.append((errordict[e], errorfirst[e], errorlast[e], e)) list.sort() for num, first, last, e in list: - print '%d %s - %s\t%s' % (num, first, last, e) + print('%d %s - %s\t%s' % (num, first, last, e)) def main(): modify = 0 Modified: python/branches/py3k-struni/Tools/scripts/mkreal.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/mkreal.py (original) +++ python/branches/py3k-struni/Tools/scripts/mkreal.py Fri Aug 3 19:06:41 2007 @@ -48,12 +48,12 @@ if progname == '-c': progname = 'mkreal' args = sys.argv[1:] if not args: - print 'usage:', progname, 'path ...' + print('usage:', progname, 'path ...') sys.exit(2) status = 0 for name in args: if not os.path.islink(name): - print progname+':', name+':', 'not a symlink' + print(progname+':', name+':', 'not a symlink') status = 1 else: if os.path.isdir(name): Modified: python/branches/py3k-struni/Tools/scripts/ndiff.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/ndiff.py (original) +++ python/branches/py3k-struni/Tools/scripts/ndiff.py Fri Aug 3 19:06:41 2007 @@ -74,7 +74,7 @@ a = f1.readlines(); f1.close() b = f2.readlines(); f2.close() for line in difflib.ndiff(a, b): - print line, + print(line, end=' ') return 1 @@ -109,8 +109,8 @@ return fail("need 2 filename args") f1name, f2name = args if noisy: - print '-:', f1name - print '+:', f2name + print('-:', f1name) + print('+:', f2name) return fcompare(f1name, f2name) # read ndiff output from stdin, and print file1 (which=='1') or Modified: python/branches/py3k-struni/Tools/scripts/objgraph.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/objgraph.py (original) +++ python/branches/py3k-struni/Tools/scripts/objgraph.py Fri Aug 3 19:06:41 2007 @@ -80,7 +80,7 @@ store(file2undef, fn, name) store(undef2file, name, fn) elif not type in ignore: - print fn + ':' + name + ': unknown type ' + type + print(fn + ':' + name + ': unknown type ' + type) # Print all names that were undefined in some module and where they are # defined. @@ -89,7 +89,7 @@ flist = file2undef.keys() flist.sort() for filename in flist: - print filename + ':' + print(filename + ':') elist = file2undef[filename] elist.sort() for ext in elist: @@ -98,9 +98,9 @@ else: tabs = '\t\t' if not def2file.has_key(ext): - print '\t' + ext + tabs + ' *undefined' + print('\t' + ext + tabs + ' *undefined') else: - print '\t' + ext + tabs + flat(def2file[ext]) + print('\t' + ext + tabs + flat(def2file[ext])) # Print for each module the names of the other modules that use it. # @@ -114,14 +114,14 @@ callers = callers + undef2file[label] if callers: callers.sort() - print filename + ':' + print(filename + ':') lastfn = '' for fn in callers: if fn <> lastfn: - print '\t' + fn + print('\t' + fn) lastfn = fn else: - print filename + ': unused' + print(filename + ': unused') # Print undefined names and where they are used. # @@ -134,11 +134,11 @@ elist = undefs.keys() elist.sort() for ext in elist: - print ext + ':' + print(ext + ':') flist = undefs[ext] flist.sort() for filename in flist: - print '\t' + filename + print('\t' + filename) # Print warning messages about names defined in more than one file. # @@ -149,8 +149,8 @@ names.sort() for name in names: if len(def2file[name]) > 1: - print 'warning:', name, 'multiply defined:', - print flat(def2file[name]) + print('warning:', name, 'multiply defined:', end=' ') + print(flat(def2file[name])) sys.stdout = savestdout # Main program @@ -160,14 +160,14 @@ optlist, args = getopt.getopt(sys.argv[1:], 'cdu') except getopt.error: sys.stdout = sys.stderr - print 'Usage:', os.path.basename(sys.argv[0]), - print '[-cdu] [file] ...' - print '-c: print callers per objectfile' - print '-d: print callees per objectfile' - print '-u: print usage of undefined symbols' - print 'If none of -cdu is specified, all are assumed.' - print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),' - print 'e.g.: nm -o /lib/libc.a | objgraph' + print('Usage:', os.path.basename(sys.argv[0]), end=' ') + print('[-cdu] [file] ...') + print('-c: print callers per objectfile') + print('-d: print callees per objectfile') + print('-u: print usage of undefined symbols') + print('If none of -cdu is specified, all are assumed.') + print('Use "nm -o" to generate the input (on IRIX: "nm -Bo"),') + print('e.g.: nm -o /lib/libc.a | objgraph') return 1 optu = optc = optd = 0 for opt, void in optlist: @@ -192,15 +192,15 @@ more = (optu + optc + optd > 1) if optd: if more: - print '---------------All callees------------------' + print('---------------All callees------------------') printcallee() if optu: if more: - print '---------------Undefined callees------------' + print('---------------Undefined callees------------') printundef() if optc: if more: - print '---------------All Callers------------------' + print('---------------All Callers------------------') printcaller() return 0 Modified: python/branches/py3k-struni/Tools/scripts/pdeps.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/pdeps.py (original) +++ python/branches/py3k-struni/Tools/scripts/pdeps.py Fri Aug 3 19:06:41 2007 @@ -30,25 +30,25 @@ def main(): args = sys.argv[1:] if not args: - print 'usage: pdeps file.py file.py ...' + print('usage: pdeps file.py file.py ...') return 2 # table = {} for arg in args: process(arg, table) # - print '--- Uses ---' + print('--- Uses ---') printresults(table) # - print '--- Used By ---' + print('--- Used By ---') inv = inverse(table) printresults(inv) # - print '--- Closure of Uses ---' + print('--- Closure of Uses ---') reach = closure(table) printresults(reach) # - print '--- Closure of Used By ---' + print('--- Closure of Used By ---') invreach = inverse(reach) printresults(invreach) # @@ -151,12 +151,12 @@ for mod in modules: list = table[mod] list.sort() - print mod.ljust(maxlen), ':', + print(mod.ljust(maxlen), ':', end=' ') if mod in list: - print '(*)', + print('(*)', end=' ') for ref in list: - print ref, - print + print(ref, end=' ') + print() # Call main and honor exit status Modified: python/branches/py3k-struni/Tools/scripts/pysource.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/pysource.py (original) +++ python/branches/py3k-struni/Tools/scripts/pysource.py Fri Aug 3 19:06:41 2007 @@ -27,7 +27,7 @@ debug = False def print_debug(msg): - if debug: print msg + if debug: print(msg) def _open(fullpath): @@ -124,7 +124,7 @@ if __name__ == "__main__": # Two simple examples/tests for fullpath in walk_python_files(['.']): - print fullpath - print "----------" + print(fullpath) + print("----------") for fullpath in walk_python_files(['.'], is_python=can_be_compiled): - print fullpath + print(fullpath) Modified: python/branches/py3k-struni/Tools/scripts/rgrep.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/rgrep.py (original) +++ python/branches/py3k-struni/Tools/scripts/rgrep.py Fri Aug 3 19:06:41 2007 @@ -52,12 +52,12 @@ lines.reverse() for line in lines: if prog.search(line): - print line + print(line) def usage(msg, code=2): sys.stdout = sys.stderr - print msg - print __doc__ + print(msg) + print(__doc__) sys.exit(code) if __name__ == '__main__': Modified: python/branches/py3k-struni/Tools/scripts/suff.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/suff.py (original) +++ python/branches/py3k-struni/Tools/scripts/suff.py Fri Aug 3 19:06:41 2007 @@ -17,7 +17,7 @@ keys = suffixes.keys() keys.sort() for suff in keys: - print repr(suff), len(suffixes[suff]) + print(repr(suff), len(suffixes[suff])) def getsuffix(filename): suff = '' Modified: python/branches/py3k-struni/Tools/scripts/texcheck.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/texcheck.py (original) +++ python/branches/py3k-struni/Tools/scripts/texcheck.py Fri Aug 3 19:06:41 2007 @@ -65,10 +65,10 @@ try: o_lineno, o_symbol = openers.pop() except IndexError: - print "\nDelimiter mismatch. On line %d, encountered closing '%s' without corresponding open" % (c_lineno, c_symbol) + print("\nDelimiter mismatch. On line %d, encountered closing '%s' without corresponding open" % (c_lineno, c_symbol)) return if o_symbol in pairmap.get(c_symbol, [c_symbol]): return - print "\nOpener '%s' on line %d was not closed before encountering '%s' on line %d" % (o_symbol, o_lineno, c_symbol, c_lineno) + print("\nOpener '%s' on line %d was not closed before encountering '%s' on line %d" % (o_symbol, o_lineno, c_symbol, c_lineno)) return def checkit(source, opts, morecmds=[]): @@ -120,7 +120,7 @@ # Check balancing of open/close parenthesis, brackets, and begin/end blocks for begend, name, punct in delimiters.findall(line): if '-v' in opts: - print lineno, '|', begend, name, punct, + print(lineno, '|', begend, name, punct, end=' ') if begend == 'begin' and '-d' not in opts: openers.append((lineno, name)) elif punct in openpunct: @@ -130,7 +130,7 @@ elif punct in pairmap: matchclose(lineno, punct, openers, pairmap) if '-v' in opts: - print ' --> ', openers + print(' --> ', openers) # Balance opening and closing braces for open, close in braces.findall(line): @@ -140,7 +140,7 @@ try: bracestack.pop() except IndexError: - print r'Warning, unmatched } on line %s.' % (lineno,) + print(r'Warning, unmatched } on line %s.' % (lineno,)) # Optionally, skip LaTeX specific checks if '-d' in opts: @@ -151,11 +151,11 @@ if '822' in line or '.html' in line: continue # Ignore false positives for urls and for /rfc822 if '\\' + cmd in validcmds: - print 'Warning, forward slash used on line %d with cmd: /%s' % (lineno, cmd) + print('Warning, forward slash used on line %d with cmd: /%s' % (lineno, cmd)) # Check for markup requiring {} for correct spacing for cmd in spacingmarkup.findall(line): - print r'Warning, \%s should be written as \%s{} on line %d' % (cmd, cmd, lineno) + print(r'Warning, \%s should be written as \%s{} on line %d' % (cmd, cmd, lineno)) # Validate commands nc = line.find(r'\newcommand') @@ -165,7 +165,7 @@ validcmds.add(line[start+1:end]) for cmd in texcmd.findall(line): if cmd not in validcmds: - print r'Warning, unknown tex cmd on line %d: \%s' % (lineno, cmd) + print(r'Warning, unknown tex cmd on line %d: \%s' % (lineno, cmd)) # Check table levels (make sure lineii only inside tableii) m = tablestart.search(line) @@ -174,23 +174,23 @@ tablestartline = lineno m = tableline.search(line) if m and m.group(1) != tablelevel: - print r'Warning, \line%s on line %d does not match \table%s on line %d' % (m.group(1), lineno, tablelevel, tablestartline) + print(r'Warning, \line%s on line %d does not match \table%s on line %d' % (m.group(1), lineno, tablelevel, tablestartline)) if tableend.search(line): tablelevel = '' # Style guide warnings if 'e.g.' in line or 'i.e.' in line: - print r'Style warning, avoid use of i.e or e.g. on line %d' % (lineno,) + print(r'Style warning, avoid use of i.e or e.g. on line %d' % (lineno,)) for dw in doubledwords.findall(line): - print r'Doubled word warning. "%s" on line %d' % (dw, lineno) + print(r'Doubled word warning. "%s" on line %d' % (dw, lineno)) lastline = lineno for lineno, symbol in openers: - print "Unmatched open delimiter '%s' on line %d" % (symbol, lineno) + print("Unmatched open delimiter '%s' on line %d" % (symbol, lineno)) for lineno in bracestack: - print "Unmatched { on line %d" % (lineno,) - print 'Done checking %d lines.' % (lastline,) + print("Unmatched { on line %d" % (lineno,)) + print('Done checking %d lines.' % (lastline,)) return 0 def main(args=None): @@ -199,11 +199,11 @@ optitems, arglist = getopt.getopt(args, "k:mdhs:v") opts = dict(optitems) if '-h' in opts or args==[]: - print __doc__ + print(__doc__) return 0 if len(arglist) < 1: - print 'Please specify a file to be checked' + print('Please specify a file to be checked') return 1 for i, filespec in enumerate(arglist): @@ -214,12 +214,12 @@ err = [] for filename in arglist: - print '=' * 30 - print "Checking", filename + print('=' * 30) + print("Checking", filename) try: f = open(filename) except IOError: - print 'Cannot open file %s.' % arglist[0] + print('Cannot open file %s.' % arglist[0]) return 2 try: Modified: python/branches/py3k-struni/Tools/scripts/texi2html.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/texi2html.py (original) +++ python/branches/py3k-struni/Tools/scripts/texi2html.py Fri Aug 3 19:06:41 2007 @@ -275,7 +275,7 @@ if not self.skip: self.process(accu) accu = [] if initial_lineno > 0: - print '*** EOF before @bye' + print('*** EOF before @bye') break lineno = lineno + 1 mo = cmprog.match(line) @@ -306,10 +306,10 @@ accu.append(line) # if self.skip: - print '*** Still skipping at the end' + print('*** Still skipping at the end') if self.stack: - print '*** Stack not empty at the end' - print '***', self.stack + print('*** Stack not empty at the end') + print('***', self.stack) if self.includedepth == 0: while self.nodestack: self.nodestack[-1].finalize() @@ -338,7 +338,7 @@ try: text = ''.join(args) except: - print args + print(args) raise TypeError if self.savetext <> None: self.savetext = self.savetext + text @@ -350,7 +350,7 @@ # Complete the current node -- write footnotes and close file def endnode(self): if self.savetext <> None: - print '*** Still saving text at end of node' + print('*** Still saving text at end of node') dummy = self.collectsavings() if self.footnotes: self.writefootnotes() @@ -382,10 +382,10 @@ # This mostly distinguishes between menus and normal text def process(self, accu): if self.debugging > 1: - print '!'*self.debugging, 'process:', self.skip, self.stack, - if accu: print accu[0][:30], - if accu[0][30:] or accu[1:]: print '...', - print + print('!'*self.debugging, 'process:', self.skip, self.stack, end=' ') + if accu: print(accu[0][:30], end=' ') + if accu[0][30:] or accu[1:]: print('...', end=' ') + print() if self.inmenu(): # XXX should be done differently for line in accu: @@ -461,7 +461,7 @@ continue if c == '}': if not stack: - print '*** Unmatched }' + print('*** Unmatched }') self.write('}') continue cmd = stack[-1] @@ -509,12 +509,12 @@ continue method() if stack: - print '*** Stack not empty at para:', stack + print('*** Stack not empty at para:', stack) # --- Handle unknown embedded @-commands --- def unknown_open(self, cmd): - print '*** No open func for @' + cmd + '{...}' + print('*** No open func for @' + cmd + '{...}') cmd = cmd + '{' self.write('@', cmd) if not self.unknown.has_key(cmd): @@ -523,7 +523,7 @@ self.unknown[cmd] = self.unknown[cmd] + 1 def unknown_close(self, cmd): - print '*** No close func for @' + cmd + '{...}' + print('*** No close func for @' + cmd + '{...}') cmd = '}' + cmd self.write('}') if not self.unknown.has_key(cmd): @@ -532,7 +532,7 @@ self.unknown[cmd] = self.unknown[cmd] + 1 def unknown_handle(self, cmd): - print '*** No handler for @' + cmd + print('*** No handler for @' + cmd) self.write('@', cmd) if not self.unknown.has_key(cmd): self.unknown[cmd] = 1 @@ -555,9 +555,9 @@ try: fp = open(file, 'r') except IOError as msg: - print '*** Can\'t open include file', repr(file) + print('*** Can\'t open include file', repr(file)) return - print '!'*self.debugging, '--> file', repr(file) + print('!'*self.debugging, '--> file', repr(file)) save_done = self.done save_skip = self.skip save_stack = self.stack @@ -568,7 +568,7 @@ self.done = save_done self.skip = save_skip self.stack = save_stack - print '!'*self.debugging, '<-- file', repr(file) + print('!'*self.debugging, '<-- file', repr(file)) # --- Special Insertions --- @@ -764,7 +764,7 @@ elif os.path.exists(imagelocation+'.gif'): # MySQL uses GIF files filename += '.gif' else: - print "*** Cannot find image " + imagelocation + print("*** Cannot find image " + imagelocation) #TODO: what is 'ext'? self.write(' 1: - print '!'*self.debugging, 'command:', self.skip, self.stack, \ - '@' + cmd, args + print('!'*self.debugging, 'command:', self.skip, self.stack, \ + '@' + cmd, args) try: func = getattr(self, 'do_' + cmd) except AttributeError: @@ -890,7 +890,7 @@ func(args) def unknown_cmd(self, cmd, args): - print '*** unknown', '@' + cmd, args + print('*** unknown', '@' + cmd, args) if not self.unknown.has_key(cmd): self.unknown[cmd] = 1 else: @@ -899,11 +899,11 @@ def do_end(self, args): words = args.split() if not words: - print '*** @end w/o args' + print('*** @end w/o args') else: cmd = words[0] if not self.stack or self.stack[-1] <> cmd: - print '*** @end', cmd, 'unexpected' + print('*** @end', cmd, 'unexpected') else: del self.stack[-1] try: @@ -915,7 +915,7 @@ def unknown_end(self, cmd): cmd = 'end ' + cmd - print '*** unknown', '@' + cmd + print('*** unknown', '@' + cmd) if not self.unknown.has_key(cmd): self.unknown[cmd] = 1 else: @@ -965,7 +965,7 @@ self.skip = self.skip - 1 del self.stackinfo[len(self.stack) + 1] except KeyError: - print '*** end_ifset: KeyError :', len(self.stack) + 1 + print('*** end_ifset: KeyError :', len(self.stack) + 1) def bgn_ifclear(self, args): if args in self.values.keys() \ @@ -980,7 +980,7 @@ self.skip = self.skip - 1 del self.stackinfo[len(self.stack) + 1] except KeyError: - print '*** end_ifclear: KeyError :', len(self.stack) + 1 + print('*** end_ifclear: KeyError :', len(self.stack) + 1) def open_value(self): self.startsaving() @@ -990,7 +990,7 @@ if key in self.values.keys(): self.write(self.values[key]) else: - print '*** Undefined value: ', key + print('*** Undefined value: ', key) # --- Beginning a file --- @@ -1052,9 +1052,9 @@ [name, next, prev, up] = parts[:4] file = self.dirname + '/' + makefile(name) if self.filenames.has_key(file): - print '*** Filename already in use: ', file + print('*** Filename already in use: ', file) else: - if self.debugging: print '!'*self.debugging, '--- writing', file + if self.debugging: print('!'*self.debugging, '--- writing', file) self.filenames[file] = 1 # self.nodefp = open(file, 'w') self.nodename = name @@ -1169,7 +1169,7 @@ self.expand(args) self.write('\n') if self.debugging or self.print_headers: - print '---', args + print('---', args) def do_contents(self, args): # pass @@ -1549,7 +1549,7 @@ if self.whichindex.has_key(name): self.index(name, args) else: - print '*** No index named', repr(name) + print('*** No index named', repr(name)) def do_cindex(self, args): self.index('cp', args) def do_findex(self, args): self.index('fn', args) @@ -1565,12 +1565,12 @@ def do_synindex(self, args): words = args.split() if len(words) <> 2: - print '*** bad @synindex', args + print('*** bad @synindex', args) return [old, new] = words if not self.whichindex.has_key(old) or \ not self.whichindex.has_key(new): - print '*** bad key(s) in @synindex', args + print('*** bad key(s) in @synindex', args) return if old <> new and \ self.whichindex[old] is not self.whichindex[new]: @@ -1585,15 +1585,15 @@ if self.whichindex.has_key(name): self.prindex(name) else: - print '*** No index named', repr(name) + print('*** No index named', repr(name)) def prindex(self, name): iscodeindex = (name not in self.noncodeindices) index = self.whichindex[name] if not index: return if self.debugging: - print '!'*self.debugging, '--- Generating', \ - self.indextitle[name], 'index' + print('!'*self.debugging, '--- Generating', \ + self.indextitle[name], 'index') # The node already provides a title index1 = [] junkprog = re.compile('^(@[a-z]+)?{') @@ -1616,7 +1616,7 @@ for sortkey, key, node in index1: if (key, node) == (prevkey, prevnode): continue - if self.debugging > 1: print '!'*self.debugging, key, ':', node + if self.debugging > 1: print('!'*self.debugging, key, ':', node) self.write('
') if iscodeindex: key = '@code{' + key + '}' if key != prevkey: @@ -1629,11 +1629,11 @@ def report(self): if self.unknown: - print '--- Unrecognized commands ---' + print('--- Unrecognized commands ---') cmds = self.unknown.keys() cmds.sort() for cmd in cmds: - print cmd.ljust(20), self.unknown[cmd] + print(cmd.ljust(20), self.unknown[cmd]) class TexinfoParserHTML3(TexinfoParser): @@ -1773,86 +1773,86 @@ # PROJECT FILE try: fp = open(projectfile,'w') - print>>fp, '[OPTIONS]' - print>>fp, 'Auto Index=Yes' - print>>fp, 'Binary TOC=No' - print>>fp, 'Binary Index=Yes' - print>>fp, 'Compatibility=1.1' - print>>fp, 'Compiled file=' + resultfile + '' - print>>fp, 'Contents file=' + contentfile + '' - print>>fp, 'Default topic=' + defaulttopic + '' - print>>fp, 'Error log file=ErrorLog.log' - print>>fp, 'Index file=' + indexfile + '' - print>>fp, 'Title=' + title + '' - print>>fp, 'Display compile progress=Yes' - print>>fp, 'Full-text search=Yes' - print>>fp, 'Default window=main' - print>>fp, '' - print>>fp, '[WINDOWS]' - print>>fp, ('main=,"' + contentfile + '","' + indexfile + print('[OPTIONS]', file=fp) + print('Auto Index=Yes', file=fp) + print('Binary TOC=No', file=fp) + print('Binary Index=Yes', file=fp) + print('Compatibility=1.1', file=fp) + print('Compiled file=' + resultfile + '', file=fp) + print('Contents file=' + contentfile + '', file=fp) + print('Default topic=' + defaulttopic + '', file=fp) + print('Error log file=ErrorLog.log', file=fp) + print('Index file=' + indexfile + '', file=fp) + print('Title=' + title + '', file=fp) + print('Display compile progress=Yes', file=fp) + print('Full-text search=Yes', file=fp) + print('Default window=main', file=fp) + print('', file=fp) + print('[WINDOWS]', file=fp) + print('main=,"' + contentfile + '","' + indexfile + '","","",,,,,0x23520,222,0x1046,[10,10,780,560],' - '0xB0000,,,,,,0') - print>>fp, '' - print>>fp, '[FILES]' - print>>fp, '' + '0xB0000,,,,,,0', file=fp) + print('', file=fp) + print('[FILES]', file=fp) + print('', file=fp) self.dumpfiles(fp) fp.close() except IOError as msg: - print projectfile, ':', msg + print(projectfile, ':', msg) sys.exit(1) # CONTENT FILE try: fp = open(contentfile,'w') - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, ('') - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, ' ' - print>>fp, ' ' - print>>fp, ' ' - print>>fp, ' ' - print>>fp, ' ' + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print(' ', file=fp) + print(' ', file=fp) + print(' ', file=fp) + print(' ', file=fp) + print(' ', file=fp) self.dumpnodes(fp) - print>>fp, '' - print>>fp, '' + print('', file=fp) + print('', file=fp) fp.close() except IOError as msg: - print contentfile, ':', msg + print(contentfile, ':', msg) sys.exit(1) # INDEX FILE try: fp = open(indexfile ,'w') - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, ('') - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, '' - print>>fp, '' + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) + print('', file=fp) self.dumpindex(fp) - print>>fp, '' - print>>fp, '' + print('', file=fp) + print('', file=fp) fp.close() except IOError as msg: - print indexfile , ':', msg + print(indexfile , ':', msg) sys.exit(1) def dumpfiles(self, outfile=sys.stdout): filelist = self.filenames.values() filelist.sort() for filename in filelist: - print>>outfile, filename + print(filename, file=outfile) def dumpnodes(self, outfile=sys.stdout): self.dumped = {} @@ -1860,10 +1860,10 @@ nodename, dummy, dummy, dummy, dummy = self.nodelist[0] self.topnode = nodename - print>>outfile, '
    ' + print('
      ', file=outfile) for node in self.nodelist: self.dumpnode(node,0,outfile) - print>>outfile, '
    ' + print('
', file=outfile) def dumpnode(self, node, indent=0, outfile=sys.stdout): if node: @@ -1877,11 +1877,11 @@ self.dumped[nodename] = 1 # Print info for this node - print>>outfile, ' '*indent, - print>>outfile, '
  • ', - print>>outfile, '', - print>>outfile, '', - print>>outfile, '' + print(' '*indent, end=' ', file=outfile) + print('
  • ', end=' ', file=outfile) + print('', end=' ', file=outfile) + print('', end=' ', file=outfile) + print('', file=outfile) # Does this node have menu items? try: @@ -1894,13 +1894,13 @@ if menu: currentnode = self.current if currentnode != self.topnode: # XXX this is a hack - print>>outfile, ' '*indent + '
      ' + print(' '*indent + '
        ', file=outfile) indent += 2 for item in menu: menunode = self.getnode(item) self.dumpnode(menunode,indent,outfile) if currentnode != self.topnode: # XXX this is a hack - print>>outfile, ' '*indent + '
      ' + print(' '*indent + '
    ', file=outfile) indent -= 2 def getnode(self, nodename): @@ -1914,16 +1914,16 @@ # (args,nodename) == (key,location) def dumpindex(self, outfile=sys.stdout): - print>>outfile, '
      ' + print('
        ', file=outfile) for (key,location) in self.indexlist: key = self.codeexpand(key) location = makefile(location) location = self.dirname + '/' + location - print>>outfile, '
      • ', - print>>outfile, '', - print>>outfile, '', - print>>outfile, '' - print>>outfile, '
      ' + print('
    • ', end=' ', file=outfile) + print('', end=' ', file=outfile) + print('', end=' ', file=outfile) + print('', file=outfile) + print('
    ', file=outfile) def codeexpand(self, line): co = self.codeprog.match(line) @@ -2041,8 +2041,8 @@ helpbase = sys.argv[2] del sys.argv[1:3] if len(sys.argv) <> 3: - print 'usage: texi2hh [-d [-d]] [-p] [-c] [-3] [-H htmlhelp]', \ - 'inputfile outputdirectory' + print('usage: texi2hh [-d [-d]] [-p] [-c] [-3] [-H htmlhelp]', \ + 'inputfile outputdirectory') sys.exit(2) if html3: @@ -2064,7 +2064,7 @@ try: fp = open(file, 'r') except IOError as msg: - print file, ':', msg + print(file, ':', msg) sys.exit(1) parser.parse(fp) Modified: python/branches/py3k-struni/Tools/scripts/treesync.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/treesync.py (original) +++ python/branches/py3k-struni/Tools/scripts/treesync.py Fri Aug 3 19:06:41 2007 @@ -54,35 +54,35 @@ try: [slave, master] = args except ValueError: - print "usage: python", sys.argv[0] or "treesync.py", - print "[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]", - print "slavedir masterdir" + print("usage: python", sys.argv[0] or "treesync.py", end=' ') + print("[-n] [-y] [-m y|n|a] [-s y|n|a] [-d y|n|a] [-f n|y|a]", end=' ') + print("slavedir masterdir") return process(slave, master) def process(slave, master): cvsdir = os.path.join(master, "CVS") if not os.path.isdir(cvsdir): - print "skipping master subdirectory", master - print "-- not under CVS" + print("skipping master subdirectory", master) + print("-- not under CVS") return - print "-"*40 - print "slave ", slave - print "master", master + print("-"*40) + print("slave ", slave) + print("master", master) if not os.path.isdir(slave): if not okay("create slave directory %s?" % slave, answer=create_directories): - print "skipping master subdirectory", master - print "-- no corresponding slave", slave + print("skipping master subdirectory", master) + print("-- no corresponding slave", slave) return - print "creating slave directory", slave + print("creating slave directory", slave) try: os.mkdir(slave) except os.error as msg: - print "can't make slave directory", slave, ":", msg + print("can't make slave directory", slave, ":", msg) return else: - print "made slave directory", slave + print("made slave directory", slave) cvsdir = None subdirs = [] names = os.listdir(master) @@ -117,13 +117,13 @@ mf = None if not sf: if not mf: - print "Neither master nor slave exists", master + print("Neither master nor slave exists", master) return - print "Creating missing slave", slave + print("Creating missing slave", slave) copy(master, slave, answer=create_files) return if not mf: - print "Not updating missing master", master + print("Not updating missing master", master) return if sf and mf: if identical(sf, mf): @@ -134,22 +134,22 @@ # Master is newer -- copy master to slave sf.close() mf.close() - print "Master ", master - print "is newer than slave", slave + print("Master ", master) + print("is newer than slave", slave) copy(master, slave, answer=write_slave) return # Slave is newer -- copy slave to master - print "Slave is", sft-mft, "seconds newer than master" + print("Slave is", sft-mft, "seconds newer than master") # But first check what to do about CRLF mf.seek(0) fun = funnychars(mf) mf.close() sf.close() if fun: - print "***UPDATING MASTER (BINARY COPY)***" + print("***UPDATING MASTER (BINARY COPY)***") copy(slave, master, "rb", answer=write_master) else: - print "***UPDATING MASTER***" + print("***UPDATING MASTER***") copy(slave, master, "r", answer=write_master) BUFSIZE = 16*1024 @@ -174,8 +174,8 @@ return 0 def copy(src, dst, rmode="rb", wmode="wb", answer='ask'): - print "copying", src - print " to", dst + print("copying", src) + print(" to", dst) if not okay("okay to copy? ", answer): return f = open(src, rmode) @@ -203,7 +203,7 @@ return 1 if answer[:1] == 'n': return 0 - print "Yes or No please -- try again:" + print("Yes or No please -- try again:") return okay(prompt) if __name__ == '__main__': Modified: python/branches/py3k-struni/Tools/scripts/untabify.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/untabify.py (original) +++ python/branches/py3k-struni/Tools/scripts/untabify.py Fri Aug 3 19:06:41 2007 @@ -13,8 +13,8 @@ if not args: raise getopt.error, "At least one file argument required" except getopt.error as msg: - print msg - print "usage:", sys.argv[0], "[-t tabwidth] file ..." + print(msg) + print("usage:", sys.argv[0], "[-t tabwidth] file ...") return for optname, optvalue in opts: if optname == '-t': @@ -29,7 +29,7 @@ text = f.read() f.close() except IOError as msg: - print "%r: I/O error: %s" % (filename, msg) + print("%r: I/O error: %s" % (filename, msg)) return newtext = text.expandtabs(tabsize) if newtext == text: @@ -46,7 +46,7 @@ f = open(filename, "w") f.write(newtext) f.close() - print filename + print(filename) if __name__ == '__main__': main() Modified: python/branches/py3k-struni/Tools/scripts/which.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/which.py (original) +++ python/branches/py3k-struni/Tools/scripts/which.py Fri Aug 3 19:06:41 2007 @@ -37,7 +37,7 @@ mode = S_IMODE(st[ST_MODE]) if mode & 0o111: if not ident: - print filename + print(filename) ident = st[:3] else: if st[:3] == ident: Modified: python/branches/py3k-struni/Tools/scripts/xxci.py ============================================================================== --- python/branches/py3k-struni/Tools/scripts/xxci.py (original) +++ python/branches/py3k-struni/Tools/scripts/xxci.py Fri Aug 3 19:06:41 2007 @@ -18,14 +18,14 @@ args = sys.argv[1:] if args: return args - print 'No arguments, checking almost *, in "ls -t" order' + print('No arguments, checking almost *, in "ls -t" order') list = [] for file in os.listdir(os.curdir): if not skipfile(file): list.append((getmtime(file), file)) list.sort() if not list: - print 'Nothing to do -- exit 1' + print('Nothing to do -- exit 1') sys.exit(1) list.sort() list.reverse() @@ -89,7 +89,7 @@ def go(args): for file in args: - print file + ':' + print(file + ':') if differing(file): showdiffs(file) if askyesno('Check in ' + file + ' ? '): @@ -119,4 +119,4 @@ setup() go(getargs()) except KeyboardInterrupt: - print '[Intr]' + print('[Intr]') Modified: python/branches/py3k-struni/Tools/unicode/comparecodecs.py ============================================================================== --- python/branches/py3k-struni/Tools/unicode/comparecodecs.py (original) +++ python/branches/py3k-struni/Tools/unicode/comparecodecs.py Fri Aug 3 19:06:41 2007 @@ -11,7 +11,7 @@ def compare_codecs(encoding1, encoding2): - print 'Comparing encoding/decoding of %r and %r' % (encoding1, encoding2) + print('Comparing encoding/decoding of %r and %r' % (encoding1, encoding2)) mismatch = 0 # Check encoding for i in range(sys.maxunicode): @@ -25,8 +25,8 @@ except UnicodeError as reason: c2 = '' if c1 != c2: - print ' * encoding mismatch for 0x%04X: %-14r != %r' % \ - (i, c1, c2) + print(' * encoding mismatch for 0x%04X: %-14r != %r' % \ + (i, c1, c2)) mismatch += 1 # Check decoding for i in range(256): @@ -40,14 +40,14 @@ except UnicodeError: u2 = u'' if u1 != u2: - print ' * decoding mismatch for 0x%04X: %-14r != %r' % \ - (i, u1, u2) + print(' * decoding mismatch for 0x%04X: %-14r != %r' % \ + (i, u1, u2)) mismatch += 1 if mismatch: - print - print 'Found %i mismatches' % mismatch + print() + print('Found %i mismatches' % mismatch) else: - print '-> Codecs are identical.' + print('-> Codecs are identical.') if __name__ == '__main__': compare_codecs(sys.argv[1], sys.argv[2]) Modified: python/branches/py3k-struni/Tools/unicode/gencodec.py ============================================================================== --- python/branches/py3k-struni/Tools/unicode/gencodec.py (original) +++ python/branches/py3k-struni/Tools/unicode/gencodec.py Fri Aug 3 19:06:41 2007 @@ -131,7 +131,7 @@ return '(' + ', '.join(['0x%0*X' % (precision, item) for item in t]) + ')' except TypeError as why: - print '* failed to convert %r: %s' % (t, why) + print('* failed to convert %r: %s' % (t, why)) raise def python_mapdef_code(varname, map, comments=1, precisions=(2, 4)): @@ -383,18 +383,18 @@ name = nameprefix + name codefile = name + '.py' marshalfile = name + '.mapping' - print 'converting %s to %s and %s' % (mapname, + print('converting %s to %s and %s' % (mapname, dirprefix + codefile, - dirprefix + marshalfile) + dirprefix + marshalfile)) try: map = readmap(os.path.join(dir,mapname)) if not map: - print '* map is empty; skipping' + print('* map is empty; skipping') else: pymap(mappathname, map, dirprefix + codefile,name,comments) marshalmap(mappathname, map, dirprefix + marshalfile) except ValueError as why: - print '* conversion failed: %s' % why + print('* conversion failed: %s' % why) raise def rewritepythondir(dir, dirprefix='', comments=1): @@ -405,17 +405,17 @@ continue name = mapname[:-len('.mapping')] codefile = name + '.py' - print 'converting %s to %s' % (mapname, - dirprefix + codefile) + print('converting %s to %s' % (mapname, + dirprefix + codefile)) try: map = marshal.load(open(os.path.join(dir,mapname), 'rb')) if not map: - print '* map is empty; skipping' + print('* map is empty; skipping') else: pymap(mapname, map, dirprefix + codefile,name,comments) except ValueError as why: - print '* conversion failed: %s' % why + print('* conversion failed: %s' % why) if __name__ == '__main__': Modified: python/branches/py3k-struni/Tools/unicode/listcodecs.py ============================================================================== --- python/branches/py3k-struni/Tools/unicode/listcodecs.py (original) +++ python/branches/py3k-struni/Tools/unicode/listcodecs.py Fri Aug 3 19:06:41 2007 @@ -26,8 +26,8 @@ # Probably an error from importing the codec; still it's # a valid code name if _debug: - print '* problem importing codec %r: %s' % \ - (name, reason) + print('* problem importing codec %r: %s' % \ + (name, reason)) names.append(name) return names @@ -35,7 +35,7 @@ if __name__ == '__main__': names = listcodecs(encodings.__path__[0]) names.sort() - print 'all_codecs = [' + print('all_codecs = [') for name in names: - print ' %r,' % name - print ']' + print(' %r,' % name) + print(']') Modified: python/branches/py3k-struni/Tools/unicode/makeunicodedata.py ============================================================================== --- python/branches/py3k-struni/Tools/unicode/makeunicodedata.py (original) +++ python/branches/py3k-struni/Tools/unicode/makeunicodedata.py Fri Aug 3 19:06:41 2007 @@ -60,21 +60,21 @@ def maketables(trace=0): - print "--- Reading", UNICODE_DATA % "", "..." + print("--- Reading", UNICODE_DATA % "", "...") version = "" unicode = UnicodeData(UNICODE_DATA % version, COMPOSITION_EXCLUSIONS % version, EASTASIAN_WIDTH % version) - print len(filter(None, unicode.table)), "characters" + print(len(filter(None, unicode.table)), "characters") for version in old_versions: - print "--- Reading", UNICODE_DATA % ("-"+version), "..." + print("--- Reading", UNICODE_DATA % ("-"+version), "...") old_unicode = UnicodeData(UNICODE_DATA % ("-"+version), COMPOSITION_EXCLUSIONS % ("-"+version), EASTASIAN_WIDTH % ("-"+version)) - print len(filter(None, old_unicode.table)), "characters" + print(len(filter(None, old_unicode.table)), "characters") merge_old_version(version, unicode, old_unicode) makeunicodename(unicode, trace) @@ -93,7 +93,7 @@ FILE = "Modules/unicodedata_db.h" - print "--- Preparing", FILE, "..." + print("--- Preparing", FILE, "...") # 1) database properties @@ -203,93 +203,92 @@ l = comp_last[l] comp_data[f*total_last+l] = char - print len(table), "unique properties" - print len(decomp_prefix), "unique decomposition prefixes" - print len(decomp_data), "unique decomposition entries:", - print decomp_size, "bytes" - print total_first, "first characters in NFC" - print total_last, "last characters in NFC" - print len(comp_pairs), "NFC pairs" + print(len(table), "unique properties") + print(len(decomp_prefix), "unique decomposition prefixes") + print(len(decomp_data), "unique decomposition entries:", end=' ') + print(decomp_size, "bytes") + print(total_first, "first characters in NFC") + print(total_last, "last characters in NFC") + print(len(comp_pairs), "NFC pairs") - print "--- Writing", FILE, "..." + print("--- Writing", FILE, "...") fp = open(FILE, "w") - print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION) - print >>fp - print >>fp, '#define UNIDATA_VERSION "%s"' % UNIDATA_VERSION - print >>fp, "/* a list of unique database records */" - print >>fp, \ - "const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {" + print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp) + print(file=fp) + print('#define UNIDATA_VERSION "%s"' % UNIDATA_VERSION, file=fp) + print("/* a list of unique database records */", file=fp) + print("const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {", file=fp) for item in table: - print >>fp, " {%d, %d, %d, %d, %d}," % item - print >>fp, "};" - print >>fp - - print >>fp, "/* Reindexing of NFC first characters. */" - print >>fp, "#define TOTAL_FIRST",total_first - print >>fp, "#define TOTAL_LAST",total_last - print >>fp, "struct reindex{int start;short count,index;};" - print >>fp, "struct reindex nfc_first[] = {" + print(" {%d, %d, %d, %d, %d}," % item, file=fp) + print("};", file=fp) + print(file=fp) + + print("/* Reindexing of NFC first characters. */", file=fp) + print("#define TOTAL_FIRST",total_first, file=fp) + print("#define TOTAL_LAST",total_last, file=fp) + print("struct reindex{int start;short count,index;};", file=fp) + print("struct reindex nfc_first[] = {", file=fp) for start,end in comp_first_ranges: - print >>fp," { %d, %d, %d}," % (start,end-start,comp_first[start]) - print >>fp," {0,0,0}" - print >>fp,"};\n" - print >>fp, "struct reindex nfc_last[] = {" + print(" { %d, %d, %d}," % (start,end-start,comp_first[start]), file=fp) + print(" {0,0,0}", file=fp) + print("};\n", file=fp) + print("struct reindex nfc_last[] = {", file=fp) for start,end in comp_last_ranges: - print >>fp," { %d, %d, %d}," % (start,end-start,comp_last[start]) - print >>fp," {0,0,0}" - print >>fp,"};\n" + print(" { %d, %d, %d}," % (start,end-start,comp_last[start]), file=fp) + print(" {0,0,0}", file=fp) + print("};\n", file=fp) # FIXME: the following tables could be made static, and # the support code moved into unicodedatabase.c - print >>fp, "/* string literals */" - print >>fp, "const char *_PyUnicode_CategoryNames[] = {" + print("/* string literals */", file=fp) + print("const char *_PyUnicode_CategoryNames[] = {", file=fp) for name in CATEGORY_NAMES: - print >>fp, " \"%s\"," % name - print >>fp, " NULL" - print >>fp, "};" + print(" \"%s\"," % name, file=fp) + print(" NULL", file=fp) + print("};", file=fp) - print >>fp, "const char *_PyUnicode_BidirectionalNames[] = {" + print("const char *_PyUnicode_BidirectionalNames[] = {", file=fp) for name in BIDIRECTIONAL_NAMES: - print >>fp, " \"%s\"," % name - print >>fp, " NULL" - print >>fp, "};" + print(" \"%s\"," % name, file=fp) + print(" NULL", file=fp) + print("};", file=fp) - print >>fp, "const char *_PyUnicode_EastAsianWidthNames[] = {" + print("const char *_PyUnicode_EastAsianWidthNames[] = {", file=fp) for name in EASTASIANWIDTH_NAMES: - print >>fp, " \"%s\"," % name - print >>fp, " NULL" - print >>fp, "};" + print(" \"%s\"," % name, file=fp) + print(" NULL", file=fp) + print("};", file=fp) - print >>fp, "static const char *decomp_prefix[] = {" + print("static const char *decomp_prefix[] = {", file=fp) for name in decomp_prefix: - print >>fp, " \"%s\"," % name - print >>fp, " NULL" - print >>fp, "};" + print(" \"%s\"," % name, file=fp) + print(" NULL", file=fp) + print("};", file=fp) # split record index table index1, index2, shift = splitbins(index, trace) - print >>fp, "/* index tables for the database records */" - print >>fp, "#define SHIFT", shift + print("/* index tables for the database records */", file=fp) + print("#define SHIFT", shift, file=fp) Array("index1", index1).dump(fp, trace) Array("index2", index2).dump(fp, trace) # split decomposition index table index1, index2, shift = splitbins(decomp_index, trace) - print >>fp, "/* decomposition data */" + print("/* decomposition data */", file=fp) Array("decomp_data", decomp_data).dump(fp, trace) - print >>fp, "/* index tables for the decomposition data */" - print >>fp, "#define DECOMP_SHIFT", shift + print("/* index tables for the decomposition data */", file=fp) + print("#define DECOMP_SHIFT", shift, file=fp) Array("decomp_index1", index1).dump(fp, trace) Array("decomp_index2", index2).dump(fp, trace) index, index2, shift = splitbins(comp_data, trace) - print >>fp, "/* NFC pairs */" - print >>fp, "#define COMP_SHIFT", shift + print("/* NFC pairs */", file=fp) + print("#define COMP_SHIFT", shift, file=fp) Array("comp_index", index).dump(fp, trace) Array("comp_data", index2).dump(fp, trace) @@ -306,30 +305,30 @@ index[i] = cache[record] = len(records) records.append(record) index1, index2, shift = splitbins(index, trace) - print >>fp, "static const change_record change_records_%s[] = {" % cversion + print("static const change_record change_records_%s[] = {" % cversion, file=fp) for record in records: - print >>fp, "\t{ %s }," % ", ".join(map(str,record)) - print >>fp, "};" + print("\t{ %s }," % ", ".join(map(str,record)), file=fp) + print("};", file=fp) Array("changes_%s_index" % cversion, index1).dump(fp, trace) Array("changes_%s_data" % cversion, index2).dump(fp, trace) - print >>fp, "static const change_record* get_change_%s(Py_UCS4 n)" % cversion - print >>fp, "{" - print >>fp, "\tint index;" - print >>fp, "\tif (n >= 0x110000) index = 0;" - print >>fp, "\telse {" - print >>fp, "\t\tindex = changes_%s_index[n>>%d];" % (cversion, shift) - print >>fp, "\t\tindex = changes_%s_data[(index<<%d)+(n & %d)];" % \ - (cversion, shift, ((1<>fp, "\t}" - print >>fp, "\treturn change_records_%s+index;" % cversion - print >>fp, "}\n" - print >>fp, "static Py_UCS4 normalization_%s(Py_UCS4 n)" % cversion - print >>fp, "{" - print >>fp, "\tswitch(n) {" + print("static const change_record* get_change_%s(Py_UCS4 n)" % cversion, file=fp) + print("{", file=fp) + print("\tint index;", file=fp) + print("\tif (n >= 0x110000) index = 0;", file=fp) + print("\telse {", file=fp) + print("\t\tindex = changes_%s_index[n>>%d];" % (cversion, shift), file=fp) + print("\t\tindex = changes_%s_data[(index<<%d)+(n & %d)];" % \ + (cversion, shift, ((1<>fp, "\tcase %s: return 0x%s;" % (hex(k), v) - print >>fp, "\tdefault: return 0;" - print >>fp, "\t}\n}\n" + print("\tcase %s: return 0x%s;" % (hex(k), v), file=fp) + print("\tdefault: return 0;", file=fp) + print("\t}\n}\n", file=fp) fp.close() @@ -340,7 +339,7 @@ FILE = "Objects/unicodetype_db.h" - print "--- Preparing", FILE, "..." + print("--- Preparing", FILE, "...") # extract unicode types dummy = (0, 0, 0, 0, 0, 0) @@ -405,25 +404,25 @@ table.append(item) index[char] = i - print len(table), "unique character type entries" + print(len(table), "unique character type entries") - print "--- Writing", FILE, "..." + print("--- Writing", FILE, "...") fp = open(FILE, "w") - print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION) - print >>fp - print >>fp, "/* a list of unique character type descriptors */" - print >>fp, "const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = {" + print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp) + print(file=fp) + print("/* a list of unique character type descriptors */", file=fp) + print("const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = {", file=fp) for item in table: - print >>fp, " {%d, %d, %d, %d, %d, %d}," % item - print >>fp, "};" - print >>fp + print(" {%d, %d, %d, %d, %d, %d}," % item, file=fp) + print("};", file=fp) + print(file=fp) # split decomposition index table index1, index2, shift = splitbins(index, trace) - print >>fp, "/* type indexes */" - print >>fp, "#define SHIFT", shift + print("/* type indexes */", file=fp) + print("#define SHIFT", shift, file=fp) Array("index1", index1).dump(fp, trace) Array("index2", index2).dump(fp, trace) @@ -436,7 +435,7 @@ FILE = "Modules/unicodename_db.h" - print "--- Preparing", FILE, "..." + print("--- Preparing", FILE, "...") # collect names names = [None] * len(unicode.chars) @@ -448,7 +447,7 @@ if name and name[0] != "<": names[char] = name + chr(0) - print len(filter(lambda n: n is not None, names)), "distinct names" + print(len(filter(lambda n: n is not None, names)), "distinct names") # collect unique words from names (note that we differ between # words inside a sentence, and words ending a sentence. the @@ -469,7 +468,7 @@ else: words[w] = [len(words)] - print n, "words in text;", b, "bytes" + print(n, "words in text;", b, "bytes") wordlist = words.items() @@ -485,19 +484,19 @@ escapes = 0 while escapes * 256 < len(wordlist): escapes = escapes + 1 - print escapes, "escapes" + print(escapes, "escapes") short = 256 - escapes assert short > 0 - print short, "short indexes in lexicon" + print(short, "short indexes in lexicon") # statistics n = 0 for i in range(short): n = n + len(wordlist[i][1]) - print n, "short indexes in phrasebook" + print(n, "short indexes in phrasebook") # pick the most commonly used words, and sort the rest on falling # length (to maximize overlap) @@ -566,29 +565,29 @@ codehash = Hash("code", data, 47) - print "--- Writing", FILE, "..." + print("--- Writing", FILE, "...") fp = open(FILE, "w") - print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION) - print >>fp - print >>fp, "#define NAME_MAXLEN", 256 - print >>fp - print >>fp, "/* lexicon */" + print("/* this file was generated by %s %s */" % (SCRIPT, VERSION), file=fp) + print(file=fp) + print("#define NAME_MAXLEN", 256, file=fp) + print(file=fp) + print("/* lexicon */", file=fp) Array("lexicon", lexicon).dump(fp, trace) Array("lexicon_offset", lexicon_offset).dump(fp, trace) # split decomposition index table offset1, offset2, shift = splitbins(phrasebook_offset, trace) - print >>fp, "/* code->name phrasebook */" - print >>fp, "#define phrasebook_shift", shift - print >>fp, "#define phrasebook_short", short + print("/* code->name phrasebook */", file=fp) + print("#define phrasebook_shift", shift, file=fp) + print("#define phrasebook_short", short, file=fp) Array("phrasebook", phrasebook).dump(fp, trace) Array("phrasebook_offset1", offset1).dump(fp, trace) Array("phrasebook_offset2", offset2).dump(fp, trace) - print >>fp, "/* name->code dictionary */" + print("/* name->code dictionary */", file=fp) codehash.dump(fp, trace) fp.close() @@ -781,7 +780,7 @@ else: raise AssertionError, "ran out of polynominals" - print size, "slots in hash table" + print(size, "slots in hash table") table = [None] * size @@ -813,7 +812,7 @@ if incr > mask: incr = incr ^ poly - print n, "collisions" + print(n, "collisions") self.collisions = n for i in range(len(table)): @@ -845,7 +844,7 @@ # write data to file, as a C array size = getsize(self.data) if trace: - print >>sys.stderr, self.name+":", size*len(self.data), "bytes" + print(self.name+":", size*len(self.data), "bytes", file=sys.stderr) file.write("static ") if size == 1: file.write("unsigned char") @@ -895,10 +894,10 @@ import sys if trace: def dump(t1, t2, shift, bytes): - print >>sys.stderr, "%d+%d bins at shift %d; %d bytes" % ( - len(t1), len(t2), shift, bytes) - print >>sys.stderr, "Size of original table:", len(t)*getsize(t), \ - "bytes" + print("%d+%d bins at shift %d; %d bytes" % ( + len(t1), len(t2), shift, bytes), file=sys.stderr) + print("Size of original table:", len(t)*getsize(t), \ + "bytes", file=sys.stderr) n = len(t)-1 # last valid index maxshift = 0 # the most we can shift n and still have something left if n > 0: @@ -930,7 +929,7 @@ bytes = b t1, t2, shift = best if trace: - print >>sys.stderr, "Best:", + print("Best:", end=' ', file=sys.stderr) dump(t1, t2, shift, bytes) if __debug__: # exhaustively verify that the decomposition is correct Modified: python/branches/py3k-struni/Tools/unicode/mkstringprep.py ============================================================================== --- python/branches/py3k-struni/Tools/unicode/mkstringprep.py (original) +++ python/branches/py3k-struni/Tools/unicode/mkstringprep.py Fri Aug 3 19:06:41 2007 @@ -106,7 +106,7 @@ ########### Generate compact Python versions of the tables ############# -print """# This file is generated by mkstringprep.py. DO NOT EDIT. +print("""# This file is generated by mkstringprep.py. DO NOT EDIT. \"\"\"Library that exposes various tables found in the StringPrep RFC 3454. There are two kinds of tables: sets, for which a member test is provided, @@ -114,9 +114,9 @@ \"\"\" import unicodedata -""" +""") -print "assert unicodedata.unidata_version == %s" % repr(unicodedata.unidata_version) +print("assert unicodedata.unidata_version == %s" % repr(unicodedata.unidata_version)) # A.1 is the table of unassigned characters # XXX Plane 15 PUA is listed as unassigned in Python. @@ -134,13 +134,13 @@ # assert table == Cn -print """ +print(""" def in_table_a1(code): if unicodedata.category(code) != 'Cn': return False c = ord(code) if 0xFDD0 <= c < 0xFDF0: return False return (c & 0xFFFF) not in (0xFFFE, 0xFFFF) -""" +""") # B.1 cannot easily be derived name, table = tables[0] @@ -148,11 +148,11 @@ assert name == "B.1" table = table.keys() table.sort() -print """ +print(""" b1_set = """ + compact_set(table) + """ def in_table_b1(code): return ord(code) in b1_set -""" +""") # B.2 and B.3 is case folding. # It takes CaseFolding.txt into account, which is @@ -180,20 +180,20 @@ b3 = b3_exceptions.items() b3.sort() -print """ -b3_exceptions = {""" +print(""" +b3_exceptions = {""") for i,(k,v) in enumerate(b3): - print "0x%x:%s," % (k, repr(v)), + print("0x%x:%s," % (k, repr(v)), end=' ') if i % 4 == 3: - print -print "}" + print() +print("}") -print """ +print(""" def map_table_b3(code): r = b3_exceptions.get(ord(code)) if r is not None: return r return code.lower() -""" +""") def map_table_b3(code): r = b3_exceptions.get(ord(code)) @@ -222,7 +222,7 @@ # B.3 should not add any additional special cases assert specials == {} -print """ +print(""" def map_table_b2(a): al = map_table_b3(a) b = unicodedata.normalize("NFKC", al) @@ -232,7 +232,7 @@ return c else: return al -""" +""") # C.1.1 is a table with a single character name, table = tables[0] @@ -240,10 +240,10 @@ assert name == "C.1.1" assert table == {0x20:0x20} -print """ +print(""" def in_table_c11(code): return code == u" " -""" +""") # C.1.2 is the rest of all space characters name, table = tables[0] @@ -254,13 +254,13 @@ # Zs = set(gen_category(["Zs"])) - set([0x20]) # assert Zs == table -print """ +print(""" def in_table_c12(code): return unicodedata.category(code) == "Zs" and code != u" " def in_table_c11_c12(code): return unicodedata.category(code) == "Zs" -""" +""") # C.2.1 ASCII control characters name, table_c21 = tables[0] @@ -272,10 +272,10 @@ table_c21 = set(table_c21.keys()) assert Cc_ascii == table_c21 -print """ +print(""" def in_table_c21(code): return ord(code) < 128 and unicodedata.category(code) == "Cc" -""" +""") # C.2.2 Non-ASCII control characters. It also includes # a number of characters in category Cf. @@ -290,7 +290,7 @@ specials = list(table_c22 - Cc_nonascii) specials.sort() -print """c22_specials = """ + compact_set(specials) + """ +print("""c22_specials = """ + compact_set(specials) + """ def in_table_c22(code): c = ord(code) if c < 128: return False @@ -300,7 +300,7 @@ def in_table_c21_c22(code): return unicodedata.category(code) == "Cc" or \\ ord(code) in c22_specials -""" +""") # C.3 Private use name, table = tables[0] @@ -310,10 +310,10 @@ Co = set(gen_category(["Co"])) assert set(table.keys()) == Co -print """ +print(""" def in_table_c3(code): return unicodedata.category(code) == "Co" -""" +""") # C.4 Non-character code points, xFFFE, xFFFF # plus process internal codes @@ -327,13 +327,13 @@ table = set(table.keys()) assert table == nonchar -print """ +print(""" def in_table_c4(code): c = ord(code) if c < 0xFDD0: return False if c < 0xFDF0: return True return (ord(code) & 0xFFFF) in (0xFFFE, 0xFFFF) -""" +""") # C.5 Surrogate codes name, table = tables[0] @@ -343,10 +343,10 @@ Cs = set(gen_category(["Cs"])) assert set(table.keys()) == Cs -print """ +print(""" def in_table_c5(code): return unicodedata.category(code) == "Cs" -""" +""") # C.6 Inappropriate for plain text name, table = tables[0] @@ -356,11 +356,11 @@ table = table.keys() table.sort() -print """ +print(""" c6_set = """ + compact_set(table) + """ def in_table_c6(code): return ord(code) in c6_set -""" +""") # C.7 Inappropriate for canonical representation name, table = tables[0] @@ -370,11 +370,11 @@ table = table.keys() table.sort() -print """ +print(""" c7_set = """ + compact_set(table) + """ def in_table_c7(code): return ord(code) in c7_set -""" +""") # C.8 Change display properties or are deprecated name, table = tables[0] @@ -384,11 +384,11 @@ table = table.keys() table.sort() -print """ +print(""" c8_set = """ + compact_set(table) + """ def in_table_c8(code): return ord(code) in c8_set -""" +""") # C.9 Tagging characters name, table = tables[0] @@ -398,11 +398,11 @@ table = table.keys() table.sort() -print """ +print(""" c9_set = """ + compact_set(table) + """ def in_table_c9(code): return ord(code) in c9_set -""" +""") # D.1 Characters with bidirectional property "R" or "AL" name, table = tables[0] @@ -412,10 +412,10 @@ RandAL = set(gen_bidirectional(["R","AL"])) assert set(table.keys()) == RandAL -print """ +print(""" def in_table_d1(code): return unicodedata.bidirectional(code) in ("R","AL") -""" +""") # D.2 Characters with bidirectional property "L" name, table = tables[0] @@ -425,7 +425,7 @@ L = set(gen_bidirectional(["L"])) assert set(table.keys()) == L -print """ +print(""" def in_table_d2(code): return unicodedata.bidirectional(code) == "L" -""" +""") Modified: python/branches/py3k-struni/Tools/versioncheck/checkversions.py ============================================================================== --- python/branches/py3k-struni/Tools/versioncheck/checkversions.py (original) +++ python/branches/py3k-struni/Tools/versioncheck/checkversions.py Fri Aug 3 19:06:41 2007 @@ -28,7 +28,7 @@ try: execfile(fullname) except: - print '** Exception in', fullname + print('** Exception in', fullname) def walk1tree(tree): os.path.walk(tree, check1dir, None) @@ -38,7 +38,7 @@ try: options, arguments = getopt.getopt(sys.argv[1:], 'v:') except getopt.error: - print USAGE + print(USAGE) sys.exit(1) for o, a in options: if o == '-v': Modified: python/branches/py3k-struni/Tools/versioncheck/pyversioncheck.py ============================================================================== --- python/branches/py3k-struni/Tools/versioncheck/pyversioncheck.py (original) +++ python/branches/py3k-struni/Tools/versioncheck/pyversioncheck.py Fri Aug 3 19:06:41 2007 @@ -18,12 +18,12 @@ if verbose > VERBOSE_NORMAL: return ok if ok < 0: - print '%s: No correctly formatted current version file found'%(package) + print('%s: No correctly formatted current version file found'%(package)) elif ok == 1: - print '%s: up-to-date (version %s)'%(package, version) + print('%s: up-to-date (version %s)'%(package, version)) else: - print '%s: version %s installed, version %s found:' % \ - (package, version, newversion) + print('%s: version %s installed, version %s found:' % \ + (package, version, newversion)) if verbose > VERBOSE_SILENT: while 1: line = fp.readline() @@ -33,7 +33,7 @@ def checkonly(package, url, version, verbose=0): if verbose >= VERBOSE_EACHFILE: - print '%s:'%package + print('%s:'%package) if isinstance(url, str): ok, newversion, fp = _check1version(package, url, version, verbose) else: @@ -45,51 +45,51 @@ def _check1version(package, url, version, verbose=0): if verbose >= VERBOSE_EACHFILE: - print ' Checking %s'%url + print(' Checking %s'%url) try: fp = urllib.urlopen(url) except IOError as arg: if verbose >= VERBOSE_EACHFILE: - print ' Cannot open:', arg + print(' Cannot open:', arg) return -1, None, None msg = rfc822.Message(fp, seekable=0) newversion = msg.getheader('current-version') if not newversion: if verbose >= VERBOSE_EACHFILE: - print ' No "Current-Version:" header in URL or URL not found' + print(' No "Current-Version:" header in URL or URL not found') return -1, None, None version = version.lower().strip() newversion = newversion.lower().strip() if version == newversion: if verbose >= VERBOSE_EACHFILE: - print ' Version identical (%s)'%newversion + print(' Version identical (%s)'%newversion) return 1, version, fp else: if verbose >= VERBOSE_EACHFILE: - print ' Versions different (installed: %s, new: %s)'% \ - (version, newversion) + print(' Versions different (installed: %s, new: %s)'% \ + (version, newversion)) return 0, newversion, fp def _test(): - print '--- TEST VERBOSE=1' - print '--- Testing existing and identical version file' + print('--- TEST VERBOSE=1') + print('--- Testing existing and identical version file') versioncheck('VersionTestPackage', _TESTDIR+'Version10.txt', '1.0', verbose=1) - print '--- Testing existing package with new version' + print('--- Testing existing package with new version') versioncheck('VersionTestPackage', _TESTDIR+'Version11.txt', '1.0', verbose=1) - print '--- Testing package with non-existing version file' + print('--- Testing package with non-existing version file') versioncheck('VersionTestPackage', _TESTDIR+'nonexistent.txt', '1.0', verbose=1) - print '--- Test package with 2 locations, first non-existing second ok' + print('--- Test package with 2 locations, first non-existing second ok') versfiles = [_TESTDIR+'nonexistent.txt', _TESTDIR+'Version10.txt'] versioncheck('VersionTestPackage', versfiles, '1.0', verbose=1) - print '--- TEST VERBOSE=2' - print '--- Testing existing and identical version file' + print('--- TEST VERBOSE=2') + print('--- Testing existing and identical version file') versioncheck('VersionTestPackage', _TESTDIR+'Version10.txt', '1.0', verbose=2) - print '--- Testing existing package with new version' + print('--- Testing existing package with new version') versioncheck('VersionTestPackage', _TESTDIR+'Version11.txt', '1.0', verbose=2) - print '--- Testing package with non-existing version file' + print('--- Testing package with non-existing version file') versioncheck('VersionTestPackage', _TESTDIR+'nonexistent.txt', '1.0', verbose=2) - print '--- Test package with 2 locations, first non-existing second ok' + print('--- Test package with 2 locations, first non-existing second ok') versfiles = [_TESTDIR+'nonexistent.txt', _TESTDIR+'Version10.txt'] versioncheck('VersionTestPackage', versfiles, '1.0', verbose=2) Modified: python/branches/py3k-struni/Tools/webchecker/wcgui.py ============================================================================== --- python/branches/py3k-struni/Tools/webchecker/wcgui.py (original) +++ python/branches/py3k-struni/Tools/webchecker/wcgui.py Fri Aug 3 19:06:41 2007 @@ -76,8 +76,8 @@ opts, args = getopt.getopt(sys.argv[1:], 't:m:qva') except getopt.error as msg: sys.stdout = sys.stderr - print msg - print __doc__%vars(webchecker) + print(msg) + print(__doc__%vars(webchecker)) sys.exit(2) webchecker.verbose = webchecker.VERBOSE webchecker.nonames = webchecker.NONAMES Modified: python/branches/py3k-struni/Tools/webchecker/webchecker.py ============================================================================== --- python/branches/py3k-struni/Tools/webchecker/webchecker.py (original) +++ python/branches/py3k-struni/Tools/webchecker/webchecker.py Fri Aug 3 19:06:41 2007 @@ -155,8 +155,8 @@ opts, args = getopt.getopt(sys.argv[1:], 'Rd:m:nqr:t:vxa') except getopt.error as msg: sys.stdout = sys.stderr - print msg - print __doc__%globals() + print(msg) + print(__doc__%globals()) sys.exit(2) # The extra_roots variable collects extra roots. @@ -186,7 +186,7 @@ checkext = not checkext if verbose > 0: - print AGENTNAME, "version", __version__ + print(AGENTNAME, "version", __version__) if restart: c = load_pickle(dumpfile=dumpfile, verbose=verbose) @@ -222,32 +222,32 @@ c.run() except KeyboardInterrupt: if verbose > 0: - print "[run interrupted]" + print("[run interrupted]") try: c.report() except KeyboardInterrupt: if verbose > 0: - print "[report interrupted]" + print("[report interrupted]") finally: if c.save_pickle(dumpfile): if dumpfile == DUMPFILE: - print "Use ``%s -R'' to restart." % sys.argv[0] + print("Use ``%s -R'' to restart." % sys.argv[0]) else: - print "Use ``%s -R -d %s'' to restart." % (sys.argv[0], - dumpfile) + print("Use ``%s -R -d %s'' to restart." % (sys.argv[0], + dumpfile)) def load_pickle(dumpfile=DUMPFILE, verbose=VERBOSE): if verbose > 0: - print "Loading checkpoint from %s ..." % dumpfile + print("Loading checkpoint from %s ..." % dumpfile) f = open(dumpfile, "rb") c = pickle.load(f) f.close() if verbose > 0: - print "Done." - print "Root:", "\n ".join(c.roots) + print("Done.") + print("Root:", "\n ".join(c.roots)) return c @@ -297,7 +297,7 @@ def message(self, format, *args): if args: format = format%args - print format + print(format) def __getstate__(self): return (self.roots, self.todo, self.done, self.bad, self.round) @@ -689,7 +689,7 @@ if self.verbose >= level: if args: msg = msg%args - print msg + print(msg) # Method to retrieve names. def getnames(self): Modified: python/branches/py3k-struni/Tools/webchecker/websucker.py ============================================================================== --- python/branches/py3k-struni/Tools/webchecker/websucker.py (original) +++ python/branches/py3k-struni/Tools/webchecker/websucker.py Fri Aug 3 19:06:41 2007 @@ -22,8 +22,8 @@ try: opts, args = getopt.getopt(sys.argv[1:], "qv") except getopt.error as msg: - print msg - print "usage:", sys.argv[0], "[-qv] ... [rooturl] ..." + print(msg) + print("usage:", sys.argv[0], "[-qv] ... [rooturl] ...") return 2 for o, a in opts: if o == "-q": @@ -36,9 +36,9 @@ ('User-agent', 'websucker/%s' % __version__), ] for arg in args: - print "Adding root", arg + print("Adding root", arg) c.addroot(arg) - print "Run..." + print("Run...") c.run() class Sucker(webchecker.Checker): @@ -116,7 +116,7 @@ return head, tail = os.path.split(dir) if not tail: - print "Huh? Don't know how to make dir", dir + print("Huh? Don't know how to make dir", dir) return makedirs(head) os.mkdir(dir, 0o777) From python-3000-checkins at python.org Fri Aug 3 20:40:50 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 3 Aug 2007 20:40:50 +0200 (CEST) Subject: [Python-3000-checkins] r56707 - in python/branches/py3k-struni: Lib/doctest.py Lib/test/test_zipimport.py Modules/zipimport.c Python/import.c Message-ID: <20070803184050.10FB01E400B@bag.python.org> Author: guido.van.rossum Date: Fri Aug 3 20:40:49 2007 New Revision: 56707 Modified: python/branches/py3k-struni/Lib/doctest.py python/branches/py3k-struni/Lib/test/test_zipimport.py python/branches/py3k-struni/Modules/zipimport.c python/branches/py3k-struni/Python/import.c Log: SF patch# 1766592 by Paul Colomiets. Fix test_zipimport. Modified: python/branches/py3k-struni/Lib/doctest.py ============================================================================== --- python/branches/py3k-struni/Lib/doctest.py (original) +++ python/branches/py3k-struni/Lib/doctest.py Fri Aug 3 20:40:49 2007 @@ -209,7 +209,7 @@ filename = _module_relative_path(package, filename) if hasattr(package, '__loader__'): if hasattr(package.__loader__, 'get_data'): - return package.__loader__.get_data(filename), filename + return package.__loader__.get_data(filename).decode('utf-8'), filename return open(filename, encoding="utf-8").read(), filename def _indent(s, indent=4): Modified: python/branches/py3k-struni/Lib/test/test_zipimport.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_zipimport.py (original) +++ python/branches/py3k-struni/Lib/test/test_zipimport.py Fri Aug 3 20:40:49 2007 @@ -153,18 +153,16 @@ def testBadMagic(self): # make pyc magic word invalid, forcing loading from .py - m0 = ord(test_pyc[0]) - m0 ^= 0x04 # flip an arbitrary bit - badmagic_pyc = chr(m0) + test_pyc[1:] + badmagic_pyc = bytes(test_pyc) + badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badmagic_pyc)} self.doTest(".py", files, TESTMOD) def testBadMagic2(self): # make pyc magic word invalid, causing an ImportError - m0 = ord(test_pyc[0]) - m0 ^= 0x04 # flip an arbitrary bit - badmagic_pyc = chr(m0) + test_pyc[1:] + badmagic_pyc = bytes(test_pyc) + badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)} try: self.doTest(".py", files, TESTMOD) @@ -174,10 +172,9 @@ self.fail("expected ImportError; import from bad pyc") def testBadMTime(self): - t3 = ord(test_pyc[7]) - t3 ^= 0x02 # flip the second bit -- not the first as that one - # isn't stored in the .py's mtime in the zip archive. - badtime_pyc = test_pyc[:7] + chr(t3) + test_pyc[8:] + badtime_pyc = bytes(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), TESTMOD + pyc_ext: (NOW, badtime_pyc)} self.doTest(".py", files, TESTMOD) @@ -232,7 +229,7 @@ z.compression = self.compression try: name = "testdata.dat" - data = "".join([chr(x) for x in range(256)]) * 500 + data = bytes(x for x in range(256)) z.writestr(name, data) z.close() zi = zipimport.zipimporter(TEMP_ZIP) @@ -246,7 +243,7 @@ src = """if 1: # indent hack def get_file(): return __file__ - if __loader__.get_data("some.data") != "some data": + if __loader__.get_data("some.data") != b"some data": raise AssertionError, "bad data"\n""" pyc = make_pyc(compile(src, "", "exec"), NOW) files = {TESTMOD + pyc_ext: (NOW, pyc), Modified: python/branches/py3k-struni/Modules/zipimport.c ============================================================================== --- python/branches/py3k-struni/Modules/zipimport.c (original) +++ python/branches/py3k-struni/Modules/zipimport.c Fri Aug 3 20:40:49 2007 @@ -475,8 +475,12 @@ strcpy(path + len, ".py"); toc_entry = PyDict_GetItemString(self->files, path); - if (toc_entry != NULL) - return get_data(PyString_AsString(self->archive), toc_entry); + if (toc_entry != NULL) { + PyObject *bytes = get_data(PyString_AsString(self->archive), toc_entry); + PyObject *res = PyUnicode_FromString(PyBytes_AsString(bytes)); + Py_XDECREF(bytes); + return res; + } /* we have the module, but no source */ Py_INCREF(Py_None); @@ -857,8 +861,10 @@ } buf[data_size] = '\0'; - if (compress == 0) /* data is not compressed */ + if (compress == 0) { /* data is not compressed */ + raw_data = PyBytes_FromStringAndSize(buf, data_size); return raw_data; + } /* Decompress with zlib */ decompress = get_decompress_func(); @@ -896,8 +902,8 @@ unmarshal_code(char *pathname, PyObject *data, time_t mtime) { PyObject *code; - char *buf = PyString_AsString(data); - Py_ssize_t size = PyString_Size(data); + char *buf = PyBytes_AsString(data); + Py_ssize_t size = PyBytes_Size(data); if (size <= 9) { PyErr_SetString(ZipImportError, @@ -942,14 +948,16 @@ static PyObject * normalize_line_endings(PyObject *source) { - char *buf, *q, *p = PyString_AsString(source); + char *buf, *q, *p = PyBytes_AsString(source); PyObject *fixed_source; + int len = 0; - if (!p) - return NULL; + if (!p) { + return PyBytes_FromStringAndSize("\n\0", 2); + } /* one char extra for trailing \n and one for terminating \0 */ - buf = (char *)PyMem_Malloc(PyString_Size(source) + 2); + buf = (char *)PyMem_Malloc(PyBytes_Size(source) + 2); if (buf == NULL) { PyErr_SetString(PyExc_MemoryError, "zipimport: no memory to allocate " @@ -965,10 +973,11 @@ } else *q++ = *p; + len++; } *q++ = '\n'; /* add trailing \n */ *q = '\0'; - fixed_source = PyString_FromString(buf); + fixed_source = PyBytes_FromStringAndSize(buf, len + 2); PyMem_Free(buf); return fixed_source; } @@ -984,7 +993,7 @@ if (fixed_source == NULL) return NULL; - code = Py_CompileString(PyString_AsString(fixed_source), pathname, + code = Py_CompileString(PyBytes_AsString(fixed_source), pathname, Py_file_input); Py_DECREF(fixed_source); return code; Modified: python/branches/py3k-struni/Python/import.c ============================================================================== --- python/branches/py3k-struni/Python/import.c (original) +++ python/branches/py3k-struni/Python/import.c Fri Aug 3 20:40:49 2007 @@ -2620,7 +2620,7 @@ buf[2] = (char) ((pyc_magic >> 16) & 0xff); buf[3] = (char) ((pyc_magic >> 24) & 0xff); - return PyString_FromStringAndSize(buf, 4); + return PyBytes_FromStringAndSize(buf, 4); } static PyObject * From python-3000-checkins at python.org Fri Aug 3 21:03:39 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 3 Aug 2007 21:03:39 +0200 (CEST) Subject: [Python-3000-checkins] r56708 - in python/branches/py3k-struni/Lib: SocketServer.py test/test_socketserver.py Message-ID: <20070803190339.D8DB71E4017@bag.python.org> Author: guido.van.rossum Date: Fri Aug 3 21:03:39 2007 New Revision: 56708 Modified: python/branches/py3k-struni/Lib/SocketServer.py python/branches/py3k-struni/Lib/test/test_socketserver.py Log: SF patch# 1764815 by Paul Colomiets. Fix for test_socketserver. Use io.BytesIO instead of io.StringIO, and adjust tests. Modified: python/branches/py3k-struni/Lib/SocketServer.py ============================================================================== --- python/branches/py3k-struni/Lib/SocketServer.py (original) +++ python/branches/py3k-struni/Lib/SocketServer.py Fri Aug 3 21:03:39 2007 @@ -574,10 +574,10 @@ """Define self.rfile and self.wfile for datagram sockets.""" def setup(self): - from io import StringIO + from io import BytesIO self.packet, self.socket = self.request - self.rfile = StringIO(self.packet) - self.wfile = StringIO() + self.rfile = BytesIO(self.packet) + self.wfile = BytesIO() def finish(self): self.socket.sendto(self.wfile.getvalue(), self.client_address) Modified: python/branches/py3k-struni/Lib/test/test_socketserver.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_socketserver.py (original) +++ python/branches/py3k-struni/Lib/test/test_socketserver.py Fri Aug 3 21:03:39 2007 @@ -38,7 +38,7 @@ self.server_close() raise -teststring = "hello world\n" +teststring = b"hello world\n" def receive(sock, n, timeout=20): r, w, x = select.select([sock], [], [], timeout) @@ -51,7 +51,7 @@ s = socket.socket(proto, socket.SOCK_DGRAM) s.sendto(teststring, addr) buf = data = receive(s, 100) - while data and '\n' not in buf: + while data and b'\n' not in buf: data = receive(s, 100) buf += data verify(buf == teststring) @@ -62,7 +62,7 @@ s.connect(addr) s.sendall(teststring) buf = data = receive(s, 100) - while data and '\n' not in buf: + while data and b'\n' not in buf: data = receive(s, 100) buf += data verify(buf == teststring) From python-3000-checkins at python.org Fri Aug 3 21:19:25 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 3 Aug 2007 21:19:25 +0200 (CEST) Subject: [Python-3000-checkins] r56709 - in python/branches/py3k-struni/Lib: cookielib.py test/test_urllib2.py urllib.py urllib2.py Message-ID: <20070803191925.8C78B1E401C@bag.python.org> Author: guido.van.rossum Date: Fri Aug 3 21:19:24 2007 New Revision: 56709 Modified: python/branches/py3k-struni/Lib/cookielib.py python/branches/py3k-struni/Lib/test/test_urllib2.py python/branches/py3k-struni/Lib/urllib.py python/branches/py3k-struni/Lib/urllib2.py Log: SF patch# 1762940 by Joe Gregorio. Fix test_cookielib and test_urllib2. (The changes to urllib make urllib.quote() work correctly for Unicode strings; but they don't fix test_urllib.) Modified: python/branches/py3k-struni/Lib/cookielib.py ============================================================================== --- python/branches/py3k-struni/Lib/cookielib.py (original) +++ python/branches/py3k-struni/Lib/cookielib.py Fri Aug 3 21:19:24 2007 @@ -644,8 +644,6 @@ # And here, kind of: draft-fielding-uri-rfc2396bis-03 # (And in draft IRI specification: draft-duerst-iri-05) # (And here, for new URI schemes: RFC 2718) - if isinstance(path, str): - path = path.encode("utf-8") path = urllib.quote(path, HTTP_PATH_SAFE) path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path) return path Modified: python/branches/py3k-struni/Lib/test/test_urllib2.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllib2.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllib2.py Fri Aug 3 21:19:24 2007 @@ -1003,7 +1003,7 @@ self.assertEqual(len(http_handler.requests), 2) self.assertFalse(http_handler.requests[0].has_header(auth_header)) userpass = '%s:%s' % (user, password) - auth_hdr_value = 'Basic '+base64.encodestring(userpass).strip() + auth_hdr_value = 'Basic ' + str(base64.encodestring(userpass)).strip() self.assertEqual(http_handler.requests[1].get_header(auth_header), auth_hdr_value) Modified: python/branches/py3k-struni/Lib/urllib.py ============================================================================== --- python/branches/py3k-struni/Lib/urllib.py (original) +++ python/branches/py3k-struni/Lib/urllib.py Fri Aug 3 21:19:24 2007 @@ -1133,7 +1133,23 @@ always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' '0123456789' '_.-') -_safemaps = {} +_safe_quoters= {} + +class Quoter: + def __init__(self, safe): + self.cache = {} + self.safe = safe + always_safe + + def __call__(self, c): + try: + return self.cache[c] + except KeyError: + if ord(c) < 256: + res = (c in self.safe) and c or ('%%%02X' % ord(c)) + self.cache[c] = res + return res + else: + return "".join(['%%%02X' % i for i in c.encode("utf-8")]) def quote(s, safe = '/'): """quote('abc def') -> 'abc%20def' @@ -1158,15 +1174,11 @@ """ cachekey = (safe, always_safe) try: - safe_map = _safemaps[cachekey] + quoter = _safe_quoters[cachekey] except KeyError: - safe += always_safe - safe_map = {} - for i in range(256): - c = chr(i) - safe_map[c] = (c in safe) and c or ('%%%02X' % i) - _safemaps[cachekey] = safe_map - res = map(safe_map.__getitem__, s) + quoter = Quoter(safe) + _safe_quoters[cachekey] = quoter + res = map(quoter, s) return ''.join(res) def quote_plus(s, safe = ''): Modified: python/branches/py3k-struni/Lib/urllib2.py ============================================================================== --- python/branches/py3k-struni/Lib/urllib2.py (original) +++ python/branches/py3k-struni/Lib/urllib2.py Fri Aug 3 21:19:24 2007 @@ -679,7 +679,7 @@ proxy_type = orig_type if user and password: user_pass = '%s:%s' % (unquote(user), unquote(password)) - creds = base64.b64encode(user_pass).strip() + creds = str(base64.b64encode(user_pass)).strip() req.add_header('Proxy-authorization', 'Basic ' + creds) hostport = unquote(hostport) req.set_proxy(hostport, proxy_type) @@ -802,7 +802,7 @@ user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) - auth = 'Basic %s' % base64.b64encode(raw).strip() + auth = 'Basic %s' % str(base64.b64encode(raw)).strip() if req.headers.get(self.auth_header, None) == auth: return None req.add_header(self.auth_header, auth) From python-3000-checkins at python.org Fri Aug 3 22:30:34 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 22:30:34 +0200 (CEST) Subject: [Python-3000-checkins] r56711 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070803203034.49E781E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 22:30:33 2007 New Revision: 56711 Modified: python/branches/py3k-struni/Lib/httplib.py Log: A few local changes for consistency of string literals. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Fri Aug 3 22:30:33 2007 @@ -67,6 +67,7 @@ """ import errno +import io import mimetools import socket from urlparse import urlsplit @@ -307,7 +308,7 @@ self.status = self.status + '; bad seek' break -class HTTPResponse: +class HTTPResponse(io.IOBase): # strict: If true, raise BadStatusLine if the status line can't be # parsed as a valid HTTP/1.0 or 1.1 status line. By default it is @@ -897,7 +898,7 @@ self.send(body) def getresponse(self): - "Get the response from the server." + """Get the response from the server.""" # if a prior response has been completed, then forget about it. if self.__response and self.__response.isclosed(): @@ -1032,13 +1033,13 @@ avail = len(self._buf) while size is None or avail < size: s = self._read() - if s == '': + if s == "": break L.append(s) avail += len(s) all = "".join(L) if size is None: - self._buf = '' + self._buf = "" return all else: self._buf = all[size:] From python-3000-checkins at python.org Fri Aug 3 22:31:38 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 22:31:38 +0200 (CEST) Subject: [Python-3000-checkins] r56712 - python/branches/py3k-struni/Lib/test/test_urllib2net.py Message-ID: <20070803203138.E02001E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 22:31:38 2007 New Revision: 56712 Modified: python/branches/py3k-struni/Lib/test/test_urllib2net.py Log: Hack: Fix some test_urllib2.net tests by getting them access to the raw socket so they can check the timeout value. Should change the code under test to expose the timeout in a more direct way. Modified: python/branches/py3k-struni/Lib/test/test_urllib2net.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllib2net.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllib2net.py Fri Aug 3 22:31:38 2007 @@ -270,45 +270,47 @@ class TimeoutTest(unittest.TestCase): def test_http_basic(self): u = urllib2.urlopen("http://www.python.org") - self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None) + self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None) def test_http_NoneWithdefault(self): prev = socket.getdefaulttimeout() socket.setdefaulttimeout(60) try: u = urllib2.urlopen("http://www.python.org", timeout=None) - self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60) + self.assertTrue(u.fp.raw.fp._sock.gettimeout(), 60) finally: socket.setdefaulttimeout(prev) def test_http_Value(self): u = urllib2.urlopen("http://www.python.org", timeout=120) - self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120) + self.assertEqual(u.fp.raw.fp._sock.gettimeout(), 120) def test_http_NoneNodefault(self): u = urllib2.urlopen("http://www.python.org", timeout=None) - self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None) + self.assertTrue(u.fp.raw.fp._sock.gettimeout() is None) def test_ftp_basic(self): u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/") - self.assertTrue(u.fp.fp._sock.gettimeout() is None) + self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) def test_ftp_NoneWithdefault(self): prev = socket.getdefaulttimeout() socket.setdefaulttimeout(60) try: - u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=None) - self.assertEqual(u.fp.fp._sock.gettimeout(), 60) + u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", + timeout=None) + self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) finally: socket.setdefaulttimeout(prev) def test_ftp_NoneNodefault(self): - u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=None) - self.assertTrue(u.fp.fp._sock.gettimeout() is None) + u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", + timeout=None) + self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) def test_ftp_Value(self): u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=60) - self.assertEqual(u.fp.fp._sock.gettimeout(), 60) + self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) def test_main(): From python-3000-checkins at python.org Fri Aug 3 22:32:27 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 22:32:27 +0200 (CEST) Subject: [Python-3000-checkins] r56713 - python/branches/py3k-struni/Lib/BaseHTTPServer.py Message-ID: <20070803203227.CAFFE1E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 22:32:27 2007 New Revision: 56713 Modified: python/branches/py3k-struni/Lib/BaseHTTPServer.py Log: Treat HTTP status line as ISO-8859-1 as in httplib module. Modified: python/branches/py3k-struni/Lib/BaseHTTPServer.py ============================================================================== --- python/branches/py3k-struni/Lib/BaseHTTPServer.py (original) +++ python/branches/py3k-struni/Lib/BaseHTTPServer.py Fri Aug 3 22:32:27 2007 @@ -230,7 +230,7 @@ self.command = None # set in case of error on the first line self.request_version = version = "HTTP/0.9" # Default self.close_connection = 1 - requestline = self.raw_requestline + requestline = str(self.raw_requestline, 'iso-8859-1') if requestline[-2:] == '\r\n': requestline = requestline[:-2] elif requestline[-1:] == '\n': From python-3000-checkins at python.org Fri Aug 3 22:40:09 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 22:40:09 +0200 (CEST) Subject: [Python-3000-checkins] r56714 - in python/branches/py3k-struni/Lib: io.py socket.py test/test_socket.py Message-ID: <20070803204009.DE02A1E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 22:40:09 2007 New Revision: 56714 Modified: python/branches/py3k-struni/Lib/io.py python/branches/py3k-struni/Lib/socket.py python/branches/py3k-struni/Lib/test/test_socket.py Log: Make sure socket.close() doesn't interfere with socket.makefile(). If a makefile()-generated object is open and its parent socket is closed, the parent socket should remain open until the child is closed, too. The code to support this is moderately complex and requires one extra slots in the socket object. This change fixes httplib so that several urllib2net test cases pass again. Add SocketCloser class to socket.py, which encapsulates the refcounting logic for sockets after makefile() has been called. Move SocketIO class from io module to socket module. It's only use is to implement the raw I/O methods on top of a socket to support makefile(). Add unittests to test_socket to cover various patterns of close and makefile. Modified: python/branches/py3k-struni/Lib/io.py ============================================================================== --- python/branches/py3k-struni/Lib/io.py (original) +++ python/branches/py3k-struni/Lib/io.py Fri Aug 3 22:40:09 2007 @@ -442,34 +442,6 @@ return self._mode -class SocketIO(RawIOBase): - - """Raw I/O implementation for stream sockets.""" - - # XXX More docs - - def __init__(self, sock, mode): - assert mode in ("r", "w", "rw") - RawIOBase.__init__(self) - self._sock = sock - self._mode = mode - - def readinto(self, b): - return self._sock.recv_into(b) - - def write(self, b): - return self._sock.send(b) - - def readable(self): - return "r" in self._mode - - def writable(self): - return "w" in self._mode - - def fileno(self): - return self._sock.fileno() - - class BufferedIOBase(IOBase): """Base class for buffered IO objects. Modified: python/branches/py3k-struni/Lib/socket.py ============================================================================== --- python/branches/py3k-struni/Lib/socket.py (original) +++ python/branches/py3k-struni/Lib/socket.py Fri Aug 3 22:40:09 2007 @@ -89,22 +89,67 @@ # True if os.dup() can duplicate socket descriptors. # (On Windows at least, os.dup only works on files) -_can_dup_socket = hasattr(_socket, "dup") +_can_dup_socket = hasattr(_socket.socket, "dup") if _can_dup_socket: def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0): nfd = os.dup(fd) return socket(family, type, proto, fileno=nfd) +class SocketCloser: + + """Helper to manage socket close() logic for makefile(). + + The OS socket should not be closed until the socket and all + of its makefile-children are closed. If the refcount is zero + when socket.close() is called, this is easy: Just close the + socket. If the refcount is non-zero when socket.close() is + called, then the real close should not occur until the last + makefile-child is closed. + """ + + def __init__(self, sock): + self._sock = sock + self._makefile_refs = 0 + # Test whether the socket is open. + try: + sock.fileno() + self._socket_open = True + except error: + self._socket_open = False + + def socket_close(self): + self._socket_open = False + self.close() + + def makefile_open(self): + self._makefile_refs += 1 + + def makefile_close(self): + self._makefile_refs -= 1 + self.close() + + def close(self): + if not (self._socket_open or self._makefile_refs): + self._sock._real_close() + class socket(_socket.socket): """A subclass of _socket.socket adding the makefile() method.""" - __slots__ = ["__weakref__"] + __slots__ = ["__weakref__", "_closer"] if not _can_dup_socket: __slots__.append("_base") + def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None): + if fileno is None: + _socket.socket.__init__(self, family, type, proto) + else: + _socket.socket.__init__(self, family, type, proto, fileno) + # Defer creating a SocketCloser until makefile() is actually called. + self._closer = None + def __repr__(self): """Wrap __repr__() to reveal the real class name.""" s = _socket.socket.__repr__(self) @@ -128,14 +173,6 @@ conn.close() return wrapper, addr - if not _can_dup_socket: - def close(self): - """Wrap close() to close the _base as well.""" - _socket.socket.close(self) - base = getattr(self, "_base", None) - if base is not None: - base.close() - def makefile(self, mode="r", buffering=None, *, encoding=None, newline=None): """Return an I/O stream connected to the socket. @@ -156,7 +193,9 @@ rawmode += "r" if writing: rawmode += "w" - raw = io.SocketIO(self, rawmode) + if self._closer is None: + self._closer = SocketCloser(self) + raw = SocketIO(self, rawmode, self._closer) if buffering is None: buffering = -1 if buffering < 0: @@ -183,6 +222,65 @@ text.mode = mode return text + def close(self): + if self._closer is None: + self._real_close() + else: + self._closer.socket_close() + + # _real_close calls close on the _socket.socket base class. + + if not _can_dup_socket: + def _real_close(self): + _socket.socket.close(self) + base = getattr(self, "_base", None) + if base is not None: + self._base = None + base.close() + else: + def _real_close(self): + _socket.socket.close(self) + + +class SocketIO(io.RawIOBase): + + """Raw I/O implementation for stream sockets. + + This class supports the makefile() method on sockets. It provides + the raw I/O interface on top of a socket object. + """ + + # XXX More docs + + def __init__(self, sock, mode, closer): + assert mode in ("r", "w", "rw") + io.RawIOBase.__init__(self) + self._sock = sock + self._mode = mode + self._closer = closer + closer.makefile_open() + + def readinto(self, b): + return self._sock.recv_into(b) + + def write(self, b): + return self._sock.send(b) + + def readable(self): + return "r" in self._mode + + def writable(self): + return "w" in self._mode + + def fileno(self): + return self._sock.fileno() + + def close(self): + if self.closed: + return + self._closer.makefile_close() + io.RawIOBase.close(self) + def getfqdn(name=''): """Get fully qualified domain name from name. Modified: python/branches/py3k-struni/Lib/test/test_socket.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_socket.py (original) +++ python/branches/py3k-struni/Lib/test/test_socket.py Fri Aug 3 22:40:09 2007 @@ -163,6 +163,11 @@ self.cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) class SocketConnectedTest(ThreadedTCPSocketTest): + """Socket tests for client-server connection. + + self.cli_conn is a client socket connected to the server. The + setUp() method guarantees that it is connected to the server. + """ def __init__(self, methodName='runTest'): ThreadedTCPSocketTest.__init__(self, methodName=methodName) @@ -618,6 +623,10 @@ self.assertEqual(read, [sd]) self.assertEqual(sd.recv(1), b'') + # Calling close() many times should be safe. + conn.close() + conn.close() + def _testClose(self): self.cli.connect((HOST, PORT)) time.sleep(1.0) @@ -710,6 +719,16 @@ self.cli.send(MSG) class FileObjectClassTestCase(SocketConnectedTest): + """Unit tests for the object returned by socket.makefile() + + self.serv_file is the io object returned by makefile() on + the client connection. You can read from this file to + get output from the server. + + self.cli_file is the io object returned by makefile() on the + server connection. You can write to this file to send output + to the client. + """ bufsize = -1 # Use default buffer size @@ -779,6 +798,26 @@ self.cli_file.write(MSG) self.cli_file.flush() + def testCloseAfterMakefile(self): + # The file returned by makefile should keep the socket open. + self.cli_conn.close() + # read until EOF + msg = self.serv_file.read() + self.assertEqual(msg, MSG) + + def _testCloseAfterMakefile(self): + self.cli_file.write(MSG) + self.cli_file.flush() + + def testMakefileAfterMakefileClose(self): + self.serv_file.close() + msg = self.cli_conn.recv(len(MSG)) + self.assertEqual(msg, MSG) + + def _testMakefileAfterMakefileClose(self): + self.cli_file.write(MSG) + self.cli_file.flush() + def testClosedAttr(self): self.assert_(not self.serv_file.closed) From python-3000-checkins at python.org Fri Aug 3 22:40:45 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 3 Aug 2007 22:40:45 +0200 (CEST) Subject: [Python-3000-checkins] r56715 - python/branches/py3k-struni/Lib/test/test_complex.py Message-ID: <20070803204045.42FE31E4013@bag.python.org> Author: guido.van.rossum Date: Fri Aug 3 22:40:44 2007 New Revision: 56715 Modified: python/branches/py3k-struni/Lib/test/test_complex.py Log: Make test_complex pass again now that floordiv and mod are illegal. Modified: python/branches/py3k-struni/Lib/test/test_complex.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_complex.py (original) +++ python/branches/py3k-struni/Lib/test/test_complex.py Fri Aug 3 22:40:44 2007 @@ -89,8 +89,8 @@ self.assertRaises(ZeroDivisionError, complex.__truediv__, 1+1j, 0+0j) def test_floordiv(self): - self.assertAlmostEqual(complex.__floordiv__(3+0j, 1.5+0j), 2) - self.assertRaises(ZeroDivisionError, complex.__floordiv__, 3+0j, 0+0j) + self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 1.5+0j) + self.assertRaises(TypeError, complex.__floordiv__, 3+0j, 0+0j) def test_richcompare(self): self.assertRaises(OverflowError, complex.__eq__, 1+1j, 1<<10000) @@ -105,18 +105,13 @@ self.assertRaises(TypeError, complex.__ge__, 1+1j, 2+2j) def test_mod(self): - self.assertRaises(ZeroDivisionError, (1+1j).__mod__, 0+0j) - - a = 3.33+4.43j - try: - a % 0 - except ZeroDivisionError: - pass - else: - self.fail("modulo parama can't be 0") + # % is no longer supported on complex numbers + self.assertRaises(TypeError, (1+1j).__mod__, 0+0j) + self.assertRaises(TypeError, lambda: (3.33+4.43j) % 0) def test_divmod(self): - self.assertRaises(ZeroDivisionError, divmod, 1+1j, 0+0j) + self.assertRaises(TypeError, divmod, 1+1j, 1+0j) + self.assertRaises(TypeError, divmod, 1+1j, 0+0j) def test_pow(self): self.assertAlmostEqual(pow(1+1j, 0+0j), 1.0) From python-3000-checkins at python.org Fri Aug 3 22:56:14 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 22:56:14 +0200 (CEST) Subject: [Python-3000-checkins] r56716 - python/branches/py3k-struni/Lib/test/test_httplib.py Message-ID: <20070803205614.8212B1E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 22:56:14 2007 New Revision: 56716 Modified: python/branches/py3k-struni/Lib/test/test_httplib.py Log: Fix tests to use bytes() where the actual sockets return bytes(). Use io.BytesIO() instead of StringIO.StringIO(). FakeSocket still accepts regular strings and coverts them to bytes internally. Modified: python/branches/py3k-struni/Lib/test/test_httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_httplib.py (original) +++ python/branches/py3k-struni/Lib/test/test_httplib.py Fri Aug 3 22:56:14 2007 @@ -1,5 +1,5 @@ import httplib -import StringIO +import io import sys import socket @@ -8,7 +8,9 @@ from test import test_support class FakeSocket: - def __init__(self, text, fileclass=StringIO.StringIO): + def __init__(self, text, fileclass=io.BytesIO): + if isinstance(text, str): + text = bytes(text) self.text = text self.fileclass = fileclass self.data = b'' @@ -21,20 +23,20 @@ raise httplib.UnimplementedFileMode() return self.fileclass(self.text) -class NoEOFStringIO(StringIO.StringIO): +class NoEOFStringIO(io.BytesIO): """Like StringIO, but raises AssertionError on EOF. This is used below to test that httplib doesn't try to read more from the underlying file than it should. """ def read(self, n=-1): - data = StringIO.StringIO.read(self, n) + data = io.BytesIO.read(self, n) if data == '': raise AssertionError('caller tried to read past EOF') return data def readline(self, length=None): - data = StringIO.StringIO.readline(self, length) + data = io.BytesIO.readline(self, length) if data == '': raise AssertionError('caller tried to read past EOF') return data @@ -80,7 +82,7 @@ sock = FakeSocket(body) resp = httplib.HTTPResponse(sock) resp.begin() - self.assertEqual(resp.read(), 'Text') + self.assertEqual(resp.read(), b"Text") resp.close() body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" From python-3000-checkins at python.org Fri Aug 3 23:03:08 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Fri, 3 Aug 2007 23:03:08 +0200 (CEST) Subject: [Python-3000-checkins] r56717 - python/branches/py3k-struni/Lib/test/test_urllib2net.py Message-ID: <20070803210308.5BC651E400B@bag.python.org> Author: jeremy.hylton Date: Fri Aug 3 23:03:02 2007 New Revision: 56717 Modified: python/branches/py3k-struni/Lib/test/test_urllib2net.py Log: Fix an absurdly invasive test. Checks that an io object somewhere in the stack of wrappers is actually closed. --This line, and those below, will be ignored-- M test_urllib2net.py Modified: python/branches/py3k-struni/Lib/test/test_urllib2net.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllib2net.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllib2net.py Fri Aug 3 23:03:02 2007 @@ -75,11 +75,9 @@ # delve deep into response to fetch socket._socketobject response = urllib2.urlopen("http://www.python.org/") abused_fileobject = response.fp - self.assert_(abused_fileobject.__class__ is socket._fileobject) - httpresponse = abused_fileobject._sock + httpresponse = abused_fileobject.raw self.assert_(httpresponse.__class__ is httplib.HTTPResponse) fileobject = httpresponse.fp - self.assert_(fileobject.__class__ is socket._fileobject) self.assert_(not fileobject.closed) response.close() From python-3000-checkins at python.org Fri Aug 3 23:15:24 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 3 Aug 2007 23:15:24 +0200 (CEST) Subject: [Python-3000-checkins] r56718 - python/branches/py3k-struni/Lib/test/test_descr.py Message-ID: <20070803211524.AC1711E4013@bag.python.org> Author: guido.van.rossum Date: Fri Aug 3 23:15:23 2007 New Revision: 56718 Modified: python/branches/py3k-struni/Lib/test/test_descr.py Log: Fix failure do to outlawing complex floordiv/mod. Modified: python/branches/py3k-struni/Lib/test/test_descr.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_descr.py (original) +++ python/branches/py3k-struni/Lib/test/test_descr.py Fri Aug 3 23:15:23 2007 @@ -442,7 +442,9 @@ def complexes(): if verbose: print("Testing complex operations...") - numops(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge', 'int', 'long', 'float']) + numops(100.0j, 3.0j, + skip=['lt', 'le', 'gt', 'ge', 'int', 'long', 'float', + 'divmod', 'mod']) class Number(complex): __slots__ = ['prec'] def __new__(cls, *args, **kwds): From python-3000-checkins at python.org Sat Aug 4 00:27:52 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sat, 4 Aug 2007 00:27:52 +0200 (CEST) Subject: [Python-3000-checkins] r56719 - python/branches/py3k-struni/Modules/socketmodule.c Message-ID: <20070803222752.03C691E400B@bag.python.org> Author: guido.van.rossum Date: Sat Aug 4 00:27:51 2007 New Revision: 56719 Modified: python/branches/py3k-struni/Modules/socketmodule.c Log: Get rid of a bogus assert when recv_into() is called with a zero-length buffer. We just return 0 in this case now, like for all zero-length reads. Modified: python/branches/py3k-struni/Modules/socketmodule.c ============================================================================== --- python/branches/py3k-struni/Modules/socketmodule.c (original) +++ python/branches/py3k-struni/Modules/socketmodule.c Sat Aug 4 00:27:51 2007 @@ -2193,6 +2193,10 @@ select_error(); return -1; } + if (len == 0) { + /* If 0 bytes were requested, do nothing. */ + return 0; + } #ifndef __VMS Py_BEGIN_ALLOW_THREADS @@ -2322,7 +2326,6 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recv_into", kwlist, &buf, &buflen, &recvlen, &flags)) return NULL; - assert(buf != 0 && buflen > 0); if (recvlen < 0) { PyErr_SetString(PyExc_ValueError, From python-3000-checkins at python.org Sat Aug 4 04:34:25 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 04:34:25 +0200 (CEST) Subject: [Python-3000-checkins] r56720 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070804023425.9AAAB1E4011@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 04:34:24 2007 New Revision: 56720 Modified: python/branches/py3k-struni/Lib/httplib.py Log: HTTPResponse should not inherit from io.IOBase. I'm not sure why I thought it should originally, but it introduces an __del__() method on the response which cause the close() to be called too soon using the HTTP compat class. Also, remove some stale comments. The HTTPResponse calls makefile() immediately, so there is no risk of it closing the socket. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Sat Aug 4 04:34:24 2007 @@ -308,7 +308,7 @@ self.status = self.status + '; bad seek' break -class HTTPResponse(io.IOBase): +class HTTPResponse: # strict: If true, raise BadStatusLine if the status line can't be # parsed as a valid HTTP/1.0 or 1.1 status line. By default it is @@ -1205,10 +1205,6 @@ try: response = self._conn.getresponse() except BadStatusLine as e: - ### hmm. if getresponse() ever closes the socket on a bad request, - ### then we are going to have problems with self.sock - - ### should we keep this behavior? do people use it? # keep the socket open (as a file), and return it self.file = self._conn.sock.makefile('rb', 0) @@ -1399,7 +1395,7 @@ status, reason, headers = h.getreply() print('status =', status) print('reason =', reason) - print("read", len(h.getfile().read())) + print('read', len(h.getfile().read())) print() if headers: for header in headers.headers: print(header.strip()) From python-3000-checkins at python.org Sat Aug 4 04:58:43 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 04:58:43 +0200 (CEST) Subject: [Python-3000-checkins] r56721 - python/branches/py3k-struni/Modules/_ssl.c Message-ID: <20070804025843.03B101E400B@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 04:58:42 2007 New Revision: 56721 Modified: python/branches/py3k-struni/Modules/_ssl.c Log: Change read() on SSL socket to return bytes. Modified: python/branches/py3k-struni/Modules/_ssl.c ============================================================================== --- python/branches/py3k-struni/Modules/_ssl.c (original) +++ python/branches/py3k-struni/Modules/_ssl.c Sat Aug 4 04:58:42 2007 @@ -496,7 +496,7 @@ if (!PyArg_ParseTuple(args, "|i:read", &len)) return NULL; - if (!(buf = PyString_FromStringAndSize((char *) 0, len))) + if (!(buf = PyBytes_FromStringAndSize((char *) 0, len))) return NULL; /* first check if there are bytes ready to be read */ @@ -518,7 +518,7 @@ do { err = 0; Py_BEGIN_ALLOW_THREADS - count = SSL_read(self->ssl, PyString_AsString(buf), len); + count = SSL_read(self->ssl, PyBytes_AS_STRING(buf), len); err = SSL_get_error(self->ssl, count); Py_END_ALLOW_THREADS if(PyErr_CheckSignals()) { @@ -545,12 +545,15 @@ return PySSL_SetError(self, count); } if (count != len) - _PyString_Resize(&buf, count); + if (PyBytes_Resize(buf, count) < 0) { + Py_DECREF(buf); + return NULL; + } return buf; } PyDoc_STRVAR(PySSL_SSLread_doc, -"read([len]) -> string\n\ +"read([len]) -> bytes\n\ \n\ Read up to len bytes from the SSL socket."); From python-3000-checkins at python.org Sat Aug 4 05:25:18 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 05:25:18 +0200 (CEST) Subject: [Python-3000-checkins] r56722 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070804032518.08A701E400B@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 05:25:17 2007 New Revision: 56722 Modified: python/branches/py3k-struni/Lib/httplib.py Log: Fix several more paths from the SSL code. In particular, watch out for comparing b"" to "". They're not equal, but you can start at the code asking whether buf == "" for a long time before realizing that it will never be True. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Sat Aug 4 05:25:17 2007 @@ -435,14 +435,13 @@ # do we have a Content-Length? # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked" + self.length = None length = self.msg.getheader("content-length") if length and not self.chunked: try: self.length = int(length) except ValueError: - self.length = None - else: - self.length = None + pass # does the body have a fixed length? (of zero) if (status == NO_CONTENT or status == NOT_MODIFIED or @@ -453,9 +452,9 @@ # if the connection remains open, and we aren't using chunked, and # a content-length was not provided, then assume that the connection # WILL close. - if not self.will_close and \ - not self.chunked and \ - self.length is None: + if (not self.will_close and + not self.chunked and + self.length is None): self.will_close = 1 def _check_close(self): @@ -998,11 +997,11 @@ def __init__(self, sock, ssl, bufsize=None): SharedSocketClient.__init__(self, sock) self._ssl = ssl - self._buf = '' + self._buf = b"" self._bufsize = bufsize or self.__class__.BUFSIZE def _read(self): - buf = '' + buf = b"" # put in a loop so that we retry on transient errors while True: try: @@ -1033,13 +1032,13 @@ avail = len(self._buf) while size is None or avail < size: s = self._read() - if s == "": + if s == b"": break L.append(s) avail += len(s) - all = "".join(L) + all = b"".join(L) if size is None: - self._buf = "" + self._buf = b"" return all else: self._buf = all[size:] @@ -1047,20 +1046,20 @@ def readline(self): L = [self._buf] - self._buf = '' + self._buf = b"" while 1: i = L[-1].find("\n") if i >= 0: break s = self._read() - if s == '': + if s == b"": break L.append(s) if i == -1: # loop exited because there is no more data - return "".join(L) + return b"".join(L) else: - all = "".join(L) + all = b"".join(L) # XXX could do enough bookkeeping not to do a 2nd search i = all.find("\n") + 1 line = all[:i] From python-3000-checkins at python.org Sat Aug 4 05:34:03 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 05:34:03 +0200 (CEST) Subject: [Python-3000-checkins] r56723 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070804033403.4B8311E400B@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 05:34:03 2007 New Revision: 56723 Modified: python/branches/py3k-struni/Lib/httplib.py Log: Use BytesIO instead of StringIO. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Sat Aug 4 05:34:03 2007 @@ -72,8 +72,6 @@ import socket from urlparse import urlsplit -from io import StringIO - __all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPSConnection", "HTTPException", "NotConnected", "UnknownProtocol", "UnknownTransferEncoding", "UnimplementedFileMode", @@ -411,7 +409,7 @@ self.length = None self.chunked = 0 self.will_close = 1 - self.msg = HTTPMessage(StringIO()) + self.msg = HTTPMessage(io.BytesIO()) return self.msg = HTTPMessage(self.fp, 0) From python-3000-checkins at python.org Sat Aug 4 05:41:20 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 05:41:20 +0200 (CEST) Subject: [Python-3000-checkins] r56724 - python/branches/py3k-struni/Lib/httplib.py Message-ID: <20070804034120.47ADE1E400D@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 05:41:19 2007 New Revision: 56724 Modified: python/branches/py3k-struni/Lib/httplib.py Log: Make sure LineAndFileWrapper gets bytes() as its first argument. This change fixes a test in test_urllib. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Sat Aug 4 05:41:19 2007 @@ -340,7 +340,7 @@ self.will_close = _UNKNOWN # conn will close at end of response def _read_status(self): - # Initialize with Simple-Response defaults + # Initialize with Simple-Response defaults. line = str(self.fp.readline(), "iso-8859-1") if self.debuglevel > 0: print("reply:", repr(line)) @@ -363,8 +363,10 @@ self.close() raise BadStatusLine(line) else: - # assume it's a Simple-Response from an 0.9 server - self.fp = LineAndFileWrapper(line, self.fp) + # Assume it's a Simple-Response from an 0.9 server. + # We have to convert the first line back to raw bytes + # because self.fp.readline() needs to return bytes. + self.fp = LineAndFileWrapper(bytes(line), self.fp) return "HTTP/0.9", 200, "" # The status code is a three-digit number From python-3000-checkins at python.org Sat Aug 4 05:42:27 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 05:42:27 +0200 (CEST) Subject: [Python-3000-checkins] r56725 - python/branches/py3k-struni/Lib/test/test_urllib.py Message-ID: <20070804034227.D64B61E4011@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 05:42:26 2007 New Revision: 56725 Modified: python/branches/py3k-struni/Lib/test/test_urllib.py Log: Fix tests that tried to sneak strings through httplib. The httplib interface returns bytes for now. Modified: python/branches/py3k-struni/Lib/test/test_urllib.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllib.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllib.py Sat Aug 4 05:42:26 2007 @@ -2,12 +2,12 @@ import urllib import httplib +import io import unittest from test import test_support import os import mimetools import tempfile -import StringIO import ftplib import threading import socket @@ -99,15 +99,15 @@ """Test urlopen() opening a fake http connection.""" def fakehttp(self, fakedata): - class FakeSocket(StringIO.StringIO): + class FakeSocket(io.BytesIO): def sendall(self, str): pass def makefile(self, mode, name): return self def read(self, amt=None): - if self.closed: return '' - return StringIO.StringIO.read(self, amt) + if self.closed: return b"" + return io.BytesIO.read(self, amt) def readline(self, length=None): - if self.closed: return '' - return StringIO.StringIO.readline(self, length) + if self.closed: return b"" + return io.BytesIO.readline(self, length) class FakeHTTPConnection(httplib.HTTPConnection): def connect(self): self.sock = FakeSocket(fakedata) @@ -118,20 +118,20 @@ httplib.HTTP._connection_class = httplib.HTTPConnection def test_read(self): - self.fakehttp('Hello!') + self.fakehttp(b"Hello!") try: fp = urllib.urlopen("http://python.org/") - self.assertEqual(fp.readline(), 'Hello!') - self.assertEqual(fp.readline(), '') + self.assertEqual(fp.readline(), b"Hello!") + self.assertEqual(fp.readline(), b"") finally: self.unfakehttp() def test_empty_socket(self): - """urlopen() raises IOError if the underlying socket does not send any - data. (#1680230) """ - self.fakehttp('') + # urlopen() raises IOError if the underlying socket does not send any + # data. (#1680230) + self.fakehttp(b"") try: - self.assertRaises(IOError, urllib.urlopen, 'http://something') + self.assertRaises(IOError, urllib.urlopen, "http://something") finally: self.unfakehttp() From python-3000-checkins at python.org Sat Aug 4 05:46:11 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 05:46:11 +0200 (CEST) Subject: [Python-3000-checkins] r56726 - python/branches/py3k-struni/Lib/test/test_urllibnet.py Message-ID: <20070804034611.9EBD01E400B@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 05:46:11 2007 New Revision: 56726 Modified: python/branches/py3k-struni/Lib/test/test_urllibnet.py Log: Fix test: readline() now returns bytes Modified: python/branches/py3k-struni/Lib/test/test_urllibnet.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllibnet.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllibnet.py Sat Aug 4 05:46:11 2007 @@ -54,8 +54,8 @@ # Test both readline and readlines. open_url = urllib.urlopen("http://www.python.org/") try: - self.assert_(isinstance(open_url.readline(), basestring), - "readline did not return a string") + self.assert_(isinstance(open_url.readline(), bytes), + "readline did not return bytes") self.assert_(isinstance(open_url.readlines(), list), "readlines did not return a list") finally: From python-3000-checkins at python.org Sat Aug 4 18:43:59 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sat, 4 Aug 2007 18:43:59 +0200 (CEST) Subject: [Python-3000-checkins] r56737 - python/branches/py3k-struni/Objects/typeobject.c Message-ID: <20070804164359.F07D71E400D@bag.python.org> Author: guido.van.rossum Date: Sat Aug 4 18:43:59 2007 New Revision: 56737 Modified: python/branches/py3k-struni/Objects/typeobject.c Log: Fix an obvious bug caused by a switch to Unicode. However, this will need to be fixed further to allow non-ASCII letters in names; leaving this to MvL. Modified: python/branches/py3k-struni/Objects/typeobject.c ============================================================================== --- python/branches/py3k-struni/Objects/typeobject.c (original) +++ python/branches/py3k-struni/Objects/typeobject.c Sat Aug 4 18:43:59 2007 @@ -1579,7 +1579,8 @@ if (n == 0) n = 1; for (i = 0; i < n; i++, p++) { - if (i > 255 || (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_')) { + if (*p > 127 || + (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_')) { PyErr_SetString(PyExc_TypeError, "__slots__ must be identifiers"); return 0; From python-3000-checkins at python.org Sat Aug 4 19:43:16 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sat, 4 Aug 2007 19:43:16 +0200 (CEST) Subject: [Python-3000-checkins] r56739 - python/branches/py3k-struni/Lib/test/test_tokenize.py Message-ID: <20070804174316.36F9A1E400D@bag.python.org> Author: guido.van.rossum Date: Sat Aug 4 19:43:15 2007 New Revision: 56739 Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py Log: Make test_tokenize pass again: Add code to test_roundtrip() that figures out the encoding from the first two lines of the file. (We need to refactor this again to make it available to all places that need this, e.g. linecache.py.) Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_tokenize.py (original) +++ python/branches/py3k-struni/Lib/test/test_tokenize.py Sat Aug 4 19:43:15 2007 @@ -80,7 +80,10 @@ """ +# ' Emacs hint + import os, glob, random, time, sys +import re from io import StringIO from test.test_support import (verbose, findfile, is_resource_enabled, TestFailed) @@ -96,7 +99,17 @@ # tokenization doesn't match the first. def test_roundtrip(f): ## print 'Testing:', f - fobj = open(f) + # Get the encoding first + fobj = open(f, encoding="latin-1") + first2lines = fobj.readline() + fobj.readline() + fobj.close() + m = re.search(r"coding:\s*(\S+)", first2lines) + if m: + encoding = m.group(1) + print(" coding:", encoding) + else: + encoding = "utf-8" + fobj = open(f, encoding=encoding) try: fulltok = list(generate_tokens(fobj.readline)) finally: @@ -185,8 +198,6 @@ testdir = os.path.dirname(f) or os.curdir testfiles = glob.glob(testdir + os.sep + 'test*.py') - # Exclude test_pep263 which is encoded in KOI8-R - testfiles = [t for t in testfiles if not t.endswith("pep263.py")] if not is_resource_enabled('compiler'): testfiles = random.sample(testfiles, 10) From python-3000-checkins at python.org Sat Aug 4 19:55:44 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sat, 4 Aug 2007 19:55:44 +0200 (CEST) Subject: [Python-3000-checkins] r56740 - python/branches/py3k-struni/Lib/test/test_tokenize.py Message-ID: <20070804175544.1FB831E4016@bag.python.org> Author: guido.van.rossum Date: Sat Aug 4 19:55:43 2007 New Revision: 56740 Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py Log: Make test_tokenize really pass -- don't add extra output. Modified: python/branches/py3k-struni/Lib/test/test_tokenize.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_tokenize.py (original) +++ python/branches/py3k-struni/Lib/test/test_tokenize.py Sat Aug 4 19:55:43 2007 @@ -98,7 +98,7 @@ # and tokenized again from the latter. The test fails if the second # tokenization doesn't match the first. def test_roundtrip(f): - ## print 'Testing:', f + ## print('Testing:', f) # Get the encoding first fobj = open(f, encoding="latin-1") first2lines = fobj.readline() + fobj.readline() @@ -106,7 +106,7 @@ m = re.search(r"coding:\s*(\S+)", first2lines) if m: encoding = m.group(1) - print(" coding:", encoding) + ## print(" coding:", encoding) else: encoding = "utf-8" fobj = open(f, encoding=encoding) From python-3000-checkins at python.org Sat Aug 4 21:22:08 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 21:22:08 +0200 (CEST) Subject: [Python-3000-checkins] r56742 - python/branches/py3k-struni/Lib/httplib.py python/branches/py3k-struni/Lib/urllib.py Message-ID: <20070804192208.40EAB1E4018@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 21:22:00 2007 New Revision: 56742 Modified: python/branches/py3k-struni/Lib/httplib.py python/branches/py3k-struni/Lib/urllib.py Log: Change urllib to use HTTPConnection rather than old HTTP class. The HTTP class is a backwards compatibility layer for the Python 1.5 API. (The only remaining use in the std library is xmlrpclib.) The current change makes urllib issue HTTP/1.0 requests with HTTPConnection, because is accesses HTTPResponse.fp directly instead of using the read() method. Using fp directly interacts poorly with persistent connections. There are probably better solutions than the current one, but this is a start. Modified: python/branches/py3k-struni/Lib/httplib.py ============================================================================== --- python/branches/py3k-struni/Lib/httplib.py (original) +++ python/branches/py3k-struni/Lib/httplib.py Sat Aug 4 21:22:00 2007 @@ -322,6 +322,13 @@ # accepts iso-8859-1. def __init__(self, sock, debuglevel=0, strict=0, method=None): + # XXX If the response includes a content-length header, we + # need to make sure that the client doesn't read more than the + # specified number of bytes. If it does, it will block until + # the server times out and closes the connection. (The only + # applies to HTTP/1.1 connections.) Since some clients access + # self.fp directly rather than calling read(), this is a little + # tricky. self.fp = sock.makefile("rb", 0) self.debuglevel = debuglevel self.strict = strict Modified: python/branches/py3k-struni/Lib/urllib.py ============================================================================== --- python/branches/py3k-struni/Lib/urllib.py (original) +++ python/branches/py3k-struni/Lib/urllib.py Sat Aug 4 21:22:00 2007 @@ -81,11 +81,13 @@ return opener.open(url) else: return opener.open(url, data) + def urlretrieve(url, filename=None, reporthook=None, data=None): global _urlopener if not _urlopener: _urlopener = FancyURLopener() return _urlopener.retrieve(url, filename, reporthook, data) + def urlcleanup(): if _urlopener: _urlopener.cleanup() @@ -310,37 +312,44 @@ auth = base64.b64encode(user_passwd).strip() else: auth = None - h = httplib.HTTP(host) + http_conn = httplib.HTTPConnection(host) + # XXX We should fix urllib so that it works with HTTP/1.1. + http_conn._http_vsn = 10 + http_conn._http_vsn_str = "HTTP/1.0" + + headers = {} + if proxy_auth: + headers["Proxy-Authorization"] = "Basic %s" % proxy_auth + if auth: + headers["Authorization"] = "Basic %s" % auth + if realhost: + headers["Host"] = realhost + for header, value in self.addheaders: + headers[header] = value + if data is not None: - h.putrequest('POST', selector) - h.putheader('Content-Type', 'application/x-www-form-urlencoded') - h.putheader('Content-Length', '%d' % len(data)) + headers["Content-Type"] = "application/x-www-form-urlencoded" + http_conn.request("POST", selector, data, headers) else: - h.putrequest('GET', selector) - if proxy_auth: h.putheader('Proxy-Authorization', 'Basic %s' % proxy_auth) - if auth: h.putheader('Authorization', 'Basic %s' % auth) - if realhost: h.putheader('Host', realhost) - for args in self.addheaders: h.putheader(*args) - h.endheaders() - if data is not None: - h.send(data) - errcode, errmsg, headers = h.getreply() - fp = h.getfile() - if errcode == -1: - if fp: fp.close() + http_conn.request("GET", selector, headers=headers) + + try: + response = http_conn.getresponse() + except httplib.BadStatusLine: # something went wrong with the HTTP status line - raise IOError, ('http protocol error', 0, - 'got a bad status line', None) - if errcode == 200: - return addinfourl(fp, headers, "http:" + url) + raise IOError('http protocol error', 0, + 'got a bad status line', None) + + if response.status == 200: + return addinfourl(response.fp, response.msg, "http:" + url) else: - if data is None: - return self.http_error(url, fp, errcode, errmsg, headers) - else: - return self.http_error(url, fp, errcode, errmsg, headers, data) + return self.http_error( + url, response.fp, + response.status, response.reason, response.msg, data) def http_error(self, url, fp, errcode, errmsg, headers, data=None): """Handle http errors. + Derived class can override this, or provide specific handlers named http_error_DDD where DDD is the 3-digit error code.""" # First check if there's a specific handler for this error @@ -872,6 +881,8 @@ class addbase: """Base class for addinfo and addclosehook.""" + # XXX Add a method to expose the timeout on the underlying socket? + def __init__(self, fp): self.fp = fp self.read = self.fp.read From python-3000-checkins at python.org Sat Aug 4 21:23:16 2007 From: python-3000-checkins at python.org (jeremy.hylton) Date: Sat, 4 Aug 2007 21:23:16 +0200 (CEST) Subject: [Python-3000-checkins] r56743 - python/branches/py3k-struni/Lib/test/test_urllib.py Message-ID: <20070804192316.B3AB51E4011@bag.python.org> Author: jeremy.hylton Date: Sat Aug 4 21:23:09 2007 New Revision: 56743 Modified: python/branches/py3k-struni/Lib/test/test_urllib.py Log: Fix test for new version of urllib that uses HTTPConnection directly. Changes the way the httplib classes are stubbed out. Modified: python/branches/py3k-struni/Lib/test/test_urllib.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_urllib.py (original) +++ python/branches/py3k-struni/Lib/test/test_urllib.py Sat Aug 4 21:23:09 2007 @@ -111,11 +111,11 @@ class FakeHTTPConnection(httplib.HTTPConnection): def connect(self): self.sock = FakeSocket(fakedata) - assert httplib.HTTP._connection_class == httplib.HTTPConnection - httplib.HTTP._connection_class = FakeHTTPConnection + self._connection_class = httplib.HTTPConnection + httplib.HTTPConnection = FakeHTTPConnection def unfakehttp(self): - httplib.HTTP._connection_class = httplib.HTTPConnection + httplib.HTTPConnection = self._connection_class def test_read(self): self.fakehttp(b"Hello!") From python-3000-checkins at python.org Sun Aug 5 04:19:23 2007 From: python-3000-checkins at python.org (neal.norwitz) Date: Sun, 5 Aug 2007 04:19:23 +0200 (CEST) Subject: [Python-3000-checkins] r56748 - in python/branches/p3yk: Lib/test/test_scope.py Python/symtable.c Message-ID: <20070805021923.8CE3F1E4E29@bag.python.org> Author: neal.norwitz Date: Sun Aug 5 04:19:04 2007 New Revision: 56748 Modified: python/branches/p3yk/Lib/test/test_scope.py python/branches/p3yk/Python/symtable.c Log: Make from X import * outside module scope an error. Modified: python/branches/p3yk/Lib/test/test_scope.py ============================================================================== --- python/branches/p3yk/Lib/test/test_scope.py (original) +++ python/branches/p3yk/Lib/test/test_scope.py Sun Aug 5 04:19:04 2007 @@ -223,25 +223,6 @@ return getrefcount # global or local? """) - # and verify a few cases that should work - - exec(""" -def noproblem1(): - from sys import * - f = lambda x:x - -def noproblem2(): - from sys import * - def f(x): - return x + 1 - -def noproblem3(): - from sys import * - def f(x): - global y - y = x -""") - def testLambdas(self): f1 = lambda x: lambda y: x + y Modified: python/branches/p3yk/Python/symtable.c ============================================================================== --- python/branches/p3yk/Python/symtable.c (original) +++ python/branches/p3yk/Python/symtable.c Sun Aug 5 04:19:04 2007 @@ -1478,10 +1478,10 @@ else { if (st->st_cur->ste_type != ModuleBlock) { int lineno = st->st_cur->ste_lineno; - if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) { - Py_DECREF(store_name); - return 0; - } + PyErr_SetString(PyExc_SyntaxError, IMPORT_STAR_WARNING); + PyErr_SyntaxLocation(st->st_filename, lineno); + Py_DECREF(store_name); + return 0; } st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR; Py_DECREF(store_name); From python-3000-checkins at python.org Sun Aug 5 04:35:31 2007 From: python-3000-checkins at python.org (neal.norwitz) Date: Sun, 5 Aug 2007 04:35:31 +0200 (CEST) Subject: [Python-3000-checkins] r56750 - in python/branches/p3yk: Modules/_csv.c Modules/_hotshot.c Modules/bz2module.c Objects/fileobject.c Objects/frameobject.c Objects/genobject.c Message-ID: <20070805023531.BC8851E50CF@bag.python.org> Author: neal.norwitz Date: Sun Aug 5 04:35:01 2007 New Revision: 56750 Modified: python/branches/p3yk/Modules/_csv.c python/branches/p3yk/Modules/_hotshot.c python/branches/p3yk/Modules/bz2module.c python/branches/p3yk/Objects/fileobject.c python/branches/p3yk/Objects/frameobject.c python/branches/p3yk/Objects/genobject.c Log: Use READONLY consistently instead of RO Modified: python/branches/p3yk/Modules/_csv.c ============================================================================== --- python/branches/p3yk/Modules/_csv.c (original) +++ python/branches/p3yk/Modules/_csv.c Sun Aug 5 04:35:01 2007 @@ -861,8 +861,8 @@ #define R_OFF(x) offsetof(ReaderObj, x) static struct PyMemberDef Reader_memberlist[] = { - { "dialect", T_OBJECT, R_OFF(dialect), RO }, - { "line_num", T_ULONG, R_OFF(line_num), RO }, + { "dialect", T_OBJECT, R_OFF(dialect), READONLY }, + { "line_num", T_ULONG, R_OFF(line_num), READONLY }, { NULL } }; @@ -1239,7 +1239,7 @@ #define W_OFF(x) offsetof(WriterObj, x) static struct PyMemberDef Writer_memberlist[] = { - { "dialect", T_OBJECT, W_OFF(dialect), RO }, + { "dialect", T_OBJECT, W_OFF(dialect), READONLY }, { NULL } }; Modified: python/branches/p3yk/Modules/_hotshot.c ============================================================================== --- python/branches/p3yk/Modules/_hotshot.c (original) +++ python/branches/p3yk/Modules/_hotshot.c Sun Aug 5 04:35:01 2007 @@ -1266,7 +1266,7 @@ }; static PyMemberDef logreader_members[] = { - {"info", T_OBJECT, offsetof(LogReaderObject, info), RO, + {"info", T_OBJECT, offsetof(LogReaderObject, info), READONLY, PyDoc_STR("Dictionary mapping informational keys to lists of values.")}, {NULL} }; Modified: python/branches/p3yk/Modules/bz2module.c ============================================================================== --- python/branches/p3yk/Modules/bz2module.c (original) +++ python/branches/p3yk/Modules/bz2module.c Sun Aug 5 04:35:01 2007 @@ -1775,7 +1775,7 @@ #define OFF(x) offsetof(BZ2DecompObject, x) static PyMemberDef BZ2Decomp_members[] = { - {"unused_data", T_OBJECT, OFF(unused_data), RO}, + {"unused_data", T_OBJECT, OFF(unused_data), READONLY}, {NULL} /* Sentinel */ }; Modified: python/branches/p3yk/Objects/fileobject.c ============================================================================== --- python/branches/p3yk/Objects/fileobject.c (original) +++ python/branches/p3yk/Objects/fileobject.c Sun Aug 5 04:35:01 2007 @@ -1773,11 +1773,11 @@ #define OFF(x) offsetof(PyFileObject, x) static PyMemberDef file_memberlist[] = { - {"mode", T_OBJECT, OFF(f_mode), RO, + {"mode", T_OBJECT, OFF(f_mode), READONLY, "file mode ('r', 'U', 'w', 'a', possibly with 'b' or '+' added)"}, - {"name", T_OBJECT, OFF(f_name), RO, + {"name", T_OBJECT, OFF(f_name), READONLY, "file name"}, - {"encoding", T_OBJECT, OFF(f_encoding), RO, + {"encoding", T_OBJECT, OFF(f_encoding), READONLY, "file encoding"}, /* getattr(f, "closed") is implemented without this table */ {NULL} /* Sentinel */ Modified: python/branches/p3yk/Objects/frameobject.c ============================================================================== --- python/branches/p3yk/Objects/frameobject.c (original) +++ python/branches/p3yk/Objects/frameobject.c Sun Aug 5 04:35:01 2007 @@ -15,11 +15,11 @@ #define OFF(x) offsetof(PyFrameObject, x) static PyMemberDef frame_memberlist[] = { - {"f_back", T_OBJECT, OFF(f_back), RO}, - {"f_code", T_OBJECT, OFF(f_code), RO}, - {"f_builtins", T_OBJECT, OFF(f_builtins),RO}, - {"f_globals", T_OBJECT, OFF(f_globals), RO}, - {"f_lasti", T_INT, OFF(f_lasti), RO}, + {"f_back", T_OBJECT, OFF(f_back), READONLY}, + {"f_code", T_OBJECT, OFF(f_code), READONLY}, + {"f_builtins", T_OBJECT, OFF(f_builtins),READONLY}, + {"f_globals", T_OBJECT, OFF(f_globals), READONLY}, + {"f_lasti", T_INT, OFF(f_lasti), READONLY}, {"f_exc_type", T_OBJECT, OFF(f_exc_type)}, {"f_exc_value", T_OBJECT, OFF(f_exc_value)}, {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)}, Modified: python/branches/p3yk/Objects/genobject.c ============================================================================== --- python/branches/p3yk/Objects/genobject.c (original) +++ python/branches/p3yk/Objects/genobject.c Sun Aug 5 04:35:01 2007 @@ -282,8 +282,8 @@ static PyMemberDef gen_memberlist[] = { - {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), RO}, - {"gi_running", T_INT, offsetof(PyGenObject, gi_running), RO}, + {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), READONLY}, + {"gi_running", T_INT, offsetof(PyGenObject, gi_running), READONLY}, {NULL} /* Sentinel */ }; From python-3000-checkins at python.org Sun Aug 5 17:29:30 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sun, 5 Aug 2007 17:29:30 +0200 (CEST) Subject: [Python-3000-checkins] r56753 - in python/branches/py3k-struni: Demo/scripts/morse.py Demo/scripts/toaiff.py Doc/Makefile.deps Doc/lib/lib.tex Doc/lib/libaudioop.tex Doc/lib/libsun.tex Doc/lib/libsunaudio.tex Doc/lib/libundoc.tex Lib/audiodev.py Lib/code.py Lib/idlelib/EditorWindow.py Lib/idlelib/PyShell.py Lib/idlelib/ScriptBinding.py Lib/idlelib/run.py Lib/plat-sunos5/SUNAUDIODEV.py Lib/test/README Lib/test/output/test_linuxaudiodev Lib/test/regrtest.py Lib/test/test___all__.py Lib/test/test_generators.py Lib/test/test_genexps.py Lib/test/test_linuxaudiodev.py Lib/test/test_scope.py Lib/test/test_sunaudiodev.py Lib/test/test_sundry.py Lib/test/test_syntax.py Lib/test/test_unpack_ex.py Lib/toaiff.py Lib/traceback.py Mac/Demo/sound/morse.py Makefile.pre.in Misc/BeOS-setup.py Misc/NEWS Misc/cheatsheet Modules/Setup.dist Modules/_csv.c Modules/_hotshot.c Modules/bz2module.c Modules/linuxaudiodev.c Modules/sunaudiodev.c Objects/frameobject.c Objects/genobject.c PC/os2vacpp/makefile PC/os2vacpp/makefile.omk Python/symtable.c Tools/audiopy setup.py Message-ID: <20070805152930.2067A1E4002@bag.python.org> Author: guido.van.rossum Date: Sun Aug 5 17:29:28 2007 New Revision: 56753 Added: python/branches/py3k-struni/Demo/scripts/toaiff.py - copied unchanged from r56750, python/branches/p3yk/Demo/scripts/toaiff.py Removed: python/branches/py3k-struni/Demo/scripts/morse.py python/branches/py3k-struni/Doc/lib/libsun.tex python/branches/py3k-struni/Doc/lib/libsunaudio.tex python/branches/py3k-struni/Lib/audiodev.py python/branches/py3k-struni/Lib/plat-sunos5/SUNAUDIODEV.py python/branches/py3k-struni/Lib/test/output/test_linuxaudiodev python/branches/py3k-struni/Lib/test/test_linuxaudiodev.py python/branches/py3k-struni/Lib/test/test_sunaudiodev.py python/branches/py3k-struni/Lib/toaiff.py python/branches/py3k-struni/Mac/Demo/sound/morse.py python/branches/py3k-struni/Modules/linuxaudiodev.c python/branches/py3k-struni/Modules/sunaudiodev.c python/branches/py3k-struni/Tools/audiopy/ Modified: python/branches/py3k-struni/ (props changed) python/branches/py3k-struni/Doc/Makefile.deps python/branches/py3k-struni/Doc/lib/lib.tex python/branches/py3k-struni/Doc/lib/libaudioop.tex python/branches/py3k-struni/Doc/lib/libundoc.tex python/branches/py3k-struni/Lib/code.py python/branches/py3k-struni/Lib/idlelib/EditorWindow.py python/branches/py3k-struni/Lib/idlelib/PyShell.py python/branches/py3k-struni/Lib/idlelib/ScriptBinding.py python/branches/py3k-struni/Lib/idlelib/run.py python/branches/py3k-struni/Lib/test/README python/branches/py3k-struni/Lib/test/regrtest.py python/branches/py3k-struni/Lib/test/test___all__.py python/branches/py3k-struni/Lib/test/test_generators.py python/branches/py3k-struni/Lib/test/test_genexps.py python/branches/py3k-struni/Lib/test/test_scope.py python/branches/py3k-struni/Lib/test/test_sundry.py python/branches/py3k-struni/Lib/test/test_syntax.py python/branches/py3k-struni/Lib/test/test_unpack_ex.py python/branches/py3k-struni/Lib/traceback.py python/branches/py3k-struni/Makefile.pre.in python/branches/py3k-struni/Misc/BeOS-setup.py python/branches/py3k-struni/Misc/NEWS python/branches/py3k-struni/Misc/cheatsheet python/branches/py3k-struni/Modules/Setup.dist python/branches/py3k-struni/Modules/_csv.c python/branches/py3k-struni/Modules/_hotshot.c python/branches/py3k-struni/Modules/bz2module.c python/branches/py3k-struni/Objects/frameobject.c python/branches/py3k-struni/Objects/genobject.c python/branches/py3k-struni/PC/os2vacpp/makefile python/branches/py3k-struni/PC/os2vacpp/makefile.omk python/branches/py3k-struni/Python/symtable.c python/branches/py3k-struni/setup.py Log: Merged revisions 56492-56752 via svnmerge from svn+ssh://pythondev at svn.python.org/python/branches/p3yk ........ r56497 | kurt.kaiser | 2007-07-22 14:55:16 -0700 (Sun, 22 Jul 2007) | 4 lines In the case of syntax errors, in py3k format_exception_only() was including line number and position in the final line of the exception notification, duplicating info in previous lines. ........ r56501 | kurt.kaiser | 2007-07-22 19:35:50 -0700 (Sun, 22 Jul 2007) | 2 lines Hum, needed a newline in the last change. ........ r56536 | kurt.kaiser | 2007-07-24 19:06:48 -0700 (Tue, 24 Jul 2007) | 5 lines Not all instantiations of SyntaxError set the args attribute. e.g. symtable.c Modify format_exception_only() to get SyntaxError attributes directly instead of unpacking 'args'. ........ r56537 | kurt.kaiser | 2007-07-24 19:13:03 -0700 (Tue, 24 Jul 2007) | 3 lines Update doctest strings: traceback.py no longer prints redundant location information in the last line of the exception display. ........ r56627 | kurt.kaiser | 2007-07-29 21:06:57 -0700 (Sun, 29 Jul 2007) | 2 lines Interactive interpreter emulator (code.py) failing to print exceptions. ........ r56628 | kurt.kaiser | 2007-07-29 21:41:02 -0700 (Sun, 29 Jul 2007) | 2 lines Eliminate extra lines before and after tracebacks. ........ r56638 | kurt.kaiser | 2007-07-31 19:36:45 -0700 (Tue, 31 Jul 2007) | 3 lines Refactor syntax error display in shell and edit windows; move colorize_syntax_error() to EditorWindow; update to py3k. ........ r56685 | neal.norwitz | 2007-08-02 22:20:23 -0700 (Thu, 02 Aug 2007) | 10 lines Remove several h/w and o/s specific modules that are undocumented, obsolete, and/or not widely used: linuxaudiodev.c, sunaudiodev.c Lib/plat-sunos5/SUNAUDIODEV.py Lib/audiodev.py Tools/audiopy/audiopy Move Lib/toaiff.py to Demo. See PEP 3108 for most of the details. ........ r56686 | neal.norwitz | 2007-08-02 22:21:48 -0700 (Thu, 02 Aug 2007) | 4 lines Missed one module that should have been removed since it relied on audiodev which was removed. ........ r56748 | neal.norwitz | 2007-08-04 19:19:04 -0700 (Sat, 04 Aug 2007) | 1 line Make from X import * outside module scope an error. ........ r56750 | neal.norwitz | 2007-08-04 19:35:01 -0700 (Sat, 04 Aug 2007) | 1 line Use READONLY consistently instead of RO ........ Deleted: /python/branches/py3k-struni/Demo/scripts/morse.py ============================================================================== --- /python/branches/py3k-struni/Demo/scripts/morse.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,149 +0,0 @@ -# DAH should be three DOTs. -# Space between DOTs and DAHs should be one DOT. -# Space between two letters should be one DAH. -# Space between two words should be DOT DAH DAH. - -import sys, math, audiodev - -DOT = 30 -DAH = 3 * DOT -OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ... - -morsetab = { - 'A': '.-', 'a': '.-', - 'B': '-...', 'b': '-...', - 'C': '-.-.', 'c': '-.-.', - 'D': '-..', 'd': '-..', - 'E': '.', 'e': '.', - 'F': '..-.', 'f': '..-.', - 'G': '--.', 'g': '--.', - 'H': '....', 'h': '....', - 'I': '..', 'i': '..', - 'J': '.---', 'j': '.---', - 'K': '-.-', 'k': '-.-', - 'L': '.-..', 'l': '.-..', - 'M': '--', 'm': '--', - 'N': '-.', 'n': '-.', - 'O': '---', 'o': '---', - 'P': '.--.', 'p': '.--.', - 'Q': '--.-', 'q': '--.-', - 'R': '.-.', 'r': '.-.', - 'S': '...', 's': '...', - 'T': '-', 't': '-', - 'U': '..-', 'u': '..-', - 'V': '...-', 'v': '...-', - 'W': '.--', 'w': '.--', - 'X': '-..-', 'x': '-..-', - 'Y': '-.--', 'y': '-.--', - 'Z': '--..', 'z': '--..', - '0': '-----', - '1': '.----', - '2': '..---', - '3': '...--', - '4': '....-', - '5': '.....', - '6': '-....', - '7': '--...', - '8': '---..', - '9': '----.', - ',': '--..--', - '.': '.-.-.-', - '?': '..--..', - ';': '-.-.-.', - ':': '---...', - "'": '.----.', - '-': '-....-', - '/': '-..-.', - '(': '-.--.-', - ')': '-.--.-', - '_': '..--.-', - ' ': ' ' -} - -# If we play at 44.1 kHz (which we do), then if we produce one sine -# wave in 100 samples, we get a tone of 441 Hz. If we produce two -# sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz -# appears to be a nice one for playing morse code. -def mkwave(octave): - global sinewave, nowave - sinewave = '' - for i in range(100): - val = int(math.sin(math.pi * float(i) * octave / 50.0) * 30000) - sinewave = sinewave + chr((val >> 8) & 255) + chr(val & 255) - nowave = '\0' * 200 - -mkwave(OCTAVE) - -def main(): - import getopt, string - try: - opts, args = getopt.getopt(sys.argv[1:], 'o:p:') - except getopt.error: - sys.stderr.write('Usage ' + sys.argv[0] + - ' [ -o outfile ] [ args ] ...\n') - sys.exit(1) - dev = None - for o, a in opts: - if o == '-o': - import aifc - dev = aifc.open(a, 'w') - dev.setframerate(44100) - dev.setsampwidth(2) - dev.setnchannels(1) - if o == '-p': - mkwave(string.atoi(a)) - if not dev: - import audiodev - dev = audiodev.AudioDev() - dev.setoutrate(44100) - dev.setsampwidth(2) - dev.setnchannels(1) - dev.close = dev.stop - dev.writeframesraw = dev.writeframes - if args: - line = string.join(args) - else: - line = sys.stdin.readline() - while line: - mline = morse(line) - play(mline, dev) - if hasattr(dev, 'wait'): - dev.wait() - if not args: - line = sys.stdin.readline() - else: - line = '' - dev.close() - -# Convert a string to morse code with \001 between the characters in -# the string. -def morse(line): - res = '' - for c in line: - try: - res = res + morsetab[c] + '\001' - except KeyError: - pass - return res - -# Play a line of morse code. -def play(line, dev): - for c in line: - if c == '.': - sine(dev, DOT) - elif c == '-': - sine(dev, DAH) - else: # space - pause(dev, DAH + DOT) - pause(dev, DOT) - -def sine(dev, length): - for i in range(length): - dev.writeframesraw(sinewave) - -def pause(dev, length): - for i in range(length): - dev.writeframesraw(nowave) - -if __name__ == '__main__' or sys.argv[0] == __name__: - main() Modified: python/branches/py3k-struni/Doc/Makefile.deps ============================================================================== --- python/branches/py3k-struni/Doc/Makefile.deps (original) +++ python/branches/py3k-struni/Doc/Makefile.deps Sun Aug 5 17:29:28 2007 @@ -199,7 +199,6 @@ lib/libcrypto.tex \ lib/libhashlib.tex \ lib/libhmac.tex \ - lib/libsun.tex \ lib/libxdrlib.tex \ lib/libimghdr.tex \ lib/libformatter.tex \ @@ -259,7 +258,6 @@ lib/libsymbol.tex \ lib/libbinhex.tex \ lib/libuu.tex \ - lib/libsunaudio.tex \ lib/libfileinput.tex \ lib/libimaplib.tex \ lib/libpoplib.tex \ Modified: python/branches/py3k-struni/Doc/lib/lib.tex ============================================================================== --- python/branches/py3k-struni/Doc/lib/lib.tex (original) +++ python/branches/py3k-struni/Doc/lib/lib.tex Sun Aug 5 17:29:28 2007 @@ -416,10 +416,6 @@ % OTHER PLATFORM-SPECIFIC STUFF % ============= -\input{libsun} % SUNOS ONLY -\input{libsunaudio} -% XXX(nnorwitz): the modules below this comment should be kept. - \input{windows} % MS Windows ONLY \input{libmsilib} \input{libmsvcrt} @@ -430,9 +426,6 @@ \input{libundoc} %\chapter{Obsolete Modules} -%\input{libcmpcache} -%\input{libcmp} -%\input{libni} \chapter{Reporting Bugs} \input{reportingbugs} Modified: python/branches/py3k-struni/Doc/lib/libaudioop.tex ============================================================================== --- python/branches/py3k-struni/Doc/lib/libaudioop.tex (original) +++ python/branches/py3k-struni/Doc/lib/libaudioop.tex Sun Aug 5 17:29:28 2007 @@ -7,9 +7,8 @@ The \module{audioop} module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed -integer samples 8, 16 or 32 bits wide, stored in Python strings. This -is the same format as used by the \refmodule{al} and \refmodule{sunaudiodev} -modules. All scalar items are integers, unless specified otherwise. +integer samples 8, 16 or 32 bits wide, stored in Python strings. +All scalar items are integers, unless specified otherwise. % This para is mostly here to provide an excuse for the index entries... This module provides support for a-LAW, u-LAW and Intel/DVI ADPCM encodings. Deleted: /python/branches/py3k-struni/Doc/lib/libsun.tex ============================================================================== --- /python/branches/py3k-struni/Doc/lib/libsun.tex Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,7 +0,0 @@ -\chapter{SunOS Specific Services} -\label{sunos} - -The modules described in this chapter provide interfaces to features -that are unique to SunOS 5 (also known as Solaris version 2). - -\localmoduletable Deleted: /python/branches/py3k-struni/Doc/lib/libsunaudio.tex ============================================================================== --- /python/branches/py3k-struni/Doc/lib/libsunaudio.tex Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,146 +0,0 @@ -\section{\module{sunaudiodev} --- - Access to Sun audio hardware} - -\declaremodule{builtin}{sunaudiodev} - \platform{SunOS} -\modulesynopsis{Access to Sun audio hardware.} - - -This module allows you to access the Sun audio interface. The Sun -audio hardware is capable of recording and playing back audio data -in u-LAW\index{u-LAW} format with a sample rate of 8K per second. A -full description can be found in the \manpage{audio}{7I} manual page. - -The module -\refmodule[sunaudiodev-constants]{SUNAUDIODEV}\refstmodindex{SUNAUDIODEV} -defines constants which may be used with this module. - -This module defines the following variables and functions: - -\begin{excdesc}{error} -This exception is raised on all errors. The argument is a string -describing what went wrong. -\end{excdesc} - -\begin{funcdesc}{open}{mode} -This function opens the audio device and returns a Sun audio device -object. This object can then be used to do I/O on. The \var{mode} parameter -is one of \code{'r'} for record-only access, \code{'w'} for play-only -access, \code{'rw'} for both and \code{'control'} for access to the -control device. Since only one process is allowed to have the recorder -or player open at the same time it is a good idea to open the device -only for the activity needed. See \manpage{audio}{7I} for details. - -As per the manpage, this module first looks in the environment -variable \code{AUDIODEV} for the base audio device filename. If not -found, it falls back to \file{/dev/audio}. The control device is -calculated by appending ``ctl'' to the base audio device. -\end{funcdesc} - - -\subsection{Audio Device Objects \label{audio-device-objects}} - -The audio device objects are returned by \function{open()} define the -following methods (except \code{control} objects which only provide -\method{getinfo()}, \method{setinfo()}, \method{fileno()}, and -\method{drain()}): - -\begin{methoddesc}[audio device]{close}{} -This method explicitly closes the device. It is useful in situations -where deleting the object does not immediately close it since there -are other references to it. A closed device should not be used again. -\end{methoddesc} - -\begin{methoddesc}[audio device]{fileno}{} -Returns the file descriptor associated with the device. This can be -used to set up \code{SIGPOLL} notification, as described below. -\end{methoddesc} - -\begin{methoddesc}[audio device]{drain}{} -This method waits until all pending output is processed and then returns. -Calling this method is often not necessary: destroying the object will -automatically close the audio device and this will do an implicit drain. -\end{methoddesc} - -\begin{methoddesc}[audio device]{flush}{} -This method discards all pending output. It can be used avoid the -slow response to a user's stop request (due to buffering of up to one -second of sound). -\end{methoddesc} - -\begin{methoddesc}[audio device]{getinfo}{} -This method retrieves status information like input and output volume, -etc. and returns it in the form of -an audio status object. This object has no methods but it contains a -number of attributes describing the current device status. The names -and meanings of the attributes are described in -\code{} and in the \manpage{audio}{7I} -manual page. Member names -are slightly different from their C counterparts: a status object is -only a single structure. Members of the \cdata{play} substructure have -\samp{o_} prepended to their name and members of the \cdata{record} -structure have \samp{i_}. So, the C member \cdata{play.sample_rate} is -accessed as \member{o_sample_rate}, \cdata{record.gain} as \member{i_gain} -and \cdata{monitor_gain} plainly as \member{monitor_gain}. -\end{methoddesc} - -\begin{methoddesc}[audio device]{ibufcount}{} -This method returns the number of samples that are buffered on the -recording side, i.e.\ the program will not block on a -\function{read()} call of so many samples. -\end{methoddesc} - -\begin{methoddesc}[audio device]{obufcount}{} -This method returns the number of samples buffered on the playback -side. Unfortunately, this number cannot be used to determine a number -of samples that can be written without blocking since the kernel -output queue length seems to be variable. -\end{methoddesc} - -\begin{methoddesc}[audio device]{read}{size} -This method reads \var{size} samples from the audio input and returns -them as a Python string. The function blocks until enough data is available. -\end{methoddesc} - -\begin{methoddesc}[audio device]{setinfo}{status} -This method sets the audio device status parameters. The \var{status} -parameter is an device status object as returned by \function{getinfo()} and -possibly modified by the program. -\end{methoddesc} - -\begin{methoddesc}[audio device]{write}{samples} -Write is passed a Python string containing audio samples to be played. -If there is enough buffer space free it will immediately return, -otherwise it will block. -\end{methoddesc} - -The audio device supports asynchronous notification of various events, -through the SIGPOLL signal. Here's an example of how you might enable -this in Python: - -\begin{verbatim} -def handle_sigpoll(signum, frame): - print 'I got a SIGPOLL update' - -import fcntl, signal, STROPTS - -signal.signal(signal.SIGPOLL, handle_sigpoll) -fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG) -\end{verbatim} - - -\section{\module{SUNAUDIODEV} --- - Constants used with \module{sunaudiodev}} - -\declaremodule[sunaudiodev-constants]{standard}{SUNAUDIODEV} - \platform{SunOS} -\modulesynopsis{Constants for use with \refmodule{sunaudiodev}.} - - -This is a companion module to -\refmodule{sunaudiodev}\refbimodindex{sunaudiodev} which defines -useful symbolic constants like \constant{MIN_GAIN}, -\constant{MAX_GAIN}, \constant{SPEAKER}, etc. The names of the -constants are the same names as used in the C include file -\code{}, with the leading string \samp{AUDIO_} -stripped. Modified: python/branches/py3k-struni/Doc/lib/libundoc.tex ============================================================================== --- python/branches/py3k-struni/Doc/lib/libundoc.tex (original) +++ python/branches/py3k-struni/Doc/lib/libundoc.tex Sun Aug 5 17:29:28 2007 @@ -52,19 +52,8 @@ \section{Multimedia} \begin{description} -\item[\module{audiodev}] ---- Platform-independent API for playing audio data. - -\item[\module{linuxaudiodev}] ---- Play audio data on the Linux audio device. Replaced in Python 2.3 - by the \module{ossaudiodev} module. - \item[\module{sunaudio}] --- Interpret Sun audio headers (may become obsolete or a tool/demo). - -\item[\module{toaiff}] ---- Convert "arbitrary" sound files to AIFF files; should probably - become a tool or demo. Requires the external program \program{sox}. \end{description} Deleted: /python/branches/py3k-struni/Lib/audiodev.py ============================================================================== --- /python/branches/py3k-struni/Lib/audiodev.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,257 +0,0 @@ -"""Classes for manipulating audio devices (currently only for Sun and SGI)""" - -__all__ = ["error","AudioDev"] - -class error(Exception): - pass - -class Play_Audio_sgi: - # Private instance variables -## if 0: access frameratelist, nchannelslist, sampwidthlist, oldparams, \ -## params, config, inited_outrate, inited_width, \ -## inited_nchannels, port, converter, classinited: private - - classinited = 0 - frameratelist = nchannelslist = sampwidthlist = None - - def initclass(self): - import AL - self.frameratelist = [ - (48000, AL.RATE_48000), - (44100, AL.RATE_44100), - (32000, AL.RATE_32000), - (22050, AL.RATE_22050), - (16000, AL.RATE_16000), - (11025, AL.RATE_11025), - ( 8000, AL.RATE_8000), - ] - self.nchannelslist = [ - (1, AL.MONO), - (2, AL.STEREO), - (4, AL.QUADRO), - ] - self.sampwidthlist = [ - (1, AL.SAMPLE_8), - (2, AL.SAMPLE_16), - (3, AL.SAMPLE_24), - ] - self.classinited = 1 - - def __init__(self): - import al, AL - if not self.classinited: - self.initclass() - self.oldparams = [] - self.params = [AL.OUTPUT_RATE, 0] - self.config = al.newconfig() - self.inited_outrate = 0 - self.inited_width = 0 - self.inited_nchannels = 0 - self.converter = None - self.port = None - return - - def __del__(self): - if self.port: - self.stop() - if self.oldparams: - import al, AL - al.setparams(AL.DEFAULT_DEVICE, self.oldparams) - self.oldparams = [] - - def wait(self): - if not self.port: - return - import time - while self.port.getfilled() > 0: - time.sleep(0.1) - self.stop() - - def stop(self): - if self.port: - self.port.closeport() - self.port = None - if self.oldparams: - import al, AL - al.setparams(AL.DEFAULT_DEVICE, self.oldparams) - self.oldparams = [] - - def setoutrate(self, rate): - for (raw, cooked) in self.frameratelist: - if rate == raw: - self.params[1] = cooked - self.inited_outrate = 1 - break - else: - raise error, 'bad output rate' - - def setsampwidth(self, width): - for (raw, cooked) in self.sampwidthlist: - if width == raw: - self.config.setwidth(cooked) - self.inited_width = 1 - break - else: - if width == 0: - import AL - self.inited_width = 0 - self.config.setwidth(AL.SAMPLE_16) - self.converter = self.ulaw2lin - else: - raise error, 'bad sample width' - - def setnchannels(self, nchannels): - for (raw, cooked) in self.nchannelslist: - if nchannels == raw: - self.config.setchannels(cooked) - self.inited_nchannels = 1 - break - else: - raise error, 'bad # of channels' - - def writeframes(self, data): - if not (self.inited_outrate and self.inited_nchannels): - raise error, 'params not specified' - if not self.port: - import al, AL - self.port = al.openport('Python', 'w', self.config) - self.oldparams = self.params[:] - al.getparams(AL.DEFAULT_DEVICE, self.oldparams) - al.setparams(AL.DEFAULT_DEVICE, self.params) - if self.converter: - data = self.converter(data) - self.port.writesamps(data) - - def getfilled(self): - if self.port: - return self.port.getfilled() - else: - return 0 - - def getfillable(self): - if self.port: - return self.port.getfillable() - else: - return self.config.getqueuesize() - - # private methods -## if 0: access *: private - - def ulaw2lin(self, data): - import audioop - return audioop.ulaw2lin(data, 2) - -class Play_Audio_sun: -## if 0: access outrate, sampwidth, nchannels, inited_outrate, inited_width, \ -## inited_nchannels, converter: private - - def __init__(self): - self.outrate = 0 - self.sampwidth = 0 - self.nchannels = 0 - self.inited_outrate = 0 - self.inited_width = 0 - self.inited_nchannels = 0 - self.converter = None - self.port = None - return - - def __del__(self): - self.stop() - - def setoutrate(self, rate): - self.outrate = rate - self.inited_outrate = 1 - - def setsampwidth(self, width): - self.sampwidth = width - self.inited_width = 1 - - def setnchannels(self, nchannels): - self.nchannels = nchannels - self.inited_nchannels = 1 - - def writeframes(self, data): - if not (self.inited_outrate and self.inited_width and self.inited_nchannels): - raise error, 'params not specified' - if not self.port: - import sunaudiodev, SUNAUDIODEV - self.port = sunaudiodev.open('w') - info = self.port.getinfo() - info.o_sample_rate = self.outrate - info.o_channels = self.nchannels - if self.sampwidth == 0: - info.o_precision = 8 - self.o_encoding = SUNAUDIODEV.ENCODING_ULAW - # XXX Hack, hack -- leave defaults - else: - info.o_precision = 8 * self.sampwidth - info.o_encoding = SUNAUDIODEV.ENCODING_LINEAR - self.port.setinfo(info) - if self.converter: - data = self.converter(data) - self.port.write(data) - - def wait(self): - if not self.port: - return - self.port.drain() - self.stop() - - def stop(self): - if self.port: - self.port.flush() - self.port.close() - self.port = None - - def getfilled(self): - if self.port: - return self.port.obufcount() - else: - return 0 - -## # Nobody remembers what this method does, and it's broken. :-( -## def getfillable(self): -## return BUFFERSIZE - self.getfilled() - -def AudioDev(): - # Dynamically try to import and use a platform specific module. - try: - import al - except ImportError: - try: - import sunaudiodev - return Play_Audio_sun() - except ImportError: - try: - import Audio_mac - except ImportError: - raise error, 'no audio device' - else: - return Audio_mac.Play_Audio_mac() - else: - return Play_Audio_sgi() - -def test(fn = None): - import sys - if sys.argv[1:]: - fn = sys.argv[1] - else: - fn = 'f:just samples:just.aif' - import aifc - af = aifc.open(fn, 'r') - print(fn, af.getparams()) - p = AudioDev() - p.setoutrate(af.getframerate()) - p.setsampwidth(af.getsampwidth()) - p.setnchannels(af.getnchannels()) - BUFSIZ = af.getframerate()/af.getsampwidth()/af.getnchannels() - while 1: - data = af.readframes(BUFSIZ) - if not data: break - print(len(data)) - p.writeframes(data) - p.wait() - -if __name__ == '__main__': - test() Modified: python/branches/py3k-struni/Lib/code.py ============================================================================== --- python/branches/py3k-struni/Lib/code.py (original) +++ python/branches/py3k-struni/Lib/code.py Sun Aug 5 17:29:28 2007 @@ -111,16 +111,16 @@ if filename and type is SyntaxError: # Work hard to stuff the correct filename in the exception try: - msg, (dummy_filename, lineno, offset, line) = value - except: + msg, (dummy_filename, lineno, offset, line) = value.args + except ValueError: # Not the format we expect; leave it alone pass else: # Stuff in the right filename value = SyntaxError(msg, (filename, lineno, offset, line)) sys.last_value = value - list = traceback.format_exception_only(type, value) - map(self.write, list) + lines = traceback.format_exception_only(type, value) + self.write(''.join(lines)) def showtraceback(self): """Display the exception that just occurred. @@ -137,13 +137,13 @@ sys.last_traceback = tb tblist = traceback.extract_tb(tb) del tblist[:1] - list = traceback.format_list(tblist) - if list: - list.insert(0, "Traceback (most recent call last):\n") - list[len(list):] = traceback.format_exception_only(type, value) + lines = traceback.format_list(tblist) + if lines: + lines.insert(0, "Traceback (most recent call last):\n") + lines.extend(traceback.format_exception_only(type, value)) finally: tblist = tb = None - map(self.write, list) + self.write(''.join(lines)) def write(self, data): """Write a string. @@ -184,7 +184,7 @@ def interact(self, banner=None): """Closely emulate the interactive Python console. - The optional banner argument specify the banner to print + The optional banner argument specifies the banner to print before the first interaction; by default it prints a banner similar to the one printed by the real Python interpreter, followed by the current class name in parentheses (so as not Modified: python/branches/py3k-struni/Lib/idlelib/EditorWindow.py ============================================================================== --- python/branches/py3k-struni/Lib/idlelib/EditorWindow.py (original) +++ python/branches/py3k-struni/Lib/idlelib/EditorWindow.py Sun Aug 5 17:29:28 2007 @@ -1,6 +1,7 @@ import sys import os import re +import string import imp from itertools import count from Tkinter import * @@ -602,6 +603,19 @@ theme = idleConf.GetOption('main','Theme','name') self.text.config(idleConf.GetHighlight(theme, "normal")) + IDENTCHARS = string.ascii_letters + string.digits + "_" + + def colorize_syntax_error(self, text, pos): + text.tag_add("ERROR", pos) + char = text.get(pos) + if char and char in self.IDENTCHARS: + text.tag_add("ERROR", pos + " wordstart", pos) + if '\n' == text.get(pos): # error at line end + text.mark_set("insert", pos) + else: + text.mark_set("insert", pos + "+1c") + text.see(pos) + def ResetFont(self): "Update the text widgets' font if it is changed" # Called from configDialog.py @@ -1004,6 +1018,8 @@ "n" * newtabwidth) text.configure(tabs=pixels) +### begin autoindent code ### (configuration was moved to beginning of class) + # If ispythonsource and guess are true, guess a good value for # indentwidth based on file content (if possible), and if # indentwidth != tabwidth set usetabs false. Modified: python/branches/py3k-struni/Lib/idlelib/PyShell.py ============================================================================== --- python/branches/py3k-struni/Lib/idlelib/PyShell.py (original) +++ python/branches/py3k-struni/Lib/idlelib/PyShell.py Sun Aug 5 17:29:28 2007 @@ -3,7 +3,6 @@ import os import os.path import sys -import string import getopt import re import socket @@ -35,7 +34,6 @@ from . import RemoteDebugger from . import macosxSupport -IDENTCHARS = string.ascii_letters + string.digits + "_" LOCALHOST = '127.0.0.1' try: @@ -624,47 +622,30 @@ \n""" % (filename,)) def showsyntaxerror(self, filename=None): - """Extend base class method: Add Colorizing + """Override Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret. """ - text = self.tkconsole.text - stuff = self.unpackerror() - if stuff: - msg, lineno, offset, line = stuff - if lineno == 1: - pos = "iomark + %d chars" % (offset-1) - else: - pos = "iomark linestart + %d lines + %d chars" % \ - (lineno-1, offset-1) - text.tag_add("ERROR", pos) - text.see(pos) - char = text.get(pos) - if char and char in IDENTCHARS: - text.tag_add("ERROR", pos + " wordstart", pos) - self.tkconsole.resetoutput() - self.write("SyntaxError: %s\n" % str(msg)) - else: - self.tkconsole.resetoutput() - InteractiveInterpreter.showsyntaxerror(self, filename) - self.tkconsole.showprompt() - - def unpackerror(self): + tkconsole = self.tkconsole + text = tkconsole.text + text.tag_remove("ERROR", "1.0", "end") type, value, tb = sys.exc_info() - ok = type is SyntaxError - if ok: - try: - msg, (dummy_filename, lineno, offset, line) = value - if not offset: - offset = 0 - except: - ok = 0 - if ok: - return msg, lineno, offset, line + msg = value.msg or "" + lineno = value.lineno or 1 + offset = value.offset or 0 + if offset == 0: + lineno += 1 #mark end of offending line + if lineno == 1: + pos = "iomark + %d chars" % (offset-1) else: - return None + pos = "iomark linestart + %d lines + %d chars" % \ + (lineno-1, offset-1) + tkconsole.colorize_syntax_error(text, pos) + tkconsole.resetoutput() + self.write("SyntaxError: %s\n" % msg) + tkconsole.showprompt() def showtraceback(self): "Extend base class method to reset output properly" Modified: python/branches/py3k-struni/Lib/idlelib/ScriptBinding.py ============================================================================== --- python/branches/py3k-struni/Lib/idlelib/ScriptBinding.py (original) +++ python/branches/py3k-struni/Lib/idlelib/ScriptBinding.py Sun Aug 5 17:29:28 2007 @@ -23,12 +23,11 @@ import tabnanny import tokenize import tkMessageBox +from .EditorWindow import EditorWindow from . import PyShell from .configHandler import idleConf -IDENTCHARS = string.ascii_letters + string.digits + "_" - indent_message = """Error: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR @@ -83,7 +82,7 @@ self.shell = shell = self.flist.open_shell() saved_stream = shell.get_warning_stream() shell.set_warning_stream(shell.stderr) - f = open(filename, 'r') + f = file(filename, 'r') source = f.read() f.close() if '\r' in source: @@ -91,40 +90,25 @@ source = re.sub(r"\r", "\n", source) if source and source[-1] != '\n': source = source + '\n' - text = self.editwin.text + editwin = self.editwin + text = editwin.text text.tag_remove("ERROR", "1.0", "end") try: - try: - # If successful, return the compiled code - return compile(source, filename, "exec") - except (SyntaxError, OverflowError) as err: - try: - msg, (errorfilename, lineno, offset, line) = err.args - if not errorfilename: - err.args = msg, (filename, lineno, offset, line) - err.filename = filename - self.colorize_syntax_error(msg, lineno, offset) - except: - msg = str(err) - self.errorbox("Syntax error", - "There's an error in your program:\n" + msg) - return False + # If successful, return the compiled code + return compile(source, filename, "exec") + except (SyntaxError, OverflowError) as value: + msg = value.msg or "" + lineno = value.lineno or 1 + offset = value.offset or 0 + if offset == 0: + lineno += 1 #mark end of offending line + pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) + editwin.colorize_syntax_error(text, pos) + self.errorbox("SyntaxError", "%-20s" % msg) + return False finally: shell.set_warning_stream(saved_stream) - def colorize_syntax_error(self, msg, lineno, offset): - text = self.editwin.text - pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) - text.tag_add("ERROR", pos) - char = text.get(pos) - if char and char in IDENTCHARS: - text.tag_add("ERROR", pos + " wordstart", pos) - if '\n' == text.get(pos): # error at line end - text.mark_set("insert", pos) - else: - text.mark_set("insert", pos + "+1c") - text.see(pos) - def run_module_event(self, event): """Run the module after setting up the environment. @@ -199,10 +183,10 @@ icon=tkMessageBox.QUESTION, type=tkMessageBox.OKCANCEL, default=tkMessageBox.OK, - master=self.editwin.text) + parent=self.editwin.text) return mb.show() def errorbox(self, title, message): # XXX This should really be a function of EditorWindow... - tkMessageBox.showerror(title, message, master=self.editwin.text) + tkMessageBox.showerror(title, message, parent=self.editwin.text) self.editwin.text.focus_set() Modified: python/branches/py3k-struni/Lib/idlelib/run.py ============================================================================== --- python/branches/py3k-struni/Lib/idlelib/run.py (original) +++ python/branches/py3k-struni/Lib/idlelib/run.py Sun Aug 5 17:29:28 2007 @@ -149,14 +149,14 @@ typ, val, tb = excinfo = sys.exc_info() sys.last_type, sys.last_value, sys.last_traceback = excinfo tbe = traceback.extract_tb(tb) - print('\nTraceback (most recent call last):', file=efile) + print('Traceback (most recent call last):', file=efile) exclude = ("run.py", "rpc.py", "threading.py", "Queue.py", "RemoteDebugger.py", "bdb.py") cleanup_traceback(tbe, exclude) traceback.print_list(tbe, file=efile) lines = traceback.format_exception_only(typ, val) for line in lines: - print(line, end=' ', file=efile) + print(line, end='', file=efile) def cleanup_traceback(tb, exclude): "Remove excluded traces from beginning/end of tb; get cached lines" Deleted: /python/branches/py3k-struni/Lib/plat-sunos5/SUNAUDIODEV.py ============================================================================== --- /python/branches/py3k-struni/Lib/plat-sunos5/SUNAUDIODEV.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,40 +0,0 @@ -# Symbolic constants for use with sunaudiodev module -# The names are the same as in audioio.h with the leading AUDIO_ -# removed. - -# Not all values are supported on all releases of SunOS. - -# Encoding types, for fields i_encoding and o_encoding - -ENCODING_NONE = 0 # no encoding assigned -ENCODING_ULAW = 1 # u-law encoding -ENCODING_ALAW = 2 # A-law encoding -ENCODING_LINEAR = 3 # Linear PCM encoding - -# Gain ranges for i_gain, o_gain and monitor_gain - -MIN_GAIN = 0 # minimum gain value -MAX_GAIN = 255 # maximum gain value - -# Balance values for i_balance and o_balance - -LEFT_BALANCE = 0 # left channel only -MID_BALANCE = 32 # equal left/right channel -RIGHT_BALANCE = 64 # right channel only -BALANCE_SHIFT = 3 - -# Port names for i_port and o_port - -PORT_A = 1 -PORT_B = 2 -PORT_C = 3 -PORT_D = 4 - -SPEAKER = 0x01 # output to built-in speaker -HEADPHONE = 0x02 # output to headphone jack -LINE_OUT = 0x04 # output to line out - -MICROPHONE = 0x01 # input from microphone -LINE_IN = 0x02 # input from line in -CD = 0x04 # input from on-board CD inputs -INTERNAL_CD_IN = CD # input from internal CDROM Modified: python/branches/py3k-struni/Lib/test/README ============================================================================== --- python/branches/py3k-struni/Lib/test/README (original) +++ python/branches/py3k-struni/Lib/test/README Sun Aug 5 17:29:28 2007 @@ -372,7 +372,7 @@ * ``findfile(file)`` - you can call this function to locate a file somewhere along sys.path or in the Lib/test tree - see - test_linuxaudiodev.py for an example of its use. + test_ossaudiodev.py for an example of its use. * ``fcmp(x,y)`` - you can call this function to compare two floating point numbers when you expect them to only be approximately equal Deleted: /python/branches/py3k-struni/Lib/test/output/test_linuxaudiodev ============================================================================== --- /python/branches/py3k-struni/Lib/test/output/test_linuxaudiodev Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,7 +0,0 @@ -test_linuxaudiodev -expected rate >= 0, not -1 -expected sample size >= 0, not -2 -nchannels must be 1 or 2, not 3 -unknown audio encoding: 177 -for linear unsigned 16-bit little-endian audio, expected sample size 16, not 8 -for linear unsigned 8-bit audio, expected sample size 8, not 16 Modified: python/branches/py3k-struni/Lib/test/regrtest.py ============================================================================== --- python/branches/py3k-struni/Lib/test/regrtest.py (original) +++ python/branches/py3k-struni/Lib/test/regrtest.py Sun Aug 5 17:29:28 2007 @@ -1106,8 +1106,6 @@ self.expected = set(s.split()) # expected to be skipped on every platform, even Linux - self.expected.add('test_linuxaudiodev') - if not os.path.supports_unicode_filenames: self.expected.add('test_pep277') @@ -1134,7 +1132,6 @@ self.expected.add(skip) if sys.platform != 'sunos5': - self.expected.add('test_sunaudiodev') self.expected.add('test_nis') self.valid = True Modified: python/branches/py3k-struni/Lib/test/test___all__.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test___all__.py (original) +++ python/branches/py3k-struni/Lib/test/test___all__.py Sun Aug 5 17:29:28 2007 @@ -39,7 +39,6 @@ self.check_all("StringIO") self.check_all("UserString") self.check_all("aifc") - self.check_all("audiodev") self.check_all("base64") self.check_all("bdb") self.check_all("binhex") @@ -135,7 +134,6 @@ self.check_all("textwrap") self.check_all("threading") self.check_all("timeit") - self.check_all("toaiff") self.check_all("tokenize") self.check_all("traceback") self.check_all("tty") Modified: python/branches/py3k-struni/Lib/test/test_generators.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_generators.py (original) +++ python/branches/py3k-struni/Lib/test/test_generators.py Sun Aug 5 17:29:28 2007 @@ -733,14 +733,14 @@ ... yield 1 Traceback (most recent call last): .. -SyntaxError: 'return' with argument inside generator (, line 3) +SyntaxError: 'return' with argument inside generator >>> def f(): ... yield 1 ... return 22 Traceback (most recent call last): .. -SyntaxError: 'return' with argument inside generator (, line 3) +SyntaxError: 'return' with argument inside generator "return None" is not the same as "return" in a generator: @@ -749,7 +749,7 @@ ... return None Traceback (most recent call last): .. -SyntaxError: 'return' with argument inside generator (, line 3) +SyntaxError: 'return' with argument inside generator These are fine: @@ -878,7 +878,7 @@ ... if 0: ... yield 2 # because it's a generator (line 10) Traceback (most recent call last): -SyntaxError: 'return' with argument inside generator (, line 10) +SyntaxError: 'return' with argument inside generator This one caused a crash (see SF bug 567538): @@ -1525,27 +1525,27 @@ >>> f=lambda: (yield 1),(yield 2) Traceback (most recent call last): ... -SyntaxError: 'yield' outside function (, line 1) +SyntaxError: 'yield' outside function >>> def f(): return lambda x=(yield): 1 Traceback (most recent call last): ... -SyntaxError: 'return' with argument inside generator (, line 1) +SyntaxError: 'return' with argument inside generator >>> def f(): x = yield = y Traceback (most recent call last): ... -SyntaxError: assignment to yield expression not possible (, line 1) +SyntaxError: assignment to yield expression not possible >>> def f(): (yield bar) = y Traceback (most recent call last): ... -SyntaxError: can't assign to yield expression (, line 1) +SyntaxError: can't assign to yield expression >>> def f(): (yield bar) += y Traceback (most recent call last): ... -SyntaxError: augmented assignment to yield expression not possible (, line 1) +SyntaxError: augmented assignment to yield expression not possible Now check some throw() conditions: Modified: python/branches/py3k-struni/Lib/test/test_genexps.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_genexps.py (original) +++ python/branches/py3k-struni/Lib/test/test_genexps.py Sun Aug 5 17:29:28 2007 @@ -137,12 +137,12 @@ >>> (y for y in (1,2)) = 10 Traceback (most recent call last): ... - SyntaxError: can't assign to generator expression (, line 1) + SyntaxError: can't assign to generator expression >>> (y for y in (1,2)) += 10 Traceback (most recent call last): ... - SyntaxError: augmented assignment to generator expression not possible (, line 1) + SyntaxError: augmented assignment to generator expression not possible ########### Tests borrowed from or inspired by test_generators.py ############ Deleted: /python/branches/py3k-struni/Lib/test/test_linuxaudiodev.py ============================================================================== --- /python/branches/py3k-struni/Lib/test/test_linuxaudiodev.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,92 +0,0 @@ -from test import test_support -test_support.requires('audio') - -from test.test_support import verbose, findfile, TestFailed, TestSkipped - -import errno -import fcntl -import linuxaudiodev -import os -import sys -import select -import sunaudio -import time -import audioop - -SND_FORMAT_MULAW_8 = 1 - -def play_sound_file(path): - fp = open(path, 'r') - size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) - data = fp.read() - fp.close() - - if enc != SND_FORMAT_MULAW_8: - print("Expect .au file with 8-bit mu-law samples") - return - - try: - a = linuxaudiodev.open('w') - except linuxaudiodev.error as msg: - if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): - raise TestSkipped, msg - raise TestFailed, msg - - # convert the data to 16-bit signed - data = audioop.ulaw2lin(data, 2) - - # set the data format - if sys.byteorder == 'little': - fmt = linuxaudiodev.AFMT_S16_LE - else: - fmt = linuxaudiodev.AFMT_S16_BE - - # at least check that these methods can be invoked - a.bufsize() - a.obufcount() - a.obuffree() - a.getptr() - a.fileno() - - # set parameters based on .au file headers - a.setparameters(rate, 16, nchannels, fmt) - a.write(data) - a.flush() - a.close() - -def test_errors(): - a = linuxaudiodev.open("w") - size = 8 - fmt = linuxaudiodev.AFMT_U8 - rate = 8000 - nchannels = 1 - try: - a.setparameters(-1, size, nchannels, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, -2, nchannels, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, 3, fmt) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, nchannels, 177) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) - except ValueError as msg: - print(msg) - try: - a.setparameters(rate, 16, nchannels, fmt) - except ValueError as msg: - print(msg) - -def test(): - play_sound_file(findfile('audiotest.au')) - test_errors() - -test() Modified: python/branches/py3k-struni/Lib/test/test_scope.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_scope.py (original) +++ python/branches/py3k-struni/Lib/test/test_scope.py Sun Aug 5 17:29:28 2007 @@ -223,25 +223,6 @@ return getrefcount # global or local? """) - # and verify a few cases that should work - - exec(""" -def noproblem1(): - from sys import * - f = lambda x:x - -def noproblem2(): - from sys import * - def f(x): - return x + 1 - -def noproblem3(): - from sys import * - def f(x): - global y - y = x -""") - def testLambdas(self): f1 = lambda x: lambda y: x + y Deleted: /python/branches/py3k-struni/Lib/test/test_sunaudiodev.py ============================================================================== --- /python/branches/py3k-struni/Lib/test/test_sunaudiodev.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,28 +0,0 @@ -from test.test_support import verbose, findfile, TestFailed, TestSkipped -import sunaudiodev -import os - -try: - audiodev = os.environ["AUDIODEV"] -except KeyError: - audiodev = "/dev/audio" - -if not os.path.exists(audiodev): - raise TestSkipped("no audio device found!") - -def play_sound_file(path): - fp = open(path, 'r') - data = fp.read() - fp.close() - try: - a = sunaudiodev.open('w') - except sunaudiodev.error as msg: - raise TestFailed, msg - else: - a.write(data) - a.close() - -def test(): - play_sound_file(findfile('audiotest.au')) - -test() Modified: python/branches/py3k-struni/Lib/test/test_sundry.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_sundry.py (original) +++ python/branches/py3k-struni/Lib/test/test_sundry.py Sun Aug 5 17:29:28 2007 @@ -13,7 +13,6 @@ import SimpleHTTPServer import SimpleXMLRPCServer import aifc - import audiodev import bdb import cgitb import cmd @@ -99,7 +98,6 @@ import tabnanny import telnetlib import timeit - import toaiff import token try: import tty # not available on Windows Modified: python/branches/py3k-struni/Lib/test/test_syntax.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_syntax.py (original) +++ python/branches/py3k-struni/Lib/test/test_syntax.py Sun Aug 5 17:29:28 2007 @@ -33,7 +33,7 @@ >>> None = 1 Traceback (most recent call last): -SyntaxError: assignment to keyword (, line 1) +SyntaxError: assignment to keyword It's a syntax error to assign to the empty tuple. Why isn't it an error to assign to the empty list? It will always raise some error at @@ -41,31 +41,31 @@ >>> () = 1 Traceback (most recent call last): -SyntaxError: can't assign to () (, line 1) +SyntaxError: can't assign to () >>> f() = 1 Traceback (most recent call last): -SyntaxError: can't assign to function call (, line 1) +SyntaxError: can't assign to function call >>> del f() Traceback (most recent call last): -SyntaxError: can't delete function call (, line 1) +SyntaxError: can't delete function call >>> a + 1 = 2 Traceback (most recent call last): -SyntaxError: can't assign to operator (, line 1) +SyntaxError: can't assign to operator >>> (x for x in x) = 1 Traceback (most recent call last): -SyntaxError: can't assign to generator expression (, line 1) +SyntaxError: can't assign to generator expression >>> 1 = 1 Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) +SyntaxError: can't assign to literal >>> "abc" = 1 Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) +SyntaxError: can't assign to literal >>> `1` = 1 Traceback (most recent call last): @@ -78,15 +78,15 @@ >>> (a, "b", c) = (1, 2, 3) Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) +SyntaxError: can't assign to literal >>> [a, b, c + 1] = [1, 2, 3] Traceback (most recent call last): -SyntaxError: can't assign to operator (, line 1) +SyntaxError: can't assign to operator >>> a if 1 else b = 1 Traceback (most recent call last): -SyntaxError: can't assign to conditional expression (, line 1) +SyntaxError: can't assign to conditional expression From compiler_complex_args(): @@ -101,7 +101,7 @@ >>> def f(x, y=1, z): ... pass Traceback (most recent call last): -SyntaxError: non-default argument follows default argument (, line 1) +SyntaxError: non-default argument follows default argument >>> def f(x, None): ... pass @@ -136,7 +136,7 @@ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> f(x for x in L, 1) Traceback (most recent call last): -SyntaxError: Generator expression must be parenthesized if not sole argument (, line 1) +SyntaxError: Generator expression must be parenthesized if not sole argument >>> f((x for x in L), 1) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] @@ -168,7 +168,7 @@ ... i244, i245, i246, i247, i248, i249, i250, i251, i252, ... i253, i254, i255) Traceback (most recent call last): -SyntaxError: more than 255 arguments (, line 1) +SyntaxError: more than 255 arguments The actual error cases counts positional arguments, keyword arguments, and generator expression arguments separately. This test combines the @@ -202,37 +202,37 @@ ... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, ... i252=1, i253=1, i254=1, i255=1) Traceback (most recent call last): -SyntaxError: more than 255 arguments (, line 1) +SyntaxError: more than 255 arguments >>> f(lambda x: x[0] = 3) Traceback (most recent call last): -SyntaxError: lambda cannot contain assignment (, line 1) +SyntaxError: lambda cannot contain assignment The grammar accepts any test (basically, any expression) in the keyword slot of a call site. Test a few different options. >>> f(x()=2) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) +SyntaxError: keyword can't be an expression >>> f(a or b=1) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) +SyntaxError: keyword can't be an expression >>> f(x.y=1) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) +SyntaxError: keyword can't be an expression From ast_for_expr_stmt(): >>> (x for x in x) += 1 Traceback (most recent call last): -SyntaxError: augmented assignment to generator expression not possible (, line 1) +SyntaxError: augmented assignment to generator expression not possible >>> None += 1 Traceback (most recent call last): -SyntaxError: assignment to keyword (, line 1) +SyntaxError: assignment to keyword >>> f() += 1 Traceback (most recent call last): -SyntaxError: illegal expression for augmented assignment (, line 1) +SyntaxError: illegal expression for augmented assignment Test continue in finally in weird combinations. @@ -259,7 +259,7 @@ ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 6) + SyntaxError: 'continue' not supported inside 'finally' clause This is essentially a continue in a finally which should not be allowed. @@ -274,7 +274,7 @@ ... pass Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 7) + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... try: @@ -283,7 +283,7 @@ ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 5) + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -293,7 +293,7 @@ ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 6) + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -306,7 +306,7 @@ ... pass Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 7) + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -318,7 +318,7 @@ ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 8) + SyntaxError: 'continue' not supported inside 'finally' clause There is one test for a break that is not in a loop. The compiler uses a single data structure to keep track of try-finally and loops, @@ -333,7 +333,7 @@ ... print(3) Traceback (most recent call last): ... - SyntaxError: 'break' outside loop (, line 3) + SyntaxError: 'break' outside loop This should probably raise a better error than a SystemError (or none at all). In 2.5 there was a missing exception and an assert was triggered in a debug @@ -420,7 +420,7 @@ ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 2) + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -428,7 +428,7 @@ ... x() = 1 Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 4) + SyntaxError: can't assign to function call >>> if 1: ... x() = 1 @@ -438,7 +438,7 @@ ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 2) + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -448,7 +448,7 @@ ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 4) + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -458,7 +458,7 @@ ... x() = 1 Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 6) + SyntaxError: can't assign to function call """ Modified: python/branches/py3k-struni/Lib/test/test_unpack_ex.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_unpack_ex.py (original) +++ python/branches/py3k-struni/Lib/test/test_unpack_ex.py Sun Aug 5 17:29:28 2007 @@ -116,32 +116,32 @@ >>> a, *b, c, *d, e = range(10) # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: two starred expressions in assignment (...) + SyntaxError: two starred expressions in assignment >>> [*b, *c] = range(10) # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: two starred expressions in assignment (...) + SyntaxError: two starred expressions in assignment >>> *a = range(10) # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: starred assignment target must be in a list or tuple (...) + SyntaxError: starred assignment target must be in a list or tuple >>> *a # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: can use starred expression only as assignment target (...) + SyntaxError: can use starred expression only as assignment target >>> *1 # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: can use starred expression only as assignment target (...) + SyntaxError: can use starred expression only as assignment target >>> x = *a # doctest:+ELLIPSIS Traceback (most recent call last): ... - SyntaxError: can use starred expression only as assignment target (...) + SyntaxError: can use starred expression only as assignment target """ Deleted: /python/branches/py3k-struni/Lib/toaiff.py ============================================================================== --- /python/branches/py3k-struni/Lib/toaiff.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,107 +0,0 @@ -"""Convert "arbitrary" sound files to AIFF (Apple and SGI's audio format). - -Input may be compressed. -Uncompressed file type may be AIFF, WAV, VOC, 8SVX, NeXT/Sun, and others. -An exception is raised if the file is not of a recognized type. -Returned filename is either the input filename or a temporary filename; -in the latter case the caller must ensure that it is removed. -Other temporary files used are removed by the function. -""" - -import os -import tempfile -import pipes -import sndhdr - -__all__ = ["error", "toaiff"] - -table = {} - -t = pipes.Template() -t.append('sox -t au - -t aiff -r 8000 -', '--') -table['au'] = t - -# XXX The following is actually sub-optimal. -# XXX The HCOM sampling rate can be 22k, 22k/2, 22k/3 or 22k/4. -# XXX We must force the output sampling rate else the SGI won't play -# XXX files sampled at 5.5k or 7.333k; however this means that files -# XXX sampled at 11k are unnecessarily expanded. -# XXX Similar comments apply to some other file types. -t = pipes.Template() -t.append('sox -t hcom - -t aiff -r 22050 -', '--') -table['hcom'] = t - -t = pipes.Template() -t.append('sox -t voc - -t aiff -r 11025 -', '--') -table['voc'] = t - -t = pipes.Template() -t.append('sox -t wav - -t aiff -', '--') -table['wav'] = t - -t = pipes.Template() -t.append('sox -t 8svx - -t aiff -r 16000 -', '--') -table['8svx'] = t - -t = pipes.Template() -t.append('sox -t sndt - -t aiff -r 16000 -', '--') -table['sndt'] = t - -t = pipes.Template() -t.append('sox -t sndr - -t aiff -r 16000 -', '--') -table['sndr'] = t - -uncompress = pipes.Template() -uncompress.append('uncompress', '--') - - -class error(Exception): - pass - -def toaiff(filename): - temps = [] - ret = None - try: - ret = _toaiff(filename, temps) - finally: - for temp in temps[:]: - if temp != ret: - try: - os.unlink(temp) - except os.error: - pass - temps.remove(temp) - return ret - -def _toaiff(filename, temps): - if filename[-2:] == '.Z': - (fd, fname) = tempfile.mkstemp() - os.close(fd) - temps.append(fname) - sts = uncompress.copy(filename, fname) - if sts: - raise error, filename + ': uncompress failed' - else: - fname = filename - try: - ftype = sndhdr.whathdr(fname) - if ftype: - ftype = ftype[0] # All we're interested in - except IOError as msg: - if type(msg) == type(()) and len(msg) == 2 and \ - type(msg[0]) == type(0) and type(msg[1]) == type(''): - msg = msg[1] - if type(msg) != type(''): - msg = repr(msg) - raise error, filename + ': ' + msg - if ftype == 'aiff': - return fname - if ftype is None or not ftype in table: - raise error, '%s: unsupported audio file type %r' % (filename, ftype) - (fd, temp) = tempfile.mkstemp() - os.close(fd) - temps.append(temp) - sts = table[ftype].copy(fname, temp) - if sts: - raise error, filename + ': conversion to aiff failed' - return temp Modified: python/branches/py3k-struni/Lib/traceback.py ============================================================================== --- python/branches/py3k-struni/Lib/traceback.py (original) +++ python/branches/py3k-struni/Lib/traceback.py Sun Aug 5 17:29:28 2007 @@ -161,7 +161,6 @@ string in the list. """ - # Gracefully handle (the way Python 2.4 and earlier did) the case of # being called with (None, None). if etype is None: @@ -177,28 +176,24 @@ # It was a syntax error; show exactly where the problem was found. lines = [] - try: - msg, (filename, lineno, offset, badline) = value.args - except Exception: - pass - else: - filename = filename or "" - lines.append(' File "%s", line %d\n' % (filename, lineno)) - if badline is not None: - lines.append(' %s\n' % badline.strip()) - if offset is not None: - caretspace = badline[:offset].lstrip() - # non-space whitespace (likes tabs) must be kept for alignment - caretspace = ((c.isspace() and c or ' ') for c in caretspace) - # only three spaces to account for offset1 == pos 0 - lines.append(' %s^\n' % ''.join(caretspace)) - value = msg - - lines.append(_format_final_exc_line(stype, value)) + filename = value.filename or "" + lineno = str(value.lineno) or '?' + lines.append(' File "%s", line %s\n' % (filename, lineno)) + badline = value.text + offset = value.offset + if badline is not None: + lines.append(' %s\n' % badline.strip()) + if offset is not None: + caretspace = badline[:offset].lstrip() + # non-space whitespace (likes tabs) must be kept for alignment + caretspace = ((c.isspace() and c or ' ') for c in caretspace) + # only three spaces to account for offset1 == pos 0 + lines.append(' %s^\n' % ''.join(caretspace)) + msg = value.msg or "" + lines.append("%s: %s\n" % (stype, msg)) return lines def _format_final_exc_line(etype, value): - """Return a list of a single line -- normal case for format_exception_only""" valuestr = _some_str(value) if value is None or not valuestr: line = "%s\n" % etype Deleted: /python/branches/py3k-struni/Mac/Demo/sound/morse.py ============================================================================== --- /python/branches/py3k-struni/Mac/Demo/sound/morse.py Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,180 +0,0 @@ -import sys, math, audiodev - -DOT = 30 -DAH = 80 -OCTAVE = 2 # 1 == 441 Hz, 2 == 882 Hz, ... -SAMPWIDTH = 2 -FRAMERATE = 44100 -BASEFREQ = 441 -QSIZE = 20000 - -morsetab = { - 'A': '.-', 'a': '.-', - 'B': '-...', 'b': '-...', - 'C': '-.-.', 'c': '-.-.', - 'D': '-..', 'd': '-..', - 'E': '.', 'e': '.', - 'F': '..-.', 'f': '..-.', - 'G': '--.', 'g': '--.', - 'H': '....', 'h': '....', - 'I': '..', 'i': '..', - 'J': '.---', 'j': '.---', - 'K': '-.-', 'k': '-.-', - 'L': '.-..', 'l': '.-..', - 'M': '--', 'm': '--', - 'N': '-.', 'n': '-.', - 'O': '---', 'o': '---', - 'P': '.--.', 'p': '.--.', - 'Q': '--.-', 'q': '--.-', - 'R': '.-.', 'r': '.-.', - 'S': '...', 's': '...', - 'T': '-', 't': '-', - 'U': '..-', 'u': '..-', - 'V': '...-', 'v': '...-', - 'W': '.--', 'w': '.--', - 'X': '-..-', 'x': '-..-', - 'Y': '-.--', 'y': '-.--', - 'Z': '--..', 'z': '--..', - '0': '-----', - '1': '.----', - '2': '..---', - '3': '...--', - '4': '....-', - '5': '.....', - '6': '-....', - '7': '--...', - '8': '---..', - '9': '----.', - ',': '--..--', - '.': '.-.-.-', - '?': '..--..', - ';': '-.-.-.', - ':': '---...', - "'": '.----.', - '-': '-....-', - '/': '-..-.', - '(': '-.--.-', - ')': '-.--.-', - '_': '..--.-', - ' ': ' ' -} - -# If we play at 44.1 kHz (which we do), then if we produce one sine -# wave in 100 samples, we get a tone of 441 Hz. If we produce two -# sine waves in these 100 samples, we get a tone of 882 Hz. 882 Hz -# appears to be a nice one for playing morse code. -def mkwave(octave): - global sinewave, nowave - sinewave = '' - n = int(FRAMERATE / BASEFREQ) - for i in range(n): - val = int(math.sin(2 * math.pi * i * octave / n) * 0x7fff) - sample = chr((val >> 8) & 255) + chr(val & 255) - sinewave = sinewave + sample[:SAMPWIDTH] - nowave = '\0' * (n*SAMPWIDTH) - -mkwave(OCTAVE) - -class BufferedAudioDev: - def __init__(self, *args): - import audiodev - self._base = audiodev.AudioDev(*args) - self._buffer = [] - self._filled = 0 - self._addmethods(self._base, self._base.__class__) - def _addmethods(self, inst, cls): - for name in cls.__dict__.keys(): - if not hasattr(self, name): - try: - setattr(self, name, getattr(inst, name)) - except: - pass - for basecls in cls.__bases__: - self._addmethods(self, inst, basecls) - def writeframesraw(self, frames): - self._buffer.append(frames) - self._filled = self._filled + len(frames) - if self._filled >= QSIZE: - self.flush() - def wait(self): - self.flush() - self._base.wait() - def flush(self): - print 'flush: %d blocks, %d bytes' % (len(self._buffer), self._filled) - if self._buffer: - import string - self._base.writeframes(string.joinfields(self._buffer, '')) - self._buffer = [] - self._filled = 0 - -def main(args = sys.argv[1:]): - import getopt, string - try: - opts, args = getopt.getopt(args, 'o:p:') - except getopt.error: - sys.stderr.write('Usage ' + sys.argv[0] + - ' [ -o outfile ] [ args ] ...\n') - sys.exit(1) - dev = None - for o, a in opts: - if o == '-o': - import aifc - dev = aifc.open(a, 'w') - dev.setframerate(FRAMERATE) - dev.setsampwidth(SAMPWIDTH) - dev.setnchannels(1) - if o == '-p': - mkwave(string.atoi(a)) - if not dev: - dev = BufferedAudioDev() - dev.setoutrate(FRAMERATE) - dev.setsampwidth(SAMPWIDTH) - dev.setnchannels(1) - dev.close = dev.stop - if args: - line = string.join(args) - else: - line = sys.stdin.readline() - while line: - print line - mline = morse(line) - print mline - play(mline, dev) - if hasattr(dev, 'wait'): - dev.wait() - if not args: - line = sys.stdin.readline() - else: - line = '' - dev.close() - -# Convert a string to morse code with \001 between the characters in -# the string. -def morse(line): - res = '' - for c in line: - try: - res = res + morsetab[c] + '\001' - except KeyError: - pass - return res - -# Play a line of morse code. -def play(line, dev): - for c in line: - if c == '.': - sine(dev, DOT) - elif c == '-': - sine(dev, DAH) - else: - pause(dev, DAH) - pause(dev, DOT) - -def sine(dev, length): - dev.writeframesraw(sinewave*length) - -def pause(dev, length): - dev.writeframesraw(nowave*length) - -if __name__ == '__main__' or sys.argv[0] == __name__: - main() Modified: python/branches/py3k-struni/Makefile.pre.in ============================================================================== --- python/branches/py3k-struni/Makefile.pre.in (original) +++ python/branches/py3k-struni/Makefile.pre.in Sun Aug 5 17:29:28 2007 @@ -608,7 +608,7 @@ QUICKTESTOPTS= $(TESTOPTS) -x test_thread test_signal test_strftime \ test_unicodedata test_re test_sre test_select test_poll \ - test_linuxaudiodev test_struct test_sunaudiodev test_zlib + test_struct test_zlib quicktest: all platform -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -$(TESTPYTHON) $(TESTPROG) $(QUICKTESTOPTS) Modified: python/branches/py3k-struni/Misc/BeOS-setup.py ============================================================================== --- python/branches/py3k-struni/Misc/BeOS-setup.py (original) +++ python/branches/py3k-struni/Misc/BeOS-setup.py Sun Aug 5 17:29:28 2007 @@ -445,15 +445,6 @@ define_macros = expat_defs, libraries = ['expat']) ) - # Platform-specific libraries - if platform == 'linux2': - # Linux-specific modules - exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) - - if platform == 'sunos5': - # SunOS specific modules - exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) - self.extensions.extend(exts) # Call the method for detecting whether _tkinter can be compiled Modified: python/branches/py3k-struni/Misc/NEWS ============================================================================== --- python/branches/py3k-struni/Misc/NEWS (original) +++ python/branches/py3k-struni/Misc/NEWS Sun Aug 5 17:29:28 2007 @@ -186,8 +186,12 @@ AST -> bytecode mechanism. - Removed these modules: - * Bastion, bsddb185, exceptions, md5, MimeWriter, mimify, popen2, rexec, - sets, sha, stringold, strop, timing, xmllib. + * audiodev, Bastion, bsddb185, exceptions, linuxaudiodev, + md5, MimeWriter, mimify, popen2, + rexec, sets, sha, stringold, strop, sunaudiodev, timing, xmllib. + +- Moved these modules to Tools/Demos: + * toaiff - Remove obsolete IRIX modules: al/AL, cd/CD, cddb, cdplayer, cl/CL, DEVICE, ERRNO, FILE, fl/FL, flp, fm, GET, gl/GL, GLWS, IN, imgfile, IOCTL, jpeg, Modified: python/branches/py3k-struni/Misc/cheatsheet ============================================================================== --- python/branches/py3k-struni/Misc/cheatsheet (original) +++ python/branches/py3k-struni/Misc/cheatsheet Sun Aug 5 17:29:28 2007 @@ -1808,7 +1808,6 @@ asynchat Support for 'chat' style protocols asyncore Asynchronous File I/O (in select style) atexit Register functions to be called at exit of Python interpreter. -audiodev Audio support for a few platforms. base64 Conversions to/from base64 RFC-MIME transport encoding . BaseHTTPServer Base class forhttp services. Bastion "Bastionification" utility (control access to instance vars) @@ -1871,7 +1870,6 @@ inspect Tool for probing live Python objects. keyword List of Python keywords. linecache Cache lines from files. -linuxaudiodev Lunix /dev/audio support. locale Support for number formatting using the current locale settings. logging Python logging facility. @@ -1946,7 +1944,6 @@ textwrap Object for wrapping and filling text. threading Proposed new higher-level threading interfaces threading_api (doc of the threading module) -toaiff Convert "arbitrary" sound files to AIFF files . token Tokens (from "token.h"). tokenize Compiles a regular expression that recognizes Python tokens. traceback Format and print Python stack traces. @@ -2042,10 +2039,6 @@ DEVICE More constants for gl imgfile Imglib image file interface -* Suns * - - sunaudiodev Access to sun audio interface - Workspace exploration and idiom hints Modified: python/branches/py3k-struni/Modules/Setup.dist ============================================================================== --- python/branches/py3k-struni/Modules/Setup.dist (original) +++ python/branches/py3k-struni/Modules/Setup.dist Sun Aug 5 17:29:28 2007 @@ -236,17 +236,6 @@ #_sha shamodule.c -# SunOS specific modules -- off by default: - -#sunaudiodev sunaudiodev.c - - -# A Linux specific module -- off by default; this may also work on -# some *BSDs. - -#linuxaudiodev linuxaudiodev.c - - # The _tkinter module. # # The command for _tkinter is long and site specific. Please Modified: python/branches/py3k-struni/Modules/_csv.c ============================================================================== --- python/branches/py3k-struni/Modules/_csv.c (original) +++ python/branches/py3k-struni/Modules/_csv.c Sun Aug 5 17:29:28 2007 @@ -861,8 +861,8 @@ #define R_OFF(x) offsetof(ReaderObj, x) static struct PyMemberDef Reader_memberlist[] = { - { "dialect", T_OBJECT, R_OFF(dialect), RO }, - { "line_num", T_ULONG, R_OFF(line_num), RO }, + { "dialect", T_OBJECT, R_OFF(dialect), READONLY }, + { "line_num", T_ULONG, R_OFF(line_num), READONLY }, { NULL } }; @@ -1239,7 +1239,7 @@ #define W_OFF(x) offsetof(WriterObj, x) static struct PyMemberDef Writer_memberlist[] = { - { "dialect", T_OBJECT, W_OFF(dialect), RO }, + { "dialect", T_OBJECT, W_OFF(dialect), READONLY }, { NULL } }; Modified: python/branches/py3k-struni/Modules/_hotshot.c ============================================================================== --- python/branches/py3k-struni/Modules/_hotshot.c (original) +++ python/branches/py3k-struni/Modules/_hotshot.c Sun Aug 5 17:29:28 2007 @@ -1266,7 +1266,7 @@ }; static PyMemberDef logreader_members[] = { - {"info", T_OBJECT, offsetof(LogReaderObject, info), RO, + {"info", T_OBJECT, offsetof(LogReaderObject, info), READONLY, PyDoc_STR("Dictionary mapping informational keys to lists of values.")}, {NULL} }; Modified: python/branches/py3k-struni/Modules/bz2module.c ============================================================================== --- python/branches/py3k-struni/Modules/bz2module.c (original) +++ python/branches/py3k-struni/Modules/bz2module.c Sun Aug 5 17:29:28 2007 @@ -1624,7 +1624,7 @@ #define OFF(x) offsetof(BZ2DecompObject, x) static PyMemberDef BZ2Decomp_members[] = { - {"unused_data", T_OBJECT, OFF(unused_data), RO}, + {"unused_data", T_OBJECT, OFF(unused_data), READONLY}, {NULL} /* Sentinel */ }; Deleted: /python/branches/py3k-struni/Modules/linuxaudiodev.c ============================================================================== --- /python/branches/py3k-struni/Modules/linuxaudiodev.c Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,501 +0,0 @@ -/* Hey Emacs, this is -*-C-*- - ****************************************************************************** - * linuxaudiodev.c -- Linux audio device for python. - * - * Author : Peter Bosch - * Created On : Thu Mar 2 21:10:33 2000 - * Status : Unknown, Use with caution! - * - * Unless other notices are present in any part of this file - * explicitly claiming copyrights for other people and/or - * organizations, the contents of this file is fully copyright - * (C) 2000 Peter Bosch, all rights reserved. - ****************************************************************************** - */ - -#include "Python.h" -#include "structmember.h" - -#ifdef HAVE_FCNTL_H -#include -#else -#define O_RDONLY 00 -#define O_WRONLY 01 -#endif - - -#include -#if defined(linux) -#include - -#ifndef HAVE_STDINT_H -typedef unsigned long uint32_t; -#endif - -#elif defined(__FreeBSD__) -#include - -#ifndef SNDCTL_DSP_CHANNELS -#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS -#endif - -#endif - -typedef struct { - PyObject_HEAD - int x_fd; /* The open file */ - int x_mode; /* file mode */ - int x_icount; /* Input count */ - int x_ocount; /* Output count */ - uint32_t x_afmts; /* Audio formats supported by hardware*/ -} lad_t; - -/* XXX several format defined in soundcard.h are not supported, - including _NE (native endian) options and S32 options -*/ - -static struct { - int a_bps; - uint32_t a_fmt; - char *a_name; -} audio_types[] = { - { 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" }, - { 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" }, - { 8, AFMT_U8, "linear unsigned 8-bit audio" }, - { 8, AFMT_S8, "linear signed 8-bit audio" }, - { 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" }, - { 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" }, - { 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" }, - { 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" }, - { 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" }, -}; - -static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]); - -static PyTypeObject Ladtype; - -static PyObject *LinuxAudioError; - -static lad_t * -newladobject(PyObject *arg) -{ - lad_t *xp; - int fd, afmts, imode; - char *basedev = NULL; - char *mode = NULL; - - /* Two ways to call linuxaudiodev.open(): - open(device, mode) (for consistency with builtin open()) - open(mode) (for backwards compatibility) - because the *first* argument is optional, parsing args is - a wee bit tricky. */ - if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode)) - return NULL; - if (mode == NULL) { /* only one arg supplied */ - mode = basedev; - basedev = NULL; - } - - if (strcmp(mode, "r") == 0) - imode = O_RDONLY; - else if (strcmp(mode, "w") == 0) - imode = O_WRONLY; - else { - PyErr_SetString(LinuxAudioError, "mode should be 'r' or 'w'"); - return NULL; - } - - /* Open the correct device. The base device name comes from the - * AUDIODEV environment variable first, then /dev/dsp. The - * control device tacks "ctl" onto the base device name. - * - * Note that the only difference between /dev/audio and /dev/dsp - * is that the former uses logarithmic mu-law encoding and the - * latter uses 8-bit unsigned encoding. - */ - - if (basedev == NULL) { /* called with one arg */ - basedev = getenv("AUDIODEV"); - if (basedev == NULL) /* $AUDIODEV not set */ - basedev = "/dev/dsp"; - } - - if ((fd = open(basedev, imode)) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - if (imode == O_WRONLY && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { - PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); - return NULL; - } - /* Create and initialize the object */ - if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) { - close(fd); - return NULL; - } - xp->x_fd = fd; - xp->x_mode = imode; - xp->x_icount = xp->x_ocount = 0; - xp->x_afmts = afmts; - return xp; -} - -static void -lad_dealloc(lad_t *xp) -{ - /* if already closed, don't reclose it */ - if (xp->x_fd != -1) - close(xp->x_fd); - PyObject_Del(xp); -} - -static PyObject * -lad_read(lad_t *self, PyObject *args) -{ - int size, count; - char *cp; - PyObject *rv; - - if (!PyArg_ParseTuple(args, "i:read", &size)) - return NULL; - rv = PyString_FromStringAndSize(NULL, size); - if (rv == NULL) - return NULL; - cp = PyString_AS_STRING(rv); - if ((count = read(self->x_fd, cp, size)) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - Py_DECREF(rv); - return NULL; - } - self->x_icount += count; - _PyString_Resize(&rv, count); - return rv; -} - -static PyObject * -lad_write(lad_t *self, PyObject *args) -{ - char *cp; - int rv, size; - fd_set write_set_fds; - struct timeval tv; - int select_retval; - - if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) - return NULL; - - /* use select to wait for audio device to be available */ - FD_ZERO(&write_set_fds); - FD_SET(self->x_fd, &write_set_fds); - tv.tv_sec = 4; /* timeout values */ - tv.tv_usec = 0; - - while (size > 0) { - select_retval = select(self->x_fd+1, NULL, &write_set_fds, NULL, &tv); - tv.tv_sec = 1; tv.tv_usec = 0; /* willing to wait this long next time*/ - if (select_retval) { - if ((rv = write(self->x_fd, cp, size)) == -1) { - if (errno != EAGAIN) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } else { - errno = 0; /* EAGAIN: buffer is full, try again */ - } - } else { - self->x_ocount += rv; - size -= rv; - cp += rv; - } - } else { - /* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */ - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -lad_close(lad_t *self, PyObject *unused) -{ - if (self->x_fd >= 0) { - close(self->x_fd); - self->x_fd = -1; - } - Py_RETURN_NONE; -} - -static PyObject * -lad_fileno(lad_t *self, PyObject *unused) -{ - return PyInt_FromLong(self->x_fd); -} - -static PyObject * -lad_setparameters(lad_t *self, PyObject *args) -{ - int rate, ssize, nchannels, n, fmt, emulate=0; - - if (!PyArg_ParseTuple(args, "iiii|i:setparameters", - &rate, &ssize, &nchannels, &fmt, &emulate)) - return NULL; - - if (rate < 0) { - PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", - rate); - return NULL; - } - if (ssize < 0) { - PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", - ssize); - return NULL; - } - if (nchannels != 1 && nchannels != 2) { - PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", - nchannels); - return NULL; - } - - for (n = 0; n < n_audio_types; n++) - if (fmt == audio_types[n].a_fmt) - break; - if (n == n_audio_types) { - PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); - return NULL; - } - if (audio_types[n].a_bps != ssize) { - PyErr_Format(PyExc_ValueError, - "for %s, expected sample size %d, not %d", - audio_types[n].a_name, audio_types[n].a_bps, ssize); - return NULL; - } - - if (emulate == 0) { - if ((self->x_afmts & audio_types[n].a_fmt) == 0) { - PyErr_Format(PyExc_ValueError, - "%s format not supported by device", - audio_types[n].a_name); - return NULL; - } - } - if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, - &audio_types[n].a_fmt) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -static int -_ssize(lad_t *self, int *nchannels, int *ssize) -{ - int fmt; - - fmt = 0; - if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0) - return -errno; - - switch (fmt) { - case AFMT_MU_LAW: - case AFMT_A_LAW: - case AFMT_U8: - case AFMT_S8: - *ssize = sizeof(char); - break; - case AFMT_S16_LE: - case AFMT_S16_BE: - case AFMT_U16_LE: - case AFMT_U16_BE: - *ssize = sizeof(short); - break; - case AFMT_MPEG: - case AFMT_IMA_ADPCM: - default: - return -EOPNOTSUPP; - } - if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) - return -errno; - return 0; -} - - -/* bufsize returns the size of the hardware audio buffer in number - of samples */ -static PyObject * -lad_bufsize(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); -} - -/* obufcount returns the number of samples that are available in the - hardware for playing */ -static PyObject * -lad_obufcount(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / - (ssize * nchannels)); -} - -/* obufcount returns the number of samples that can be played without - blocking */ -static PyObject * -lad_obuffree(lad_t *self, PyObject *unused) -{ - audio_buf_info ai; - int nchannels=0, ssize=0; - - if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return PyInt_FromLong(ai.bytes / (ssize * nchannels)); -} - -/* Flush the device */ -static PyObject * -lad_flush(lad_t *self, PyObject *unused) -{ - if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - Py_RETURN_NONE; -} - -static PyObject * -lad_getptr(lad_t *self, PyObject *unused) -{ - count_info info; - int req; - - if (self->x_mode == O_RDONLY) - req = SNDCTL_DSP_GETIPTR; - else - req = SNDCTL_DSP_GETOPTR; - if (ioctl(self->x_fd, req, &info) == -1) { - PyErr_SetFromErrno(LinuxAudioError); - return NULL; - } - return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); -} - -static PyMethodDef lad_methods[] = { - { "read", (PyCFunction)lad_read, METH_VARARGS }, - { "write", (PyCFunction)lad_write, METH_VARARGS }, - { "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS }, - { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS }, - { "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS }, - { "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS }, - { "flush", (PyCFunction)lad_flush, METH_NOARGS }, - { "close", (PyCFunction)lad_close, METH_NOARGS }, - { "fileno", (PyCFunction)lad_fileno, METH_NOARGS }, - { "getptr", (PyCFunction)lad_getptr, METH_NOARGS }, - { NULL, NULL} /* sentinel */ -}; - -static PyObject * -lad_getattr(lad_t *xp, char *name) -{ - return Py_FindMethod(lad_methods, (PyObject *)xp, name); -} - -static PyTypeObject Ladtype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "linuxaudiodev.linux_audio_device", /*tp_name*/ - sizeof(lad_t), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)lad_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)lad_getattr, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; - -static PyObject * -ladopen(PyObject *self, PyObject *args) -{ - return (PyObject *)newladobject(args); -} - -static PyMethodDef linuxaudiodev_methods[] = { - { "open", ladopen, METH_VARARGS }, - { 0, 0 }, -}; - -void -initlinuxaudiodev(void) -{ - PyObject *m; - - m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods); - if (m == NULL) - return; - - LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL); - if (LinuxAudioError) - PyModule_AddObject(m, "error", LinuxAudioError); - - if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) - return; - if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1) - return; - - return; -} Deleted: /python/branches/py3k-struni/Modules/sunaudiodev.c ============================================================================== --- /python/branches/py3k-struni/Modules/sunaudiodev.c Sun Aug 5 17:29:28 2007 +++ (empty file) @@ -1,463 +0,0 @@ - -/* Sad objects */ - -#include "Python.h" -#include "structmember.h" - -#ifdef HAVE_SYS_AUDIOIO_H -#define SOLARIS -#endif - -#ifdef HAVE_FCNTL_H -#include -#endif - -#include -#include -#ifdef SOLARIS -#include -#else -#include -#endif - -/* #define offsetof(str,mem) ((int)(((str *)0)->mem)) */ - -typedef struct { - PyObject_HEAD - int x_fd; /* The open file */ - int x_icount; /* # samples read */ - int x_ocount; /* # samples written */ - int x_isctl; /* True if control device */ - -} sadobject; - -typedef struct { - PyObject_HEAD - audio_info_t ai; -} sadstatusobject; - -static PyTypeObject Sadtype; -static PyTypeObject Sadstatustype; -static sadstatusobject *sads_alloc(void); /* Forward */ - -static PyObject *SunAudioError; - -#define is_sadobject(v) (Py_Type(v) == &Sadtype) -#define is_sadstatusobject(v) (Py_Type(v) == &Sadstatustype) - - -static sadobject * -newsadobject(PyObject *args) -{ - sadobject *xp; - int fd; - char *mode; - int imode; - char* basedev; - char* ctldev; - char* opendev; - - /* Check arg for r/w/rw */ - if (!PyArg_ParseTuple(args, "s", &mode)) - return NULL; - if (strcmp(mode, "r") == 0) - imode = 0; - else if (strcmp(mode, "w") == 0) - imode = 1; - else if (strcmp(mode, "rw") == 0) - imode = 2; - else if (strcmp(mode, "control") == 0) - imode = -1; - else { - PyErr_SetString(SunAudioError, - "Mode should be one of 'r', 'w', 'rw' or 'control'"); - return NULL; - } - - /* Open the correct device. The base device name comes from the - * AUDIODEV environment variable first, then /dev/audio. The - * control device tacks "ctl" onto the base device name. - */ - basedev = getenv("AUDIODEV"); - if (!basedev) - basedev = "/dev/audio"; - ctldev = PyMem_NEW(char, strlen(basedev) + 4); - if (!ctldev) { - PyErr_NoMemory(); - return NULL; - } - strcpy(ctldev, basedev); - strcat(ctldev, "ctl"); - - if (imode < 0) { - opendev = ctldev; - fd = open(ctldev, 2); - } - else { - opendev = basedev; - fd = open(basedev, imode); - } - if (fd < 0) { - PyErr_SetFromErrnoWithFilename(SunAudioError, opendev); - PyMem_DEL(ctldev); - return NULL; - } - PyMem_DEL(ctldev); - - /* Create and initialize the object */ - xp = PyObject_New(sadobject, &Sadtype); - if (xp == NULL) { - close(fd); - return NULL; - } - xp->x_fd = fd; - xp->x_icount = xp->x_ocount = 0; - xp->x_isctl = (imode < 0); - - return xp; -} - -/* Sad methods */ - -static void -sad_dealloc(sadobject *xp) -{ - close(xp->x_fd); - PyObject_Del(xp); -} - -static PyObject * -sad_read(sadobject *self, PyObject *args) -{ - int size, count; - char *cp; - PyObject *rv; - - if (!PyArg_ParseTuple(args, "i:read", &size)) - return NULL; - rv = PyString_FromStringAndSize(NULL, size); - if (rv == NULL) - return NULL; - - if (!(cp = PyString_AsString(rv))) - goto finally; - - count = read(self->x_fd, cp, size); - if (count < 0) { - PyErr_SetFromErrno(SunAudioError); - goto finally; - } -#if 0 - /* TBD: why print this message if you can handle the condition? - * assume it's debugging info which we can just as well get rid - * of. in any case this message should *not* be using printf! - */ - if (count != size) - printf("sunaudio: funny read rv %d wtd %d\n", count, size); -#endif - self->x_icount += count; - return rv; - - finally: - Py_DECREF(rv); - return NULL; -} - -static PyObject * -sad_write(sadobject *self, PyObject *args) -{ - char *cp; - int count, size; - - if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) - return NULL; - - count = write(self->x_fd, cp, size); - if (count < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } -#if 0 - if (count != size) - printf("sunaudio: funny write rv %d wanted %d\n", count, size); -#endif - self->x_ocount += count; - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_getinfo(sadobject *self) -{ - sadstatusobject *rv; - - if (!(rv = sads_alloc())) - return NULL; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - Py_DECREF(rv); - return NULL; - } - return (PyObject *)rv; -} - -static PyObject * -sad_setinfo(sadobject *self, sadstatusobject *arg) -{ - if (!is_sadstatusobject(arg)) { - PyErr_SetString(PyExc_TypeError, - "Must be sun audio status object"); - return NULL; - } - if (ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_ibufcount(sadobject *self) -{ - audio_info_t ai; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - return PyInt_FromLong(ai.record.samples - self->x_icount); -} - -static PyObject * -sad_obufcount(sadobject *self) -{ - audio_info_t ai; - - if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - /* x_ocount is in bytes, whereas play.samples is in frames */ - /* we want frames */ - return PyInt_FromLong(self->x_ocount / (ai.play.channels * - ai.play.precision / 8) - - ai.play.samples); -} - -static PyObject * -sad_drain(sadobject *self) -{ - if (ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -#ifdef SOLARIS -static PyObject * -sad_getdev(sadobject *self) -{ - struct audio_device ad; - - if (ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - return Py_BuildValue("(sss)", ad.name, ad.version, ad.config); -} -#endif - -static PyObject * -sad_flush(sadobject *self) -{ - if (ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0) { - PyErr_SetFromErrno(SunAudioError); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_close(sadobject *self) -{ - - if (self->x_fd >= 0) { - close(self->x_fd); - self->x_fd = -1; - } - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -sad_fileno(sadobject *self) -{ - return PyInt_FromLong(self->x_fd); -} - - -static PyMethodDef sad_methods[] = { - { "read", (PyCFunction)sad_read, METH_VARARGS }, - { "write", (PyCFunction)sad_write, METH_VARARGS }, - { "ibufcount", (PyCFunction)sad_ibufcount, METH_NOARGS }, - { "obufcount", (PyCFunction)sad_obufcount, METH_NOARGS }, -#define CTL_METHODS 4 - { "getinfo", (PyCFunction)sad_getinfo, METH_NOARGS }, - { "setinfo", (PyCFunction)sad_setinfo, METH_O}, - { "drain", (PyCFunction)sad_drain, METH_NOARGS }, - { "flush", (PyCFunction)sad_flush, METH_NOARGS }, -#ifdef SOLARIS - { "getdev", (PyCFunction)sad_getdev, METH_NOARGS }, -#endif - { "close", (PyCFunction)sad_close, METH_NOARGS }, - { "fileno", (PyCFunction)sad_fileno, METH_NOARGS }, - {NULL, NULL} /* sentinel */ -}; - -static PyObject * -sad_getattr(sadobject *xp, char *name) -{ - if (xp->x_isctl) - return Py_FindMethod(sad_methods+CTL_METHODS, - (PyObject *)xp, name); - else - return Py_FindMethod(sad_methods, (PyObject *)xp, name); -} - -/* ----------------------------------------------------------------- */ - -static sadstatusobject * -sads_alloc(void) { - return PyObject_New(sadstatusobject, &Sadstatustype); -} - -static void -sads_dealloc(sadstatusobject *xp) -{ - PyMem_DEL(xp); -} - -#define OFF(x) offsetof(audio_info_t,x) -static struct memberlist sads_ml[] = { - { "i_sample_rate", T_UINT, OFF(record.sample_rate) }, - { "i_channels", T_UINT, OFF(record.channels) }, - { "i_precision", T_UINT, OFF(record.precision) }, - { "i_encoding", T_UINT, OFF(record.encoding) }, - { "i_gain", T_UINT, OFF(record.gain) }, - { "i_port", T_UINT, OFF(record.port) }, - { "i_samples", T_UINT, OFF(record.samples) }, - { "i_eof", T_UINT, OFF(record.eof) }, - { "i_pause", T_UBYTE, OFF(record.pause) }, - { "i_error", T_UBYTE, OFF(record.error) }, - { "i_waiting", T_UBYTE, OFF(record.waiting) }, - { "i_open", T_UBYTE, OFF(record.open) , RO}, - { "i_active", T_UBYTE, OFF(record.active) , RO}, -#ifdef SOLARIS - { "i_buffer_size", T_UINT, OFF(record.buffer_size) }, - { "i_balance", T_UBYTE, OFF(record.balance) }, - { "i_avail_ports", T_UINT, OFF(record.avail_ports) }, -#endif - - { "o_sample_rate", T_UINT, OFF(play.sample_rate) }, - { "o_channels", T_UINT, OFF(play.channels) }, - { "o_precision", T_UINT, OFF(play.precision) }, - { "o_encoding", T_UINT, OFF(play.encoding) }, - { "o_gain", T_UINT, OFF(play.gain) }, - { "o_port", T_UINT, OFF(play.port) }, - { "o_samples", T_UINT, OFF(play.samples) }, - { "o_eof", T_UINT, OFF(play.eof) }, - { "o_pause", T_UBYTE, OFF(play.pause) }, - { "o_error", T_UBYTE, OFF(play.error) }, - { "o_waiting", T_UBYTE, OFF(play.waiting) }, - { "o_open", T_UBYTE, OFF(play.open) , RO}, - { "o_active", T_UBYTE, OFF(play.active) , RO}, -#ifdef SOLARIS - { "o_buffer_size", T_UINT, OFF(play.buffer_size) }, - { "o_balance", T_UBYTE, OFF(play.balance) }, - { "o_avail_ports", T_UINT, OFF(play.avail_ports) }, -#endif - - { "monitor_gain", T_UINT, OFF(monitor_gain) }, - { NULL, 0, 0}, -}; - -static PyObject * -sads_getattr(sadstatusobject *xp, char *name) -{ - return PyMember_Get((char *)&xp->ai, sads_ml, name); -} - -static int -sads_setattr(sadstatusobject *xp, char *name, PyObject *v) -{ - - if (v == NULL) { - PyErr_SetString(PyExc_TypeError, - "can't delete sun audio status attributes"); - return -1; - } - return PyMember_Set((char *)&xp->ai, sads_ml, name, v); -} - -/* ------------------------------------------------------------------- */ - - -static PyTypeObject Sadtype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "sunaudiodev.sun_audio_device", /*tp_name*/ - sizeof(sadobject), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)sad_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)sad_getattr, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; - -static PyTypeObject Sadstatustype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "sunaudiodev.sun_audio_device_status", /*tp_name*/ - sizeof(sadstatusobject), /*tp_size*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)sads_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)sads_getattr, /*tp_getattr*/ - (setattrfunc)sads_setattr, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ -}; -/* ------------------------------------------------------------------- */ - -static PyObject * -sadopen(PyObject *self, PyObject *args) -{ - return (PyObject *)newsadobject(args); -} - -static PyMethodDef sunaudiodev_methods[] = { - { "open", sadopen, METH_VARARGS }, - { 0, 0 }, -}; - -void -initsunaudiodev(void) -{ - PyObject *m, *d; - - m = Py_InitModule("sunaudiodev", sunaudiodev_methods); - if (m == NULL) - return; - d = PyModule_GetDict(m); - SunAudioError = PyErr_NewException("sunaudiodev.error", NULL, NULL); - if (SunAudioError) - PyDict_SetItemString(d, "error", SunAudioError); -} Modified: python/branches/py3k-struni/Objects/frameobject.c ============================================================================== --- python/branches/py3k-struni/Objects/frameobject.c (original) +++ python/branches/py3k-struni/Objects/frameobject.c Sun Aug 5 17:29:28 2007 @@ -15,11 +15,11 @@ #define OFF(x) offsetof(PyFrameObject, x) static PyMemberDef frame_memberlist[] = { - {"f_back", T_OBJECT, OFF(f_back), RO}, - {"f_code", T_OBJECT, OFF(f_code), RO}, - {"f_builtins", T_OBJECT, OFF(f_builtins),RO}, - {"f_globals", T_OBJECT, OFF(f_globals), RO}, - {"f_lasti", T_INT, OFF(f_lasti), RO}, + {"f_back", T_OBJECT, OFF(f_back), READONLY}, + {"f_code", T_OBJECT, OFF(f_code), READONLY}, + {"f_builtins", T_OBJECT, OFF(f_builtins),READONLY}, + {"f_globals", T_OBJECT, OFF(f_globals), READONLY}, + {"f_lasti", T_INT, OFF(f_lasti), READONLY}, {"f_exc_type", T_OBJECT, OFF(f_exc_type)}, {"f_exc_value", T_OBJECT, OFF(f_exc_value)}, {"f_exc_traceback", T_OBJECT, OFF(f_exc_traceback)}, Modified: python/branches/py3k-struni/Objects/genobject.c ============================================================================== --- python/branches/py3k-struni/Objects/genobject.c (original) +++ python/branches/py3k-struni/Objects/genobject.c Sun Aug 5 17:29:28 2007 @@ -282,8 +282,8 @@ static PyMemberDef gen_memberlist[] = { - {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), RO}, - {"gi_running", T_INT, offsetof(PyGenObject, gi_running), RO}, + {"gi_frame", T_OBJECT, offsetof(PyGenObject, gi_frame), READONLY}, + {"gi_running", T_INT, offsetof(PyGenObject, gi_running), READONLY}, {NULL} /* Sentinel */ }; Modified: python/branches/py3k-struni/PC/os2vacpp/makefile ============================================================================== --- python/branches/py3k-struni/PC/os2vacpp/makefile (original) +++ python/branches/py3k-struni/PC/os2vacpp/makefile Sun Aug 5 17:29:28 2007 @@ -856,20 +856,6 @@ $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h \ $(PY_INCLUDE)\tupleobject.h -sunaudiodev.obj: $(PY_INCLUDE)\abstract.h $(OS2TCPIP)\Include\sys\ioctl.h $(PY_INCLUDE)\ceval.h \ - $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ - pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ - $(PY_INCLUDE)\floatobject.h $(PY_INCLUDE)\funcobject.h $(PY_INCLUDE)\import.h \ - $(PY_INCLUDE)\intobject.h $(PY_INCLUDE)\intrcheck.h $(PY_INCLUDE)\listobject.h \ - $(PY_INCLUDE)\longobject.h $(PY_INCLUDE)\methodobject.h \ - $(PY_INCLUDE)\modsupport.h $(PY_INCLUDE)\moduleobject.h $(PY_INCLUDE)\mymalloc.h \ - $(PY_INCLUDE)\myproto.h $(PY_INCLUDE)\object.h $(PY_INCLUDE)\objimpl.h \ - $(PY_INCLUDE)\pydebug.h $(PY_INCLUDE)\pyerrors.h $(PY_INCLUDE)\pyfpe.h \ - $(PY_INCLUDE)\pystate.h $(PY_INCLUDE)\python.h $(PY_INCLUDE)\pythonrun.h \ - $(PY_INCLUDE)\rangeobject.h $(PY_INCLUDE)\sliceobject.h \ - $(PY_INCLUDE)\stringobject.h $(PY_INCLUDE)\structmember.h \ - $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h - syslogmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h \ $(PY_INCLUDE)\classobject.h $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h \ pyconfig.h $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h \ Modified: python/branches/py3k-struni/PC/os2vacpp/makefile.omk ============================================================================== --- python/branches/py3k-struni/PC/os2vacpp/makefile.omk (original) +++ python/branches/py3k-struni/PC/os2vacpp/makefile.omk Sun Aug 5 17:29:28 2007 @@ -171,8 +171,6 @@ # # Multimedia: # audioop.c -- Various Compute Operations on Audio Samples - # imageop.c -- Various Compute Operations on Video Samples - # sunaudiodev.c -- Wrapper of Sun Audio Device API # Database: # dbmmodule.c -- Wrapper of DBM Database API (Generic Flavor) @@ -627,15 +625,6 @@ pystate.h python.h pythonrun.h rangeobject.h sliceobject.h \ stringobject.h sysmodule.h traceback.h tupleobject.h -sunaudiodev.obj: abstract.h c:\mptn\include\sys\ioctl.h ceval.h \ - classobject.h cobject.h complexobject.h pyconfig.h dictobject.h \ - fileobject.h floatobject.h funcobject.h import.h intobject.h \ - intrcheck.h listobject.h longobject.h methodobject.h modsupport.h \ - moduleobject.h mymalloc.h myproto.h object.h objimpl.h pydebug.h \ - pyerrors.h pyfpe.h pystate.h python.h pythonrun.h rangeobject.h \ - sliceobject.h stringobject.h structmember.h sysmodule.h \ - traceback.h tupleobject.h - syslogmodule.obj: abstract.h ceval.h classobject.h cobject.h \ complexobject.h pyconfig.h dictobject.h fileobject.h floatobject.h \ funcobject.h import.h intobject.h intrcheck.h listobject.h \ Modified: python/branches/py3k-struni/Python/symtable.c ============================================================================== --- python/branches/py3k-struni/Python/symtable.c (original) +++ python/branches/py3k-struni/Python/symtable.c Sun Aug 5 17:29:28 2007 @@ -1471,10 +1471,10 @@ else { if (st->st_cur->ste_type != ModuleBlock) { int lineno = st->st_cur->ste_lineno; - if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) { - Py_DECREF(store_name); - return 0; - } + PyErr_SetString(PyExc_SyntaxError, IMPORT_STAR_WARNING); + PyErr_SyntaxLocation(st->st_filename, lineno); + Py_DECREF(store_name); + return 0; } st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR; Py_DECREF(store_name); Modified: python/branches/py3k-struni/setup.py ============================================================================== --- python/branches/py3k-struni/setup.py (original) +++ python/branches/py3k-struni/setup.py Sun Aug 5 17:29:28 2007 @@ -1074,24 +1074,12 @@ exts.append(Extension('_fileio', ['_fileio.c'])) # Platform-specific libraries - if platform == 'linux2': - # Linux-specific modules - exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) - else: - missing.append('linuxaudiodev') - if platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', 'freebsd7'): exts.append( Extension('ossaudiodev', ['ossaudiodev.c']) ) else: missing.append('ossaudiodev') - if platform == 'sunos5': - # SunOS specific modules - exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) - else: - missing.append('sunaudiodev') - if platform == 'darwin' and ("--disable-toolbox-glue" not in sysconfig.get_config_var("CONFIG_ARGS")): From python-3000-checkins at python.org Sun Aug 5 17:39:16 2007 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sun, 5 Aug 2007 17:39:16 +0200 (CEST) Subject: [Python-3000-checkins] r56754 - in python/branches/py3k-struni: Doc/lib/libbsddb.tex Lib/bsddb/__init__.py Lib/test/test_bsddb.py Modules/_bsddb.c Message-ID: <20070805153916.870871E4002@bag.python.org> Author: martin.v.loewis Date: Sun Aug 5 17:39:16 2007 New Revision: 56754 Modified: python/branches/py3k-struni/Doc/lib/libbsddb.tex python/branches/py3k-struni/Lib/bsddb/__init__.py python/branches/py3k-struni/Lib/test/test_bsddb.py python/branches/py3k-struni/Modules/_bsddb.c Log: Make bsddb use bytes as keys and values. Add StringKeys and StringValues classes. Fix test suite. Modified: python/branches/py3k-struni/Doc/lib/libbsddb.tex ============================================================================== --- python/branches/py3k-struni/Doc/lib/libbsddb.tex (original) +++ python/branches/py3k-struni/Doc/lib/libbsddb.tex Sun Aug 5 17:39:16 2007 @@ -93,6 +93,17 @@ interpretation. \end{funcdesc} +\begin{classdesc}{StringKeys}{db} + Wrapper class around a DB object that supports string keys + (rather than bytes). All keys are encoded as UTF-8, then passed + to the underlying object. \versionadded{3.0} +\end{classdesc} + +\begin{classdesc}{StringValues}{db} + Wrapper class around a DB object that supports string values + (rather than bytes). All values are encoded as UTF-8, then passed + to the underlying object. \versionadded{3.0} +\end{classdesc} \begin{seealso} \seemodule{dbhash}{DBM-style interface to the \module{bsddb}} Modified: python/branches/py3k-struni/Lib/bsddb/__init__.py ============================================================================== --- python/branches/py3k-struni/Lib/bsddb/__init__.py (original) +++ python/branches/py3k-struni/Lib/bsddb/__init__.py Sun Aug 5 17:39:16 2007 @@ -64,15 +64,9 @@ #---------------------------------------------------------------------- -import sys, os +import sys, os, UserDict +from weakref import ref -# for backwards compatibility with python versions older than 2.3, the -# iterator interface is dynamically defined and added using a mixin -# class. old python can't tokenize it due to the yield keyword. -if sys.version >= '2.3': - import UserDict - from weakref import ref - exec(""" class _iter_mixin(UserDict.DictMixin): def _make_iter_cursor(self): cur = _DeadlockWrap(self.db.cursor) @@ -145,10 +139,6 @@ except _bsddb.DBCursorClosedError: # the database was modified during iteration. abort. return -""") -else: - class _iter_mixin: pass - class _DBWithCursor(_iter_mixin): """ @@ -290,6 +280,138 @@ self._checkOpen() return _DeadlockWrap(self.db.sync) +class _ExposedProperties: + @property + def _cursor_refs(self): + return self.db._cursor_refs + +class StringKeys(UserDict.DictMixin, _ExposedProperties): + """Wrapper around DB object that automatically encodes + all keys as UTF-8; the keys must be strings.""" + + def __init__(self, db): + self.db = db + + def __len__(self): + return len(self.db) + + def __getitem__(self, key): + return self.db[key.encode("utf-8")] + + def __setitem__(self, key, value): + self.db[key.encode("utf-8")] = value + + def __delitem__(self, key): + del self.db[key.encode("utf-8")] + + def __iter__(self): + for k in self.db: + yield k.decode("utf-8") + + def close(self): + self.db.close() + + def keys(self): + for k in self.db.keys(): + yield k.decode("utf-8") + + def has_key(self, key): + return self.db.has_key(key.encode("utf-8")) + + __contains__ = has_key + + def values(self): + return self.db.values() + + def items(self): + for k,v in self.db.items(): + yield k.decode("utf-8"), v + + def set_location(self, key): + return self.db.set_location(key.encode("utf-8")) + + def next(self): + key, value = self.db.next() + return key.decode("utf-8"), value + + def previous(self): + key, value = self.db.previous() + return key.decode("utf-8"), value + + def first(self): + key, value = self.db.first() + return key.decode("utf-8"), value + + def last(self): + key, value = self.db.last() + return key.decode("utf-8"), value + + def sync(self): + return self.db.sync() + +class StringValues(UserDict.DictMixin, _ExposedProperties): + """Wrapper around DB object that automatically encodes + all keys as UTF-8; the keys must be strings.""" + + def __init__(self, db): + self.db = db + + def __len__(self): + return len(self.db) + + def __getitem__(self, key): + return self.db[key].decode("utf-8") + + def __setitem__(self, key, value): + self.db[key] = value.encode("utf-8") + + def __delitem__(self, key): + del self.db[key] + + def __iter__(self): + return iter(self.db) + + def close(self): + self.db.close() + + def keys(self): + return self.db.keys() + + def has_key(self, key): + return self.db.has_key(key) + + __contains__ = has_key + + def values(self): + for v in self.db.values(): + yield v.decode("utf-8") + + def items(self): + for k,v in self.db.items(): + yield k, v.decode("utf-8") + + def set_location(self, key): + return self.db.set_location(key) + + def next(self): + key, value = self.db.next() + return key, value.decode("utf-8") + + def previous(self): + key, value = self.db.previous() + return key, value.decode("utf-8") + + def first(self): + key, value = self.db.first() + return key, value.decode("utf-8") + + def last(self): + key, value = self.db.last() + return key, value.decode("utf-8") + + def sync(self): + return self.db.sync() + #---------------------------------------------------------------------- # Compatibility object factory functions @@ -375,7 +497,7 @@ if file is not None and os.path.isfile(file): os.unlink(file) else: - raise error, "flags should be one of 'r', 'w', 'c' or 'n'" + raise error, "flags should be one of 'r', 'w', 'c' or 'n', not "+repr(flag) return flags | db.DB_THREAD #---------------------------------------------------------------------- Modified: python/branches/py3k-struni/Lib/test/test_bsddb.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_bsddb.py (original) +++ python/branches/py3k-struni/Lib/test/test_bsddb.py Sun Aug 5 17:39:16 2007 @@ -12,8 +12,12 @@ class TestBSDDB(unittest.TestCase): openflag = 'c' + def do_open(self, *args, **kw): + # openmethod is a list so that it's not mistaken as an instance method + return bsddb.StringValues(bsddb.StringKeys(self.openmethod[0](*args, **kw))) + def setUp(self): - self.f = self.openmethod[0](self.fname, self.openflag, cachesize=32768) + self.f = self.do_open(self.fname, self.openflag, cachesize=32768) self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='') for k, v in self.d.items(): self.f[k] = v @@ -47,7 +51,7 @@ # so finish here. return self.f.close() - self.f = self.openmethod[0](self.fname, 'w') + self.f = self.do_open(self.fname, 'w') for k, v in self.d.items(): self.assertEqual(self.f[k], v) Modified: python/branches/py3k-struni/Modules/_bsddb.c ============================================================================== --- python/branches/py3k-struni/Modules/_bsddb.c (original) +++ python/branches/py3k-struni/Modules/_bsddb.c Sun Aug 5 17:39:16 2007 @@ -99,7 +99,7 @@ #endif #define PY_BSDDB_VERSION "4.5.0" -static char *rcs_id = "$Id$"; +static char *svn_id = "$Id$"; #if (PY_VERSION_HEX < 0x02050000) @@ -413,7 +413,7 @@ /* no need to do anything, the structure has already been zeroed */ } - else if (PyString_Check(keyobj)) { + else if (PyBytes_Check(keyobj)) { /* verify access method type */ type = _DB_get_type(self); if (type == -1) @@ -425,8 +425,8 @@ return 0; } - key->data = PyString_AS_STRING(keyobj); - key->size = PyString_GET_SIZE(keyobj); + key->data = PyBytes_AS_STRING(keyobj); + key->size = PyBytes_GET_SIZE(keyobj); } else if (PyInt_Check(keyobj)) { @@ -460,7 +460,7 @@ } else { PyErr_Format(PyExc_TypeError, - "String or Integer object expected for key, %s found", + "Bytes or Integer object expected for key, %s found", Py_Type(keyobj)->tp_name); return 0; } @@ -721,13 +721,13 @@ case DB_RECNO: case DB_QUEUE: - retval = Py_BuildValue("is#", *((db_recno_t*)key.data), + retval = Py_BuildValue("iy#", *((db_recno_t*)key.data), data.data, data.size); break; case DB_HASH: case DB_BTREE: default: - retval = Py_BuildValue("s#s#", key.data, key.size, + retval = Py_BuildValue("y#y#", key.data, key.size, data.data, data.size); break; } @@ -1196,18 +1196,13 @@ else if (PyInt_Check(result)) { retval = PyInt_AsLong(result); } - else if (PyString_Check(result)) { + else if (PyBytes_Check(result)) { char* data; Py_ssize_t size; CLEAR_DBT(*secKey); -#if PYTHON_API_VERSION <= 1007 - /* 1.5 compatibility */ - size = PyString_Size(result); - data = PyString_AsString(result); -#else - PyString_AsStringAndSize(result, &data, &size); -#endif + size = PyBytes_Size(result); + data = PyBytes_AsString(result); secKey->flags = DB_DBT_APPMALLOC; /* DB will free */ secKey->data = malloc(size); /* TODO, check this */ if (secKey->data) { @@ -1548,7 +1543,7 @@ retval = Py_BuildValue("s#s#", key.data, key.size, data.data, data.size); else /* return just the data */ - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); FREE_DBT(data); } FREE_DBT(key); @@ -1617,13 +1612,13 @@ else if (!err) { PyObject *pkeyObj; PyObject *dataObj; - dataObj = PyString_FromStringAndSize(data.data, data.size); + dataObj = PyBytes_FromStringAndSize(data.data, data.size); if (self->primaryDBType == DB_RECNO || self->primaryDBType == DB_QUEUE) pkeyObj = PyInt_FromLong(*(int *)pkey.data); else - pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size); + pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size); if (flags & DB_SET_RECNO) /* return key , pkey and data */ { @@ -1632,7 +1627,7 @@ if (type == DB_RECNO || type == DB_QUEUE) keyObj = PyInt_FromLong(*(int *)key.data); else - keyObj = PyString_FromStringAndSize(key.data, key.size); + keyObj = PyBytes_FromStringAndSize(key.data, key.size); #if (PY_VERSION_HEX >= 0x02040000) retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); #else @@ -1753,7 +1748,7 @@ } else if (!err) { /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */ - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); /* Even though the flags require DB_DBT_MALLOC, data is not always allocated. 4.4: allocated, 4.5: *not* allocated. :-( */ @@ -2801,7 +2796,7 @@ retval = NULL; } else { - retval = PyString_FromStringAndSize((char*)data.data, data.size); + retval = PyBytes_FromStringAndSize((char*)data.data, data.size); FREE_DBT(data); } @@ -2952,7 +2947,7 @@ case DB_BTREE: case DB_HASH: default: - item = PyString_FromStringAndSize((char*)key.data, key.size); + item = PyBytes_FromStringAndSize((char*)key.data, key.size); break; case DB_RECNO: case DB_QUEUE: @@ -2962,7 +2957,7 @@ break; case _VALUES_LIST: - item = PyString_FromStringAndSize((char*)data.data, data.size); + item = PyBytes_FromStringAndSize((char*)data.data, data.size); break; case _ITEMS_LIST: @@ -3303,13 +3298,13 @@ else { PyObject *pkeyObj; PyObject *dataObj; - dataObj = PyString_FromStringAndSize(data.data, data.size); + dataObj = PyBytes_FromStringAndSize(data.data, data.size); if (self->mydb->primaryDBType == DB_RECNO || self->mydb->primaryDBType == DB_QUEUE) pkeyObj = PyInt_FromLong(*(int *)pkey.data); else - pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size); + pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size); if (key.data && key.size) /* return key, pkey and data */ { @@ -3318,7 +3313,7 @@ if (type == DB_RECNO || type == DB_QUEUE) keyObj = PyInt_FromLong(*(int *)key.data); else - keyObj = PyString_FromStringAndSize(key.data, key.size); + keyObj = PyBytes_FromStringAndSize(key.data, key.size); #if (PY_VERSION_HEX >= 0x02040000) retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); #else @@ -4610,7 +4605,7 @@ if (log_list) { char **log_list_start; for (log_list_start = log_list; *log_list != NULL; ++log_list) { - item = PyString_FromString (*log_list); + item = PyUnicode_FromString (*log_list); if (item == NULL) { Py_DECREF(list); list = NULL; @@ -4910,7 +4905,7 @@ RETURN_IF_ERR(); - return PyString_FromStringAndSize(key.data, key.size); + return PyBytes_FromStringAndSize(key.data, key.size); } static PyObject* @@ -5335,7 +5330,7 @@ if (self->db_env->db_home == NULL) { RETURN_NONE(); } - return PyString_FromString(self->db_env->db_home); + return PyUnicode_FromString(self->db_env->db_home); } return Py_FindMethod(DBEnv_methods, (PyObject* )self, name); @@ -5654,9 +5649,9 @@ { PyObject* m; PyObject* d; - PyObject* pybsddb_version_s = PyString_FromString( PY_BSDDB_VERSION ); - PyObject* db_version_s = PyString_FromString( DB_VERSION_STRING ); - PyObject* cvsid_s = PyString_FromString( rcs_id ); + PyObject* pybsddb_version_s = PyUnicode_FromString(PY_BSDDB_VERSION); + PyObject* db_version_s = PyUnicode_FromString(DB_VERSION_STRING); + PyObject* svnid_s = PyUnicode_FromString(svn_id); /* Initialize the type of the new type objects here; doing it here is required for portability to Windows without requiring C++. */ @@ -5683,12 +5678,12 @@ /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); PyDict_SetItemString(d, "__version__", pybsddb_version_s); - PyDict_SetItemString(d, "cvsid", cvsid_s); + PyDict_SetItemString(d, "cvsid", svnid_s); PyDict_SetItemString(d, "DB_VERSION_STRING", db_version_s); Py_DECREF(pybsddb_version_s); pybsddb_version_s = NULL; - Py_DECREF(cvsid_s); - cvsid_s = NULL; + Py_DECREF(svnid_s); + svnid_s = NULL; Py_DECREF(db_version_s); db_version_s = NULL; From python-3000-checkins at python.org Sun Aug 5 22:26:12 2007 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sun, 5 Aug 2007 22:26:12 +0200 (CEST) Subject: [Python-3000-checkins] r56755 - in python/branches/py3k-struni: Doc/api/concrete.tex Objects/bytesobject.c Objects/unicodeobject.c Message-ID: <20070805202612.58CFF1E4002@bag.python.org> Author: martin.v.loewis Date: Sun Aug 5 22:26:11 2007 New Revision: 56755 Modified: python/branches/py3k-struni/Doc/api/concrete.tex python/branches/py3k-struni/Objects/bytesobject.c python/branches/py3k-struni/Objects/unicodeobject.c Log: Change PyUnicode_FromString[AndSize] to expect UTF-8. Modified: python/branches/py3k-struni/Doc/api/concrete.tex ============================================================================== --- python/branches/py3k-struni/Doc/api/concrete.tex (original) +++ python/branches/py3k-struni/Doc/api/concrete.tex Sun Aug 5 22:26:11 2007 @@ -996,10 +996,11 @@ \var{u} is \NULL{}. \end{cfuncdesc} -\begin{cfuncdesc}{PyObject*}{PyUnicode_FromString}{const char *u} +\begin{cfuncdesc}{PyObject*}{PyUnicode_FromStringAndSize}{const char *u, + Py_ssize_t size} Create a Unicode Object from the char buffer \var{u}. - \var{u} must be 0-terminated, the bytes will be interpreted as - being latin-1 encoded. \var{u} may also be \NULL{} which causes the + The bytes will be interpreted as being UTF-8 encoded. + \var{u} may also be \NULL{} which causes the contents to be undefined. It is the user's responsibility to fill in the needed data. The buffer is copied into the new object. If the buffer is not \NULL{}, the return value might be a shared object. @@ -1008,6 +1009,12 @@ \versionadded{3.0} \end{cfuncdesc} +\begin{cfuncdesc}{PyObject*}{PyUnicode_FromString}{const char*u} + Create a Unicode object from an UTF-8 encoded null-terminated + char buffer \var{u}. + \versionadded{3.0} +\end{funcdesc} + \begin{cfuncdesc}{PyObject*}{PyUnicode_FromFormat}{const char *format, ...} Take a C \cfunction{printf()}-style \var{format} string and a variable number of arguments, calculate the size of the resulting Modified: python/branches/py3k-struni/Objects/bytesobject.c ============================================================================== --- python/branches/py3k-struni/Objects/bytesobject.c (original) +++ python/branches/py3k-struni/Objects/bytesobject.c Sun Aug 5 22:26:11 2007 @@ -2724,11 +2724,13 @@ static PyObject * bytes_reduce(PyBytesObject *self) { - return Py_BuildValue("(O(s#s))", - Py_Type(self), - self->ob_bytes == NULL ? "" : self->ob_bytes, - Py_Size(self), - "latin-1"); + PyObject *latin1; + if (self->ob_bytes) + latin1 = PyUnicode_DecodeLatin1(self->ob_bytes, + Py_Size(self), NULL); + else + latin1 = PyUnicode_FromString(""); + return Py_BuildValue("(O(Ns))", Py_Type(self), latin1, "latin-1"); } static PySequenceMethods bytes_as_sequence = { Modified: python/branches/py3k-struni/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k-struni/Objects/unicodeobject.c (original) +++ python/branches/py3k-struni/Objects/unicodeobject.c Sun Aug 5 22:26:11 2007 @@ -427,7 +427,9 @@ { PyUnicodeObject *unicode; /* If the Unicode data is known at construction time, we can apply - some optimizations which share commonly used objects. */ + some optimizations which share commonly used objects. + Also, this means the input must be UTF-8, so fall back to the + UTF-8 decoder at the end. */ if (u != NULL) { /* Optimization for empty strings */ @@ -436,8 +438,9 @@ return (PyObject *)unicode_empty; } - /* Single characters are shared when using this constructor */ - if (size == 1) { + /* Single characters are shared when using this constructor. + Restrict to ASCII, since the input must be UTF-8. */ + if (size == 1 && Py_CHARMASK(*u) < 128) { unicode = unicode_latin1[Py_CHARMASK(*u)]; if (!unicode) { unicode = _PyUnicode_New(1); @@ -449,21 +452,14 @@ Py_INCREF(unicode); return (PyObject *)unicode; } + + return PyUnicode_DecodeUTF8(u, size, NULL); } unicode = _PyUnicode_New(size); if (!unicode) return NULL; - /* Copy the Unicode data into the new object */ - if (u != NULL) { - Py_UNICODE *p = unicode->str; - while (size--) - *p++ = Py_CHARMASK(*u++); - /* Don't need to write trailing 0 because - that's already done by _PyUnicode_New */ - } - return (PyObject *)unicode; } From python-3000-checkins at python.org Mon Aug 6 00:23:10 2007 From: python-3000-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2007 00:23:10 +0200 (CEST) Subject: [Python-3000-checkins] r56757 - in python/branches/py3k-struni: Lib/tempfile.py Misc/ACKS Message-ID: <20070805222310.F04F31E4006@bag.python.org> Author: brett.cannon Date: Mon Aug 6 00:23:10 2007 New Revision: 56757 Modified: python/branches/py3k-struni/Lib/tempfile.py python/branches/py3k-struni/Misc/ACKS Log: Move tempfile over to the io module. Makes test_threaded_import pass. Thanks Paul Colomiets. Modified: python/branches/py3k-struni/Lib/tempfile.py ============================================================================== --- python/branches/py3k-struni/Lib/tempfile.py (original) +++ python/branches/py3k-struni/Lib/tempfile.py Mon Aug 6 00:23:10 2007 @@ -197,7 +197,7 @@ filename = _os.path.join(dir, name) try: fd = _os.open(filename, flags, 0o600) - fp = _os.fdopen(fd, 'w') + fp = _io.open(fd, 'w') fp.write('blat') fp.close() _os.unlink(filename) @@ -438,7 +438,7 @@ flags |= _os.O_TEMPORARY (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) - file = _os.fdopen(fd, mode, bufsize) + file = _io.open(fd, mode, bufsize) return _TemporaryFileWrapper(file, name, delete) if _os.name != 'posix' or _os.sys.platform == 'cygwin': @@ -471,7 +471,7 @@ (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags) try: _os.unlink(name) - return _os.fdopen(fd, mode, bufsize) + return _io.open(fd, mode, bufsize) except: _os.close(fd) raise Modified: python/branches/py3k-struni/Misc/ACKS ============================================================================== --- python/branches/py3k-struni/Misc/ACKS (original) +++ python/branches/py3k-struni/Misc/ACKS Mon Aug 6 00:23:10 2007 @@ -134,6 +134,7 @@ Dave Cole Benjamin Collar Jeffery Collins +Paul Colomiets Matt Conway David M. Cooke Greg Copeland From python-3000-checkins at python.org Mon Aug 6 03:55:41 2007 From: python-3000-checkins at python.org (neal.norwitz) Date: Mon, 6 Aug 2007 03:55:41 +0200 (CEST) Subject: [Python-3000-checkins] r56760 - in python/branches/p3yk: Doc/info/Makefile Doc/lib/librunpy.tex Doc/lib/libxmlrpclib.tex Doc/tut/tut.tex Doc/whatsnew/whatsnew25.tex Include/structmember.h Lib/distutils/command/register.py Lib/distutils/command/upload.py Lib/httplib.py Lib/runpy.py Lib/socket.py Lib/test/test_asynchat.py Lib/test/test_asyncore.py Lib/test/test_codecmaps_cn.py Lib/test/test_math.py Lib/test/test_multibytecodec_support.py Lib/test/test_pow.py Lib/test/test_resource.py Lib/test/test_runpy.py Lib/test/test_smtplib.py Lib/test/test_socket_ssl.py Lib/test/test_unicodedata.py Lib/test/test_urllib2_localnet.py Lib/threading.py Modules/cjkcodecs/_codecs_cn.c Modules/unicodedata.c Objects/stringobject.c Objects/unicodeobject.c PC/pyconfig.h Python/structmember.c configure configure.in pyconfig.h.in Message-ID: <20070806015541.7BA0E1E4006@bag.python.org> Author: neal.norwitz Date: Mon Aug 6 03:55:39 2007 New Revision: 56760 Modified: python/branches/p3yk/ (props changed) python/branches/p3yk/Doc/info/Makefile python/branches/p3yk/Doc/lib/librunpy.tex python/branches/p3yk/Doc/lib/libxmlrpclib.tex python/branches/p3yk/Doc/tut/tut.tex python/branches/p3yk/Doc/whatsnew/whatsnew25.tex python/branches/p3yk/Include/structmember.h python/branches/p3yk/Lib/distutils/command/register.py python/branches/p3yk/Lib/distutils/command/upload.py python/branches/p3yk/Lib/httplib.py python/branches/p3yk/Lib/runpy.py python/branches/p3yk/Lib/socket.py python/branches/p3yk/Lib/test/test_asynchat.py python/branches/p3yk/Lib/test/test_asyncore.py python/branches/p3yk/Lib/test/test_codecmaps_cn.py python/branches/p3yk/Lib/test/test_math.py python/branches/p3yk/Lib/test/test_multibytecodec_support.py python/branches/p3yk/Lib/test/test_pow.py python/branches/p3yk/Lib/test/test_resource.py python/branches/p3yk/Lib/test/test_runpy.py python/branches/p3yk/Lib/test/test_smtplib.py python/branches/p3yk/Lib/test/test_socket_ssl.py python/branches/p3yk/Lib/test/test_unicodedata.py python/branches/p3yk/Lib/test/test_urllib2_localnet.py python/branches/p3yk/Lib/threading.py python/branches/p3yk/Modules/cjkcodecs/_codecs_cn.c python/branches/p3yk/Modules/unicodedata.c python/branches/p3yk/Objects/stringobject.c python/branches/p3yk/Objects/unicodeobject.c python/branches/p3yk/PC/pyconfig.h python/branches/p3yk/Python/structmember.c python/branches/p3yk/configure python/branches/p3yk/configure.in python/branches/p3yk/pyconfig.h.in Log: Merged revisions 56477-56759 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r56485 | facundo.batista | 2007-07-21 17:13:00 -0700 (Sat, 21 Jul 2007) | 5 lines Selectively enable tests for asyncore.readwrite based on the presence of poll support in the select module (since this is the only case in which readwrite can be called). [GSoC - Alan McIntyre] ........ r56488 | nick.coghlan | 2007-07-22 03:18:07 -0700 (Sun, 22 Jul 2007) | 1 line Add explicit relative import tests for runpy.run_module ........ r56509 | nick.coghlan | 2007-07-23 06:41:45 -0700 (Mon, 23 Jul 2007) | 5 lines Correctly cleanup sys.modules after executing runpy relative import tests Restore Python 2.4 ImportError when attempting to execute a package (as imports cannot be guaranteed to work properly if you try it) ........ r56519 | nick.coghlan | 2007-07-24 06:07:38 -0700 (Tue, 24 Jul 2007) | 1 line Tweak runpy test to do a better job of confirming that sys has been manipulated correctly ........ r56520 | nick.coghlan | 2007-07-24 06:58:28 -0700 (Tue, 24 Jul 2007) | 1 line Fix an incompatibility between the -i and -m command line switches as reported on python-dev by PJE - runpy.run_module now leaves any changes it makes to the sys module intact after the function terminates ........ r56523 | nick.coghlan | 2007-07-24 07:39:23 -0700 (Tue, 24 Jul 2007) | 1 line Try to get rid of spurious failure in test_resource on the Debian buildbots by changing the file size limit before attempting to close the file ........ r56533 | facundo.batista | 2007-07-24 14:20:42 -0700 (Tue, 24 Jul 2007) | 7 lines New tests for basic behavior of smtplib.SMTP and smtpd.DebuggingServer. Change to use global host & port number variables. Modified the 'server' to take a string to send back in order to vary test server responses. Added a test for the reaction of smtplib.SMTP to a non-200 HELO response. [GSoC - Alan McIntyre] ........ r56538 | nick.coghlan | 2007-07-25 05:57:48 -0700 (Wed, 25 Jul 2007) | 1 line More buildbot cleanup - let the OS assign the port for test_urllib2_localnet ........ r56539 | nick.coghlan | 2007-07-25 06:18:58 -0700 (Wed, 25 Jul 2007) | 1 line Add a temporary diagnostic message before a strange failure on the alpha Debian buildbot ........ r56543 | martin.v.loewis | 2007-07-25 09:24:23 -0700 (Wed, 25 Jul 2007) | 2 lines Change location of the package index to pypi.python.org/pypi ........ r56551 | georg.brandl | 2007-07-26 02:36:25 -0700 (Thu, 26 Jul 2007) | 2 lines tabs, newlines and crs are valid XML characters. ........ r56553 | nick.coghlan | 2007-07-26 07:03:00 -0700 (Thu, 26 Jul 2007) | 1 line Add explicit test for a misbehaving math.floor ........ r56561 | mark.hammond | 2007-07-26 21:52:32 -0700 (Thu, 26 Jul 2007) | 3 lines In consultation with Kristjan Jonsson, only define WINVER and _WINNT_WIN32 if (a) we are building Python itself and (b) no one previously defined them ........ r56562 | mark.hammond | 2007-07-26 22:08:54 -0700 (Thu, 26 Jul 2007) | 2 lines Correctly detect AMD64 architecture on VC2003 ........ r56566 | nick.coghlan | 2007-07-27 03:36:30 -0700 (Fri, 27 Jul 2007) | 1 line Make test_math error messages more meaningful for small discrepancies in results ........ r56588 | martin.v.loewis | 2007-07-27 11:28:22 -0700 (Fri, 27 Jul 2007) | 2 lines Bug #978833: Close https sockets by releasing the _ssl object. ........ r56601 | martin.v.loewis | 2007-07-28 00:03:05 -0700 (Sat, 28 Jul 2007) | 3 lines Bug #1704793: Return UTF-16 pair if unicodedata.lookup cannot represent the result in a single character. ........ r56604 | facundo.batista | 2007-07-28 07:21:22 -0700 (Sat, 28 Jul 2007) | 9 lines Moved all of the capture_server socket setup code into the try block so that the event gets set if a failure occurs during server setup (otherwise the test will block forever). Changed to let the OS assign the server port number, and client side of test waits for port number assignment before proceeding. The test data in DispatcherWithSendTests is also sent in multiple send() calls instead of one to make sure this works properly. [GSoC - Alan McIntyre] ........ r56611 | georg.brandl | 2007-07-29 01:26:10 -0700 (Sun, 29 Jul 2007) | 2 lines Clarify PEP 343 description. ........ r56614 | georg.brandl | 2007-07-29 02:11:15 -0700 (Sun, 29 Jul 2007) | 2 lines try-except-finally is new in 2.5. ........ r56617 | facundo.batista | 2007-07-29 07:23:08 -0700 (Sun, 29 Jul 2007) | 9 lines Added tests for asynchat classes simple_producer & fifo, and the find_prefix_at_end function. Check behavior of a string given as a producer. Added tests for behavior of asynchat.async_chat when given int, long, and None terminator arguments. Added usepoll attribute to TestAsynchat to allow running the asynchat tests with poll support chosen whether it's available or not (improves coverage of asyncore code). [GSoC - Alan McIntyre] ........ r56620 | georg.brandl | 2007-07-29 10:38:35 -0700 (Sun, 29 Jul 2007) | 2 lines Bug #1763149: use proper slice syntax in docstring. (backport) ........ r56624 | mark.hammond | 2007-07-29 17:45:29 -0700 (Sun, 29 Jul 2007) | 4 lines Correct use of Py_BUILD_CORE - now make sure it is defined before it is referenced, and also fix definition of _WIN32_WINNT. Resolves patch 1761803. ........ r56632 | facundo.batista | 2007-07-30 20:03:34 -0700 (Mon, 30 Jul 2007) | 8 lines When running asynchat tests on OS X (darwin), the test client now overrides asyncore.dispatcher.handle_expt to do nothing, since select.poll gives a POLLHUP error at the completion of these tests. Added timeout & count arguments to several asyncore.loop calls to avoid the possibility of a test hanging up a build. [GSoC - Alan McIntyre] ........ r56633 | nick.coghlan | 2007-07-31 06:38:01 -0700 (Tue, 31 Jul 2007) | 1 line Eliminate RLock race condition reported in SF bug #1764059 ........ r56636 | martin.v.loewis | 2007-07-31 12:57:56 -0700 (Tue, 31 Jul 2007) | 2 lines Define _BSD_SOURCE, to get access to POSIX extensions on OpenBSD 4.1+. ........ r56653 | facundo.batista | 2007-08-01 16:18:36 -0700 (Wed, 01 Aug 2007) | 9 lines Allow the OS to select a free port for each test server. For DebuggingServerTests, construct SMTP objects with a localhost argument to avoid abysmally long FQDN lookups (not relevant to items under test) on some machines that would cause the test to fail. Moved server setup code in the server function inside the try block to avoid the possibility of setup failure hanging the test. Minor edits to conform to PEP 8. [GSoC - Alan McIntyre] ........ r56681 | matthias.klose | 2007-08-02 14:33:13 -0700 (Thu, 02 Aug 2007) | 2 lines - Allow Emacs 22 for building the documentation in info format. ........ r56689 | neal.norwitz | 2007-08-02 23:46:29 -0700 (Thu, 02 Aug 2007) | 1 line Py_ssize_t is defined regardless of HAVE_LONG_LONG. Will backport ........ r56727 | hyeshik.chang | 2007-08-03 21:10:18 -0700 (Fri, 03 Aug 2007) | 3 lines Fix gb18030 codec's bug that doesn't map two-byte characters on GB18030 extension in encoding. (bug reported by Bjorn Stabell) ........ r56751 | neal.norwitz | 2007-08-04 20:23:31 -0700 (Sat, 04 Aug 2007) | 7 lines Handle errors when generating a warning. The value is always written to the returned pointer if getting it was successful, even if a warning causes an error. (This probably doesn't matter as the caller will probably discard the value.) Will backport. ........ Modified: python/branches/p3yk/Doc/info/Makefile ============================================================================== --- python/branches/p3yk/Doc/info/Makefile (original) +++ python/branches/p3yk/Doc/info/Makefile Mon Aug 6 03:55:39 2007 @@ -34,10 +34,10 @@ check-emacs-version: @v="`$(EMACS) --version 2>&1 | egrep '^(GNU |X)Emacs [12]*'`"; \ - if `echo "$$v" | grep '^GNU Emacs 21' >/dev/null 2>&1`; then \ + if `echo "$$v" | grep '^GNU Emacs 2[12]' >/dev/null 2>&1`; then \ echo "Using $(EMACS) to build the info docs"; \ else \ - echo "GNU Emacs 21 is required to build the info docs"; \ + echo "GNU Emacs 21 or 22 is required to build the info docs"; \ echo "Found $$v"; \ false; \ fi Modified: python/branches/p3yk/Doc/lib/librunpy.tex ============================================================================== --- python/branches/p3yk/Doc/lib/librunpy.tex (original) +++ python/branches/p3yk/Doc/lib/librunpy.tex Mon Aug 6 03:55:39 2007 @@ -56,9 +56,11 @@ If the argument \var{alter_sys} is supplied and evaluates to \code{True}, then \code{sys.argv[0]} is updated with the value of \code{__file__} and \code{sys.modules[__name__]} is updated with a -temporary module object for the module being executed. Both -\code{sys.argv[0]} and \code{sys.modules[__name__]} are restored to -their original values before the function returns. +new module object for the module being executed. Note that neither +\code{sys.argv[0]} nor \code{sys.modules[__name__]} are restored to +their original values before the function returns - if client code +needs these values preserved, it must either save them explicitly or +else avoid enabling the automatic alterations to \module{sys}. Note that this manipulation of \module{sys} is not thread-safe. Other threads may see the partially initialised module, as well as the Modified: python/branches/p3yk/Doc/lib/libxmlrpclib.tex ============================================================================== --- python/branches/p3yk/Doc/lib/libxmlrpclib.tex (original) +++ python/branches/p3yk/Doc/lib/libxmlrpclib.tex Mon Aug 6 03:55:39 2007 @@ -94,7 +94,8 @@ \samp{>}, and \samp{\&} will be automatically escaped. However, it's the caller's responsibility to ensure that the string is free of characters that aren't allowed in XML, such as the control characters -with ASCII values between 0 and 31; failing to do this will result in +with ASCII values between 0 and 31 (except, of course, tab, newline and +carriage return); failing to do this will result in an XML-RPC request that isn't well-formed XML. If you have to pass arbitrary strings via XML-RPC, use the \class{Binary} wrapper class described below. Modified: python/branches/p3yk/Doc/tut/tut.tex ============================================================================== --- python/branches/p3yk/Doc/tut/tut.tex (original) +++ python/branches/p3yk/Doc/tut/tut.tex Mon Aug 6 03:55:39 2007 @@ -3748,7 +3748,9 @@ \keyword{finally} clause has been executed. The \keyword{finally} clause is also executed ``on the way out'' when any other clause of the \keyword{try} statement is left via a \keyword{break}, \keyword{continue} -or \keyword{return} statement. A more complicated example: +or \keyword{return} statement. A more complicated example (having +\keyword{except} and \keyword{finally} clauses in the same \keyword{try} +statement works as of Python 2.5): \begin{verbatim} >>> def divide(x, y): Modified: python/branches/p3yk/Doc/whatsnew/whatsnew25.tex ============================================================================== --- python/branches/p3yk/Doc/whatsnew/whatsnew25.tex (original) +++ python/branches/p3yk/Doc/whatsnew/whatsnew25.tex Mon Aug 6 03:55:39 2007 @@ -640,15 +640,20 @@ \end{verbatim} The expression is evaluated, and it should result in an object that -supports the context management protocol. This object may return a -value that can optionally be bound to the name \var{variable}. (Note -carefully that \var{variable} is \emph{not} assigned the result of -\var{expression}.) The object can then run set-up code -before \var{with-block} is executed and some clean-up code -is executed after the block is done, even if the block raised an exception. +supports the context management protocol (that is, has \method{__enter__()} +and \method{__exit__()} methods. -To enable the statement in Python 2.5, you need -to add the following directive to your module: +The object's \method{__enter__()} is called before \var{with-block} is +executed and therefore can run set-up code. It also may return a value +that is bound to the name \var{variable}, if given. (Note carefully +that \var{variable} is \emph{not} assigned the result of \var{expression}.) + +After execution of the \var{with-block} is finished, the object's +\method{__exit__()} method is called, even if the block raised an exception, +and can therefore run clean-up code. + +To enable the statement in Python 2.5, you need to add the following +directive to your module: \begin{verbatim} from __future__ import with_statement @@ -668,9 +673,13 @@ \end{verbatim} After this statement has executed, the file object in \var{f} will -have been automatically closed, even if the 'for' loop +have been automatically closed, even if the \keyword{for} loop raised an exception part-way through the block. +\note{In this case, \var{f} is the same object created by + \function{open()}, because \method{file.__enter__()} returns + \var{self}.} + The \module{threading} module's locks and condition variables also support the '\keyword{with}' statement: Modified: python/branches/p3yk/Include/structmember.h ============================================================================== --- python/branches/p3yk/Include/structmember.h (original) +++ python/branches/p3yk/Include/structmember.h Mon Aug 6 03:55:39 2007 @@ -68,11 +68,12 @@ #ifdef HAVE_LONG_LONG #define T_LONGLONG 17 #define T_ULONGLONG 18 -#define T_PYSSIZET 19 /* Py_ssize_t */ #endif /* HAVE_LONG_LONG */ +#define T_PYSSIZET 19 /* Py_ssize_t */ #define T_NONE 20 /* Value is always None */ + /* Flags */ #define READONLY 1 #define RO READONLY /* Shorthand */ Modified: python/branches/p3yk/Lib/distutils/command/register.py ============================================================================== --- python/branches/p3yk/Lib/distutils/command/register.py (original) +++ python/branches/p3yk/Lib/distutils/command/register.py Mon Aug 6 03:55:39 2007 @@ -22,7 +22,7 @@ description = ("register the distribution with the Python package index") - DEFAULT_REPOSITORY = 'http://www.python.org/pypi' + DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi' user_options = [ ('repository=', 'r', Modified: python/branches/p3yk/Lib/distutils/command/upload.py ============================================================================== --- python/branches/p3yk/Lib/distutils/command/upload.py (original) +++ python/branches/p3yk/Lib/distutils/command/upload.py Mon Aug 6 03:55:39 2007 @@ -20,7 +20,7 @@ description = "upload binary package to PyPI" - DEFAULT_REPOSITORY = 'http://www.python.org/pypi' + DEFAULT_REPOSITORY = 'http://pypi.python.org/pypi' user_options = [ ('repository=', 'r', Modified: python/branches/p3yk/Lib/httplib.py ============================================================================== --- python/branches/p3yk/Lib/httplib.py (original) +++ python/branches/p3yk/Lib/httplib.py Mon Aug 6 03:55:39 2007 @@ -1119,6 +1119,9 @@ def __getattr__(self, attr): return getattr(self._sock, attr) + def close(self): + SharedSocketClient.close(self) + self._ssl = None class HTTPSConnection(HTTPConnection): "This class allows communication via SSL." Modified: python/branches/p3yk/Lib/runpy.py ============================================================================== --- python/branches/p3yk/Lib/runpy.py (original) +++ python/branches/p3yk/Lib/runpy.py Mon Aug 6 03:55:39 2007 @@ -33,36 +33,21 @@ return run_globals def _run_module_code(code, init_globals=None, - mod_name=None, mod_fname=None, - mod_loader=None, alter_sys=False): + mod_name=None, mod_fname=None, + mod_loader=None, alter_sys=False): """Helper for run_module""" # Set up the top level namespace dictionary if alter_sys: - # Modify sys.argv[0] and sys.module[mod_name] - temp_module = imp.new_module(mod_name) - mod_globals = temp_module.__dict__ - saved_argv0 = sys.argv[0] - restore_module = mod_name in sys.modules - if restore_module: - saved_module = sys.modules[mod_name] + # Modify sys.argv[0] and sys.modules[mod_name] sys.argv[0] = mod_fname - sys.modules[mod_name] = temp_module - try: - _run_code(code, mod_globals, init_globals, - mod_name, mod_fname, mod_loader) - finally: - sys.argv[0] = saved_argv0 - if restore_module: - sys.modules[mod_name] = saved_module - else: - del sys.modules[mod_name] - # Copy the globals of the temporary module, as they - # may be cleared when the temporary module goes away - return mod_globals.copy() + module = imp.new_module(mod_name) + sys.modules[mod_name] = module + mod_globals = module.__dict__ else: # Leave the sys module alone - return _run_code(code, {}, init_globals, - mod_name, mod_fname, mod_loader) + mod_globals = {} + return _run_code(code, mod_globals, init_globals, + mod_name, mod_fname, mod_loader) # This helper is needed due to a missing component in the PEP 302 @@ -84,10 +69,13 @@ """ loader = get_loader(mod_name) if loader is None: - raise ImportError("No module named " + mod_name) + raise ImportError("No module named %s" % mod_name) + if loader.is_package(mod_name): + raise ImportError(("%s is a package and cannot " + + "be directly executed") % mod_name) code = loader.get_code(mod_name) if code is None: - raise ImportError("No code object available for " + mod_name) + raise ImportError("No code object available for %s" % mod_name) filename = _get_filename(loader, mod_name) if run_name is None: run_name = mod_name Modified: python/branches/p3yk/Lib/socket.py ============================================================================== --- python/branches/p3yk/Lib/socket.py (original) +++ python/branches/p3yk/Lib/socket.py Mon Aug 6 03:55:39 2007 @@ -144,6 +144,10 @@ send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy __getattr__ = _dummy +# Wrapper around platform socket objects. This implements +# a platform-independent dup() functionality. The +# implementation currently relies on reference counting +# to close the underlying socket object. class _socketobject(object): __doc__ = _realsocket.__doc__ Modified: python/branches/p3yk/Lib/test/test_asynchat.py ============================================================================== --- python/branches/p3yk/Lib/test/test_asynchat.py (original) +++ python/branches/p3yk/Lib/test/test_asynchat.py Mon Aug 6 03:55:39 2007 @@ -3,12 +3,17 @@ import thread # If this fails, we can't test this module import asyncore, asynchat, socket, threading, time import unittest +import sys from test import test_support HOST = "127.0.0.1" PORT = 54322 +SERVER_QUIT = 'QUIT\n' class echo_server(threading.Thread): + # parameter to determine the number of bytes passed back to the + # client each send + chunk_size = 1 def run(self): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -17,15 +22,28 @@ PORT = test_support.bind_port(sock, HOST, PORT) sock.listen(1) conn, client = sock.accept() - buffer = "" - while "\n" not in buffer: + self.buffer = "" + # collect data until quit message is seen + while SERVER_QUIT not in self.buffer: data = conn.recv(1) if not data: break - buffer = buffer + data - while buffer: - n = conn.send(buffer) - buffer = buffer[n:] + self.buffer = self.buffer + data + + # remove the SERVER_QUIT message + self.buffer = self.buffer.replace(SERVER_QUIT, '') + + # re-send entire set of collected data + try: + # this may fail on some tests, such as test_close_when_done, since + # the client closes the channel when it's done sending + while self.buffer: + n = conn.send(self.buffer[:self.chunk_size]) + time.sleep(0.001) + self.buffer = self.buffer[n:] + except: + pass + conn.close() sock.close() @@ -33,61 +51,201 @@ def __init__(self, terminator): asynchat.async_chat.__init__(self) - self.contents = None + self.contents = [] self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((HOST, PORT)) self.set_terminator(terminator) - self.buffer = "" + self.buffer = '' def handle_connect(self): pass - ##print "Connected" + + if sys.platform == 'darwin': + # select.poll returns a select.POLLHUP at the end of the tests + # on darwin, so just ignore it + def handle_expt(self): + pass def collect_incoming_data(self, data): - self.buffer = self.buffer + data + self.buffer += data def found_terminator(self): - #print "Received:", repr(self.buffer) - self.contents = self.buffer + self.contents.append(self.buffer) self.buffer = "" - self.close() class TestAsynchat(unittest.TestCase): + usepoll = False + def setUp (self): pass def tearDown (self): pass - def test_line_terminator(self): + def line_terminator_check(self, term, server_chunk): s = echo_server() + s.chunk_size = server_chunk s.start() - time.sleep(1) # Give server time to initialize - c = echo_client('\n') + time.sleep(0.5) # Give server time to initialize + c = echo_client(term) c.push("hello ") - c.push("world\n") - asyncore.loop() + c.push("world%s" % term) + c.push("I'm not dead yet!%s" % term) + c.push(SERVER_QUIT) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) s.join() - self.assertEqual(c.contents, 'hello world') + self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) + + # the line terminator tests below check receiving variously-sized + # chunks back from the server in order to exercise all branches of + # async_chat.handle_read + + def test_line_terminator1(self): + # test one-character terminator + for l in (1,2,3): + self.line_terminator_check('\n', l) + + def test_line_terminator2(self): + # test two-character terminator + for l in (1,2,3): + self.line_terminator_check('\r\n', l) + + def test_line_terminator3(self): + # test three-character terminator + for l in (1,2,3): + self.line_terminator_check('qqq', l) - def test_numeric_terminator(self): + def numeric_terminator_check(self, termlen): # Try reading a fixed number of bytes s = echo_server() s.start() - time.sleep(1) # Give server time to initialize - c = echo_client(6) - c.push("hello ") - c.push("world\n") - asyncore.loop() + time.sleep(0.5) # Give server time to initialize + c = echo_client(termlen) + data = "hello world, I'm not dead yet!\n" + c.push(data) + c.push(SERVER_QUIT) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) + s.join() + + self.assertEqual(c.contents, [data[:termlen]]) + + def test_numeric_terminator1(self): + # check that ints & longs both work (since type is + # explicitly checked in async_chat.handle_read) + self.numeric_terminator_check(1) + + def test_numeric_terminator2(self): + self.numeric_terminator_check(6) + + def test_none_terminator(self): + # Try reading a fixed number of bytes + s = echo_server() + s.start() + time.sleep(0.5) # Give server time to initialize + c = echo_client(None) + data = "hello world, I'm not dead yet!\n" + c.push(data) + c.push(SERVER_QUIT) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) + s.join() + + self.assertEqual(c.contents, []) + self.assertEqual(c.buffer, data) + + def test_simple_producer(self): + s = echo_server() + s.start() + time.sleep(0.5) # Give server time to initialize + c = echo_client('\n') + data = "hello world\nI'm not dead yet!\n" + p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8) + c.push_with_producer(p) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) + s.join() + + self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) + + def test_string_producer(self): + s = echo_server() + s.start() + time.sleep(0.5) # Give server time to initialize + c = echo_client('\n') + data = "hello world\nI'm not dead yet!\n" + c.push_with_producer(data+SERVER_QUIT) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) + s.join() + + self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"]) + + def test_empty_line(self): + # checks that empty lines are handled correctly + s = echo_server() + s.start() + time.sleep(0.5) # Give server time to initialize + c = echo_client('\n') + c.push("hello world\n\nI'm not dead yet!\n") + c.push(SERVER_QUIT) + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) + s.join() + + self.assertEqual(c.contents, ["hello world", "", "I'm not dead yet!"]) + + def test_close_when_done(self): + s = echo_server() + s.start() + time.sleep(0.5) # Give server time to initialize + c = echo_client('\n') + c.push("hello world\nI'm not dead yet!\n") + c.push(SERVER_QUIT) + c.close_when_done() + asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01) s.join() - self.assertEqual(c.contents, 'hello ') + self.assertEqual(c.contents, []) + # the server might have been able to send a byte or two back, but this + # at least checks that it received something and didn't just fail + # (which could still result in the client not having received anything) + self.assertTrue(len(s.buffer) > 0) + + +class TestAsynchat_WithPoll(TestAsynchat): + usepoll = True + +class TestHelperFunctions(unittest.TestCase): + def test_find_prefix_at_end(self): + self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1) + self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0) + +class TestFifo(unittest.TestCase): + def test_basic(self): + f = asynchat.fifo() + f.push(7) + f.push('a') + self.assertEqual(len(f), 2) + self.assertEqual(f.first(), 7) + self.assertEqual(f.pop(), (1, 7)) + self.assertEqual(len(f), 1) + self.assertEqual(f.first(), 'a') + self.assertEqual(f.is_empty(), False) + self.assertEqual(f.pop(), (1, 'a')) + self.assertEqual(len(f), 0) + self.assertEqual(f.is_empty(), True) + self.assertEqual(f.pop(), (0, None)) + + def test_given_list(self): + f = asynchat.fifo(['x', 17, 3]) + self.assertEqual(len(f), 3) + self.assertEqual(f.pop(), (1, 'x')) + self.assertEqual(f.pop(), (1, 17)) + self.assertEqual(f.pop(), (1, 3)) + self.assertEqual(f.pop(), (0, None)) def test_main(verbose=None): - test_support.run_unittest(TestAsynchat) + test_support.run_unittest(TestAsynchat, TestAsynchat_WithPoll, + TestHelperFunctions, TestFifo) if __name__ == "__main__": test_main(verbose=True) Modified: python/branches/p3yk/Lib/test/test_asyncore.py ============================================================================== --- python/branches/p3yk/Lib/test/test_asyncore.py (original) +++ python/branches/p3yk/Lib/test/test_asyncore.py Mon Aug 6 03:55:39 2007 @@ -12,7 +12,7 @@ from StringIO import StringIO HOST = "127.0.0.1" -PORT = 54329 +PORT = None class dummysocket: def __init__(self): @@ -53,12 +53,14 @@ # used when testing senders; just collects what it gets until newline is sent def capture_server(evt, buf): - serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serv.settimeout(3) - serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - serv.bind(("", PORT)) - serv.listen(5) try: + serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + serv.settimeout(3) + serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + serv.bind(("", 0)) + global PORT + PORT = serv.getsockname()[1] + serv.listen(5) conn, addr = serv.accept() except socket.timeout: pass @@ -78,6 +80,7 @@ conn.close() finally: serv.close() + PORT = None evt.set() @@ -106,87 +109,83 @@ asyncore._exception(tr2) self.assertEqual(tr2.error_handled, True) -## Commented out these tests because test a non-documented function -## (which is actually public, why it's not documented?). Anyway, the -## tests *and* the function uses constants in the select module that -## are not present in Windows systems (see this thread: -## http://mail.python.org/pipermail/python-list/2001-October/109973.html) -## Note even that these constants are mentioned in the select -## documentation, as a parameter of "poll" method "register", but are -## not explicit declared as constants of the module. -## . Facundo Batista -## -## def test_readwrite(self): -## # Check that correct methods are called by readwrite() -## -## class testobj: -## def __init__(self): -## self.read = False -## self.write = False -## self.expt = False -## -## def handle_read_event(self): -## self.read = True -## -## def handle_write_event(self): -## self.write = True -## -## def handle_expt_event(self): -## self.expt = True -## -## def handle_error(self): -## self.error_handled = True -## -## for flag in (select.POLLIN, select.POLLPRI): -## tobj = testobj() -## self.assertEqual(tobj.read, False) -## asyncore.readwrite(tobj, flag) -## self.assertEqual(tobj.read, True) -## -## # check that ExitNow exceptions in the object handler method -## # bubbles all the way up through asyncore readwrite call -## tr1 = exitingdummy() -## self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) -## -## # check that an exception other than ExitNow in the object handler -## # method causes the handle_error method to get called -## tr2 = crashingdummy() -## asyncore.readwrite(tr2, flag) -## self.assertEqual(tr2.error_handled, True) -## -## tobj = testobj() -## self.assertEqual(tobj.write, False) -## asyncore.readwrite(tobj, select.POLLOUT) -## self.assertEqual(tobj.write, True) -## -## # check that ExitNow exceptions in the object handler method -## # bubbles all the way up through asyncore readwrite call -## tr1 = exitingdummy() -## self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, -## select.POLLOUT) -## -## # check that an exception other than ExitNow in the object handler -## # method causes the handle_error method to get called -## tr2 = crashingdummy() -## asyncore.readwrite(tr2, select.POLLOUT) -## self.assertEqual(tr2.error_handled, True) -## -## for flag in (select.POLLERR, select.POLLHUP, select.POLLNVAL): -## tobj = testobj() -## self.assertEqual(tobj.expt, False) -## asyncore.readwrite(tobj, flag) -## self.assertEqual(tobj.expt, True) -## -## # check that ExitNow exceptions in the object handler method -## # bubbles all the way up through asyncore readwrite calls -## tr1 = exitingdummy() -## self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) -## -## # check that an exception other than ExitNow in the object handler -## # method causes the handle_error method to get called -## tr2 = crashingdummy() -## asyncore.readwrite(tr2, flag) -## self.assertEqual(tr2.error_handled, True) + # asyncore.readwrite uses constants in the select module that + # are not present in Windows systems (see this thread: + # http://mail.python.org/pipermail/python-list/2001-October/109973.html) + # These constants should be present as long as poll is available + + if hasattr(select, 'poll'): + def test_readwrite(self): + # Check that correct methods are called by readwrite() + + class testobj: + def __init__(self): + self.read = False + self.write = False + self.expt = False + + def handle_read_event(self): + self.read = True + + def handle_write_event(self): + self.write = True + + def handle_expt_event(self): + self.expt = True + + def handle_error(self): + self.error_handled = True + + for flag in (select.POLLIN, select.POLLPRI): + tobj = testobj() + self.assertEqual(tobj.read, False) + asyncore.readwrite(tobj, flag) + self.assertEqual(tobj.read, True) + + # check that ExitNow exceptions in the object handler method + # bubbles all the way up through asyncore readwrite call + tr1 = exitingdummy() + self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) + + # check that an exception other than ExitNow in the object handler + # method causes the handle_error method to get called + tr2 = crashingdummy() + asyncore.readwrite(tr2, flag) + self.assertEqual(tr2.error_handled, True) + + tobj = testobj() + self.assertEqual(tobj.write, False) + asyncore.readwrite(tobj, select.POLLOUT) + self.assertEqual(tobj.write, True) + + # check that ExitNow exceptions in the object handler method + # bubbles all the way up through asyncore readwrite call + tr1 = exitingdummy() + self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, + select.POLLOUT) + + # check that an exception other than ExitNow in the object handler + # method causes the handle_error method to get called + tr2 = crashingdummy() + asyncore.readwrite(tr2, select.POLLOUT) + self.assertEqual(tr2.error_handled, True) + + for flag in (select.POLLERR, select.POLLHUP, select.POLLNVAL): + tobj = testobj() + self.assertEqual(tobj.expt, False) + asyncore.readwrite(tobj, flag) + self.assertEqual(tobj.expt, True) + + # check that ExitNow exceptions in the object handler method + # bubbles all the way up through asyncore readwrite calls + tr1 = exitingdummy() + self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) + + # check that an exception other than ExitNow in the object handler + # method causes the handle_error method to get called + tr2 = crashingdummy() + asyncore.readwrite(tr2, flag) + self.assertEqual(tr2.error_handled, True) def test_closeall(self): self.closeall_check(False) @@ -342,12 +341,26 @@ self.evt = threading.Event() cap = StringIO() threading.Thread(target=capture_server, args=(self.evt,cap)).start() - time.sleep(1) # Give server time to initialize - data = "Suppose there isn't a 16-ton weight?"*5 + # wait until server thread has assigned a port number + n = 1000 + while PORT is None and n > 0: + time.sleep(0.01) + n -= 1 + + # wait a little longer for the server to initialize (it sometimes + # refuses connections on slow machines without this wait) + time.sleep(0.2) + + data = "Suppose there isn't a 16-ton weight?" d = dispatcherwithsend_noread() d.create_socket(socket.AF_INET, socket.SOCK_STREAM) d.connect((HOST, PORT)) + + # give time for socket to connect + time.sleep(0.1) + + d.send(data) d.send(data) d.send('\n') @@ -358,7 +371,7 @@ self.evt.wait() - self.assertEqual(cap.getvalue(), data) + self.assertEqual(cap.getvalue(), data*2) class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests): Modified: python/branches/p3yk/Lib/test/test_codecmaps_cn.py ============================================================================== --- python/branches/p3yk/Lib/test/test_codecmaps_cn.py (original) +++ python/branches/p3yk/Lib/test/test_codecmaps_cn.py Mon Aug 6 03:55:39 2007 @@ -19,6 +19,13 @@ mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/' \ 'MICSFT/WINDOWS/CP936.TXT' +class TestGB18030Map(test_multibytecodec_support.TestBase_Mapping, + unittest.TestCase): + encoding = 'gb18030' + mapfileurl = 'http://source.icu-project.org/repos/icu/data/' \ + 'trunk/charset/data/xml/gb-18030-2000.xml' + + def test_main(): test_support.run_unittest(__name__) Modified: python/branches/p3yk/Lib/test/test_math.py ============================================================================== --- python/branches/p3yk/Lib/test/test_math.py (original) +++ python/branches/p3yk/Lib/test/test_math.py Mon Aug 6 03:55:39 2007 @@ -12,7 +12,11 @@ def ftest(self, name, value, expected): if abs(value-expected) > eps: - self.fail('%s returned %f, expected %f'%\ + # Use %r instead of %f so the error message + # displays full precision. Otherwise discrepancies + # in the last few bits will lead to very confusing + # error messages + self.fail('%s returned %r, expected %r' % (name, value, expected)) def testConstants(self): @@ -92,6 +96,10 @@ self.ftest('floor(-0.5)', math.floor(-0.5), -1) self.ftest('floor(-1.0)', math.floor(-1.0), -1) self.ftest('floor(-1.5)', math.floor(-1.5), -2) + # pow() relies on floor() to check for integers + # This fails on some platforms - so check it here + self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167) + self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167) def testFmod(self): self.assertRaises(TypeError, math.fmod) Modified: python/branches/p3yk/Lib/test/test_multibytecodec_support.py ============================================================================== --- python/branches/p3yk/Lib/test/test_multibytecodec_support.py (original) +++ python/branches/p3yk/Lib/test/test_multibytecodec_support.py Mon Aug 6 03:55:39 2007 @@ -5,7 +5,7 @@ # import sys, codecs, os.path -import unittest +import unittest, re from test import test_support from StringIO import StringIO @@ -272,6 +272,12 @@ return test_support.open_urlresource(self.mapfileurl) def test_mapping_file(self): + if self.mapfileurl.endswith('.xml'): + self._test_mapping_file_ucm() + else: + self._test_mapping_file_plain() + + def _test_mapping_file_plain(self): unichrs = lambda s: u''.join(map(unichr, map(eval, s.split('+')))) urt_wa = {} @@ -303,6 +309,14 @@ self._testpoint(csetch, unich) + def _test_mapping_file_ucm(self): + ucmdata = self.open_mapping_file().read() + uc = re.findall('', ucmdata) + for uni, coded in uc: + unich = unichr(int(uni, 16)) + codech = ''.join(chr(int(c, 16)) for c in coded.split()) + self._testpoint(codech, unich) + def test_mapping_supplemental(self): for mapping in self.supmaps: self._testpoint(*mapping) Modified: python/branches/p3yk/Lib/test/test_pow.py ============================================================================== --- python/branches/p3yk/Lib/test/test_pow.py (original) +++ python/branches/p3yk/Lib/test/test_pow.py Mon Aug 6 03:55:39 2007 @@ -106,6 +106,9 @@ # platform pow() was buggy, and Python didn't worm around it. eq = self.assertEquals a = -1.0 + # The next two tests can still fail if the platform floor() + # function doesn't treat all large inputs as integers + # test_math should also fail if that is happening eq(pow(a, 1.23e167), 1.0) eq(pow(a, -1.23e167), 1.0) for b in range(-10, 11): Modified: python/branches/p3yk/Lib/test/test_resource.py ============================================================================== --- python/branches/p3yk/Lib/test/test_resource.py (original) +++ python/branches/p3yk/Lib/test/test_resource.py Mon Aug 6 03:55:39 2007 @@ -49,17 +49,24 @@ except ValueError: limit_set = False f = open(test_support.TESTFN, "wb") - f.write("X" * 1024) try: - f.write("Y") - f.flush() - except IOError: - if not limit_set: - raise - f.close() - os.unlink(test_support.TESTFN) + f.write("X" * 1024) + try: + f.write("Y") + f.flush() + except IOError: + if not limit_set: + raise + if limit_set: + # Close will attempt to flush the byte we wrote + # Restore limit first to avoid getting a spurious error + resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) + finally: + f.close() + os.unlink(test_support.TESTFN) finally: - resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) + if limit_set: + resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) def test_fsize_toobig(self): # Be sure that setrlimit is checking for really large values Modified: python/branches/p3yk/Lib/test/test_runpy.py ============================================================================== --- python/branches/p3yk/Lib/test/test_runpy.py (original) +++ python/branches/p3yk/Lib/test/test_runpy.py Mon Aug 6 03:55:39 2007 @@ -21,12 +21,12 @@ "# Check the sys module\n" "import sys\n" "run_argv0 = sys.argv[0]\n" - "if __name__ in sys.modules:\n" - " run_name = sys.modules[__name__].__name__\n" + "run_name_in_sys_modules = __name__ in sys.modules\n" + "if run_name_in_sys_modules:\n" + " module_in_sys_modules = globals() is sys.modules[__name__].__dict__\n" "# Check nested operation\n" "import runpy\n" - "nested = runpy._run_module_code('x=1\\n', mod_name='',\n" - " alter_sys=True)\n" + "nested = runpy._run_module_code('x=1\\n', mod_name='')\n" ) @@ -37,34 +37,44 @@ loader = "Now you're just being silly" d1 = dict(initial=initial) saved_argv0 = sys.argv[0] - d2 = _run_module_code(self.test_source, - d1, - name, - file, - loader, - True) - self.failUnless("result" not in d1) - self.failUnless(d2["initial"] is initial) - self.failUnless(d2["result"] == self.expected_result) - self.failUnless(d2["nested"]["x"] == 1) - self.failUnless(d2["__name__"] is name) - self.failUnless(d2["run_name"] is name) - self.failUnless(d2["__file__"] is file) - self.failUnless(d2["run_argv0"] is file) - self.failUnless(d2["__loader__"] is loader) - self.failUnless(sys.argv[0] is saved_argv0) - self.failUnless(name not in sys.modules) + try: + d2 = _run_module_code(self.test_source, + d1, + name, + file, + loader, + alter_sys=True) + self.failUnless("result" not in d1) + self.failUnless(d2["initial"] is initial) + self.failUnless(d2["result"] == self.expected_result) + self.failUnless(d2["nested"]["x"] == 1) + self.failUnless(d2["nested"]["__name__"] == "") + self.failUnless(d2["__name__"] is name) + self.failUnless(d2["__file__"] is file) + self.failUnless(d2["__loader__"] is loader) + self.failUnless(d2["run_argv0"] is file) + self.failUnless(d2["run_name_in_sys_modules"]) + self.failUnless(d2["module_in_sys_modules"]) + self.failUnless(sys.argv[0] is not saved_argv0) + self.failUnless(name in sys.modules) + finally: + sys.argv[0] = saved_argv0 + if name in sys.modules: + del sys.modules[name] def test_run_module_code_defaults(self): saved_argv0 = sys.argv[0] d = _run_module_code(self.test_source) self.failUnless(d["result"] == self.expected_result) + self.failUnless(d["nested"]["x"] == 1) + self.failUnless(d["nested"]["__name__"] == "") self.failUnless(d["__name__"] is None) self.failUnless(d["__file__"] is None) self.failUnless(d["__loader__"] is None) self.failUnless(d["run_argv0"] is saved_argv0) - self.failUnless("run_name" not in d) + self.failUnless(not d["run_name_in_sys_modules"]) self.failUnless(sys.argv[0] is saved_argv0) + self.failUnless(None not in sys.modules) class RunModuleTest(unittest.TestCase): @@ -77,19 +87,29 @@ self.fail("Expected import error for " + mod_name) def test_invalid_names(self): + # Builtin module self.expect_import_error("sys") + # Non-existent modules self.expect_import_error("sys.imp.eric") self.expect_import_error("os.path.half") self.expect_import_error("a.bee") self.expect_import_error(".howard") self.expect_import_error("..eaten") + # Package + self.expect_import_error("logging") def test_library_module(self): run_module("runpy") + def _add_pkg_dir(self, pkg_dir): + os.mkdir(pkg_dir) + pkg_fname = os.path.join(pkg_dir, "__init__"+os.extsep+"py") + pkg_file = open(pkg_fname, "w") + pkg_file.close() + return pkg_fname + def _make_pkg(self, source, depth): pkg_name = "__runpy_pkg__" - init_fname = "__init__"+os.extsep+"py" test_fname = "runpy_test"+os.extsep+"py" pkg_dir = sub_dir = tempfile.mkdtemp() if verbose: print(" Package tree in:", sub_dir) @@ -97,11 +117,8 @@ if verbose: print(" Updated sys.path:", sys.path[0]) for i in range(depth): sub_dir = os.path.join(sub_dir, pkg_name) - os.mkdir(sub_dir) + pkg_fname = self._add_pkg_dir(sub_dir) if verbose: print(" Next level in:", sub_dir) - pkg_fname = os.path.join(sub_dir, init_fname) - pkg_file = open(pkg_fname, "w") - pkg_file.close() if verbose: print(" Created:", pkg_fname) mod_fname = os.path.join(sub_dir, test_fname) mod_file = open(mod_fname, "w") @@ -112,13 +129,9 @@ return pkg_dir, mod_fname, mod_name def _del_pkg(self, top, depth, mod_name): - for i in range(depth+1): # Don't forget the module itself - parts = mod_name.rsplit(".", i) - entry = parts[0] - try: + for entry in list(sys.modules): + if entry.startswith("__runpy_pkg__"): del sys.modules[entry] - except KeyError as ex: - if verbose: print(ex) # Persist with cleaning up if verbose: print(" Removed sys.modules entries") del sys.path[0] if verbose: print(" Removed sys.path entry") @@ -146,23 +159,81 @@ try: if verbose: print("Running from source:", mod_name) d1 = run_module(mod_name) # Read from source + self.failUnless("x" in d1) self.failUnless(d1["x"] == 1) del d1 # Ensure __loader__ entry doesn't keep file open __import__(mod_name) os.remove(mod_fname) if verbose: print("Running from compiled:", mod_name) d2 = run_module(mod_name) # Read from bytecode + self.failUnless("x" in d2) self.failUnless(d2["x"] == 1) del d2 # Ensure __loader__ entry doesn't keep file open finally: self._del_pkg(pkg_dir, depth, mod_name) if verbose: print("Module executed successfully") + def _add_relative_modules(self, base_dir, depth): + if depth <= 1: + raise ValueError("Relative module test needs depth > 1") + pkg_name = "__runpy_pkg__" + module_dir = base_dir + for i in range(depth): + parent_dir = module_dir + module_dir = os.path.join(module_dir, pkg_name) + # Add sibling module + sibling_fname = os.path.join(module_dir, "sibling"+os.extsep+"py") + sibling_file = open(sibling_fname, "w") + sibling_file.close() + if verbose: print(" Added sibling module:", sibling_fname) + # Add nephew module + uncle_dir = os.path.join(parent_dir, "uncle") + self._add_pkg_dir(uncle_dir) + if verbose: print(" Added uncle package:", uncle_dir) + cousin_dir = os.path.join(uncle_dir, "cousin") + self._add_pkg_dir(cousin_dir) + if verbose: print(" Added cousin package:", cousin_dir) + nephew_fname = os.path.join(cousin_dir, "nephew"+os.extsep+"py") + nephew_file = open(nephew_fname, "w") + nephew_file.close() + if verbose: print(" Added nephew module:", nephew_fname) + + def _check_relative_imports(self, depth, run_name=None): + contents = """\ +from __future__ import absolute_import +from . import sibling +from ..uncle.cousin import nephew +""" + pkg_dir, mod_fname, mod_name = ( + self._make_pkg(contents, depth)) + try: + self._add_relative_modules(pkg_dir, depth) + if verbose: print("Running from source:", mod_name) + d1 = run_module(mod_name) # Read from source + self.failUnless("sibling" in d1) + self.failUnless("nephew" in d1) + del d1 # Ensure __loader__ entry doesn't keep file open + __import__(mod_name) + os.remove(mod_fname) + if verbose: print("Running from compiled:", mod_name) + d2 = run_module(mod_name) # Read from bytecode + self.failUnless("sibling" in d2) + self.failUnless("nephew" in d2) + del d2 # Ensure __loader__ entry doesn't keep file open + finally: + self._del_pkg(pkg_dir, depth, mod_name) + if verbose: print("Module executed successfully") + def test_run_module(self): for depth in range(4): if verbose: print("Testing package depth:", depth) self._check_module(depth) + def test_explicit_relative_import(self): + for depth in range(2, 5): + if verbose: print("Testing relative imports at depth:", depth) + self._check_relative_imports(depth) + def test_main(): run_unittest(RunModuleCodeTest) Modified: python/branches/p3yk/Lib/test/test_smtplib.py ============================================================================== --- python/branches/p3yk/Lib/test/test_smtplib.py (original) +++ python/branches/p3yk/Lib/test/test_smtplib.py Mon Aug 6 03:55:39 2007 @@ -1,53 +1,100 @@ +import asyncore import socket import threading +import smtpd import smtplib +import StringIO +import sys import time +import select from unittest import TestCase from test import test_support +# PORT is used to communicate the port number assigned to the server +# to the test client +HOST = "localhost" +PORT = None -def server(evt): - serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serv.settimeout(3) - serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - serv.bind(("", 9091)) - serv.listen(5) +def server(evt, buf): try: + serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + serv.settimeout(3) + serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + serv.bind(("", 0)) + global PORT + PORT = serv.getsockname()[1] + serv.listen(5) conn, addr = serv.accept() except socket.timeout: pass else: - conn.send("220 Hola mundo\n") + n = 500 + while buf and n > 0: + r, w, e = select.select([], [conn], []) + if w: + sent = conn.send(buf) + buf = buf[sent:] + + n -= 1 + time.sleep(0.01) + conn.close() finally: serv.close() + PORT = None evt.set() class GeneralTests(TestCase): def setUp(self): self.evt = threading.Event() - threading.Thread(target=server, args=(self.evt,)).start() - time.sleep(.1) + servargs = (self.evt, "220 Hola mundo\n") + threading.Thread(target=server, args=servargs).start() + + # wait until server thread has assigned a port number + n = 500 + while PORT is None and n > 0: + time.sleep(0.01) + n -= 1 + + # wait a little longer (sometimes connections are refused + # on slow machines without this additional wait) + time.sleep(0.5) def tearDown(self): self.evt.wait() - def testBasic(self): + def testBasic1(self): # connects - smtp = smtplib.SMTP("localhost", 9091) + smtp = smtplib.SMTP(HOST, PORT) smtp.sock.close() + def testBasic2(self): + # connects, include port in host name + smtp = smtplib.SMTP("%s:%s" % (HOST, PORT)) + smtp.sock.close() + + def testLocalHostName(self): + # check that supplied local_hostname is used + smtp = smtplib.SMTP(HOST, PORT, local_hostname="testhost") + self.assertEqual(smtp.local_hostname, "testhost") + smtp.sock.close() + + def testNonnumericPort(self): + # check that non-numeric port raises ValueError + self.assertRaises(socket.error, smtplib.SMTP, + "localhost", "bogus") + def testTimeoutDefault(self): # default - smtp = smtplib.SMTP("localhost", 9091) + smtp = smtplib.SMTP(HOST, PORT) self.assertTrue(smtp.sock.gettimeout() is None) smtp.sock.close() def testTimeoutValue(self): # a value - smtp = smtplib.SMTP("localhost", 9091, timeout=30) + smtp = smtplib.SMTP(HOST, PORT, timeout=30) self.assertEqual(smtp.sock.gettimeout(), 30) smtp.sock.close() @@ -56,16 +103,149 @@ previous = socket.getdefaulttimeout() socket.setdefaulttimeout(30) try: - smtp = smtplib.SMTP("localhost", 9091, timeout=None) + smtp = smtplib.SMTP(HOST, PORT, timeout=None) finally: socket.setdefaulttimeout(previous) self.assertEqual(smtp.sock.gettimeout(), 30) smtp.sock.close() +# Test server using smtpd.DebuggingServer +def debugging_server(serv_evt, client_evt): + serv = smtpd.DebuggingServer(("", 0), ('nowhere', -1)) + global PORT + PORT = serv.getsockname()[1] + + try: + if hasattr(select, 'poll'): + poll_fun = asyncore.poll2 + else: + poll_fun = asyncore.poll + + n = 1000 + while asyncore.socket_map and n > 0: + poll_fun(0.01, asyncore.socket_map) + + # when the client conversation is finished, it will + # set client_evt, and it's then ok to kill the server + if client_evt.isSet(): + serv.close() + break + + n -= 1 + + except socket.timeout: + pass + finally: + # allow some time for the client to read the result + time.sleep(0.5) + serv.close() + asyncore.close_all() + PORT = None + time.sleep(0.5) + serv_evt.set() + +MSG_BEGIN = '---------- MESSAGE FOLLOWS ----------\n' +MSG_END = '------------ END MESSAGE ------------\n' + +# Test behavior of smtpd.DebuggingServer +# NOTE: the SMTP objects are created with a non-default local_hostname +# argument to the constructor, since (on some systems) the FQDN lookup +# caused by the default local_hostname sometimes takes so long that the +# test server times out, causing the test to fail. +class DebuggingServerTests(TestCase): + + def setUp(self): + # temporarily replace sys.stdout to capture DebuggingServer output + self.old_stdout = sys.stdout + self.output = StringIO.StringIO() + sys.stdout = self.output + + self.serv_evt = threading.Event() + self.client_evt = threading.Event() + serv_args = (self.serv_evt, self.client_evt) + threading.Thread(target=debugging_server, args=serv_args).start() + + # wait until server thread has assigned a port number + n = 500 + while PORT is None and n > 0: + time.sleep(0.01) + n -= 1 + + # wait a little longer (sometimes connections are refused + # on slow machines without this additional wait) + time.sleep(0.5) + + def tearDown(self): + # indicate that the client is finished + self.client_evt.set() + # wait for the server thread to terminate + self.serv_evt.wait() + # restore sys.stdout + sys.stdout = self.old_stdout + + def testBasic(self): + # connect + smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3) + smtp.quit() + + def testEHLO(self): + smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3) + expected = (502, 'Error: command "EHLO" not implemented') + self.assertEqual(smtp.ehlo(), expected) + smtp.quit() + + def testHELP(self): + smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3) + self.assertEqual(smtp.help(), 'Error: command "HELP" not implemented') + smtp.quit() + + def testSend(self): + # connect and send mail + m = 'A test message' + smtp = smtplib.SMTP(HOST, PORT, local_hostname='localhost', timeout=3) + smtp.sendmail('John', 'Sally', m) + smtp.quit() + + self.client_evt.set() + self.serv_evt.wait() + self.output.flush() + mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END) + self.assertEqual(self.output.getvalue(), mexpect) + + +class BadHELOServerTests(TestCase): + + def setUp(self): + self.old_stdout = sys.stdout + self.output = StringIO.StringIO() + sys.stdout = self.output + + self.evt = threading.Event() + servargs = (self.evt, "199 no hello for you!\n") + threading.Thread(target=server, args=servargs).start() + + # wait until server thread has assigned a port number + n = 500 + while PORT is None and n > 0: + time.sleep(0.01) + n -= 1 + + # wait a little longer (sometimes connections are refused + # on slow machines without this additional wait) + time.sleep(0.5) + + def tearDown(self): + self.evt.wait() + sys.stdout = self.old_stdout + + def testFailingHELO(self): + self.assertRaises(smtplib.SMTPConnectError, smtplib.SMTP, + HOST, PORT, 'localhost', 3) def test_main(verbose=None): - test_support.run_unittest(GeneralTests) + test_support.run_unittest(GeneralTests, DebuggingServerTests, + BadHELOServerTests) if __name__ == '__main__': test_main() Modified: python/branches/p3yk/Lib/test/test_socket_ssl.py ============================================================================== --- python/branches/p3yk/Lib/test/test_socket_ssl.py (original) +++ python/branches/p3yk/Lib/test/test_socket_ssl.py Mon Aug 6 03:55:39 2007 @@ -106,6 +106,25 @@ connector() t.join() + def test_978833(self): + if test_support.verbose: + print("test_978833 ...") + + import os, httplib + with test_support.transient_internet(): + s = socket.socket(socket.AF_INET) + s.connect(("www.sf.net", 443)) + fd = s._sock.fileno() + sock = httplib.FakeSocket(s, socket.ssl(s)) + s = None + sock.close() + try: + os.fstat(fd) + except OSError: + pass + else: + raise test_support.TestFailed("Failed to close socket") + class OpenSSLTests(unittest.TestCase): def testBasic(self): Modified: python/branches/p3yk/Lib/test/test_unicodedata.py ============================================================================== --- python/branches/p3yk/Lib/test/test_unicodedata.py (original) +++ python/branches/p3yk/Lib/test/test_unicodedata.py Mon Aug 6 03:55:39 2007 @@ -214,6 +214,9 @@ count += 1 self.assert_(count >= 10) # should have tested at least the ASCII digits + def test_bug_1704793(self): + self.assertEquals(self.db.lookup("GOTHIC LETTER FAIHU"), u'\U00010346') + def test_main(): test.test_support.run_unittest( UnicodeMiscTest, Modified: python/branches/p3yk/Lib/test/test_urllib2_localnet.py ============================================================================== --- python/branches/p3yk/Lib/test/test_urllib2_localnet.py (original) +++ python/branches/p3yk/Lib/test/test_urllib2_localnet.py Mon Aug 6 03:55:39 2007 @@ -40,14 +40,16 @@ class LoopbackHttpServerThread(threading.Thread): """Stoppable thread that runs a loopback http server.""" - def __init__(self, port, RequestHandlerClass): + def __init__(self, request_handler): threading.Thread.__init__(self) - self._RequestHandlerClass = RequestHandlerClass self._stop = False - self._port = port - self._server_address = ('127.0.0.1', self._port) self.ready = threading.Event() - self.error = None + request_handler.protocol_version = "HTTP/1.0" + self.httpd = LoopbackHttpServer(('127.0.0.1', 0), + request_handler) + #print "Serving HTTP on %s port %s" % (self.httpd.server_name, + # self.httpd.server_port) + self.port = self.httpd.server_port def stop(self): """Stops the webserver if it's currently running.""" @@ -58,24 +60,9 @@ self.join() def run(self): - protocol = "HTTP/1.0" - - try: - self._RequestHandlerClass.protocol_version = protocol - httpd = LoopbackHttpServer(self._server_address, - self._RequestHandlerClass) - - sa = httpd.socket.getsockname() - #print "Serving HTTP on", sa[0], "port", sa[1], "..." - except: - # Fail "gracefully" if we are unable to start. - self.ready.set() - self.error = sys.exc_info()[1] - raise - self.ready.set() while not self._stop: - httpd.handle_request() + self.httpd.handle_request() # Authentication infrastructure @@ -232,26 +219,21 @@ class ProxyAuthTests(unittest.TestCase): URL = "http://www.foo.com" - PORT = 8080 USER = "tester" PASSWD = "test123" REALM = "TestRealm" - PROXY_URL = "http://127.0.0.1:%d" % PORT - def setUp(self): FakeProxyHandler.digest_auth_handler.set_users({ self.USER : self.PASSWD }) FakeProxyHandler.digest_auth_handler.set_realm(self.REALM) - self.server = LoopbackHttpServerThread(self.PORT, FakeProxyHandler) + self.server = LoopbackHttpServerThread(FakeProxyHandler) self.server.start() self.server.ready.wait() - if self.server.error: - raise self.server.error - - handler = urllib2.ProxyHandler({"http" : self.PROXY_URL}) + proxy_url = "http://127.0.0.1:%d" % self.server.port + handler = urllib2.ProxyHandler({"http" : proxy_url}) self._digest_auth_handler = urllib2.ProxyDigestAuthHandler() self.opener = urllib2.build_opener(handler, self._digest_auth_handler) Modified: python/branches/p3yk/Lib/threading.py ============================================================================== --- python/branches/p3yk/Lib/threading.py (original) +++ python/branches/p3yk/Lib/threading.py Mon Aug 6 03:55:39 2007 @@ -85,9 +85,10 @@ self.__count = 0 def __repr__(self): + owner = self.__owner return "<%s(%s, %d)>" % ( self.__class__.__name__, - self.__owner and self.__owner.getName(), + owner and owner.getName(), self.__count) def acquire(self, blocking=1): Modified: python/branches/p3yk/Modules/cjkcodecs/_codecs_cn.c ============================================================================== --- python/branches/p3yk/Modules/cjkcodecs/_codecs_cn.c (original) +++ python/branches/p3yk/Modules/cjkcodecs/_codecs_cn.c Mon Aug 6 03:55:39 2007 @@ -197,6 +197,7 @@ REQUIRE_OUTBUF(2) GBK_ENCODE(c, code) + else TRYMAP_ENC(gb18030ext, code, c); else { const struct _gb18030_to_unibmp_ranges *utrrange; Modified: python/branches/p3yk/Modules/unicodedata.c ============================================================================== --- python/branches/p3yk/Modules/unicodedata.c (original) +++ python/branches/p3yk/Modules/unicodedata.c Mon Aug 6 03:55:39 2007 @@ -1077,8 +1077,7 @@ unicodedata_lookup(PyObject* self, PyObject* args) { Py_UCS4 code; - Py_UNICODE str[1]; - char errbuf[256]; + Py_UNICODE str[2]; char* name; int namelen; @@ -1086,24 +1085,20 @@ return NULL; if (!_getcode(self, name, namelen, &code)) { - /* XXX(nnorwitz): why are we allocating for the error msg? - Why not always use snprintf? */ - char fmt[] = "undefined character name '%s'"; - char *buf = PyMem_MALLOC(sizeof(fmt) + namelen); - if (buf) - sprintf(buf, fmt, name); - else { - buf = errbuf; - PyOS_snprintf(buf, sizeof(errbuf), fmt, name); - } - PyErr_SetString(PyExc_KeyError, buf); - if (buf != errbuf) - PyMem_FREE(buf); + PyErr_Format(PyExc_KeyError, "undefined character name '%s'", + name); return NULL; } +#ifndef Py_UNICODE_WIDE + if (code >= 0x10000) { + str[0] = 0xd800 + ((code - 0x10000) >> 10); + str[1] = 0xdc00 + ((code - 0x10000) & 0x3ff); + return PyUnicode_FromUnicode(str, 2); + } +#endif str[0] = (Py_UNICODE) code; - return PyUnicode_FromUnicode(str, 1); + return PyUnicode_FromUnicode(str, 1); } /* XXX Add doc strings. */ Modified: python/branches/p3yk/Objects/stringobject.c ============================================================================== --- python/branches/p3yk/Objects/stringobject.c (original) +++ python/branches/p3yk/Objects/stringobject.c Mon Aug 6 03:55:39 2007 @@ -1893,7 +1893,7 @@ "S.find(sub [,start [,end]]) -> int\n\ \n\ Return the lowest index in S where substring sub is found,\n\ -such that sub is contained within s[start,end]. Optional\n\ +such that sub is contained within s[start:end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ Return -1 on failure."); @@ -1932,7 +1932,7 @@ "S.rfind(sub [,start [,end]]) -> int\n\ \n\ Return the highest index in S where substring sub is found,\n\ -such that sub is contained within s[start,end]. Optional\n\ +such that sub is contained within s[start:end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ Return -1 on failure."); Modified: python/branches/p3yk/Objects/unicodeobject.c ============================================================================== --- python/branches/p3yk/Objects/unicodeobject.c (original) +++ python/branches/p3yk/Objects/unicodeobject.c Mon Aug 6 03:55:39 2007 @@ -5763,7 +5763,7 @@ "S.find(sub [,start [,end]]) -> int\n\ \n\ Return the lowest index in S where substring sub is found,\n\ -such that sub is contained within s[start,end]. Optional\n\ +such that sub is contained within s[start:end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ Return -1 on failure."); @@ -6504,7 +6504,7 @@ "S.rfind(sub [,start [,end]]) -> int\n\ \n\ Return the highest index in S where substring sub is found,\n\ -such that sub is contained within s[start,end]. Optional\n\ +such that sub is contained within s[start:end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ Return -1 on failure."); Modified: python/branches/p3yk/PC/pyconfig.h ============================================================================== --- python/branches/p3yk/PC/pyconfig.h (original) +++ python/branches/p3yk/PC/pyconfig.h Mon Aug 6 03:55:39 2007 @@ -32,6 +32,11 @@ #define MS_WINCE #endif +/* Deprecated USE_DL_EXPORT macro - please use Py_BUILD_CORE */ +#ifdef USE_DL_EXPORT +# define Py_BUILD_CORE +#endif /* USE_DL_EXPORT */ + /* Visual Studio 2005 introduces deprecation warnings for "insecure" and POSIX functions. The insecure functions should be replaced by *_s versions (according to Microsoft); the @@ -140,7 +145,7 @@ #if defined(_M_IA64) #define COMPILER _Py_PASTE_VERSION("64 bit (Itanium)") #define MS_WINI64 -#elif defined(_M_X64) +#elif defined(_M_X64) || defined(_M_AMD64) #define COMPILER _Py_PASTE_VERSION("64 bit (AMD64)") #define MS_WINX64 #else @@ -151,12 +156,26 @@ /* set the version macros for the windows headers */ #ifdef MS_WINX64 /* 64 bit only runs on XP or greater */ -#define _WIN32_WINNT 0x0501 -#define WINVER 0x0501 +#define Py_WINVER 0x0501 #else /* NT 4.0 or greater required otherwise */ -#define _WIN32_WINNT 0x0400 -#define WINVER 0x0400 +#define Py_WINVER 0x0400 +#endif + +/* We only set these values when building Python - we don't want to force + these values on extensions, as that will affect the prototypes and + structures exposed in the Windows headers. Even when building Python, we + allow a single source file to override this - they may need access to + structures etc so it can optionally use new Windows features if it + determines at runtime they are available. +*/ +#ifdef Py_BUILD_CORE +#ifndef WINVER +#define WINVER Py_WINVER +#endif +#ifndef _WIN32_WINNT +#define _WIN32_WINNT Py_WINVER +#endif #endif /* _W64 is not defined for VC6 or eVC4 */ @@ -287,11 +306,6 @@ # define MS_COREDLL /* deprecated old symbol */ #endif /* !MS_NO_COREDLL && ... */ -/* Deprecated USE_DL_EXPORT macro - please use Py_BUILD_CORE */ -#ifdef USE_DL_EXPORT -# define Py_BUILD_CORE -#endif /* USE_DL_EXPORT */ - /* All windows compilers that use this header support __declspec */ #define HAVE_DECLSPEC_DLL Modified: python/branches/p3yk/Python/structmember.c ============================================================================== --- python/branches/p3yk/Python/structmember.c (original) +++ python/branches/p3yk/Python/structmember.c Mon Aug 6 03:55:39 2007 @@ -156,6 +156,12 @@ return -1; } +#define WARN(msg) \ + do { \ + if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0) \ + return -1; \ + } while (0) + int PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) { @@ -174,60 +180,54 @@ addr += l->offset; switch (l->type) { case T_BYTE:{ - long long_val; - long_val = PyInt_AsLong(v); + long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; + *(char*)addr = (char)long_val; /* XXX: For compatibility, only warn about truncations for now. */ if ((long_val > CHAR_MAX) || (long_val < CHAR_MIN)) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to char"); - *(char*)addr = (char)long_val; + WARN("Truncation of value to char"); break; } case T_UBYTE:{ - long long_val; - long_val = PyInt_AsLong(v); + long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; - if ((long_val > UCHAR_MAX) || (long_val < 0)) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to unsigned char"); *(unsigned char*)addr = (unsigned char)long_val; + if ((long_val > UCHAR_MAX) || (long_val < 0)) + WARN("Truncation of value to unsigned char"); break; } case T_SHORT:{ - long long_val; - long_val = PyInt_AsLong(v); + long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; - if ((long_val > SHRT_MAX) || (long_val < SHRT_MIN)) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to short"); *(short*)addr = (short)long_val; + if ((long_val > SHRT_MAX) || (long_val < SHRT_MIN)) + WARN("Truncation of value to short"); break; } case T_USHORT:{ - long long_val; - long_val = PyInt_AsLong(v); + long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; - if ((long_val > USHRT_MAX) || (long_val < 0)) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to unsigned short"); *(unsigned short*)addr = (unsigned short)long_val; + if ((long_val > USHRT_MAX) || (long_val < 0)) + WARN("Truncation of value to unsigned short"); break; } case T_INT:{ - long long_val; - long_val = PyInt_AsLong(v); + long long_val = PyInt_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; - if ((long_val > INT_MAX) || (long_val < INT_MIN)) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to int"); *(int *)addr = (int)long_val; + if ((long_val > INT_MAX) || (long_val < INT_MIN)) + WARN("Truncation of value to int"); break; } case T_UINT:{ - unsigned long ulong_val; - ulong_val = PyLong_AsUnsignedLong(v); + unsigned long ulong_val = PyLong_AsUnsignedLong(v); if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) { /* XXX: For compatibility, accept negative int values as well. */ @@ -235,11 +235,12 @@ ulong_val = PyLong_AsLong(v); if ((ulong_val == (unsigned int)-1) && PyErr_Occurred()) return -1; - PyErr_Warn(PyExc_RuntimeWarning, "Writing negative value into unsigned field"); - } + *(unsigned int *)addr = (unsigned int)ulong_val; + WARN("Writing negative value into unsigned field"); + } else + *(unsigned int *)addr = (unsigned int)ulong_val; if (ulong_val > UINT_MAX) - PyErr_Warn(PyExc_RuntimeWarning, "Truncation of value to unsigned int"); - *(unsigned int *)addr = (unsigned int)ulong_val; + WARN("Truncation of value to unsigned int"); break; } case T_LONG:{ @@ -256,9 +257,10 @@ as well. */ PyErr_Clear(); *(unsigned long*)addr = PyLong_AsLong(v); - if ((*(unsigned long*)addr == (unsigned int)-1) && PyErr_Occurred()) + if ((*(unsigned long*)addr == (unsigned int)-1) + && PyErr_Occurred()) return -1; - PyErr_Warn(PyExc_RuntimeWarning, "Writing negative value into unsigned field"); + WARN("Writing negative value into unsigned field"); } break; } @@ -270,8 +272,7 @@ break; } case T_FLOAT:{ - double double_val; - double_val = PyFloat_AsDouble(v); + double double_val = PyFloat_AsDouble(v); if ((double_val == -1) && PyErr_Occurred()) return -1; *(float*)addr = (float)double_val; Modified: python/branches/p3yk/configure ============================================================================== --- python/branches/p3yk/configure (original) +++ python/branches/p3yk/configure Mon Aug 6 03:55:39 2007 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 54283 . +# From configure.in Revision: 55739 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 3.0. # @@ -1838,6 +1838,14 @@ _ACEOF +# OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is +# also defined. This can be overridden by defining _BSD_SOURCE + +cat >>confdefs.h <<\_ACEOF +#define _BSD_SOURCE 1 +_ACEOF + + # The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables # u_int on Irix 5.3. Defining _BSD_TYPES brings it back. Modified: python/branches/p3yk/configure.in ============================================================================== --- python/branches/p3yk/configure.in (original) +++ python/branches/p3yk/configure.in Mon Aug 6 03:55:39 2007 @@ -50,6 +50,10 @@ # them. AC_DEFINE(__BSD_VISIBLE, 1, [Define on FreeBSD to activate all library features]) +# OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is +# also defined. This can be overridden by defining _BSD_SOURCE +AC_DEFINE(_BSD_SOURCE, 1, [Define on OpenBSD to activate all library features]) + # The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables # u_int on Irix 5.3. Defining _BSD_TYPES brings it back. AC_DEFINE(_BSD_TYPES, 1, [Define on Irix to enable u_int]) Modified: python/branches/p3yk/pyconfig.h.in ============================================================================== --- python/branches/p3yk/pyconfig.h.in (original) +++ python/branches/p3yk/pyconfig.h.in Mon Aug 6 03:55:39 2007 @@ -103,6 +103,10 @@ /* Define if you have the 'resize_term' function. */ #undef HAVE_CURSES_RESIZE_TERM +/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't. + */ +#undef HAVE_DECL_TZNAME + /* Define to 1 if you have the device macros. */ #undef HAVE_DEVICE_MACROS @@ -802,22 +806,22 @@ /* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS -/* The size of a `double', as computed by sizeof. */ +/* The size of `double', as computed by sizeof. */ #undef SIZEOF_DOUBLE -/* The size of a `float', as computed by sizeof. */ +/* The size of `float', as computed by sizeof. */ #undef SIZEOF_FLOAT -/* The size of a `fpos_t', as computed by sizeof. */ +/* The size of `fpos_t', as computed by sizeof. */ #undef SIZEOF_FPOS_T -/* The size of a `int', as computed by sizeof. */ +/* The size of `int', as computed by sizeof. */ #undef SIZEOF_INT -/* The size of a `long', as computed by sizeof. */ +/* The size of `long', as computed by sizeof. */ #undef SIZEOF_LONG -/* The size of a `long long', as computed by sizeof. */ +/* The size of `long long', as computed by sizeof. */ #undef SIZEOF_LONG_LONG /* The number of bytes in an off_t. */ @@ -826,25 +830,25 @@ /* The number of bytes in a pthread_t. */ #undef SIZEOF_PTHREAD_T -/* The size of a `short', as computed by sizeof. */ +/* The size of `short', as computed by sizeof. */ #undef SIZEOF_SHORT -/* The size of a `size_t', as computed by sizeof. */ +/* The size of `size_t', as computed by sizeof. */ #undef SIZEOF_SIZE_T /* The number of bytes in a time_t. */ #undef SIZEOF_TIME_T -/* The size of a `uintptr_t', as computed by sizeof. */ +/* The size of `uintptr_t', as computed by sizeof. */ #undef SIZEOF_UINTPTR_T -/* The size of a `void *', as computed by sizeof. */ +/* The size of `void *', as computed by sizeof. */ #undef SIZEOF_VOID_P -/* The size of a `wchar_t', as computed by sizeof. */ +/* The size of `wchar_t', as computed by sizeof. */ #undef SIZEOF_WCHAR_T -/* The size of a `_Bool', as computed by sizeof. */ +/* The size of `_Bool', as computed by sizeof. */ #undef SIZEOF__BOOL /* Define to 1 if you have the ANSI C header files. */ @@ -924,6 +928,9 @@ # undef _ALL_SOURCE #endif +/* Define on OpenBSD to activate all library features */ +#undef _BSD_SOURCE + /* Define on Irix to enable u_int */ #undef _BSD_TYPES @@ -980,7 +987,7 @@ /* Define to `int' if does not define. */ #undef mode_t -/* Define to `long' if does not define. */ +/* Define to `long int' if does not define. */ #undef off_t /* Define to `int' if does not define. */ @@ -989,7 +996,7 @@ /* Define to empty if the keyword does not work. */ #undef signed -/* Define to `unsigned' if does not define. */ +/* Define to `unsigned int' if does not define. */ #undef size_t /* Define to `int' if does not define. */ From python-3000-checkins at python.org Mon Aug 6 21:32:20 2007 From: python-3000-checkins at python.org (guido.van.rossum) Date: Mon, 6 Aug 2007 21:32:20 +0200 (CEST) Subject: [Python-3000-checkins] r56777 - in python/branches/py3k-struni: Lib/test/test_csv.py Modules/_csv.c Message-ID: <20070806193220.EFE1E1E4006@bag.python.org> Author: guido.van.rossum Date: Mon Aug 6 21:32:18 2007 New Revision: 56777 Modified: python/branches/py3k-struni/Lib/test/test_csv.py python/branches/py3k-struni/Modules/_csv.c Log: SF patch# 1767398 by Adam Hupp. Fix csv to read/write bytes from/to binary files. Fix the unit tests to test this and to use with TemporaryFile(). Modified: python/branches/py3k-struni/Lib/test/test_csv.py ============================================================================== --- python/branches/py3k-struni/Lib/test/test_csv.py (original) +++ python/branches/py3k-struni/Lib/test/test_csv.py Mon Aug 6 21:32:18 2007 @@ -6,7 +6,7 @@ import os import unittest from StringIO import StringIO -import tempfile +from tempfile import TemporaryFile import csv import gc from test import test_support @@ -117,17 +117,12 @@ def _write_test(self, fields, expect, **kwargs): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, **kwargs) writer.writerow(fields) fileobj.seek(0) - self.assertEqual(fileobj.read(), + self.assertEqual(str(fileobj.read()), expect + writer.dialect.lineterminator) - finally: - fileobj.close() - os.unlink(name) def test_write_arg_valid(self): self.assertRaises(csv.Error, self._write_test, None, '') @@ -192,17 +187,13 @@ raise IOError writer = csv.writer(BrokenFile()) self.assertRaises(IOError, writer.writerows, [['a']]) - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj) self.assertRaises(TypeError, writer.writerows, None) writer.writerows([['a','b'],['c','d']]) fileobj.seek(0) - self.assertEqual(fileobj.read(), "a,b\r\nc,d\r\n") - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(fileobj.read(), b"a,b\r\nc,d\r\n") def _read_test(self, input, expect, **kwargs): reader = csv.reader(input, **kwargs) @@ -333,17 +324,19 @@ quoting = csv.QUOTE_NONE escapechar = "\\" - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("abc def\nc1ccccc1 benzene\n") fileobj.seek(0) reader = csv.reader(fileobj, dialect=space()) self.assertEqual(next(reader), ["abc", "def"]) self.assertEqual(next(reader), ["c1ccccc1", "benzene"]) - finally: - fileobj.close() - os.unlink(name) + + def compare_dialect_123(self, expected, *writeargs, **kwwriteargs): + with TemporaryFile("w+b") as fileobj: + writer = csv.writer(fileobj, *writeargs, **kwwriteargs) + writer.writerow([1,2,3]) + fileobj.seek(0) + self.assertEqual(str(fileobj.read()), expected) def test_dialect_apply(self): class testA(csv.excel): @@ -352,63 +345,19 @@ delimiter = ":" class testC(csv.excel): delimiter = "|" + class testUni(csv.excel): + delimiter = "\u039B" csv.register_dialect('testC', testC) try: - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: - writer = csv.writer(fileobj) - writer.writerow([1,2,3]) - fileobj.seek(0) - self.assertEqual(fileobj.read(), "1,2,3\r\n") - finally: - fileobj.close() - os.unlink(name) - - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: - writer = csv.writer(fileobj, testA) - writer.writerow([1,2,3]) - fileobj.seek(0) - self.assertEqual(fileobj.read(), "1\t2\t3\r\n") - finally: - fileobj.close() - os.unlink(name) - - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: - writer = csv.writer(fileobj, dialect=testB()) - writer.writerow([1,2,3]) - fileobj.seek(0) - self.assertEqual(fileobj.read(), "1:2:3\r\n") - finally: - fileobj.close() - os.unlink(name) - - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: - writer = csv.writer(fileobj, dialect='testC') - writer.writerow([1,2,3]) - fileobj.seek(0) - self.assertEqual(fileobj.read(), "1|2|3\r\n") - finally: - fileobj.close() - os.unlink(name) - - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: - writer = csv.writer(fileobj, dialect=testA, delimiter=';') - writer.writerow([1,2,3]) - fileobj.seek(0) - self.assertEqual(fileobj.read(), "1;2;3\r\n") - finally: - fileobj.close() - os.unlink(name) + self.compare_dialect_123("1,2,3\r\n") + self.compare_dialect_123("1\t2\t3\r\n", testA) + self.compare_dialect_123("1:2:3\r\n", dialect=testB()) + self.compare_dialect_123("1|2|3\r\n", dialect='testC') + self.compare_dialect_123("1;2;3\r\n", dialect=testA, + delimiter=';') + self.compare_dialect_123("1\u039B2\u039B3\r\n", + dialect=testUni) finally: csv.unregister_dialect('testC') @@ -423,29 +372,19 @@ class TestCsvBase(unittest.TestCase): def readerAssertEqual(self, input, expected_result): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write(input) fileobj.seek(0) reader = csv.reader(fileobj, dialect = self.dialect) fields = list(reader) self.assertEqual(fields, expected_result) - finally: - fileobj.close() - os.unlink(name) def writerAssertEqual(self, input, expected_result): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, dialect = self.dialect) writer.writerows(input) fileobj.seek(0) - self.assertEqual(fileobj.read(), expected_result) - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), expected_result) class TestDialectExcel(TestCsvBase): dialect = 'excel' @@ -574,91 +513,59 @@ ### "long" means the row is longer than the number of fieldnames ### "short" means there are fewer elements in the row than fieldnames def test_write_simple_dict(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.DictWriter(fileobj, fieldnames = ["f1", "f2", "f3"]) writer.writerow({"f1": 10, "f3": "abc"}) fileobj.seek(0) - self.assertEqual(fileobj.read(), "10,,abc\r\n") - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), "10,,abc\r\n") def test_write_no_fields(self): fileobj = StringIO() self.assertRaises(TypeError, csv.DictWriter, fileobj) def test_read_dict_fields(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("1,2,abc\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, fieldnames=["f1", "f2", "f3"]) self.assertEqual(next(reader), {"f1": '1', "f2": '2', "f3": 'abc'}) - finally: - fileobj.close() - os.unlink(name) def test_read_dict_no_fieldnames(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("f1,f2,f3\r\n1,2,abc\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj) self.assertEqual(next(reader), {"f1": '1', "f2": '2', "f3": 'abc'}) - finally: - fileobj.close() - os.unlink(name) def test_read_long(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("1,2,abc,4,5,6\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, fieldnames=["f1", "f2"]) self.assertEqual(next(reader), {"f1": '1', "f2": '2', None: ["abc", "4", "5", "6"]}) - finally: - fileobj.close() - os.unlink(name) def test_read_long_with_rest(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("1,2,abc,4,5,6\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, fieldnames=["f1", "f2"], restkey="_rest") self.assertEqual(next(reader), {"f1": '1', "f2": '2', "_rest": ["abc", "4", "5", "6"]}) - finally: - fileobj.close() - os.unlink(name) def test_read_long_with_rest_no_fieldnames(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("f1,f2\r\n1,2,abc,4,5,6\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, restkey="_rest") self.assertEqual(next(reader), {"f1": '1', "f2": '2', "_rest": ["abc", "4", "5", "6"]}) - finally: - fileobj.close() - os.unlink(name) def test_read_short(self): - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+") as fileobj: fileobj.write("1,2,abc,4,5,6\r\n1,2,abc\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, @@ -669,9 +576,6 @@ self.assertEqual(next(reader), {"1": '1', "2": '2', "3": 'abc', "4": 'DEFAULT', "5": 'DEFAULT', "6": 'DEFAULT'}) - finally: - fileobj.close() - os.unlink(name) def test_read_multi(self): sample = [ @@ -710,64 +614,45 @@ contents = [(20-i) for i in range(20)] a = array.array('i', contents) - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, dialect="excel") writer.writerow(a) expected = ",".join([str(i) for i in a])+"\r\n" fileobj.seek(0) - self.assertEqual(fileobj.read(), expected) - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), expected) def test_double_write(self): import array contents = [(20-i)*0.1 for i in range(20)] a = array.array('d', contents) - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, dialect="excel") writer.writerow(a) expected = ",".join([str(i) for i in a])+"\r\n" fileobj.seek(0) - self.assertEqual(fileobj.read(), expected) - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), expected) def test_float_write(self): import array contents = [(20-i)*0.1 for i in range(20)] a = array.array('f', contents) - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, dialect="excel") writer.writerow(a) expected = ",".join([str(i) for i in a])+"\r\n" fileobj.seek(0) - self.assertEqual(fileobj.read(), expected) - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), expected) def test_char_write(self): import array, string - a = array.array('c', string.letters) - fd, name = tempfile.mkstemp() - fileobj = os.fdopen(fd, "w+b") - try: + a = array.array('u', string.letters) + + with TemporaryFile("w+b") as fileobj: writer = csv.writer(fileobj, dialect="excel") writer.writerow(a) expected = ",".join(a)+"\r\n" fileobj.seek(0) - self.assertEqual(fileobj.read(), expected) - finally: - fileobj.close() - os.unlink(name) + self.assertEqual(str(fileobj.read()), expected) class TestDialectValidity(unittest.TestCase): def test_quoting(self): @@ -970,20 +855,36 @@ # if writer leaks during write, last delta should be 5 or more self.assertEqual(delta < 5, True) -# commented out for now - csv module doesn't yet support Unicode -## class TestUnicode(unittest.TestCase): -## def test_unicode_read(self): -## import codecs -## f = codecs.EncodedFile(StringIO("Martin von L?wis," -## "Marc Andr? Lemburg," -## "Guido van Rossum," -## "Fran?ois Pinard\r\n"), -## data_encoding='iso-8859-1') -## reader = csv.reader(f) -## self.assertEqual(list(reader), [["Martin von L?wis", -## "Marc Andr? Lemburg", -## "Guido van Rossum", -## "Fran?ois Pinardn"]]) +class TestUnicode(unittest.TestCase): + + names = ["Martin von L?wis", + "Marc Andr? Lemburg", + "Guido van Rossum", + "Fran?ois Pinard"] + + def test_unicode_read(self): + import io + fileobj = io.TextIOWrapper(TemporaryFile("w+b"), encoding="utf-16") + with fileobj as fileobj: + fileobj.write(",".join(self.names) + "\r\n") + + fileobj.seek(0) + reader = csv.reader(fileobj) + self.assertEqual(list(reader), [self.names]) + + + def test_unicode_write(self): + import io + with TemporaryFile("w+b") as fileobj: + encwriter = io.TextIOWrapper(fileobj, encoding="utf-8") + writer = csv.writer(encwriter) + writer.writerow(self.names) + expected = ",".join(self.names)+"\r\n" + fileobj.seek(0) + self.assertEqual(str(fileobj.read()), expected) + + + def test_main(): mod = sys.modules[__name__] Modified: python/branches/py3k-struni/Modules/_csv.c ============================================================================== --- python/branches/py3k-struni/Modules/_csv.c (original) +++ python/branches/py3k-struni/Modules/_csv.c Mon Aug 6 21:32:18 2007 @@ -93,11 +93,11 @@ typedef struct { PyObject_HEAD - + int doublequote; /* is " represented by ""? */ - char delimiter; /* field separator */ - char quotechar; /* quote character */ - char escapechar; /* escape character */ + Py_UNICODE delimiter; /* field separator */ + Py_UNICODE quotechar; /* quote character */ + Py_UNICODE escapechar; /* escape character */ int skipinitialspace; /* ignore spaces following delimiter? */ PyObject *lineterminator; /* string to write between records */ int quoting; /* style of quoting to write */ @@ -116,9 +116,9 @@ PyObject *fields; /* field list for current record */ ParserState state; /* current CSV parse state */ - char *field; /* build current field in here */ + Py_UNICODE *field; /* build current field in here */ int field_size; /* size of allocated buffer */ - int field_len; /* length of current field */ + Py_ssize_t field_len; /* length of current field */ int numeric_field; /* treat field as numeric */ unsigned long line_num; /* Source-file line number */ } ReaderObj; @@ -134,11 +134,11 @@ DialectObj *dialect; /* parsing dialect */ - char *rec; /* buffer for parser.join */ + Py_UNICODE *rec; /* buffer for parser.join */ int rec_size; /* size of allocated record */ - int rec_len; /* length of record */ + Py_ssize_t rec_len; /* length of record */ int num_fields; /* number of fields in record */ -} WriterObj; +} WriterObj; static PyTypeObject Writer_Type; @@ -176,7 +176,7 @@ return Py_None; } else - return PyString_FromStringAndSize((char*)&c, 1); + return PyUnicode_DecodeASCII((char*)&c, 1, NULL); } static PyObject * @@ -230,20 +230,21 @@ } static int -_set_char(const char *name, char *target, PyObject *src, char dflt) +_set_char(const char *name, Py_UNICODE *target, PyObject *src, Py_UNICODE dflt) { if (src == NULL) *target = dflt; else { *target = '\0'; if (src != Py_None) { - const char *buf; + Py_UNICODE *buf; Py_ssize_t len; - if (PyObject_AsCharBuffer(src, &buf, &len) < 0 || - len > 1) { + buf = PyUnicode_AsUnicode(src); + len = PyUnicode_GetSize(src); + if (buf == NULL || len > 1) { PyErr_Format(PyExc_TypeError, "\"%s\" must be an 1-character string", - name); + name); return -1; } if (len > 0) @@ -257,7 +258,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt) { if (src == NULL) - *target = PyString_FromString(dflt); + *target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL); else { if (src == Py_None) *target = NULL; @@ -528,7 +529,7 @@ { PyObject *field; - field = PyString_FromStringAndSize(self->field, self->field_len); + field = PyUnicode_FromUnicode(self->field, self->field_len); if (field == NULL) return -1; self->field_len = 0; @@ -556,11 +557,12 @@ self->field_size = 4096; if (self->field != NULL) PyMem_Free(self->field); - self->field = PyMem_Malloc(self->field_size); + self->field = PyMem_New(Py_UNICODE, self->field_size); } else { self->field_size *= 2; - self->field = PyMem_Realloc(self->field, self->field_size); + self->field = PyMem_Resize(self->field, Py_UNICODE, + self->field_size); } if (self->field == NULL) { PyErr_NoMemory(); @@ -570,7 +572,7 @@ } static int -parse_add_char(ReaderObj *self, char c) +parse_add_char(ReaderObj *self, Py_UNICODE c) { if (self->field_len >= field_limit) { PyErr_Format(error_obj, "field larger than field limit (%ld)", @@ -584,7 +586,7 @@ } static int -parse_process_char(ReaderObj *self, char c) +parse_process_char(ReaderObj *self, Py_UNICODE c) { DialectObj *dialect = self->dialect; @@ -771,8 +773,8 @@ { PyObject *lineobj; PyObject *fields = NULL; - char *line, c; - int linelen; + Py_UNICODE *line, c; + Py_ssize_t linelen; if (parse_reset(self) < 0) return NULL; @@ -785,11 +787,9 @@ "newline inside string"); return NULL; } - ++self->line_num; - - line = PyString_AsString(lineobj); - linelen = PyString_Size(lineobj); - + ++self->line_num; + line = PyUnicode_AsUnicode(lineobj); + linelen = PyUnicode_GetSize(lineobj); if (line == NULL || linelen < 0) { Py_DECREF(lineobj); return NULL; @@ -962,12 +962,13 @@ * record length. */ static int -join_append_data(WriterObj *self, char *field, int quote_empty, - int *quoted, int copy_phase) +join_append_data(WriterObj *self, Py_UNICODE *field, int quote_empty, + int *quoted, int copy_phase) { DialectObj *dialect = self->dialect; - int i, rec_len; - char *lineterm; + int i; + int rec_len; + Py_UNICODE *lineterm; #define ADDCH(c) \ do {\ @@ -976,7 +977,7 @@ rec_len++;\ } while(0) - lineterm = PyString_AsString(dialect->lineterminator); + lineterm = PyUnicode_AsUnicode(dialect->lineterminator); if (lineterm == NULL) return -1; @@ -991,8 +992,9 @@ ADDCH(dialect->quotechar); /* Copy/count field data */ - for (i = 0;; i++) { - char c = field[i]; + /* If field is null just pass over */ + for (i = 0; field; i++) { + Py_UNICODE c = field[i]; int want_escape = 0; if (c == '\0') @@ -1000,8 +1002,8 @@ if (c == dialect->delimiter || c == dialect->escapechar || - c == dialect->quotechar || - strchr(lineterm, c)) { + c == dialect->quotechar || + Py_UNICODE_strchr(lineterm, c)) { if (dialect->quoting == QUOTE_NONE) want_escape = 1; else { @@ -1033,7 +1035,7 @@ if (i == 0 && quote_empty) { if (dialect->quoting == QUOTE_NONE) { PyErr_Format(error_obj, - "single empty field record must be quoted"); + "single empty field record must be quoted"); return -1; } else @@ -1058,13 +1060,14 @@ self->rec_size = (rec_len / MEM_INCR + 1) * MEM_INCR; if (self->rec != NULL) PyMem_Free(self->rec); - self->rec = PyMem_Malloc(self->rec_size); + self->rec = PyMem_New(Py_UNICODE, self->rec_size); } else { - char *old_rec = self->rec; + Py_UNICODE* old_rec = self->rec; self->rec_size = (rec_len / MEM_INCR + 1) * MEM_INCR; - self->rec = PyMem_Realloc(self->rec, self->rec_size); + self->rec = PyMem_Resize(self->rec, Py_UNICODE, + self->rec_size); if (self->rec == NULL) PyMem_Free(old_rec); } @@ -1077,7 +1080,7 @@ } static int -join_append(WriterObj *self, char *field, int *quoted, int quote_empty) +join_append(WriterObj *self, Py_UNICODE *field, int *quoted, int quote_empty) { int rec_len; @@ -1099,9 +1102,9 @@ join_append_lineterminator(WriterObj *self) { int terminator_len; - char *terminator; + Py_UNICODE *terminator; - terminator_len = PyString_Size(self->dialect->lineterminator); + terminator_len = PyUnicode_GetSize(self->dialect->lineterminator); if (terminator_len == -1) return 0; @@ -1109,10 +1112,11 @@ if (!join_check_rec_size(self, self->rec_len + terminator_len)) return 0; - terminator = PyString_AsString(self->dialect->lineterminator); + terminator = PyUnicode_AsUnicode(self->dialect->lineterminator); if (terminator == NULL) return 0; - memmove(self->rec + self->rec_len, terminator, terminator_len); + memmove(self->rec + self->rec_len, terminator, + sizeof(Py_UNICODE)*terminator_len); self->rec_len += terminator_len; return 1; @@ -1161,26 +1165,27 @@ break; } - if (PyString_Check(field)) { + if (PyUnicode_Check(field)) { append_ok = join_append(self, - PyString_AS_STRING(field), - "ed, len == 1); + PyUnicode_AS_UNICODE(field), + "ed, len == 1); Py_DECREF(field); } else if (field == Py_None) { - append_ok = join_append(self, "", "ed, len == 1); + append_ok = join_append(self, NULL, + "ed, len == 1); Py_DECREF(field); } else { PyObject *str; - str = PyObject_Str(field); - Py_DECREF(field); + str = PyObject_Unicode(field); + Py_DECREF(field); if (str == NULL) return NULL; - - append_ok = join_append(self, PyString_AS_STRING(str), - "ed, len == 1); + append_ok = join_append(self, + PyUnicode_AS_UNICODE(str), + "ed, len == 1); Py_DECREF(str); } if (!append_ok) @@ -1192,8 +1197,9 @@ if (!join_append_lineterminator(self)) return 0; - return PyObject_CallFunction(self->writeline, - "(s#)", self->rec, self->rec_len); + return PyObject_CallFunction(self->writeline, + "(u#)", self->rec, + self->rec_len); } PyDoc_STRVAR(csv_writerows_doc, From python-3000-checkins at python.org Mon Aug 6 22:55:48 2007 From: python-3000-checkins at python.org (skip.montanaro) Date: Mon, 6 Aug 2007 22:55:48 +0200 (CEST) Subject: [Python-3000-checkins] r56779 - python/branches/py3k-struni/Modules/_csv.c Message-ID: <20070806205548.63C6E1E4010@bag.python.org> Author: skip.montanaro Date: Mon Aug 6 22:55:47 2007 New Revision: 56779 Modified: python/branches/py3k-struni/Modules/_csv.c Log: One char->Py_UNICODE change missed in r56777 - according to Adam Hupp this is the change to make... Modified: python/branches/py3k-struni/Modules/_csv.c ============================================================================== --- python/branches/py3k-struni/Modules/_csv.c (original) +++ python/branches/py3k-struni/Modules/_csv.c Mon Aug 6 22:55:47 2007 @@ -169,14 +169,14 @@ } static PyObject * -get_nullchar_as_None(char c) +get_nullchar_as_None(Py_UNICODE c) { if (c == '\0') { Py_INCREF(Py_None); return Py_None; } else - return PyUnicode_DecodeASCII((char*)&c, 1, NULL); + return PyUnicode_FromUnicode((Py_UNICODE *)&c, 1); } static PyObject * From python-3000-checkins at python.org Mon Aug 6 22:59:29 2007 From: python-3000-checkins at python.org (skip.montanaro) Date: Mon, 6 Aug 2007 22:59:29 +0200 (CEST) Subject: [Python-3000-checkins] r56780 - python/branches/py3k-struni/Modules/atexitmodule.c Message-ID: <20070806205929.3AB7C1E401A@bag.python.org> Author: skip.montanaro Date: Mon Aug 6 22:59:28 2007 New Revision: 56780 Modified: python/branches/py3k-struni/Modules/atexitmodule.c Log: missing docstrings Modified: python/branches/py3k-struni/Modules/atexitmodule.c ============================================================================== --- python/branches/py3k-struni/Modules/atexitmodule.c (original) +++ python/branches/py3k-struni/Modules/atexitmodule.c Mon Aug 6 22:59:28 2007 @@ -145,6 +145,11 @@ return func; } +PyDoc_STRVAR(atexit_run_exitfuncs__doc__, +"_run_exitfuncs() -> None\n\ +\n\ +Run all registered exit functions."); + static PyObject * atexit_run_exitfuncs(PyObject *self) { @@ -154,6 +159,11 @@ Py_RETURN_NONE; } +PyDoc_STRVAR(atexit_clear__doc__, +"_clear() -> None\n\ +\n\ +Clear the list of previously registered exit functions."); + static PyObject * atexit_clear(PyObject *self) { @@ -172,6 +182,14 @@ Py_RETURN_NONE; } +PyDoc_STRVAR(atexit_unregister__doc__, +"unregister(func) -> None\n\ +\n\ +Unregister a exit function which was previously registered using\n\ +atexit.register\n\ +\n\ + func - function to be unregistered"); + static PyObject * atexit_unregister(PyObject *self, PyObject *func) { @@ -197,11 +215,11 @@ {"register", (PyCFunction) atexit_register, METH_VARARGS|METH_KEYWORDS, atexit_register__doc__}, {"_clear", (PyCFunction) atexit_clear, METH_NOARGS, - NULL}, + atexit_clear__doc__}, {"unregister", (PyCFunction) atexit_unregister, METH_O, - NULL}, + atexit_unregister__doc__}, {"_run_exitfuncs", (PyCFunction) atexit_run_exitfuncs, METH_NOARGS, - NULL}, + atexit_run_exitfuncs__doc__}, {NULL, NULL} /* sentinel */ }; @@ -209,10 +227,10 @@ /* Initialization function. */ PyDoc_STRVAR(atexit__doc__, -"atexit.py - allow programmer to define multiple exit functions to be executed\ +"allow programmer to define multiple exit functions to be executed\ upon normal program termination.\n\ \n\ -One public function, register, is defined.\n\ +Two public functions, register and unregister, are defined.\n\ "); PyMODINIT_FUNC From python-3000-checkins at python.org Mon Aug 6 23:07:54 2007 From: python-3000-checkins at python.org (skip.montanaro) Date: Mon, 6 Aug 2007 23:07:54 +0200 (CEST) Subject: [Python-3000-checkins] r56781 - in python/branches/py3k-struni/Demo: cgi/cgi2.py classes/Dbm.py metaclasses/Enum.py newmetaclasses/Enum.py pdist/cmdfw.py pdist/cmptree.py pdist/cvslib.py pdist/rrcs.py pdist/server.py scripts/ftpstats.py scripts/markov.py scripts/newslist.py threads/Coroutine.py tix/samples/OptMenu.py tkinter/guido/AttrDialog.py xml/elem_count.py xml/roundtrip.py Message-ID: <20070806210754.288F81E4010@bag.python.org> Author: skip.montanaro Date: Mon Aug 6 23:07:53 2007 New Revision: 56781 Modified: python/branches/py3k-struni/Demo/cgi/cgi2.py python/branches/py3k-struni/Demo/classes/Dbm.py python/branches/py3k-struni/Demo/metaclasses/Enum.py python/branches/py3k-struni/Demo/newmetaclasses/Enum.py python/branches/py3k-struni/Demo/pdist/cmdfw.py python/branches/py3k-struni/Demo/pdist/cmptree.py python/branches/py3k-struni/Demo/pdist/cvslib.py python/branches/py3k-struni/Demo/pdist/rrcs.py python/branches/py3k-struni/Demo/pdist/server.py python/branches/py3k-struni/Demo/scripts/ftpstats.py python/branches/py3k-struni/Demo/scripts/markov.py python/branches/py3k-struni/Demo/scripts/newslist.py python/branches/py3k-struni/Demo/threads/Coroutine.py python/branches/py3k-struni/Demo/tix/samples/OptMenu.py python/branches/py3k-struni/Demo/tkinter/guido/AttrDialog.py python/branches/py3k-struni/Demo/xml/elem_count.py python/branches/py3k-struni/Demo/xml/roundtrip.py Log: remove most uses of list(somedict.keys()) in Demo scripts Modified: python/branches/py3k-struni/Demo/cgi/cgi2.py ============================================================================== --- python/branches/py3k-struni/Demo/cgi/cgi2.py (original) +++ python/branches/py3k-struni/Demo/cgi/cgi2.py Mon Aug 6 23:07:53 2007 @@ -14,7 +14,7 @@ print("

    No Form Keys

    ") else: print("

    Form Keys

    ") - for key in list(form.keys()): + for key in form.keys(): value = form[key].value print("

    ", cgi.escape(key), ":", cgi.escape(value)) Modified: python/branches/py3k-struni/Demo/classes/Dbm.py ============================================================================== --- python/branches/py3k-struni/Demo/classes/Dbm.py (original) +++ python/branches/py3k-struni/Demo/classes/Dbm.py Mon Aug 6 23:07:53 2007 @@ -12,7 +12,7 @@ def __repr__(self): s = '' - for key in list(self.keys()): + for key in self.keys(): t = repr(key) + ': ' + repr(self[key]) if s: t = ', ' + t s = s + t @@ -32,7 +32,7 @@ def keys(self): res = [] - for key in list(self.db.keys()): + for key in self.db.keys(): res.append(eval(key)) return res Modified: python/branches/py3k-struni/Demo/metaclasses/Enum.py ============================================================================== --- python/branches/py3k-struni/Demo/metaclasses/Enum.py (original) +++ python/branches/py3k-struni/Demo/metaclasses/Enum.py Mon Aug 6 23:07:53 2007 @@ -42,7 +42,7 @@ self.__name__ = name self.__bases__ = bases self.__dict = {} - for key, value in list(dict.items()): + for key, value in dict.items(): self.__dict[key] = EnumInstance(name, key, value) def __getattr__(self, name): @@ -80,7 +80,7 @@ s = s + '(' + string.join([x.__name__ for x in self.__bases__], ", ") + ')' if self.__dict: list = [] - for key, value in list(self.__dict.items()): + for key, value in self.__dict.items(): list.append("%s: %s" % (key, int(value))) s = "%s: {%s}" % (s, string.join(list, ", ")) return s Modified: python/branches/py3k-struni/Demo/newmetaclasses/Enum.py ============================================================================== --- python/branches/py3k-struni/Demo/newmetaclasses/Enum.py (original) +++ python/branches/py3k-struni/Demo/newmetaclasses/Enum.py Mon Aug 6 23:07:53 2007 @@ -20,7 +20,7 @@ def __init__(cls, name, bases, dict): super(EnumMetaclass, cls).__init__(name, bases, dict) cls._members = [] - for attr in list(dict.keys()): + for attr in dict.keys(): if not (attr.startswith('__') and attr.endswith('__')): enumval = EnumInstance(name, attr, dict[attr]) setattr(cls, attr, enumval) Modified: python/branches/py3k-struni/Demo/pdist/cmdfw.py ============================================================================== --- python/branches/py3k-struni/Demo/pdist/cmdfw.py (original) +++ python/branches/py3k-struni/Demo/pdist/cmdfw.py Mon Aug 6 23:07:53 2007 @@ -104,9 +104,7 @@ c = c.__bases__[0] if docstrings: print("where subcommand can be:") - names = list(docstrings.keys()) - names.sort() - for name in names: + for name in sorted(docstrings.keys()): print(docstrings[name]) if self.PostUsageMessage: print(self.PostUsageMessage) Modified: python/branches/py3k-struni/Demo/pdist/cmptree.py ============================================================================== --- python/branches/py3k-struni/Demo/pdist/cmptree.py (original) +++ python/branches/py3k-struni/Demo/pdist/cmptree.py Mon Aug 6 23:07:53 2007 @@ -89,7 +89,7 @@ else: print("same mtime but different sum?!?!", end=' ') print() - for name in list(lsumdict.keys()): + for name in lsumdict.keys(): if not list(rsumdict.keys()): print(repr(name), "only locally", end=' ') fl() Modified: python/branches/py3k-struni/Demo/pdist/cvslib.py ============================================================================== --- python/branches/py3k-struni/Demo/pdist/cvslib.py (original) +++ python/branches/py3k-struni/Demo/pdist/cvslib.py Mon Aug 6 23:07:53 2007 @@ -223,15 +223,12 @@ f.close() def getlocalfiles(self): - list = list(self.entries.keys()) + entries_keys = set(self.entries.keys()) addlist = os.listdir(os.curdir) for name in addlist: - if name in list: - continue if not self.ignored(name): - list.append(name) - list.sort() - for file in list: + entries_keys.add(name) + for file in sorted(entries_keys): try: e = self.entries[file] except KeyError: @@ -257,19 +254,17 @@ print('-'*50) def keys(self): - keys = list(self.entries.keys()) - keys.sort() - return keys + return sorted(self.entries.keys()) def values(self): def value(key, self=self): return self.entries[key] - return list(map(value, list(self.keys()))) + return [value(k) for k in self.keys()] def items(self): def item(key, self=self): return (key, self.entries[key]) - return list(map(item, list(self.keys()))) + return [item(k) for k in self.keys()] def cvsexists(self, file): file = os.path.join("CVS", file) Modified: python/branches/py3k-struni/Demo/pdist/rrcs.py ============================================================================== --- python/branches/py3k-struni/Demo/pdist/rrcs.py (original) +++ python/branches/py3k-struni/Demo/pdist/rrcs.py Mon Aug 6 23:07:53 2007 @@ -71,11 +71,9 @@ x.unlock(fn) def info(x, copts, fn): - dict = x.info(fn) - keys = list(dict.keys()) - keys.sort() - for key in keys: - print(key + ':', dict[key]) + info_dict = x.info(fn) + for key in sorted(info_dict.keys()): + print(key + ':', info_dict[key]) print('='*70) def head(x, copts, fn): Modified: python/branches/py3k-struni/Demo/pdist/server.py ============================================================================== --- python/branches/py3k-struni/Demo/pdist/server.py (original) +++ python/branches/py3k-struni/Demo/pdist/server.py Mon Aug 6 23:07:53 2007 @@ -101,9 +101,7 @@ def _listmethods(self, cl=None): if not cl: cl = self.__class__ - names = list(cl.__dict__.keys()) - names = [x for x in names if x[0] != '_'] - names.sort() + names = sorted([x for x in cl.__dict__.keys() if x[0] != '_']) for base in cl.__bases__: basenames = self._listmethods(base) basenames = list(filter(lambda x, names=names: x not in names, basenames)) Modified: python/branches/py3k-struni/Demo/scripts/ftpstats.py ============================================================================== --- python/branches/py3k-struni/Demo/scripts/ftpstats.py (original) +++ python/branches/py3k-struni/Demo/scripts/ftpstats.py Mon Aug 6 23:07:53 2007 @@ -106,9 +106,7 @@ n = len(title) print('='*((70-n)/2), title, '='*((71-n)/2)) list = [] - keys = list(dict.keys()) - keys.sort() - for key in keys: + for key in sorted(dict.keys()): n = len(str(key)) list.append((len(dict[key]), key)) maxkeylength = 0 @@ -128,8 +126,7 @@ n = len(title) print('='*((70-n)/2), title, '='*((71-n)/2)) list = [] - keys = list(dict.keys()) - for key in keys: + for key in dict.keys(): list.append((-len(dict[key]), key)) list.sort() for count, key in list[:maxitems]: Modified: python/branches/py3k-struni/Demo/scripts/markov.py ============================================================================== --- python/branches/py3k-struni/Demo/scripts/markov.py (original) +++ python/branches/py3k-struni/Demo/scripts/markov.py Mon Aug 6 23:07:53 2007 @@ -87,7 +87,7 @@ return if debug: print('done.') if debug > 1: - for key in list(m.trans.keys()): + for key in m.trans.keys(): if key is None or len(key) < histsize: print(repr(key), m.trans[key]) if histsize == 0: print(repr(''), m.trans['']) Modified: python/branches/py3k-struni/Demo/scripts/newslist.py ============================================================================== --- python/branches/py3k-struni/Demo/scripts/newslist.py (original) +++ python/branches/py3k-struni/Demo/scripts/newslist.py Mon Aug 6 23:07:53 2007 @@ -172,10 +172,9 @@ createpage(p[1:], tree, p) return - kl = list(tree.keys()) + kl = sorted(tree.keys()) if l > 1: - kl.sort() if indent > 0: # Create a sub-list f.write('

  • '+p[1:]+'\n