[issue1686386] Python SEGFAULT on invalid superclass access
Thomas Herve added the comment: object.c is already inconsistent about tabs and space :). It may be better to fix it in the commit, not to clutter the patch. But I can provide a new patch if necessary. _ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1686386> _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1686386] Python SEGFAULT on tuple.__repr__ and str()
Thomas Herve added the comment: I think it could be solved both the same way: if tuple repr is wrong, there are probably some other repr code that is wrong too, so fixing PyObject_Repr is safer. _ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1686386> _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1269] Exception in pstats print_callers()
Thomas Herve added the comment: 1315 is a duplicate of this, and I end up with a very similar solution. -- nosy: +therve __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1269> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1315] Bug in pstats.print_callers
Thomas Herve added the comment: The real bug is in fact in add_callers, where it concatenates tuples instead of adding the values. I'll try to write a test this week-end if nobody beats me to it. The attached is against current trunk. -- nosy: +therve Added file: http://bugs.python.org/file8797/1315.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1315> __Index: Lib/pstats.py === --- Lib/pstats.py (revision 59136) +++ Lib/pstats.py (working copy) @@ -512,7 +512,7 @@ new_callers[func] = caller for func, caller in source.iteritems(): if func in new_callers: -new_callers[func] = caller + new_callers[func] +new_callers[func] = tuple([i[0] + i[1] for i in zip(caller, new_callers[func])]) else: new_callers[func] = caller return new_callers ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1315] Bug in pstats.print_callers
Thomas Herve added the comment: Oh I didn't see, but this one should probably closed as duplicate of 1269. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1315> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1269] Exception in pstats print_callers()
Thomas Herve added the comment: Here's my patch against trunk, with one test. Please review! -- versions: +Python 2.6 Added file: http://bugs.python.org/file8806/1269.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1269> __Index: Lib/pstats.py === --- Lib/pstats.py (revision 59183) +++ Lib/pstats.py (working copy) @@ -512,7 +512,8 @@ new_callers[func] = caller for func, caller in source.iteritems(): if func in new_callers: -new_callers[func] = caller + new_callers[func] +new_callers[func] = tuple([i[0] + i[1] for i in + zip(caller, new_callers[func])]) else: new_callers[func] = caller return new_callers Index: Lib/test/test_pstats.py === --- Lib/test/test_pstats.py (revision 0) +++ Lib/test/test_pstats.py (revision 0) @@ -0,0 +1,26 @@ +import unittest +from test import test_support +import pstats + + + +class AddCallersTestCase(unittest.TestCase): +"""Tests for pstats.add_callers helper.""" + +def test_combine_results(self): +"""pstats.add_callers should combine the call results of both target +and source by adding the call time. See issue1269.""" +target = {"a": (1, 2, 3, 4)} +source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)} +new_callers = pstats.add_callers(target, source) +self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)}) + + +def test_main(): +test_support.run_unittest( +AddCallersTestCase +) + + +if __name__ == "__main__": +test_main() ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1117670] profiler: Bad return and Bad call errors with exceptions
Thomas Herve added the comment: Ping to close this? -- nosy: +therve _ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1117670> _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2982] more tests for pyexpat
Thomas Herve <[EMAIL PROTECTED]> added the comment: I attach a first try adding tests for the handlers you mentioned. -- keywords: +patch Added file: http://bugs.python.org/file10483/2922.diff ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2982> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3027] if extended c module is calling Windows API waitForSingleObject, it will block other thread.
Thomas Herve <[EMAIL PROTECTED]> added the comment: You have to release the GIL. See http://docs.python.org/api/threads.html for some information. -- nosy: +therve ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3027> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3051] heapq change breaking compatibility
New submission from Thomas Herve <[EMAIL PROTECTED]>: A recent change in heapq implements it in terms of less-than: http://svn.python.org/view/python/trunk/Modules/_heapqmodule.c?rev=63827&r1=63675&r2=63827 Unfortunately, it breaks usage of heapq when a class only implements __le__ and not __ge__ or __cmp__. This is done this way in Twisted: http://twistedmatrix.com/trac/browser/trunk/twisted/internet/base.py#L159. If not mandatory, it would be nice if this change was reverted or that a backward compatible change was done instead. -- components: Library (Lib) messages: 67765 nosy: therve severity: normal status: open title: heapq change breaking compatibility versions: Python 2.6 ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3051> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3051] heapq change breaking compatibility
Thomas Herve <[EMAIL PROTECTED]> added the comment: Okay then. At least the issue is recorded somewhere, if someone has the same problem. ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3051> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3051] heapq change breaking compatibility
Thomas Herve <[EMAIL PROTECTED]> added the comment: Unfortunately, the modification didn't fix the problem. ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3051> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3051] heapq change breaking compatibility
Thomas Herve <[EMAIL PROTECTED]> added the comment: Yes, the last commit did the trick. Thanks. ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3051> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3051] heapq change breaking compatibility
Thomas Herve <[EMAIL PROTECTED]> added the comment: Sure, that's fine with me. ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3051> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
New submission from Thomas Herve: A new behavior was introduced in r59106 in python trunk, which look suspicious to me. Basically, every time a class defines a comparison operator, it's __hash__ method is defined to None. The simple following example shows it: >>> class A(object): ... def __init__(self, b): ... self.b = b ... def __cmp__(self, other): ... if not isinstance(other, A): ... return -1 ... return cmp(self.b, other.b) ... >>> hash(A(2)) Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not callable The problematic change is here: http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=59106&r1=58032&r2=59106 And mainly the overrides_hash call in inherit_slots. FWIW, I've encounter the problem because zope.interface is now usable on trunk. -- components: Interpreter Core messages: 58124 nosy: therve severity: major status: open title: Regression with __hash__ definition and rich comparison operators type: crash versions: Python 2.6 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: Of course, I meant unusable. -- nosy: +exarkun __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: Also, to be more clear, that happens when you define any of the functions in the name_op array (__lt__, __le___, __gt__, __ge__, ...). It's not just a problem about the object being non hashable. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: There are different ways to fix this. Reverting r59016 is one of them, but I guess it's not an acceptable solution :). >From what I understand of the changes, removing the operations (__lt__, __gt__, __le__, __ge__) from the name_op array would fix this. But I have to understand why they have been put in there in the first place. I'll try tomorrow, you assign this to me if you want. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: I gave it a try. The following patch corrects 2 problems: * classes with only __lt__ and __gt__ defined are hashable * classes defining __eq__ get a meaningful exception. I've restricted the hash_name_op to the bare minimum, but no tests failed, so I supposed it was enough :). Please review. Added file: http://bugs.python.org/file8871/1549_1.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __Index: Objects/typeobject.c === --- Objects/typeobject.c(revision 59318) +++ Objects/typeobject.c(working copy) @@ -3230,14 +3230,8 @@ type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS; } -/* Map rich comparison operators to their __xx__ namesakes */ -static char *name_op[] = { -"__lt__", -"__le__", +static char *hash_name_op[] = { "__eq__", -"__ne__", -"__gt__", -"__ge__", "__cmp__", /* These are only for overrides_hash(): */ "__hash__", @@ -3246,13 +3240,14 @@ static int overrides_hash(PyTypeObject *type) { - int i; + char **p; PyObject *dict = type->tp_dict; assert(dict != NULL); - for (i = 0; i < 8; i++) { - if (PyDict_GetItemString(dict, name_op[i]) != NULL) + for (p = hash_name_op; *p; p++) { + if (PyDict_GetItemString(dict, *p) != NULL) { return 1; +} } return 0; } @@ -4846,7 +4841,7 @@ func = lookup_method(self, "__hash__", &hash_str); - if (func != NULL) { + if (func != NULL && func != Py_None) { PyObject *res = PyEval_CallObject(func, NULL); Py_DECREF(func); if (res == NULL) @@ -4971,6 +4966,15 @@ return 0; } +static char *name_op[] = { +"__lt__", +"__le__", +"__eq__", +"__ne__", +"__gt__", +"__ge__", +}; + static PyObject * half_richcompare(PyObject *self, PyObject *other, int op) { Index: Lib/test/test_richcmp.py === --- Lib/test/test_richcmp.py(revision 59318) +++ Lib/test/test_richcmp.py(working copy) @@ -85,6 +85,35 @@ raise ValueError, "Cannot compare vectors of different length" return other + +class SimpleOrder(object): +""" +A simple class that defines order but not full comparison. +""" + +def __init__(self, value): +self.value = value + +def __lt__(self, other): +if not isinstance(other, SimpleOrder): +return True +return self.value < other.value + +def __gt__(self, other): +if not isinstance(other, SimpleOrder): +return False +return self.value > other.value + + +class DumbEqualityWithoutHash(object): +""" +A class that define __eq__, but no __hash__: it shouldn't be hashable. +""" + +def __eq__(self, other): +return False + + opmap = { "lt": (lambda a,b: a< b, operator.lt, operator.__lt__), "le": (lambda a,b: a<=b, operator.le, operator.__le__), @@ -330,8 +359,39 @@ for op in opmap["lt"]: self.assertIs(op(x, y), True) + +class HashableTest(unittest.TestCase): +""" +Test hashability of classes with rich operators defined. +""" + +def test_simpleOrderHashable(self): +""" +A class that only defines __gt__ and/or __lt__ should be hashable. +""" +a = SimpleOrder(1) +b = SimpleOrder(2) +self.assert_(a < b) +self.assert_(b > a) +self.assert_(a.__hash__ is not None) + +def test_notHashableException(self): +""" +If a class is not hashable, it should raise a TypeError with an +understandable message. +""" +a = DumbEqualityWithoutHash() +try: +hash(a) +except TypeError, e: +self.assertEquals(str(e), + "unhashable type: 'DumbEqualityWithoutHash'") +else: +raise test_support.TestFailed("Should not be here") + + def test_main(): -test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest) +test_support.run_unittest(VectorTest, NumberTest, MiscTest, DictTest, ListTest, HashableTest) if __name__ == "__main__": test_main() ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1552] fromfd() and socketpair() should return wrapped sockets
Thomas Herve added the comment: This is a nice enhancement. I attach a quick patch to add tests for that. -- nosy: +therve Added file: http://bugs.python.org/file8872/1552_test_socket.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1552> __Index: Lib/test/test_socket.py === --- Lib/test/test_socket.py (revision 59319) +++ Lib/test/test_socket.py (working copy) @@ -199,6 +199,8 @@ def setUp(self): self.serv, self.cli = socket.socketpair() +self.assert_(isinstance(self.serv, socket.socket)) +self.assert_(isinstance(self.cli, socket.socket)) def tearDown(self): self.serv.close() @@ -561,6 +563,7 @@ return # On Windows, this doesn't exist fd = self.cli_conn.fileno() sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) +self.assert_(isinstance(sock, socket.socket)) msg = sock.recv(1024) self.assertEqual(msg, MSG) ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1285940] socket intial recv() latency
Thomas Herve added the comment: Can we close this one? -- nosy: +therve _ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1285940> _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1554] [patch] socketmodule cleanups: allow the use of keywords in socket functions
New submission from Thomas Herve: I attach a patch where I use PyArg_ParseTupleAndKeywords in socketmodule where ARGSUSED was mentioned, or removed ARGSUSED if keywords already used. -- components: Library (Lib) files: socket_keywords.diff messages: 58189 nosy: therve severity: normal status: open title: [patch] socketmodule cleanups: allow the use of keywords in socket functions type: rfe versions: Python 2.6 Added file: http://bugs.python.org/file8873/socket_keywords.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1554> __Index: Modules/socketmodule.c === --- Modules/socketmodule.c (revision 59319) +++ Modules/socketmodule.c (working copy) @@ -945,7 +945,6 @@ The family field of the sockaddr structure is inspected to determine what kind of address it really is. */ -/*ARGSUSED*/ static PyObject * makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) { @@ -2817,7 +2816,6 @@ /* Initialize a new socket object. */ -/*ARGSUSED*/ static int sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) { @@ -2898,9 +2896,8 @@ /* Python interface to gethostname(). */ -/*ARGSUSED*/ static PyObject * -socket_gethostname(PyObject *self, PyObject *unused) +socket_gethostname(PyObject *self) { char buf[1024]; int res; @@ -2921,14 +2918,15 @@ /* Python interface to gethostbyname(name). */ -/*ARGSUSED*/ static PyObject * -socket_gethostbyname(PyObject *self, PyObject *args) +socket_gethostbyname(PyObject *self, PyObject *args, PyObject *kwds) { char *name; sock_addr_t addrbuf; - if (!PyArg_ParseTuple(args, "s:gethostbyname", &name)) + static char *keywords[] = {"host", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyname", keywords, &name)) return NULL; if (setipaddr(name, SAS2SA(&addrbuf), sizeof(addrbuf), AF_INET) < 0) return NULL; @@ -3080,9 +3078,8 @@ /* Python interface to gethostbyname_ex(name). */ -/*ARGSUSED*/ static PyObject * -socket_gethostbyname_ex(PyObject *self, PyObject *args) +socket_gethostbyname_ex(PyObject *self, PyObject *args, PyObject *kwds) { char *name; struct hostent *h; @@ -3107,7 +3104,9 @@ #endif #endif /* HAVE_GETHOSTBYNAME_R */ - if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name)) + static char *keywords[] = {"host", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyname_ex", keywords, &name)) return NULL; if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), AF_INET) < 0) return NULL; @@ -3152,9 +3151,8 @@ /* Python interface to gethostbyaddr(IP). */ -/*ARGSUSED*/ static PyObject * -socket_gethostbyaddr(PyObject *self, PyObject *args) +socket_gethostbyaddr(PyObject *self, PyObject *args, PyObject *kwds) { #ifdef ENABLE_IPV6 struct sockaddr_storage addr; @@ -3182,7 +3180,9 @@ int al; int af; - if (!PyArg_ParseTuple(args, "s:gethostbyaddr", &ip_num)) + static char *keywords[] = {"host", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyaddr", keywords, &ip_num)) return NULL; af = AF_UNSPEC; if (setipaddr(ip_num, sa, sizeof(addr), af) < 0) @@ -3244,13 +3244,15 @@ This only returns the port number, since the other info is already known or not useful (like the list of aliases). */ -/*ARGSUSED*/ static PyObject * -socket_getservbyname(PyObject *self, PyObject *args) +socket_getservbyname(PyObject *self, PyObject *args, PyObject *kwds) { char *name, *proto=NULL; struct servent *sp; - if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)) + + static char *keywords[] = {"servicename", "protocolname", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s:getservbyname", keywords, &name, &proto)) return NULL; Py_BEGIN_ALLOW_THREADS sp = getservbyname(name, proto); @@ -3274,14 +3276,16 @@ This only returns the service name, since the other info is already known or not useful (like the list of aliases). */ -/*ARGSUSED*/ static PyObject * -socket_getservbyport(PyObject *self, PyObject *args) +socket_getservbyport(PyObject *self, PyObject *args, PyObject *kwds) { unsigned short port; char *proto=NULL; struct servent *sp; - if (!PyArg_ParseTuple(args, "H|s:getservbyport", &port, &proto)) + + static char *keywords[] = {"servicename", "protocolname", NULL}; + + if (!PyArg_
[issue1554] [patch] socketmodule cleanups: allow the use of keywords in socket functions
Thomas Herve added the comment: It's not really for solving a problem, it's an enhancement to allow the functions to be called with keyword parameters. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1554> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1554] [patch] socketmodule cleanups: allow the use of keywords in socket functions
Thomas Herve added the comment: Alright I'll add tests to the modified functions. I don't think I have to change documentation because I kept the same name for the parameters, but I'll check. Looking at the patch more, maybe it doesn't make sense on the functions taking only one parameter though :). I'll probably remove that. Regarding ARGSUSED, I thought it was here to note functions using PyArg_ParseTuple instead of PyArg_ParseTupleAndKeywords, but looking at the svn history it seems wrong. I can put it back if there is another semantic. For METH_NOARGS, do you have a pointer to explain that? http://docs.python.org/ext/node22.html, for example, show an example of METH_NOARGS with a function without arguments. Does that have other incidence? __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1554> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1326] "internal" zipimport.zipimporter feature untested
Thomas Herve added the comment: I attach a patch adding a test and some documentation. This tries to solve issue1325 too. exarkun, does that fulfill your original request? -- nosy: +therve Added file: http://bugs.python.org/file8877/1326.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1326> __Index: Doc/library/zipimport.rst === --- Doc/library/zipimport.rst (revision 59333) +++ Doc/library/zipimport.rst (working copy) @@ -71,11 +71,20 @@ .. class:: zipimporter(archivepath) - Create a new zipimporter instance. *archivepath* must be a path to a zipfile. + Create a new zipimporter instance. *archivepath* must be a path to a + zipfile, or to a specific path inside a zipfile. For example, it can be + */tmp/myimport.zip*, or */tmp/myimport.zip/mydirectory*, if mydirectory is a + valid directory inside the archive. + :exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP archive. +.. attribute:: zimporter.archive + + The name of the zipfile targeted, without the subpath (read-only). + + .. method:: zipimporter.find_module(fullname[, path]) Search for a module specified by *fullname*. *fullname* must be the fully Index: Lib/test/test_zipimport.py === --- Lib/test/test_zipimport.py (revision 59333) +++ Lib/test/test_zipimport.py (working copy) @@ -212,6 +212,7 @@ z.close() zi = zipimport.zipimporter(TEMP_ZIP) +self.assertEquals(zi.archive, TEMP_ZIP) self.assertEquals(zi.is_package(TESTPACK), True) zi.load_module(TESTPACK) @@ -227,6 +228,36 @@ z.close() os.remove(TEMP_ZIP) +def testZipImporterMethodsInSubDirectory(self): +packdir = TESTPACK + os.sep +packdir2 = packdir + TESTPACK2 + os.sep +files = {packdir2 + "__init__" + pyc_ext: (NOW, test_pyc), + packdir2 + TESTMOD + pyc_ext: (NOW, test_pyc)} + +z = ZipFile(TEMP_ZIP, "w") +try: +for name, (mtime, data) in files.items(): +zinfo = ZipInfo(name, time.localtime(mtime)) +zinfo.compress_type = self.compression +z.writestr(zinfo, data) +z.close() + +zi = zipimport.zipimporter(TEMP_ZIP + os.sep + packdir) +self.assertEquals(zi.archive, TEMP_ZIP) +self.assertEquals(zi.is_package(TESTPACK2), True) +zi.load_module(TESTPACK2) + +self.assertEquals(zi.is_package(TESTPACK2 + os.sep + '__init__'), False) +self.assertEquals(zi.is_package(TESTPACK2 + os.sep + TESTMOD), False) + +mod_name = TESTPACK2 + os.sep + TESTMOD +mod = __import__(module_path_to_dotted_name(mod_name)) +self.assertEquals(zi.get_source(TESTPACK2), None) +self.assertEquals(zi.get_source(mod_name), None) +finally: +z.close() +os.remove(TEMP_ZIP) + def testGetData(self): z = ZipFile(TEMP_ZIP, "w") z.compression = self.compression Index: Modules/zipimport.c === --- Modules/zipimport.c (revision 59333) +++ Modules/zipimport.c (working copy) @@ -555,8 +555,15 @@ "zipimporter(archivepath) -> zipimporter object\n\ \n\ Create a new zipimporter instance. 'archivepath' must be a path to\n\ -a zipfile. ZipImportError is raised if 'archivepath' doesn't point to\n\ -a valid Zip archive."); +a zipfile, or to a specific path inside a zipfile. For example, it can be\n\ +'/tmp/myimport.zip', or '/tmp/myimport.zip/mydirectory', if mydirectory is a\n\ +valid directory inside the archive.\n\ +\n\ +'ZipImportError is raised if 'archivepath' doesn't point to a valid Zip\n\ +archive.\n\ +\n\ +The 'archive' attribute of zipimporter is a read-only copy of the\n\ +name of the zipfile targeted."); #define DEFERRED_ADDRESS(ADDR) 0 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1326] "internal" zipimport.zipimporter feature untested
Thomas Herve added the comment: The patch is against trunk. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1326> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1554] [patch] socketmodule cleanups: allow the use of keywords in socket functions
Thomas Herve added the comment: Here it is. There were several functions which didn't have any tests at all, so I had to create some. These tests are likely to fail on some platforms (like windows), but I didn't get any machine to test. Added file: http://bugs.python.org/file8878/socket_keywords_2.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1554> __Index: Lib/test/test_socket.py === --- Lib/test/test_socket.py (revision 59346) +++ Lib/test/test_socket.py (working copy) @@ -275,7 +275,66 @@ fqhn = socket.getfqdn(ip) if not fqhn in all_host_names: self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) +# Try call by named argument +ip2 = socket.gethostbyname(host=hostname) +self.assertEquals(ip, ip2) + +result2 = socket.gethostbyaddr(host=ip) +self.assertEquals((hname, aliases, ipaddrs), result2) +def testGetHostByNameEx(self): +hostname = socket.gethostname() +try: +hostname, aliaslist, iplist = socket.gethostbyname_ex(hostname) +except socket.error: +# Probably name lookup wasn't set up right; skip this test +return +for ip in iplist: +self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") +# Try call by named argument +result2 = socket.gethostbyname_ex(host=hostname) +self.assertEquals((hostname, aliaslist, iplist), result2) + +def testGetAddrInfo(self): +# Find one service that exists, then check all the related interfaces. +# I've ordered this by protocols that have both a tcp and udp +# protocol, at least for modern Linuxes. +if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6', +'freebsd7', 'freebsd8', 'darwin'): +# avoid the 'echo' service on this platform, as there is an +# assumption breaking non-standard port/protocol entry +services = ('daytime', 'qotd', 'domain') +else: +services = ('echo', 'daytime', 'domain') +for service in services: +try: +port = socket.getservbyname(service, 'tcp') +break +except socket.error: +pass +else: +raise socket.error + +hostname = socket.gethostname() +result = socket.getaddrinfo(hostname, service) +self.assert_(len(result) > 1) +result = result[0] +self.assertEquals(result[0], socket.AF_INET) +ip = result[4][0] +# It should be a valid ip address +self.assert_(len(socket.inet_aton(ip)) > 0) +port2 = result[4][1] +self.assertEquals(port, port2) + +def testGetNameInfo(self): +hostname = socket.gethostname() +host, port = socket.getnameinfo((hostname, 1234), 0) +self.assertEquals(port, '1234') + +# Try with named parameters +result2 = socket.getnameinfo(sockaddr=(hostname, 1234), flags=0) +self.assertEquals((host, port), result2) + def testRefCountGetNameInfo(self): # Testing reference count for getnameinfo import sys @@ -347,6 +406,10 @@ # Try same call with optional protocol omitted port2 = socket.getservbyname(service) eq(port, port2) +# Try same call with named arguments +port3 = socket.getservbyname(servicename=service, protocolname='tcp') +eq(port, port3) + # Try udp, but don't barf it it doesn't exist try: udpport = socket.getservbyname(service, 'udp') @@ -357,6 +420,8 @@ # Now make sure the lookup by port returns the same service name eq(socket.getservbyport(port2), service) eq(socket.getservbyport(port, 'tcp'), service) +# Try same call with named arguments +eq(socket.getservbyport(port=port, protocolname='tcp'), service) if udpport is not None: eq(socket.getservbyport(udpport, 'udp'), service) @@ -567,6 +632,19 @@ def _testFromFd(self): self.serv_conn.send(MSG) +def testFromFdNamedArguments(self): +# Testing fromfd() +if not hasattr(socket, "fromfd"): +return # On Windows, this doesn't exist +fd = self.cli_conn.fileno() +sock = socket.fromfd(fd=fd, family=socket.AF_INET, + type=socket.SOCK_STREAM) +msg = sock.recv(1024) +
[issue1336] subprocess.Popen hangs when child writes to stderr
Thomas Herve added the comment: FWIW, we encountered roughly the same problem in Twisted. However, we fixed it by disabling gc *before* fork, because the gc can occur just after the fork. See http://twistedmatrix.com/trac/ticket/2483 for the bug report, and http://twistedmatrix.com/trac/changeset/21686 for the solution. -- nosy: +therve __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1336> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1625] bz2.BZ2File doesn't support multiple streams
New submission from Thomas Herve: The BZ2File class only supports one stream per file. It possible to have multiple streams concatenated in one file, it the resulting data should be the concatenation of all the streams. It's what the bunzip2 program produces, for example. It's also supported by the gzip module. Once this done, this would add the ability to open a file for appending, by adding another stream to the file. I'll probably try to do this, but the fact it's done in C (unlike gzip) makes it harder, so if someone beats me to it, etc. -- components: Library (Lib) messages: 58619 nosy: therve severity: normal status: open title: bz2.BZ2File doesn't support multiple streams type: rfe versions: Python 2.6 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1625> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] select.epoll wrapper for Linux 2.6 epoll()
Thomas Herve added the comment: Cool, thanks for working on that. Just for the record, I don't really understand the workflow: why closing the other ticket as duplicate and not post the patch on the old one? But whatever. For this patch, I don't see the benefit of putting it in the select module, instead of a separate module. Is there a specific reason? Looking at the code, I don't have many remarks. pyepoll_new may leak if epoll_create fails. I think that allowing threading around epoll_ctl is useless, but I may be wrong. Thanks again for working on it. -- nosy: +therve __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: This is probably not the best moment (holidays etc), but please take this issue seriously. This problem completely block the community builders at pybots.org, and make any tests on current python trunk impossible. This also means that if in the meantime another regression appear, it will be even more difficult to solve it afterwards. Also, zope is not the only one affected, storm seems to suffer from the problem too (not exacly the same, though). As twisted is also unusable without zope.interface, that makes several project that can't follow python developpement at all (zope.interface error happens at import time, for the record). If this problem isn't solved in a reasonable time, it really questions the future of the community builders and their purpose. Thanks. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1549] Regression with __hash__ definition and rich comparison operators
Thomas Herve added the comment: Thanks a lot! __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1549> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: Some remarks: * the name of the function used for PyArg_ParseTupleAndKeywords in register, modify, unregister is set to control instead of the good name. * there is a leak in pyepoll_new if the parsing of arguments fails. * the indentation is sometimes tabs, sometimes spaces. That should be good to unify this (to tabs I guess, since the select module used tabs before). * it seems there is an unrelated change in sunau.py * I don't think the stdlib unittest module has skip support. You have to find another way to skip the tests if the modules aren't present. I've been able to port the epollreactor to your implementation and run the whole twisted tests with it, so I don't think there are outstanding problems. The code is fairly simple anyway. That's it for epoll and general remarks. I'll look at kqueue asap. Thanks! __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: Here I go for kqueue: * the docstring of test_kqueue.py is wrong * the tests are a bit light. It would be good the have a test like test_control_and_wait in test_epoll. * the kqueue_queue_control (and the pyepoll_poll) are now completely wrong! You should not limit to FD_SETSIZE, these 2 systems are there because they're able to handle for fds than that. Also, this buffer thing looks like a premature optimization. I'm unable to tell if it's correct or not. * the NETDEV and related flags aren't defined under OS X 10.4. I guess there are flags for freebsd, but kqueue should build on OS X too. I've been able to use this module for the twisted reactor, so the functionality is OK. But thsi FD_SETSIZE limit is a huge problem. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Changes by Thomas Herve: Added file: http://bugs.python.org/file9020/test_kqueue.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: I attached a patch with a more complete test of kqueue. It's not that great, but it's a thing. I've only tested on OS X, but it works. Regarding the ability of building an epoll object from a fd, it might be usefull in some corner cases, but that's not a priority. exarkun looked at the patch and told me that there may be some threadsafety issues: for example, when calling epoll_wait, you use self->evs unprotected. It's not very important, but you may want to tell it in the documentation. As you started the rich comparison for kevent objects, it may be interesting to have full comparison (to sort list of events). It's not a high priority though. That's all for now! __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: > What do you suggest as sort criteria? The natural sort of the tuple you used for equality, I'd say. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: You have to use sys.platform to get 'darwin', not os.name. The rest of the test seems good. I didn't spot the check of EEXIST in pyepoll_internal_ctl, I'm not sure it's a good idea. I understand it's for being able to only use register, but it's not the way it's meant to be used. At least, there should be a test for it. Your example in kqueue_queue_doc doesn't work: * it uses KQ_ADD instead of KQ_EV_ADD * on OS X, you can't use kqueue on stdin * it uses KQ_DELETE instead of KQ_EV_DELETE Maybe an example on an arbitrary fd would be better. FWIW, I would have prefer to review epoll wrapper first, then kqueue. Splitting functionalities makes it easier to review. But that will be great to have that in python :). __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1625] bz2.BZ2File doesn't support multiple streams
Thomas Herve added the comment: The gzip module supports reopening an existing file to add another stream. I think the bz2 module should not the same. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1625> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2111] mmap segfaults when trying to write a block opened with PROT_READ
New submission from Thomas Herve: Basically, the write method of mmap objects check the state with is_writable, which check the writability with the access attributes. But the mmap object can be opened correctly specifying the rights with prot=mmap.PROt_READ. Attached patch corrects the problem by setting access to ACCESS_READ with prot is set to PROT_READ, with a test. -- components: Library (Lib) files: mmap.diff messages: 62390 nosy: therve severity: normal status: open title: mmap segfaults when trying to write a block opened with PROT_READ type: crash versions: Python 2.6 Added file: http://bugs.python.org/file9429/mmap.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2111> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2112] mmap.error should be a subclass of EnvironmentError and not a direct EnvironmentError
New submission from Thomas Herve: mmap.error in mmapmodule is a direct reference to PyExc_EnvironmentError, whereas it should be a subclass. It makes it provide a specific string representation, and allows to be more specific when catching exceptions. The attached patch tries to provide that. -- components: Library (Lib) files: mmap2.diff messages: 62391 nosy: therve severity: normal status: open title: mmap.error should be a subclass of EnvironmentError and not a direct EnvironmentError type: rfe versions: Python 2.6 Added file: http://bugs.python.org/file9430/mmap2.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2112> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2165] Fix for test_logging
New submission from Thomas Herve: The attached patch fixes the test_logging failure on my machine. Please review. -- components: Tests files: test_logging.diff messages: 62727 nosy: therve severity: normal status: open title: Fix for test_logging versions: Python 2.6 Added file: http://bugs.python.org/file9493/test_logging.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2165> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2168] gdbm needs to be iterable
New submission from Thomas Herve: A recent change in shelve (r60927) raises the need for gdbm objects to be iterable. We can see it by running test_shelve on a machine with gdbm. I'll try to fix this. The same thing should be done with the dbm module I think. -- components: Library (Lib) messages: 62749 nosy: therve severity: normal status: open title: gdbm needs to be iterable versions: Python 2.6 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2168> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2168] gdbm needs to be iterable
Changes by Thomas Herve: -- keywords: +patch Added file: http://bugs.python.org/file9531/dbm.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2168> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2168] gdbm needs to be iterable
Changes by Thomas Herve: Added file: http://bugs.python.org/file9532/gdbm.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2168> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2168] gdbm needs to be iterable
Thomas Herve added the comment: Attached files add contains method to dbm and gdbm objects. It fixes failures with test_shelve. I'm ready to add more tests for this, but #1960 should probably go in first (it converts the tests to unittest, and add some coverage). Please review! __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2168> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2177] Update compiler module to handle class decorators
New submission from Thomas Herve: The attached patch (tries to?) updates compiler to handle class decorators, and also to handle the new way decorated function are handled. I had a weird bug because it seems that ast.py was modified at hand last time (r51330). This fixes the recent failures in the buildbot slaves. Please review! -- components: Library (Lib) files: compiler.diff keywords: patch messages: 62915 nosy: therve severity: normal status: open title: Update compiler module to handle class decorators versions: Python 2.6 Added file: http://bugs.python.org/file9538/compiler.diff __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2177> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1740] use unittest for test_logging
Thomas Herve added the comment: I have just one comment: I have recently modified the initialization of LogRecordSocketReceiver to not use a stupid loop to get a free port, but instead use port 0 and get the port number once bound. I think this modification should stay. -- nosy: +therve __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1740> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1657] [patch] epoll and kqueue wrappers for the select module
Thomas Herve added the comment: Is there a chance for this go in the first alpha? FWIW, I've tested it with twisted kqueue and epoll reactors, and didn't get any problems. There are still 2 typos in the patch: KQ_ADD is used 2 times in the docs instead of KQ_EV_ADD. Everything else looks good to me. __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue1657> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2760] Recent change in socket.py breaks urllib2
New submission from Thomas Herve <[EMAIL PROTECTED]>: The problematic change is here: http://svn.python.org/view/python/trunk/Lib/socket.py?rev=62627&r1=61008&r2=62627 The following script shows the problem: Python 2.6a2+ (trunk:62707, May 4 2008, 19:13:44) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib2 >>> r = urllib2.Request('http://pypi.python.org/simple') >>> f = urllib2.urlopen(r) >>> f.read() Traceback (most recent call last): File "", line 1, in File "/home/therve/.local/lib/python2.6/socket.py", line 326, in read data = self._sock.recv(rbufsize) File "/home/therve/.local/lib/python2.6/httplib.py", line 512, in read return self._read_chunked(amt) File "/home/therve/.local/lib/python2.6/httplib.py", line 548, in _read_chunked line = self.fp.readline() File "/home/therve/.local/lib/python2.6/socket.py", line 391, in readline assert buf.tell() == 0 AssertionError >>> -- components: Library (Lib) messages: 66222 nosy: therve severity: normal status: open title: Recent change in socket.py breaks urllib2 versions: Python 2.6 __ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2760> __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6560] socket sendmsg(), recvmsg() methods
Thomas Herve added the comment: This is a duplicate (although updated patch) from bug #1194378. It would still need unit tests... -- nosy: +therve ___ Python tracker <http://bugs.python.org/issue6560> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com