[ANN] PyYAML-3.07: YAML parser and emitter for Python
Announcing PyYAML-3.07 A new release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML Changes === * The emitter learned to use an optional indentation indicator for block scalars; thus scalars with leading whitespaces could now be represented in a literal or folded style. * The test suite is now included in the source distribution. To run the tests, type 'python setup.py test'. * Refactored the test suite: dropped unittest in favor of a custom test appliance. * Fixed the path resolver in the LibYAML-based dumper. * Forced an explicit document end indicator when there is a possibility of parsing ambiguity. * More setup.py improvements: the package should be usable when any combination of setuptools, Pyrex and LibYAML is installed. * Windows binary packages are statically linked against LibYAML-0.1.2. * Other minor fixes and improvements (Thank to Ingy dot Net and Andrey Somov). Resources = PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.07.tar.gz ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.07.zip Windows installer: http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.3.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.4.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.5.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.6.exe PyYAML SVN repository: http://svn.pyyaml.org/pyyaml Submit a bug report: http://pyyaml.org/newticket?component=pyyaml YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example === import yaml yaml.load( ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: http://pyyaml.org/wiki/PyYAML ... keywords: [YAML, serialization, configuration, persistance, pickle] ... ) {'keywords': ['YAML', 'serialization', 'configuration', 'persistance', 'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} print yaml.dump(_) name: PyYAML homepage: http://pyyaml.org/wiki/PyYAML description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistance, pickle] Copyright = The PyYAML module is written by Kirill Simonov x...@resolvent.net. PyYAML is released under the MIT license. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: math module for Decimals
On Sat, 27 Dec 2008 21:50:09 -0800, jerry.carl.mi wrote: Which math functions? ln, log10, exp, sqrt already exist as methods of Decimal instances. At the end of the Decimal docs there are a few examples, including computing sin and cos (but apparently they naïvely use a McLaurin series like you noticed in other module). Hi Gabriel - thanks! For example all goniometric functions are missing. As my earlier email suggested, the easiest way to fix that is to simply write some wrappers that convert floats to decimal. Of course, that assumes that you don't need more precision than floats offer -- it's easy to change the result to get less precision, but if you really do need more, then you will need to bite the bullet and find (or write) your own trigonometric functions. Or the log(x, base). Easy peasey. def log(x, base): ... return x.log10()/Decimal(base).log10() ... log(Decimal(64), 2) Decimal('5.999') If that's not accurate enough, you will need to do some additional work: def log(x, base): # Warning: INSUFFICIENTLY TESTED ... power = 1 ... while base**power = x: ... power += 1 ... power -= 1 ... x = x/Decimal(base**power) ... return x.log10()/Decimal(base).log10() + power ... log(Decimal(64), 2) Decimal('6') Or rand(). Generating random numbers is an art in of itself. Again, unless you really need the extra precision, just convert the random number to a string, then the string to a Decimal. An alternative is to find one of the many, many published algorithms for generating random numbers, and re-write that to use Decimals. However, most such algorithms aren't very random; they only give you a little bit of randomness, and increasing the precision of the numbers they return doesn't make them any more random. Sure I can spend time trying to put it all together but I thought somebody would have done that already. I believe they're all waiting for you to do it *wink* Development of Python is driven by need. If you need something, you can make a feature request, or you can build it yourself. But if everyone sits around hoping somebody else will develop the feature, nothing will ever happen. It seems though that the codes that are out there are not ready Not ready for what? Perhaps they are perfectly ready for the needs of the person who wrote them. - every one of the modules i mentioned above has some issues. Maybe I can put bits and pieces together, but if anyone knows of a well proven module (as is), I would feel much safer using that (again I am not a mathematician and poking into these algorithms makes me feel like trying to fix an automatic transmission). Decimal is a relatively new module for Python, so it's not surprising that the functionality is relatively light. But all the hard parts are done. If you need extra functionality, you have a number of choices: (1) Find another way to solve your problem, or lower your expectations. (e.g. do you need arbitrary precision?) (2) Build the extra functionality yourself. (3) Pay somebody who is an expert to build it. (4) Ask nicely and hope somebody eventually decides to build it. (5) Use another language that already provides exactly all the features your problem needs. All of these are valid strategies. Unfortunately, a very popular strategy is counter-productive: (6) Complain loudly that Python is rubbish because it doesn't have the functionality you need, and Somebody Better Fix That RIGHT NOW or else there will be trouble you betcha. I recommend against strategy number six :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help getting MoinMoin to run under WSGI
In article rnospamon-79fa22.21571527122...@news.gha.chartermi.net, Ron Garret rnospa...@flownet.com wrote: I successfully installed MoinMoin as a CGI according to the instructions on the moinmo.in site. But when I tried to switch over to running it under wsgi it failed thusly: [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] Traceback (most recent call last): [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] File /www/wikis/genesisgroup/moin.wsgi, line 49, in ? [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] ImportError: No module named MoinMoin.server.server_wsgi The problem, I believe, is that I have both Python 2.4 and 2.5 installed (it's a Debian box) and MM is installed under 2.5 but WSGI is using 2.4. I tried to fix this by setting WSGIPythonHome but to no avail. I can't figure out what to set it to. The instructions say: the WSGIPythonHome directive should be used to specify the exact location of the Python installation corresponding to the version of Python compiled against I have two problems with this. First, I didn't compile mod_wsgi, I got it pre-built as a Debian module. Second, what does the exact location of the Python installation even mean? Python2.5 is spread out in at least three different places: /usr/local/bin, /usr/lib/python2.5, and /usr/local/lib/python2.5. I've tried setting WSGIPythonHome to all of those (and a few other things as well) and nothing worked. Also, the version of Python compiled against seems very odd. What does that mean? Surely I don't have to recompile mod_wsgi every time I change to a new version of Python? Help! Thanks! rg So never mind, I figured it out. I did indeed have to recompile mod_wsgi from source to get it to use Python 2.5. (That turned out to be a major hassle. I had to do it twice. The first time through it made Apache dump core. I still don't know why.) Seems to be working now though. rg -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
janislaw napsal(a): Um, I could be only guessing what are you meant to do, unless you describe your problem in more detailed way. I.e. describe the desired behaviour, show code which you have, and describe the current behaviour. well, I am working on a tutorial for youngster (thats why i need to stay the code as easy as possible). In this game you are hunted by robots. I could use key7 on numeric keypad for left-up moving but seems to me, that 4+8 is much more standard for them. This solution has disadvantage that after you release one key, that the function keyPressHandler stopped to be called by the other pressed keys. I would have not to build moving the player in KeyPresshandler, but on another new function that would have to read periodically keys and to act afterwards Hmmm. Maybe you'd like to hook into Tkinter event loop, i.e. by custom events if you don't like periodical polling. No, that would be even more difficult. I already have a code that use your idea: from Tkinter import * root = Tk() pressedKeys=set() def onKeyPress(event): pressedKeys.add(event.keysym) def onKeyRelease(event): pressedKeys.remove(event.keysym) def move(): print list(pressedKeys) root.after(100,move) root.bind(KeyPress, onKeyPress) root.bind(KeyRelease, onKeyRelease) root.after(100,move) root.mainloop() well, I thought that gui´s have such a problem already built-in - so that i am not pressed to code it. You know, its not exactly about me - if I do it for myself, for my program, that there is no problem, but I need to explained it to begginners . And I do not want, as might be more usual, do my module, that would cover this insanity (look at it with 13-years old boy eyes ;-) ). Do you like to say me, that this is not a standard function neither in tkinter, not say gtk or the others, too? I would expect something like this: def onKeyTouch(event): print (event.keysymAll) root.bind(KeyPress, onKeyTouch) and all the pressed keys are printed all the functions OnKeyPress, OnKeyRelease, move, even set pressedKeys are in onKeyTouch P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Doing set operation on non-hashable objects
... db is a dict, where the values are also dicts. A function searches through db and returns a list of values, each of which is a dict as described above. I need to perform set operations on these lists (intersection and union) However the objects themselves are not hashable, and therefore can't be in a set, because they are dicts. I'm not sure how large each set will be, but the point is I'm trying to avoid anything looking like an O(n^2) algorithm, so I can't just use naive double-looping to check for intersection/union on a pair of lists. Well, if the lists are ordered, you can do intersection and union in O(n) time. If they are orderable, you can sort each first, giving O(n log n). Note you can do lst.sort(key=id) which will sort on ids. The lists are not ordered, since the elements of the list could be arbitrarily complex things consisting of resistors, capacitors, sub- circuits, etc. I'm trying do a little EDA program, taking the best parts from the different EDA/cad tools I've used. I finally came up with an idea using dictionaries in a certain way, so I'd like to be able to do set operators on arbitrary things that may themselves not be hashable. How do you get the object back from an ID in python? You don't; you remember the mapping in a dictionary and look it up. Exactly. A mapping between the ID and the thing itself. If there were a way to go from id to object, the whole idea of garbage collection and reference counts would fly out the window, leading to nasty crashes (or you might get to an object that is the re-used id of an older object). Yup, this makes perfect sense. It was rattling around in my head for a bit afer I wrote the original post, then this makes sense. -- http://mail.python.org/mailman/listinfo/python-list
Re: Doing set operation on non-hashable objects
On Dec 24, 12:21 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 24 Dec 2008 17:16:59 -0200, 5lvqbw...@sneakemail.com escribió: I'm writing an application which is structured roughly as follows: db is a dict, where the values are also dicts. A function searches through db and returns a list of values, each of which is a dict as described above. I need to perform set operations on these lists (intersection and union) However the objects themselves are not hashable, and therefore can't be in a set, because they are dicts. If you *only* care about object identity, you might use a dictionary that only compares by identity to anyone else: class nc_dict(dict): A hashable dictionary that isn't equal to anyone else def __eq__(self, other): return cmp(id(self),id(other))==0 def __hash__(self): return hash(id(self)) d1 = nc_dict(a=1, b=2, c=3) d2 = nc_dict(b=2, c=0, d=4) d3 = nc_dict(a=1, c=3, e=5) dd1 = nc_dict(x=d1, y=d2) dd2 = nc_dict(x=d1, y=d3) dd3 = nc_dict(y=d2, z=d3, w=d1) l1 = [dd1, dd2] l2 = [dd2, dd3] s1 = set(l1) s2 = set(l2) print s1-s2 print s2-s1 print s1s2 # instances of nc_dict with the same contents are NOT equal d4 = nc_dict(a=1, b=2, c=3) print d1, d4, d1==d4 # output: False # but we can use this function to compare contents def cmp_contents(d1, d2): try: return cmp(sorted(d1.items()), sorted(d2.items())) except Exception: return 1 # assume they're unequal print cmp_contents(d1,d4)==0 # output: True Good idea. I'll try this out. I don't think it's likely that I'll have a case where the dicts have identical values, but different identities. And if they do I probably don't care too much. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help getting MoinMoin to run under WSGI
On Dec 28, 7:22 pm, Ron Garret rnospa...@flownet.com wrote: In article rnospamon-79fa22.21571527122...@news.gha.chartermi.net, Ron Garret rnospa...@flownet.com wrote: I successfully installed MoinMoin as a CGI according to the instructions on the moinmo.in site. But when I tried to switch over to running it under wsgi it failed thusly: [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] Traceback (most recent call last): [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] File /www/wikis/genesisgroup/moin.wsgi, line 49, in ? [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] ImportError: No module named MoinMoin.server.server_wsgi The problem, I believe, is that I have both Python 2.4 and 2.5 installed (it's a Debian box) and MM is installed under 2.5 but WSGI is using 2.4. I tried to fix this by setting WSGIPythonHome but to no avail. I can't figure out what to set it to. The instructions say: the WSGIPythonHome directive should be used to specify the exact location of the Python installation corresponding to the version of Python compiled against I have two problems with this. First, I didn't compilemod_wsgi, I got it pre-built as a Debian module. Second, what does the exact location of the Python installation even mean? Python2.5 is spread out in at least three different places: /usr/local/bin, /usr/lib/python2.5, and /usr/local/lib/python2.5. I've tried setting WSGIPythonHome to all of those (and a few other things as well) and nothing worked. Also, the version of Python compiled against seems very odd. What does that mean? Surely I don't have to recompilemod_wsgievery time I change to a new version of Python? Help! Thanks! rg So never mind, I figured it out. I did indeed have to recompilemod_wsgifrom source to get it to use Python 2.5. (That turned out to be a major hassle. I had to do it twice. The first time through it made Apache dump core. I still don't know why.) Seems to be working now though. It probably crashed the first time because you didn't do a full stop of Apache and instead just did a reload. Doing a reload may not unload the Python libraries from Apache process correctly and so would have been a mix of code for different versions of Python in same process. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout.write()'s bug or doc bug?
On Dec 27, 12:31 am, Martin mar...@marcher.name wrote: Python 2.4.4 (#2, Oct 22 2008, 19:52:44) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type help, copyright, credits or license for more information. u = u\u554a print u 啊 sys.stdout.write(u + \n) Traceback (most recent call last): File stdin, line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in position 0: ordinal not in range(128) # you are trying to write unicode, you need to encode it to something that suits your needs sys.stdout.write(u.encode(UTF-8) + \n) 啊 # now go and write a hundred times Unicode is not an encoding :) Actually, I know relationship between unicode and str objects very well. That's why I only quoted the unicode-related part of file.encoding's documentation in my original post. Thank you. So, my question is, as sys.stdout IS a file object, why it does not use its encoding attribute to convert the given unicode? An implementation bug? A documenation bug? hmm I always thought sys.stdout is a file-like object not that it IS a file. In my original post, I have figured out that sys.stdout IS a file, by using type() function. And isinstance() function tells the same: Python 2.5.2 (r252:60911, Dec 18 2008, 12:39:19) [GCC 4.2.1 (Apple Inc. build 5564)] on darwin Type help, copyright, credits or license for more information. import sys type(sys.stdout) is file True isinstance(sys.stdout, file) True So, sys.stdout SHOULD do what the doc says, otherwise there is a bug either in implementation of sys.stdout, or in the documentation of file. -- http://mail.python.org/mailman/listinfo/python-list
Re: assignment with [:]
Ben Bush wrote: On Dec 26, 4:46 pm, Tim Chase python.l...@tim.thechases.com wrote: What does *not* work is 3 * [0,1,2] As you know, this gives [0,1,2,0,1,2,0,1,2] What I am hoping for is [0,3,6] I see that I can use numpy.multiply(3,range(3)) but this seems overkill to me. Can you tell I am coming to Python from Matlab? The common way to do this is just a1 = [0,1,2] a2 = [x * 3 for x in a1] or, if you need a1 to be done in place: a1[:] = [x*3 for x in a1] There is some subtlety here. The latter says to empty the list assigned to the name a1 and refill it with the products. Other references to the same list will now reflect this operation. This procedure is not equivalent to reassigning the name a1. For example: py a = [1, 2, 3] py a1 = a py a1[:] = [x*3 for x in a1] py a1 [3, 6, 9] py a1 [3, 6, 9] Whereas: py a = [1, 2, 3] py a1 = a py a1 [1, 2, 3] py a1 = [x*3 for x in a1] py a1 [3, 6, 9] py a [1, 2, 3] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: assignment with [:]
James Stroud wrote: py a = [1, 2, 3] py a1 = a py a1[:] = [x*3 for x in a1] py a1 [3, 6, 9] py a1 [3, 6, 9] This should have been: py a = [1, 2, 3] py a1 = a py a1[:] = [x*3 for x in a1] py a [3, 6, 9] py a1 [3, 6, 9] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes strings
Gabriel Genellina gagsl-...@yahoo.com.ar wrote: Hmmm, I don't think posting a potentially harmful example is actually a good idea... True - its my only example though, and nobody else was bothering to reply, so I kicked off and flushed out some response. Who was it that said that the way to get info out of usenet was to post some rubbish? :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
What is site-packages?
Hey, What is /usr/lib/pythonx.y/site-packages folder and for what it is used usually? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is site-packages?
On Sun, Dec 28, 2008 at 3:40 AM, Hussein B hubaghd...@gmail.com wrote: Hey, What is /usr/lib/pythonx.y/site-packages folder and for what it is used usually? I believe it's where third-party libraries are typically installed to. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is site-packages?
On Dec 28, 2:04 pm, Chris Rebert c...@rebertia.com wrote: On Sun, Dec 28, 2008 at 3:40 AM, Hussein B hubaghd...@gmail.com wrote: Hey, What is /usr/lib/pythonx.y/site-packages folder and for what it is used usually? I believe it's where third-party libraries are typically installed to. Cheers, Chris -- Follow the path of the Iguana...http://rebertia.com You mean like MoinMoin, Django or Pylons for example? -- http://mail.python.org/mailman/listinfo/python-list
ftp EOF error, thread and process
Hi all, My code like this raise an EOFError, It happens if I use the Process module, while, if I use thread.start_new_thread(ftp.pwd,()), it seems works well. And I wondered why. from ftplib import FTP import thread from multiprocessing import Process if __name__ == '__main__': ftp = FTP('localhost', 'movie', 'movie') print ftp.pwd() p = Process(target = ftp.pwd) # thread.start_new_thread (ftp.pwd,()), p.start() p.join() -- http://mail.python.org/mailman/listinfo/python-list
Re: What is site-packages?
On Sun, 28 Dec 2008 04:06:36 -0800, Hussein B wrote: You mean like MoinMoin, Django or Pylons for example? Yes. Or lxml, BeautifulSoup, psycopg2 and basically anything that is available on PyPI. regards, Marek -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
Hi Steven... thanks for your kind and extensive reply. Lots of good food for thought. I know it's easy to complain about lack of functionality, but it really was not my intention. Python is very cool as it is and I still know too little about it to even suggest anything. I just thought maybe I was missing something. Sure it would make my life much easier if i had a full set of Decimal (c)math functions and I suppose there are quite a few folks who would like it as well. *** It's not that it's 100% necessary, it just makes things easier. *** Just the fact that at least 3 people already tried to write a decimal math module speaks for how desired and how difficult it is. It's really just the goniometric functions that I am missing most at the moment, so maybe I can figure it out with help of what you said plus the already existing imperfect modules. Meantime maybe this discussion will caught Guido's eye... ;-) And btw I do expect that Python becomes better than Mathematica one day because it's free and open :-) Maybe when Wolfram retires ;-) Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
/kolab/bin/python: double free or corruption (fasttop)
I got this. This is a test script, to help me to understand why I have unexpected result in application. But I got a more unexpected result, and probably wrong error message about the read-only cursor. The full script is at the end. db cleanup, 326 records deleted, 9990 remains Exception in thread Thread-1: Traceback (most recent call last): File /kolab/lib/python/threading.py, line 486, in __bootstrap_inner self.run() File /kolab/lib/python/threading.py, line 446, in run self.__target(*self.__args, **self.__kwargs) File ./test/test_bdb.py, line 85, in lambda update_thread=threading.Thread(target=lambda : cleanup(db)) File ./test/test_bdb.py, line 72, in cleanup cursor.delete() DBPermissionsError: (1, 'Operation not permitted -- Write attempted on read- only cursor') Traceback (most recent call last): File ./test/test_bdb.py, line 130, in module server() File ./test/test_bdb.py, line 92, in server db[str(last)]=str(last) KeyboardInterrupt *** glibc detected *** /kolab/bin/python: double free or corruption (fasttop): 0 x09d521a8 *** === Backtrace: = /lib/i686/nosegneg/libc.so.6[0xccfd] /lib/i686/nosegneg/libc.so.6(cfree+0x90)[0x444503b0] /kolab/bin/python(__db_c_destroy+0x60)[0x81fa6f0] /kolab/bin/python(__db_refresh+0x165)[0x81f3515] /kolab/bin/python(__db_close+0x64)[0x81f3cb4] /kolab/bin/python(__db_close_pp+0xa1)[0x8204b61] /kolab/bin/python[0x812123f] /kolab/bin/python[0x8159534] /kolab/bin/python[0x815fb0a] /kolab/bin/python[0x811abbc] /kolab/bin/python[0x811abc9] /kolab/bin/python[0x80b0229] /kolab/bin/python(PyDict_SetItem+0x6e)[0x80b1c0e] /kolab/bin/python(PyDict_SetItemString+0x42)[0x80b1ce2] /kolab/bin/python(PyImport_Cleanup+0xd4)[0x8108294] /kolab/bin/python(Py_Finalize+0xbf)[0x8113f1f] /kolab/bin/python(Py_Main+0x468)[0x80845c8] /kolab/bin/python(main+0x22)[0x8084052] /lib/i686/nosegneg/libc.so.6(__libc_start_main+0xdc)[0x443fbdec] /kolab/bin/python[0x8083fa1] === Memory map: 0011-001d7000 rwxp 0011 00:00 0 001d7000-001da000 r-xp ca:03 973941 /kolab/lib/python/lib- dynload/ t ime.so 001da000-001dc000 rwxp 2000 ca:03 973941 /kolab/lib/python/lib- dynload/ t ime.so 001dc000-001e r-xp ca:03 973938 /kolab/lib/python/lib- dynload/ s trop.so 001e-001e2000 rwxp 3000 ca:03 973938 /kolab/lib/python/lib- dynload/ s trop.so 001e2000-001e3000 r-xp ca:03 973911 /kolab/lib/python/lib- dynload/ _ weakref.so 001e3000-001e4000 rwxp ca:03 973911 /kolab/lib/python/lib- dynload/ _ weakref.so 001e4000-001ea000 rwxs ca:03 1747650/tmp/db/__db.001 001ea000-001fc000 rwxs ca:03 1747651/tmp/db/__db.002 001fc000-0023e000 rwxs ca:03 1747652/tmp/db/__db.003 00388000-003e rwxs ca:03 1747653/tmp/db/__db.004 0045-00452000 r-xp ca:03 1132355/lib/libutil-2.5.so 00452000-00453000 r-xp 1000 ca:03 1132355/lib/libutil-2.5.so 00453000-00454000 rwxp 2000 ca:03 1132355/lib/libutil-2.5.so 00459000-0047e000 r-xp ca:03 1132349/lib/i686/nosegneg/ libm-2.5.so 0047e000-0047f000 r-xp 00024000 ca:03 1132349/lib/i686/nosegneg/ libm-2.5.so 0047f000-0048 rwxp 00025000 ca:03 1132349/lib/i686/nosegneg/ libm-2.5.so 0063e000-0063f000 r-xp 0063e000 00:00 0 [vdso] 0097a000-0098d000 r-xp ca:03 1134447/lib/i686/nosegneg/ libpthread-2 . 5.so 0098d000-0098e000 r-xp 00012000 ca:03 1134447/lib/i686/nosegneg/ libpthread-2 . 5.so 0098e000-0098f000 rwxp 00013000 ca:03 1134447/lib/i686/nosegneg/ libpthread-2 . 5.so 0098f000-00991000 rwxp 0098f000 00:00 0 009a8000-009e9000 rwxp 009a8000 00:00 0 00b8-00d8 r-xp ca:03 845325 /usr/lib/locale/ locale-archive 00ec9000-00ecc000 r-xp ca:03 973916 /kolab/lib/python/lib- dynload/ c StringIO.so 00ecc000-00ecd000 rwxp 3000 ca:03 973916 /kolab/lib/python/lib- dynload/ c StringIO.so 00fd2000-00fd6000 r-xp ca:03 973918 /kolab/lib/python/lib- dynload/ c ollections.so 00fd6000-00fd7000 rwxp 4000 ca:03 973918 /kolab/lib/python/lib- dynload/ c ollections.so 00fd7000-00fd8000 --xp 00fd7000 00:00 0 00fd8000-019d8000 rwxp 00fd8000 00:00 0 08048000-08433000 r-xp ca:03 430731 /kolab/bin/python 08433000-0846e000 rwxp 003eb000 ca:03 430731 /kolab/bin/python 0846e000-08478000 rwxp 0846e000 00:00 0 09ce5000-09da5000 rwxp 09ce5000 00:00 0 443c4000-443dd000 r-xp ca:03 1132323/lib/ld-2.5.so 443dd000-443de000 r-xp 00018000 ca:03 1132323/lib/ld-2.5.so 443de000-443df000 rwxp
Re: strange behavior of math.sqrt() in new 3.0 version
Tim Roberts wrote: Scott David Daniels scott.dani...@acm.org wrote: I avoid using single-letter variables except where I know the types from the name (so I use i, j, k, l, m, n as integers, s as string, and w, x, y, and z I am a little looser with (but usually float or complex). It's amazing to me that Fortran continues to live on in the hearts and minds of today's programmers. Well I think it's more that the original Fortran programmers were applied mathematicians, who have always tended to use i through m as integer variables, and that usage continues both in programming and mathematics today. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout.write()'s bug or doc bug?
On Sun, 28 Dec 2008 02:37:55 -0800, Qiangning Hong wrote: So, my question is, as sys.stdout IS a file object, why it does not use its encoding attribute to convert the given unicode? An implementation bug? A documenation bug? hmm I always thought sys.stdout is a file-like object not that it IS a file. In my original post, I have figured out that sys.stdout IS a file, by using type() function. And isinstance() function tells the same: Python 2.5.2 (r252:60911, Dec 18 2008, 12:39:19) [GCC 4.2.1 (Apple Inc. build 5564)] on darwin Type help, copyright, credits or license for more information. import sys type(sys.stdout) is file True isinstance(sys.stdout, file) True So, sys.stdout SHOULD do what the doc says, otherwise there is a bug either in implementation of sys.stdout, or in the documentation of file. The documentation says: file.encoding The encoding that this file uses. When Unicode strings are written to a file, they will be converted to byte strings using this encoding. In addition, when the file is connected to a terminal, the attribute gives the encoding that the terminal is likely to use (that information might be incorrect if the user has misconfigured the terminal). The attribute is read-only and may not be present on all file-like objects. It may also be None, in which case the file uses the system default encoding for converting Unicode strings. New in version 2.3. http://docs.python.org/library/stdtypes.html#file.encoding And I agree that sys.stdout is a file. Using Python 2.6: type(sys.stdout) type 'file' I can confirm the behaviour you report: sys.stdout.encoding 'UTF-8' u = u\u554a print u 啊 sys.stdout.write(u) Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in position 0: ordinal not in range(128) But if you explicitly convert the string, it works: sys.stdout.write(u.encode('utf-8')) 啊 I agree that this appears to be a bug, either of the write() method or the documentation. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
On Dec 28, 12:02 am, jerry.carl...@gmail.com wrote: I have been looking for a Python module with math functions that would both eat and spit Decimals. The standard math module eats Decimals allright but spits floats. Yes: it just converts the input (whether float, int, Fraction or Decimal) to a float using the __float__ method, and then applies the usual float-float maths function. I tried using the AJDecimalMathAdditions, but ran into issues like dSin (1E4) would take forever to calculate and would result in sin() 1 ... If i understand it correctly, the program is using maclaurin series to calculate the value and since it does not chop off all the multiples of 2*pi, the maclaurin approximation becomes useless when its too far from x=0. Implementing these functions *is* kinda tricky, especially if you want them to be correctly rounded, efficient, and to deal correctly with all the special cases (infinities, nans, ...). But it's far from impossible. sin and cos present particular difficulties for large arguments; probably the range of accepted inputs would have to be restricted for those functions. (1) what do folks use when they need to calculate something like exp (sin(Decimal())) or even more complex things? Any recommendations? Or am I completely missing something? Generally, something other than Python. :) (For example, GP/Pari or MPFR.) I'd like to be able to use Python for this, though. A couple of questions for you (I'm curious what additions would suit your particular use case best): - are you using Decimal for the base-10-ness or the extra precision Decimal provides? Or significant zeros? Or compatibility with existing Decimal code, or what? - what 3 functions would you most like to see added? For me, I think it would be something like sin, cos and atan (or possibly atan2). Once you've got those three, everything else is fairly easy. In particular, atan/atan2 at least gives you access to pi. (2) Is there any plan to provide a standard python module that would do that? (Python 4.0? ;-) No, there's no such plan. It's highly unlikely that the Decimal module will grow any extra math functions: it's designed to stick very closely to the IBM standard. It's not impossible that extra Decimal functions could be added in some other module, but it seems fairly unlikely. FWIW, I'm the author of the current Decimal log, log10, exp and pow functions, so I'm probably in a fairly good position to try to implement reasonably high-quality versions of some other elementary functions (again, just as an external addition to the decimal module, not as part of the decimal module itself). This is an itch I've often wanted scratched, as well. I might just have a go (Help in the form of code, tests, suggestions, etc. would be welcome!) Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
On Dec 28, 7:28 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: Ah crap, I forgot that from_float() has been left out of the decimal API. That's very annoying. Agreed. It's maybe even annoying enough that a feature request at bugs.python.org might be honoured. (Hint, hint!) It's fairly easy to emulate in Python 2.6 and above, using the as_integer_ratio float method: from decimal import Decimal from math import pi n, d = pi.as_integer_ratio() Decimal(n)/d Decimal('3.141592653589793115997963469') Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
- are you using Decimal for the base-10-ness or the extra precision Decimal provides? Or significant zeros? Or compatibility with existing Decimal code, or what? Oh boy, now I will finally prove myself illiterate... well, so be it. But i am after the extra precision: from math import * (1+1e-16)-1 0.0 ...in this trivial example above I will lose the 1e-16... which may be an issue if you code something that evaluates slightly more complex expressions. I would feel much more comfortable if I lose 1e-60. But in physics, one can get parts of an expression equal to 1e-16 while (by mistake or not) other parts are 1. Hence it becomes a greater puzzle to debug the calculation. Having the possibility to increase precision would help. Sure, you can say, there is such a small market for this application, and maybe I should use other tools. Well, I found Python so much easier to use for other reasons. And, again, it seems like there is a desire for it outside of my own office. - what 3 functions would you most like to see added? For me, I think it would be something like sin, cos and atan (or possibly atan2). Once you've got those three, everything else is fairly easy. In particular, atan/atan2 at least gives you access to pi. Agree: sin, cos and atan would do it. FWIW, I'm the author of the current Decimal log, log10, exp and pow functions, so I'm probably in a fairly good position to try to implement reasonably high-quality versions of some other elementary functions (again, just as an external addition to the decimal module, not as part of the decimal module itself). This is an itch I've often wanted scratched, as well. I might just have a go (Help in the form of code, tests, suggestions, etc. would be welcome!) Mark Wow, i would never think my posting would go that high in the Python world. I can't wait to tell my colleagues after these holidays ;-) If I improve (in my view that is) the existing modules (dmath) etc. i will keep you posted. For now I am reducing large arguments of goniometric functions by adding the following into the dmath's sin(x) and cos(x): x=Decimal.__mod__(x,Decimal('2')*pi()) Works fine for what i need, but i am sure it's not the right way to do it. Thanks Mark! -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
On Dec 28, 3:55 pm, jerry.carl...@gmail.com wrote: But i am after the extra precision: from math import * (1+1e-16)-1 0.0 Sounds like you don't care too much about the base-10 part, so there may be other solutions out there. Have you tried: 1. mpmath? 2. sympy? 3. Sage? Any of these is likely to be faster than a decimal solution. One thing that it would be *really* nice to have is a set of Python bindings to MPFR---to me, MPFR is the one obvious way to do high-precision math. Maybe bindings already exist somewhere. Sage includes them, but also includes many hundreds of megabytes of other stuff that you probably don't need or want. Maybe you could get access to MPFR via ctypes; I don't have any idea how feasible or complicated this might be. Sure, you can say, there is such a small market for this application, and maybe I should use other tools. Well, I found Python so much easier to use for other reasons. And, again, it seems like there is a desire for it outside of my own office. Well, I'd certainly find high-precision sin, cos, ... within Python useful. I'd guess the market isn't *so* small. Agree: sin, cos and atan would do it. I'll see if I can find time. I've just discovered a half-finished version of atan for Decimal sitting on my computer, complete with error analysis. Wow, i would never think my posting would go that high in the Python world. I can't wait to tell my colleagues after these holidays ;-) LOL---hardly! I'm just one of hundreds of Python core devs, and I've only been that for around a year... If I improve (in my view that is) the existing modules (dmath) etc. i will keep you posted. For now I am reducing large arguments of goniometric functions by adding the following into the dmath's sin(x) and cos(x): x=Decimal.__mod__(x,Decimal('2')*pi()) Works fine for what i need, but i am sure it's not the right way to do it. I don't know of any better way to deal with large arguments. The main problem is that the reduction step can introduce fairly large errors: for example, if you're using a value of pi that's accurate to 10**-20, say, then reducing something of magnitude 10**5*pi will give a result with error of around 10**-15. As far as I know, this problem is essentially unavoidable, and it's the reason why implementing sin for inputs like 10**9 isn't feasible. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
1. mpmath? 2. sympy? 3. Sage? Haven't tried those, i guess i have some studying to do. x=Decimal.__mod__(x,Decimal('2')*pi()) Works fine for what i need, but i am sure it's not the right way to do it. I don't know of any better way to deal with large arguments. The main problem is that the reduction step can introduce fairly large errors: for example, if you're using a value of pi that's accurate to 10**-20, say, then reducing something of magnitude 10**5*pi will give a result with error of around 10**-15. As far as I know, this problem is essentially unavoidable, and it's the reason why implementing sin for inputs like 10**9 isn't feasible. Good point. No tool will work in all parts of the universe (which is especially true for the universal ski wax). Let me check the 3 modules you listed above! -- http://mail.python.org/mailman/listinfo/python-list
Cheetah
1. In Cheetah 2.0.1, both from python 2.5.2 and 2.6, after I do a #from datetime import date, most of the datetime objects seem to work fine. For example, $date(2008, 12, 15) works. However $date.today() does not work and I get an exception required argument year not found. In Python both 2.5.2 and 2.6 (without Cheetah), the today() works fine. For some reason, though, it does not work from Cheetah. 2. In reportlab 2.2, when I generate a PDF, no matter how many nbsps I put it, I only get one space. I am using it with python 2.6. The PDF generates fine and one $nbsp works, but for some reason, when I put it in multiple times, I still only get one space. -- http://mail.python.org/mailman/listinfo/python-list
reportlab
In reportlab 2.2, when I generate a PDF, no matter how many nbsps I put it, I only get one space. I am using it with python 2.6. The PDF generates fine and one $nbsp works, but for some reason, when I put it in multiple times, I still only get one space. -- http://mail.python.org/mailman/listinfo/python-list
return in def
Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. Even when I'm not explicitly returning something I like to add return because it's a good additional visual marker for me to see where a method definition ends especially in cases where I may use a nested method. Thanks for the discussion! Roger. -- http://mail.python.org/mailman/listinfo/python-list
How to kill orphaned threads at program exit
Hi, I know that it's not possible to kill threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. I noticed that, at the end of the program, I can call threading.enumerate() and see the pending thread objects: def test_main(): ... start_suite() print threading.enumerate() I was wondering if I can do anything with that. I took a look at test/test_support which has threading_setup() and threading_cleanup() functions. Could such functions be useful to me? Thanks in advance, --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 28, 11:19 am, Roger rdcol...@gmail.com wrote: Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. Even when I'm not explicitly returning something I like to add return because it's a good additional visual marker for me to see where a method definition ends especially in cases where I may use a nested method. Thanks for the discussion! Roger. returning nothing does nothing :) -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Roger wrote: Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. It's an unnecessary affectation, but I don't believe it adds any clock ticks to your app, as the function has to return anyway. The dis module shows you they both generate exactly the same code: from dis import dis def f1(): ... print hello ... def f2(): ... print hello ... return ... dis(f1) 2 0 LOAD_CONST 1 ('hello') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE dis(f2) 2 0 LOAD_CONST 1 ('hello') 3 PRINT_ITEM 4 PRINT_NEWLINE 3 5 LOAD_CONST 0 (None) 8 RETURN_VALUE Even when I'm not explicitly returning something I like to add return because it's a good additional visual marker for me to see where a method definition ends especially in cases where I may use a nested method. Well, I suppose at least you aren't writing return None ... Normally a blank line or two suffices for me. Take a look at PEP 8 for some discussion for Python coding style. http://www.python.org/dev/peps/pep-0008/ regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill orphaned threads at program exit
In article b133b978-fe63-4893-bb33-8c96bfb59...@v5g2000prm.googlegroups.com, Giampaolo Rodola' gne...@gmail.com wrote: Hi, I know that it's not possible to kill threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. You don't say how you're creating your threads, so I'll assume you're using threading.Thread(). After creating each thread, and before calling start() on it, call setDaemon(True). -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 28, 5:19 pm, Roger rdcol...@gmail.com wrote: Hi Everyone, [...] When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. It's not particularly excessive but it is uncommon. A nekkid return can sometimes be essential within a function body, so a non-essential nekkid return could be considered just noise. G. -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Roger a écrit : When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? If it's the last statement in the function body, it is indeed excessive. OTHO I sometimes end a function with an explicit return None when there are branches with early returns, ie: def func(): if some_condition: return something return None to make really clear what happens - even if it _should_ be clear without the last statement. IOW : use your own judgement. -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
mpmath... wow... just did what i needed :-) Thanks, Mark! Hopefully i did not waste too much of your time... and perhaps this discussion will send other lost sheeps in the right direction. (Still, it would make sense to have the goniometric functions in decimal.) -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Roger wrote: Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. Same here, I always read the news, but hardly post anything since am not very much expert in Python. Even when I'm not explicitly returning something I like to add return because it's a good additional visual marker for me to see where a method definition ends especially in cases where I may use a nested method. I would personally prefer to use a comment for return rather than giving an explicit return statement. e.g. # return from function -- Manish Sinha Personal Blog: http://www.manishsinha.info Tech Blog: http://manishtech.wordpress.com OpenPGP Key: 99E6658F -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Gerard Flanagan wrote: On Dec 28, 5:19 pm, Roger rdcol...@gmail.com wrote: Hi Everyone, [...] When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. It's not particularly excessive but it is uncommon. A nekkid return can sometimes be essential within a function body, so a non-essential nekkid return could be considered just noise. If it's a function, ie the result is used by the caller, then explicitly return with the value, even if it's None. On the other hand, if it's a procedure, ie the result is always None and that result isn't used by the caller, then don't use return, except for an early exit. -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Sun, 28 Dec 2008 12:38:50 -0500, Steve Holden wrote: Roger wrote: Hi Everyone, First I want to thank everyone that posts to this group. I read it daily and always learn something new even if I never feel like I have anything to contribute but my questions. When I define a method I always include a return statement out of habit even if I don't return anything explicitly: def something(): # do something return Is this pythonic or excessive? Is this an unnecessary affectation that only adds clock ticks to my app and would I be better off removing returns where nothing is returned or is it common practice to have returns. It's an unnecessary affectation, but I don't believe it adds any clock ticks to your app, as the function has to return anyway. The dis module shows you they both generate exactly the same code: ... Even when I'm not explicitly returning something I like to add return because it's a good additional visual marker for me to see where a method definition ends especially in cases where I may use a nested method. Well, I suppose at least you aren't writing return None ... Normally a blank line or two suffices for me. Curious. When I see a bare return, the first thing I think is that the author forgot to include the return value and that it's a bug. The second thing I think is that maybe the function is a generator, and so I look for a yield. If I don't see a yield, I go back to thinking they've left out the return value, and have to spend time trying to understand the function in order to determine whether that is the case or not. In other words, even though it is perfectly valid Python, bare returns always make the intent of the function less clear for me. I'm with Bruno -- if you have a function with early exits, and you need to make the intent of the function clear, explicitly return None. Otherwise, leave it out altogether. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Apache/mod_python: Registering a request handler dynamically
Hi, Is there a way to dynamically overwrite the request handler from within mod_python scripts? Something along those lines: --- from mod_python import apache def myhandler(request): request.content_type = 'text/plain' request.write('Hello world') apache.set_default_handler(myhandler) --- I specifically want to avoid changing the Apache directive, as this code is supposed to function in a place where the user has no permission to override the Apache directive. The reason is that I am trying to hide the difference between different environments (such as mod_python or CGI) from the developer, such that the following is possible: --- #!/usr/bin/python import os, os.path os.chdir(os.path.dirname(__file__)) from PleaseHideMyEnvironment import RequestHandler def index(request): request.write('Hello World') RequestHandler(index) --- So at the time at which RequestHandler() is created, I need a way to make sure that mod_python calls to the RequestHandler instead of the normal handler, whenever a new request is made. Any idea? -Samuel -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Curious. When I see a bare return, the first thing I think is that the author forgot to include the return value and that it's a bug. The second thing I think is that maybe the function is a generator, and so I look for a yield. If I don't see a yield, I go back to thinking they've left out the return value, and have to spend time trying to understand the function in order to determine whether that is the case or not. In other words, even though it is perfectly valid Python, bare returns always make the intent of the function less clear for me. I'm with Bruno -- if you have a function with early exits, and you need to make the intent of the function clear, explicitly return None. Otherwise, leave it out altogether. -- Steven To me this is the soundest argument. Thanks for the advice. I think I'll follow this as a rule of thumb hereafter. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
On 28 Gru, 09:43, Pavel Kosina g...@post.cz wrote: well, I am working on a tutorial for youngster (thats why i need to stay the code as easy as possible). In this game you are hunted by robots. I could use key7 on numeric keypad for left-up moving but seems to me, that 4+8 is much more standard for them. Hmmm. Maybe you'd like to hook into Tkinter event loop, i.e. by custom events if you don't like periodical polling. No, that would be even more difficult. I already have a code that use your idea: from Tkinter import * root = Tk() pressedKeys=set() def onKeyPress(event): pressedKeys.add(event.keysym) def onKeyRelease(event): pressedKeys.remove(event.keysym) def move(): print list(pressedKeys) root.after(100,move) root.bind(KeyPress, onKeyPress) root.bind(KeyRelease, onKeyRelease) root.after(100,move) root.mainloop() well, I thought that gui´s have such a problem already built-in - so that i am not pressed to code it. You know, its not exactly about me - if I do it for myself, for my program, that there is no problem, but I need to explained it to begginners . And I do not want, as might be more usual, do my module, that would cover this insanity (look at it with 13-years old boy eyes ;-) ). Do you like to say me, that this is not a standard function neither in tkinter, not say gtk or the others, too? Ok, I get it then! Your goal is very humble :) In the piece of code we have came together to, there is a functionality you already want - the pressedKeys. I suppose, that you'd like to hide from the further implementors (children). You can write another module, which could contain this piece of code and could be imported by kids to have the desired features. Meaning only getting this list of keys. But what you write here: I would expect something like this: def onKeyTouch(event): print (event.keysymAll) root.bind(KeyPress, onKeyTouch) ...is a bit misleading. There is no such thing as simultaneous events - for that the event dispatcher loop is designed - to simplyfy all usual stuff with parallel paradigsm such as interrupts, thread safety etc. An event is in my eyes a response to a short action, let's call it atomic. There's no need to pretend, that clicking a few keys simultanously is sth immediate and the software could by any chance guess that a few keys were actually clicked. Even the keyboard driver does some sequential scanning on the keys, and the key codes are then send to the board sequentially as well. Try to run this code: # #Tkinter multiple keypress #Answer http://groups.google.com/group/comp.lang.python/browse_thread/thread/88788c3b0b0d51d1/c4b7efe2d71bda93 import Tkinter import pprint import time tk = Tkinter.Tk() f = Tkinter.Frame(tk, width=100, height=100) msg = Tkinter.StringVar() msg.set('Hello') l = Tkinter.Label(f, textvariable=msg) l.pack() f.pack() keys = set() lastTime = None def keyPressHandler(event): keys.add(event.char) global lastTime now = time.time() if lastTime: difference = now - lastTime if difference 0.1: #seconds print difference, 's' lastTime = now display() def keyReleaseHandler(event): keys.remove(event.char) display() def display(): msg.set(str(keys)) f.bind_all('KeyPress', keyPressHandler) f.bind_all('KeyRelease', keyReleaseHandler) f.mainloop() # ... and find out, how 'simultaneous' they are. For me it's 0.0, meaning that the event handlers were executed one after another, but sometimes there is sth like 0.0309998989105 s - proabably an USB latency, or an operating system context switch - hard to tell. If you'd like to have two key clicks to generate a single event, you'd have to write some timeout code (threading.Timer or tk stuff is handy) to check how 'simultaneous' they actually were. Search web for events in doubled inequality signs if you really want this. I don't know gtk, but hey, pygame has pygame.key.get_pressed if you'd like to switch: http://www.pygame.org/docs/ref/key.html Have luck Jan -- http://mail.python.org/mailman/listinfo/python-list
A form validation library with javascript validation
Hey everyone, Can someone advice me a beautiful or just cool library for form validation with javascript supporting? -- http://mail.python.org/mailman/listinfo/python-list
error on windows with commands.getstatusoutput
My application is trying to start twistd in a cross-platform way. Unfortunately, it works fine on my linux system, but I do not have windows, and I am trying to debug this remotely on a system I never use :o( Anyhow, here is the error I am getting: cmd = '%s -y %s -l %s' % (conf.twistd, conf.tztac, conf.twistdlog) status, output = commands.getstatusoutput(cmd) Error code: 1 Command: C:/Python25/Scripts/twistd.bat -y tzmud.tac -l var/log/twistd.log Output: '{' is not recognized as an internal or external command, operable program or batch file. Apparently, the Command works fine from the command line. So... Can I run a .bat file on windows with getstatusoutput? Anyone recognize this kind of error? Thanks for any assistance. _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/events.aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: error on windows with commands.getstatusoutput
The commands module is Unix only. See its documentation : http://docs.python.org/library/commands.html On Sun, Dec 28, 2008 at 10:03 PM, Lee Harr miss...@hotmail.com wrote: My application is trying to start twistd in a cross-platform way. Unfortunately, it works fine on my linux system, but I do not have windows, and I am trying to debug this remotely on a system I never use :o( Anyhow, here is the error I am getting: cmd = '%s -y %s -l %s' % (conf.twistd, conf.tztac, conf.twistdlog) status, output = commands.getstatusoutput(cmd) Error code: 1 Command: C:/Python25/Scripts/twistd.bat -y tzmud.tac -l var/log/twistd.log Output: '{' is not recognized as an internal or external command, operable program or batch file. Apparently, the Command works fine from the command line. So... Can I run a .bat file on windows with getstatusoutput? Anyone recognize this kind of error? Thanks for any assistance. _ Show them the way! Add maps and directions to your party invites. http://www.microsoft.com/windows/windowslive/events.aspx -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 28, 1:35 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: The second thing I think is that maybe the function is a generator, and so I look for a yield. You shouldn't, though; Generators can't contain any return statement. -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
Benjamin wrote: On Dec 28, 1:35 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: The second thing I think is that maybe the function is a generator, and so I look for a yield. You shouldn't, though; Generators can't contain any return statement. Yes, they can. It doesn't return a value, it just raises a StopIteration error. In [18]: def g(): for i in range(5): if i == 3: print 'Early exit.' return print 'Should not happen.' yield i : : In [25]: list(g()) Early exit. Out[25]: [0, 1, 2] -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 29, 8:36 am, Benjamin musiccomposit...@gmail.com wrote: On Dec 28, 1:35 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: The second thing I think is that maybe the function is a generator, and so I look for a yield. You shouldn't, though; Generators can't contain any return statement. What gave you that impression? experimentation Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. def foo(): ...for i in range(4): ... yield i ...return ... foo function foo at 0x00F5AF30 x = foo() x generator object foo at 0x00F61080 list(x) [0, 1, 2, 3] def bar(): ...for i in range(4): ... yield i ...return 42 ... File stdin, line 4 SyntaxError: 'return' with argument inside generator /experimentation manual (go to http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy then scroll down) Generator functions A function or method which uses the yield statement (see section The yield statement) is called a generator function. Such a function, when called, always returns an iterator object which can be used to execute the body of the function: calling the iterator’s next() method will cause the function to execute until it provides a value using the yield statement. When the function executes a return statement or falls off the end, a StopIteration exception is raised and the iterator will have reached the end of the set of values to be returned. /manual -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 29, 7:06 am, Roger rdcol...@gmail.com wrote: Curious. When I see a bare return, the first thing I think is that the author forgot to include the return value and that it's a bug. The second thing I think is that maybe the function is a generator, and so I look for a yield. If I don't see a yield, I go back to thinking they've left out the return value, and have to spend time trying to understand the function in order to determine whether that is the case or not. In other words, even though it is perfectly valid Python, bare returns always make the intent of the function less clear for me. I'm with Bruno -- if you have a function with early exits, and you need to make the intent of the function clear, explicitly return None. Otherwise, leave it out altogether. -- Steven To me this is the soundest argument. Thanks for the advice. I think I'll follow this as a rule of thumb hereafter. Please don't. Follow MRAB's advice, with the corollary that a generator is forced by the compiler to be a procedure in MRAB's terminology. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help getting MoinMoin to run under WSGI
In article f97e6514-1d36-42ed-b0f7-98e2b3162...@d36g2000prf.googlegroups.com, Graham Dumpleton graham.dumple...@gmail.com wrote: On Dec 28, 7:22 pm, Ron Garret rnospa...@flownet.com wrote: In article rnospamon-79fa22.21571527122...@news.gha.chartermi.net, Ron Garret rnospa...@flownet.com wrote: I successfully installed MoinMoin as a CGI according to the instructions on the moinmo.in site. But when I tried to switch over to running it under wsgi it failed thusly: [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] Traceback (most recent call last): [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] File /www/wikis/genesisgroup/moin.wsgi, line 49, in ? [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] from MoinMoin.server.server_wsgi import WsgiConfig, moinmoinApp [Sat Dec 27 21:44:14 2008] [error] [client 66.214.189.2] ImportError: No module named MoinMoin.server.server_wsgi The problem, I believe, is that I have both Python 2.4 and 2.5 installed (it's a Debian box) and MM is installed under 2.5 but WSGI is using 2.4. I tried to fix this by setting WSGIPythonHome but to no avail. I can't figure out what to set it to. The instructions say: the WSGIPythonHome directive should be used to specify the exact location of the Python installation corresponding to the version of Python compiled against I have two problems with this. First, I didn't compilemod_wsgi, I got it pre-built as a Debian module. Second, what does the exact location of the Python installation even mean? Python2.5 is spread out in at least three different places: /usr/local/bin, /usr/lib/python2.5, and /usr/local/lib/python2.5. I've tried setting WSGIPythonHome to all of those (and a few other things as well) and nothing worked. Also, the version of Python compiled against seems very odd. What does that mean? Surely I don't have to recompilemod_wsgievery time I change to a new version of Python? Help! Thanks! rg So never mind, I figured it out. I did indeed have to recompilemod_wsgifrom source to get it to use Python 2.5. (That turned out to be a major hassle. I had to do it twice. The first time through it made Apache dump core. I still don't know why.) Seems to be working now though. It probably crashed the first time because you didn't do a full stop of Apache and instead just did a reload. Doing a reload may not unload the Python libraries from Apache process correctly and so would have been a mix of code for different versions of Python in same process. Graham Yes, I don't specifically recall exactly what happened now, but that seems likely. Thanks, rg -- http://mail.python.org/mailman/listinfo/python-list
Python 3.0 Curses Unicode
Hi, I've switched to Python 3.0 for a new Japanese vocab quizzing application due to its much improved Unicode support. However, I'm running into an issue with displaying Unicode characters via curses. In Python 2.x a simple hello-world looks like: #!/usr/bin/python # coding=UTF-8 import curses import locale locale.setlocale(locale.LC_ALL,) def doStuff(stdscr): message = uhello わたし! stdscr.addstr(0, 0, message.encode(utf-8), curses.A_BLINK) stdscr.getch() # pauses until a key's hit curses.wrapper(doStuff) This works. However, when I try to come up with an equivalent for Python 3.0: #!/usr/bin/python import curses import locale locale.setlocale(locale.LC_ALL,) def doStuff(stdscr): message = hello わたし! stdscr.addstr(0, 0, message, curses.A_BLINK) stdscr.getch() # pauses until a key's hit curses.wrapper(doStuff) It fails (printing gibberish to the console). Anyone have a clue what I'm doing wrong? Thanks! -Damian PS. Is the # coding=UTF-8 header meaningless in Python 3.0? Also, is locale.setlocale(locale.LC_ALL,) still necessary for getting curses to provide Unicode support? -- http://mail.python.org/mailman/listinfo/python-list
Re: return in def
On Dec 28, 5:12 pm, John Machin sjmac...@lexicon.net wrote: On Dec 29, 7:06 am, Roger rdcol...@gmail.com wrote: Curious. When I see a bare return, the first thing I think is that the author forgot to include the return value and that it's a bug. The second thing I think is that maybe the function is a generator, and so I look for a yield. If I don't see a yield, I go back to thinking they've left out the return value, and have to spend time trying to understand the function in order to determine whether that is the case or not. In other words, even though it is perfectly valid Python, bare returns always make the intent of the function less clear for me. I'm with Bruno -- if you have a function with early exits, and you need to make the intent of the function clear, explicitly return None. Otherwise, leave it out altogether. -- Steven To me this is the soundest argument. Thanks for the advice. I think I'll follow this as a rule of thumb hereafter. Please don't. Follow MRAB's advice, with the corollary that a generator is forced by the compiler to be a procedure in MRAB's terminology. Yup, this is what I took away from this discussion. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Any equivalent to Ruby's 'hpricot' html/xpath/css selector package?
Ruby has a package called 'hpricot' which can perform limited xpath queries, and CSS selector queries. However, what makes it really useful is that it does a good job of handling the broken html that is so commonly found on the web. Does Python have anything similar, i.e. something that will not only do XPath queries, but will do so on imperfect HTML? (A good HTML neatener would also be fine, of course, as I could then pass the result to a Python XPath package.) And, what are people's favorite Python XPath solutions? Thanks, Ken McDonald -- http://mail.python.org/mailman/listinfo/python-list
Re: multiply each element of a list by a number
s...@pobox.com wrote: Colin ... perhaps faster than numpy: ... For extremely short lists, but not for much else: % for n in 1 10 100 1000 1 10 ; do echo len: $n echo -n numpy: python -m timeit -s 'import numpy ; a = numpy.array(range('$n'))' 'a*3' echo -n list: python -m timeit -s 'a = range('$n')' '[3*x for x in a]' done len: 1 numpy: 10 loops, best of 3: 11.7 usec per loop list: 100 loops, best of 3: 0.698 usec per loop len: 10 numpy: 10 loops, best of 3: 11.7 usec per loop list: 10 loops, best of 3: 2.94 usec per loop len: 100 numpy: 10 loops, best of 3: 12.1 usec per loop list: 1 loops, best of 3: 24.4 usec per loop len: 1000 numpy: 10 loops, best of 3: 15 usec per loop list: 1000 loops, best of 3: 224 usec per loop len: 1 numpy: 1 loops, best of 3: 41 usec per loop list: 100 loops, best of 3: 2.17 msec per loop len: 10 numpy: 1000 loops, best of 3: 301 usec per loop list: 10 loops, best of 3: 22.2 msec per loop This is with Python 2.4.5 on Solaris 10. YMMV. Skip, Your comment is justified for len= 100 or 1,000 but not for len= 10,000 or 100,000. I wonder about the variability of the number of loops in your data. I have tried to repeat your test with the program below, but it fails to cope with numpy. The results for Python 2.5 are: list:0.421 0.253 list:0.427 0.254 list:0.420 0.250 list:0.421 0.255 list:0.415 0.254 list:0.423 0.254 list:0.422 0.256 The results for Python 2.6 are: list:0.388 0.228 list:0.410 0.225 list:0.384 0.227 list:0.389 0.226 list:0.390 0.227 The script used above for both 2.5 and 2.6: # speedUgh.py To compare array timing ##import numpy import timeit as _t m= 100 # number of repetitions values= (10, 100) numpyRes= [] listRes= [] for n in values: sn= 'numpy.arange(' + str(n) + ')*3' t= _t.Timer(sn) ## r= t.repeat(3, m) ## numpyRes.append(sum(t.repeat(3, m)) * 100/(3*m*n)) sl='a= [3*k for k in range(' + str(n) + ')]' t= _t.Timer(stmt= sl) listRes.append( sum(t.repeat(3, m)) * 100/(3*m*n)) ##print 'numpy:', len(values)*'%8.3f' % tuple(numpyRes) print ' list:', len(values)*'%8.3f' % tuple(listRes) Colin W. -- http://mail.python.org/mailman/listinfo/python-list
RE: game engine (as in rules not graphics)
See: Chris Moss, Prolog++: The Power of Object-Oriented and Logic Programming (ISBN 0201565072) This book is a pretty handy intro to an OO version Prolog produced by Logic Programming Associates. Prolog is a wonderful tool for such things as working out a factory layout for new car production or for creating an expert system for choosing antibiotics for treating a condition. It has even been used for helping producing immigration legislation and then for providing a system for checking eligibility (other than can you survive in a desert and get through barbed wire!) One person used is to teach primary school children English grammar. The children created their own grammar rules and checked them out using Prolog. Their understanding of english grammar exceeded many university graduates after this exercise. (Google Dr. Richard Ennals). FWIW. Declaration of interest: Chris Moss is my wife's first cousin. -Original Message- From: Aaron Brady [mailto:castiro...@gmail.com] Sent: Sunday, 28 December 2008 1:22 p.m. To: python-list@python.org Subject: Re: game engine (as in rules not graphics) On Dec 27, 3:02 pm, Martin mar...@marcher.name wrote: Hello, I'd like to get in touch with game development a bit. I'm not talking about graphics but rather the game rules itself. Something likehttp://en.wikipedia.org/wiki/Monopoly_(game)#Rules, is there even a general approach to that or should I just go sketch up my rules and try to implement them. Being totally new to this topic I don't quite now what to search for to get some decent results that let me make a mental link between game rules and what the best practices are to implement them in python (or any other programming language) thanks, martin Not my expertise but here are my $0.02. You are looking for ways to represent rules: buying a house is legal in such and such situation, and the formula for calculating its price is something. You want predicates such as InJail, OwnedBy, Costs. Costs( New York Ave, 200 ) InJail( player2 ) OwnedBy( St. Charles Ave, player4 ) LegalMove( rolldie ) LegalMove( sellhouse ) There are rule-based languages out there, such as Prolog. They are equally expressive as Python (you can write a Turing machine in them), but they are more convenient for representing rules in a prog. language. Predicates are more or less equivalent to positive assertions about something. NewYorkAve.cost= 200 player2.injail= True... rolldie.islegal= True Some predicates have to be calculated, rather than stored, but Python descriptors go easy on you for that. Someone else will have to tell you how rule-based programming measures up against object-oriented programming. passes mic. -- http://mail.python.org/mailman/listinfo/python-list
RE: error on windows with commands.getstatusoutput
cmd = '%s -y %s -l %s' % (conf.twistd, conf.tztac, conf.twistdlog) status, output = commands.getstatusoutput(cmd) The commands module is Unix only. See its documentation : http://docs.python.org/library/commands.html Ah. Doh! I was going back and forth between all of the different ways to do this (os.system, os.spawn*, commands.*, subprocess.*) and lost track of the no windows for commands thing. Too bad it can't raise a more meaningful error message... Anyhow, I've replaced it with this: from subprocess import Popen, PIPE, STDOUT p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output, unused = p.communicate() status = p.returncode Does that look more windows-friendly? _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/windows/windowslive/photos.aspx -- http://mail.python.org/mailman/listinfo/python-list
[ANN] PyYAML-3.07: YAML parser and emitter for Python
Announcing PyYAML-3.07 A new release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML Changes === * The emitter learned to use an optional indentation indicator for block scalars; thus scalars with leading whitespaces could now be represented in a literal or folded style. * The test suite is now included in the source distribution. To run the tests, type 'python setup.py test'. * Refactored the test suite: dropped unittest in favor of a custom test appliance. * Fixed the path resolver in the LibYAML-based dumper. * Forced an explicit document end indicator when there is a possibility of parsing ambiguity. * More setup.py improvements: the package should be usable when any combination of setuptools, Pyrex and LibYAML is installed. * Windows binary packages are statically linked against LibYAML-0.1.2. * Other minor fixes and improvements (Thank to Ingy dot Net and Andrey Somov). Resources = PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.07.tar.gz ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.07.zip Windows installer: http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.3.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.4.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.5.exe http://pyyaml.org/download/pyyaml/PyYAML-3.07.win32-py2.6.exe PyYAML SVN repository: http://svn.pyyaml.org/pyyaml Submit a bug report: http://pyyaml.org/newticket?component=pyyaml YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example === import yaml yaml.load( ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: http://pyyaml.org/wiki/PyYAML ... keywords: [YAML, serialization, configuration, persistance, pickle] ... ) {'keywords': ['YAML', 'serialization', 'configuration', 'persistance', 'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} print yaml.dump(_) name: PyYAML homepage: http://pyyaml.org/wiki/PyYAML description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistance, pickle] Copyright = The PyYAML module is written by Kirill Simonov x...@resolvent.net. PyYAML is released under the MIT license. -- http://mail.python.org/mailman/listinfo/python-list
Need help getting MoinMoin to run under SCGI
So I have a MoinMoin installation running as a cgi and also under wsgi. Since I was on a roll I decided to press my luck and try running it under scgi. Following a suggestion in the following article: http://www.linuxjournal.com/article/9310 I wrote this little server adapter: from MoinMoin.server.server_cgi import CgiConfig, run class Config(CgiConfig): name = 'moin' import scgi import scgi.scgi_server class MoinHandler(scgi.scgi_server.SCGIHandler): def produce_cgilike(self, env, bodysize): run(Config) server = scgi.scgi_server.SCGIServer( handler_class=MoinHandler, port=4000 ) server.serve() It works -- sort of. I can fire it up and get to the login page, but it won't actually let me log in. I'm guessing this is because I haven't munged the CGI form data properly. I thought I'd ask if anyone with experience using SCGI can just tell me what I'm doing wrong before I dive into debugging this. Thanks, rg -- http://mail.python.org/mailman/listinfo/python-list
ZSI - ServiceContainer
Does Anyone know how to Make the ServiceContainer work under SSL Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get involved
kajnilss...@hotmail.com writes: I'm new to the open source comunnity and I was wondering if there are any bugs that I can trouble shoot or just some beginner tasks I can be sent? Here are some pointers to how you can assist Python: URL:http://wiki.python.org/moin/Advocacy URL:http://wiki.python.org/moin/CoreDevelopment Far more than programming tasks, assistance is always needed in areas like documentation, bug-report triage, and advocacy coordination. Thanks for your interest in helping! -- \ “Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.” —Tim O'Reilly, 2000-01-25 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
HTML Correctness and Validators
recently i wrote a blog essay about html correctness and html validators, with relations to the programing lang communities. I hope programing lang fans will take more consideration on the correctness of the doc they produces. HTML Correctness and Validators • http://xahlee.org/js/html_correctness.html plain text version follows. --- HTML Correctness and Validators Xah Lee, 2008-12-28 Some notes about html correctness and html validator. Condition Of Website Correctness My website “xahlee.org” has close to 4000 html files. All are valid html files. “Valid” here means passing the w3c's validator at http://validator.w3.org/. Being a programing and correctness nerd, correct html is important to me. (correct markup has important, practical, benefits, such as machine parsing and transformation, as picked up by the XML movement. Ultimately, it is a foundation of semantic web↗.) In programing lang communities, the programer tech geekers are fanatical about their fav lang's superiority, and in the case of functional langs, they are often proud of their correctness features. However, a look at their official docs or websites, they are ALL invalid html, with errors in just about every 10 lines of html source code. It is fucking ridiculous. lj-cut In the web development geeker communities, you can see how they are tight-assed about correct use of HTML/CSS, etc, where there are often frequent and heated debates about propriety of semantic markup, and they don't hesitate to ridicule Microsoft Internet Explorer browser, or the average HTML content producer. However, a look at the html they produced, also almost none are valid. The bad html also happens in vast majority of docs produced by organization of standards, such as the Unicode Consortium↗, IETF↗. For example, if you run w3c's validator on their IETF's home page, there are 32 errors, including “no doctype found”, and if you validate unicode's http://www.unicode.org/faq/utf_bom.html, there are 2 errors. (few years ago, they are much worse. I don't think even “w3.org”'s pages are valid back then.) In about 2006, i spent few hours research on what major websites produces valid html. To this date, I know of only one major site that produces valid html, and that is Wikipedia. This is fantastic. Wikipedia is produced by MediaWiki↗ engine, written in PHP. Many other wiki sites also run MediaWiki, so they undoubtfully are also valid. As far as i know, few other wiki or forum software also produces valid html, though they are more the exceptions than norm. (did try to check 7 random pages from “w3.org”, looks like they are all valid today.) Personal Need For Validator My personal need is to validate typically hundreds of files on my local drive. Every month or so, i do systematic regex find-replace operation on a dir. This often results over a hundred changed files. Every now and then, i improve my css or html markup semantics site wide, so the find-replace is on all 4000 files. Usually the find- replace is carefully crafted with attention to correctenss, or done in emacs interactively, so possible regex screwup is minimal, but still i wish to validate by batch after the operation. Batch validation is useful because, if i screwed up in my regex, usually it ends up with badly formed html, so html validation can catch the result. In 2008, i converted most my sites from html 4 transitional to html 4 strict. The process is quite a manual pain, even the files i start with are valid. Here are some examples. In html4strict: * “‹br›” must be inside block level tags. Image tag “‹img ...›” needs to be enclosed in a block level tag such as “‹div›”. Content inside blockquote must be wrapped with a block level tag. e.g. “‹blockquote›Time Flies‹/blockquote›” would be invalid in html4strict; you must have “‹blockquote›‹p›Time Flies‹/p›‹/blockquote›” Lets look at the image tag example. You might think it is trivial to transform because you can simply use regex to wrap a “‹div›” to image tags. However, it's not that simple. Because, for example, often i have this form: ‹img src=pretty.jpg alt=pretty girl width=565 height=809› ‹p›above: A pretty girl.‹/p› The “p” tag immediately below a “img” tag, functions as the image's caption. I have css setup so that this caption has no gap to the image above it, like this: img + p {margin-top:0px;width:100%} /* img caption */ I have the “width:100%” because normally “p” has “width:80ex” for normal paragraph. Now, if i simply wrap a “div” tag to all my “img” tags, i will end up with this form: ‹div›‹img src=pretty.jpg alt=pretty girl width=565 height=809›‹/div› ‹p›above: A pretty girl.‹/p› Now this screws up with my caption css, and there's no way to match “p” that comes after a “div › img”. Also, sometimes i have a sequence of images. Wrapping each with a “div” would introduce gaps between them. This is just a simplified example. In short, converting from html4transitional to html4strict while
ftp design question
Hi,all. I'm on a toy ftp project and I want it to be convinient for the user to cancel an undergoing downloading while continue others. The following code explains: for file in download_files: self.ftp.retrbinary('RETR '+file, fileHandler) Thers seems not a solid way to cancel this transfer and I considered thread or process but I can't handle this correctly. Thread: I can't kill the thread in another thread, so... Process: There seems something wrong(raise an EOFError exception) when I use Process(target = download_fun, args = (dir,)) for each downloading after connection built. Some suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: ftp design question
nemo wrote: Hi,all. I'm on a toy ftp project and I want it to be convinient for the user to cancel an undergoing downloading while continue others. The following code explains: for file in download_files: self.ftp.retrbinary('RETR '+file, fileHandler) Thers seems not a solid way to cancel this transfer and I considered thread or process but I can't handle this correctly. Thread: I can't kill the thread in another thread, so... Process: There seems something wrong(raise an EOFError exception) when I use Process(target = download_fun, args = (dir,)) for each downloading after connection built. Some suggestions? How about for file in download_files: try: self.ftp.retrbinary('RETR %s' % file, fileHandler) except KeyboardInterrupt: print file, transfer abandoned Then you can cancel a single file transfer with Ctrl/C. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill orphaned threads at program exit
En Sun, 28 Dec 2008 15:47:24 -0200, Roy Smith r...@panix.com escribió: In article b133b978-fe63-4893-bb33-8c96bfb59...@v5g2000prm.googlegroups.com, Giampaolo Rodola' gne...@gmail.com wrote: I know that it's not possible to kill threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. You don't say how you're creating your threads, so I'll assume you're using threading.Thread(). After creating each thread, and before calling start() on it, call setDaemon(True). The hard part is, then, to figure out some condition for the non-daemon thread to wait for before exiting. As a last resort -let's say, after waiting for N seconds for all threads to exit- one can use PyThreadState_SetAsyncExc to inject an exception into the unfinished threads. I think there is a recipe in the Python Cookbook for doing that using ctypes. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: How to display Chinese in a list retrieved from database via python
On 12月27日, 下午4时08分, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Sat, 27 Dec 2008 03:03:24 -0200,zxo102zxo...@gmail.com escribió: On 12月26日, 下午3时16分, Mark Tolonen metolone+gm...@gmail.com wrote: I was able to display 中文 successfully with this code: f=open('test.html','wt') f.write('''htmlhead META HTTP-EQUIV=Content-Type CONTENT=text/html;charset=gb2312 titletest/title/head body\xd6\xd0\xce\xc4/body/html''') f.close() Mark, I have exactly copied your code into the htdocs of my Apache server, htmlhead META HTTP-EQUIV=Content-Type CONTENT=text/html;charset=gb2312 titletest/title/head body\xd6\xd0\xce\xc4/body/html but it still shows me \xd6\xd0\xce\xc4. Any ideas? That's not the same thing as Mark T. said. The original was Python code to *write* a test file that you could open in a browser. Things like \xd6\xd0 are escape sequences interpreted by Python, not meant to literally appear in a file. Like \n -- it means start a new line, one wants a new line in the output, *not* a backslash and a letter n. \xd6\xd0 generate *two* bytes, not eight. If the file is interpreted as containing latin-1 characters, you see them as ÖÐ. But due to the charset=gb2312 line, those two bytes together make the ideograph 中. So, write the Python code (from f=open... up to f.close()) in a file and execute it. Then open the generated test.html file. You should see the two ideographs. -- Gabriel Genellina Thanks for your explanation. The example works now. It is close to my real case. I have a list in a dictionary and want to insert it into the html file. I test it with following scripts of CASE 1, CASE 2 and CASE 3. I can see 中文 in CASE 1 but that is not what I want. CASE 2 does not show me correct things. So, in CASE 3, I hacked the script of CASE 2 with a function: conv_list2str() to 'convert' the list into a string. CASE 3 can show me 中文. I don't know what is wrong with CASE 2 and what is right with CASE 3. Without knowing why, I have just hard coded my python application following CASE 3 for displaying Chinese characters from a list in a dictionary in my web application. Any ideas? Happy a New Year: 2009 ouyang CASE 1: f=open('test.html','wt') f.write('''htmlhead META HTTP-EQUIV=Content-Type CONTENT=text/html;charset=gb2312 titletest/title script language=javascript var test = ['\xd6\xd0\xce\xc4', '\xd6\xd0\xce\xc4', '\xd6\xd0\xce \xc4'] alert(test[0]) alert(test[1]) alert(test[2]) /script /head body/body/html''') f.close() CASE 2: ### mydict = {} mydict['JUNK'] = ['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce \xc4'] f_str = '''htmlhead META HTTP-EQUIV=Content-Type CONTENT=text/html;charset=gb2312 titletest/title script language=javascript var test = %(JUNK)s alert(test[0]) alert(test[1]) alert(test[2]) /script /head body/body/html''' f_str = f_str%mydict f=open('test02.html','wt') f.write(f_str) f.close() CASE 3: ### mydict = {} mydict['JUNK'] = ['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce \xc4'] f_str = '''htmlhead META HTTP-EQUIV=Content-Type CONTENT=text/html;charset=gb2312 titletest/title script language=javascript var test = %(JUNK)s alert(test[0]) alert(test[1]) alert(test[2]) /script /head body/body/html''' import string def conv_list2str(value): list_len = len(value) list_str = [ for ii in range(list_len): list_str += ''+string.strip(str(value[ii])) + '' if ii != list_len-1: list_str += , list_str += ] return list_str mydict['JUNK'] = conv_list2str(mydict['JUNK']) f_str = f_str%mydict f=open('test03.html','wt') f.write(f_str) f.close() -- http://mail.python.org/mailman/listinfo/python-list
Otra vez Python en xkcd
Hola En el especial de Navidad de este año: http://xkcd.com/521/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes strings
En Sun, 28 Dec 2008 08:59:03 -0200, Hendrik van Rooyen m...@microcorp.co.za escribió: Gabriel Genellina gagsl-...@yahoo.com.ar wrote: Hmmm, I don't think posting a potentially harmful example is actually a good idea... True - its my only example though, and nobody else was bothering to reply, so I kicked off and flushed out some response. Who was it that said that the way to get info out of usenet was to post some rubbish? :-) As in xkcd: http://xkcd.com/386/ BTW, Python is featured again in the Christmas special: http://xkcd.com/521/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
En Sun, 28 Dec 2008 06:43:20 -0200, Pavel Kosina g...@post.cz escribió: well, I am working on a tutorial for youngster (thats why i need to stay the code as easy as possible). In this game you are hunted by robots. I could use key7 on numeric keypad for left-up moving but seems to me, that 4+8 is much more standard for them. [...] well, I thought that gui´s have such a problem already built-in - so that i am not pressed to code it. You know, its not exactly about me - if I do it for myself, for my program, that there is no problem, but I need to explained it to begginners . And I do not want, as might be more usual, do my module, that would cover this insanity (look at it with 13-years old boy eyes ;-) ). Do you like to say me, that this is not a standard function neither in tkinter, not say gtk or the others, too? I don't recall any application that handles simultaneous keystrokes. Multiple keystrokes are handled at the library level, but only with regard to the modifier keys (shift, control, alt), so the application sees Control-P as a *single* synthesized event instead of four. I'm afraid you'll have to roll your own logic, as your use case isn't very common. Perhaps treat 4 followed by 8 in quick succession the same as a fictional event 48 equivalent to 7. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: ftp EOF error, thread and process
En Sun, 28 Dec 2008 10:44:11 -0200, nemo nemoking...@gmail.com escribió: My code like this raise an EOFError, It happens if I use the Process module, while, if I use thread.start_new_thread(ftp.pwd,()), it seems works well. And I wondered why. from ftplib import FTP import thread from multiprocessing import Process if __name__ == '__main__': ftp = FTP('localhost', 'movie', 'movie') print ftp.pwd() p = Process(target = ftp.pwd) # thread.start_new_thread (ftp.pwd,()), p.start() p.join() You asked the same question last week. What exactly do you want to do? Using another process in this example is just not sensible. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
why cannot assign to function call
I have a function return a reference, and want to assign to the reference, simply like this: def f(a) return a b = 0 * f( b ) = 1* but the last line will be refused as can't assign to function call. In my thought , the assignment is very nature, but why the interpreter refused to do that ? thks -- http://mail.python.org/mailman/listinfo/python-list
Re: why cannot assign to function call
On Mon, Dec 29, 2008 at 4:01 PM, scsoce scs...@gmail.com wrote: I have a function return a reference, and want to assign to the reference, simply like this: def f(a) return a b = 0 * f( b ) = 1* but the last line will be refused as can't assign to function call. In my thought , the assignment is very nature, but why the interpreter refused to do that ? That's exactly right. You _cannot_ assign to a function call. This is invalid in just about _all_ languages. Assignments are generally bound to a variable. def f(a): ... return a ... b = 0 x = f(b) x 0 cheers James -- http://mail.python.org/mailman/listinfo/python-list
Re: /kolab/bin/python: double free or corruption (fasttop)
En Sun, 28 Dec 2008 12:10:06 -0200, aspineux aspin...@gmail.com escribió: I got this. This is a test script, to help me to understand why I have unexpected result in application. But I got a more unexpected result, and probably wrong error message about the read-only cursor. def server(): dbenv, db=init_db(read_only=False) update_thread=threading.Thread(target=lambda : cleanup(db)) update_thread.setDaemon(True) update_thread.start() I'd write it as update_thread = threading.Thread(target=cleanup, args=(db,)) or: update_thread = threading.Thread(target=lambda db=db: cleanup(db)) The original code is creating a closure and I'm unsure how closures interact with threads. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: why cannot assign to function call
On Dec 29, 12:01 am, scsoce scs...@gmail.com wrote: I have a function return a reference, and want to assign to the reference, simply like this: def f(a) return a b = 0 * f( b ) = 1* but the last line will be refused as can't assign to function call. In my thought , the assignment is very nature, but why the interpreter refused to do that ? thks because all you need to do is b = 1 trying to change the return value of a function before you even know what it is so to speak, defeats the whole purpose of sending it there in the first place. just assign the variable to a new value. Thats my common sense answer, maybe somebody can give a technical one :) -- http://mail.python.org/mailman/listinfo/python-list
Re: parsing csv files class
Tim, Thank you for your suggestions that you made. I will modify my class to what you said. I will also remove find_and_replace. seeing as I won't use it anywhere else. I think I put it there for some test and forgot to delete it. I was actually deleting the header outside of the class. This works much better for me. Any other suggestions are appreciated. Thank you. -A On Sun, Dec 28, 2008 at 5:46 AM, Tim Roberts t...@probo.com wrote: alex goretoy aleksandr.gore...@gmail.com wrote: class parsercsvy(object): Return a line from a csv file or total amount of lines def __init__(self,file_name=): self.func_me_color=white_on_black self.soc=stdout_colours.stdout_colors() self.soc.me_him(['ENTER:',__name__],self.func_me_color) self.filename = file_name self.buffer = [] self.bufferp= [] if string.find(self.filename,http) != -1: resp=urllib2.urlopen(self.filename) file=resp.read() lfi=len(string.split(self.filename,/)) filename = /tmp/+string.split(self.filename,/)[lfi-1] Style issue: unless you are running Python 1.x, you virtually never need to import the string module. Also, you can always refer to the last element of a list or tuple by using [-1]: parts = self.filename.split( / ) filename = /tmp/ + parts[-1] def parse(self,filename,ret=0): self.soc.me_him(['ENTER:',__name__],self.func_me_color) i = 0 try: reader = csv.reader(file(filename, rb)) try: for row in reader: self.buffer.append(row) s,a=[],{} for j in range(len(self.buffer[0])): a[self.buffer[0][j]]=row[j] self.bufferp.append(a) i+=1 self.total = i-1 You might consider keeping the header line separate. reader = csv.reader(open(filename, rb)) header = reader.next() self.buffer = list(reader) self.bufferp = [ dict( zip( header, line ) ) for line in reader ] self.header = header Also, you don't really need a separate total variable, since it's equal to len(self.buffer). def total(self): return total number of lines in csv file self.soc.me_him(['ENTER:',__name__],self.func_me_color) self.soc.me_him(['RETURN:',self.total,__name__],self.func_me_color) return self.total There's a problem here, as this was originally written. self.total starts out being a function (this one here). But after self.parse runs, self.total will be an integer, and this function is lost. You need to decide whether you want users to just access the self.total integer, or force them to use the function. In the latter case, you can change the counter to self._total. On the other hand, the self.total counter is unnecessary: def total(self): return len(self.buffer) def find_and_replace(self,li,fi,re): find and replace a string inside a string, return list find_and_replace(list,find,replace) this=[] for l in li: #found_index=string.find(l,fi) this.append(l.replace(fi,re)) return this def find_and_replace(self,li,fi,re): return [l.replace(fi,re) for l in li] I'm not sure why this is a member of the class; it doesn't use any of the members. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list -- А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я -- http://mail.python.org/mailman/listinfo/python-list
Re: Cheetah
En Sun, 28 Dec 2008 15:01:14 -0200, sopherf...@gmail.com escribió: 1. In Cheetah 2.0.1, both from python 2.5.2 and 2.6, after I do a [...] 2. In reportlab 2.2, when I generate a PDF, no matter how many nbsps [...] Better to report those problems to each product authors. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: /kolab/bin/python: double free or corruption (fasttop)
En Mon, 29 Dec 2008 04:12:02 -0200, Gabriel Genellina gagsl-...@yahoo.com.ar escribió: En Sun, 28 Dec 2008 12:10:06 -0200, aspineux aspin...@gmail.com escribió: I got this. This is a test script, to help me to understand why I have unexpected result in application. But I got a more unexpected result, and probably wrong error message about the read-only cursor. def server(): dbenv, db=init_db(read_only=False) update_thread=threading.Thread(target=lambda : cleanup(db)) update_thread.setDaemon(True) update_thread.start() I'd write it as update_thread = threading.Thread(target=cleanup, args=(db,)) or: update_thread = threading.Thread(target=lambda db=db: cleanup(db)) The original code is creating a closure and I'm unsure how closures interact with threads. Anyway, the crash should not happen, this may be a bug in Python or bsddb: http://bugs.python.org/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: ftp design question
On Dec 29, 12:31 pm, Steve Holden st...@holdenweb.com wrote: nemo wrote: Hi,all. I'm on a toy ftp project and I want it to be convinient for the user to cancel an undergoing downloading while continue others. The following code explains: for file in download_files: self.ftp.retrbinary('RETR '+file, fileHandler) Thers seems not a solid way to cancel this transfer and I considered thread or process but I can't handle this correctly. Thread: I can't kill the thread in another thread, so... Process: There seems something wrong(raise an EOFError exception) when I use Process(target = download_fun, args = (dir,)) for each downloading after connection built. Some suggestions? How about for file in download_files: try: self.ftp.retrbinary('RETR %s' % file, fileHandler) except KeyboardInterrupt: print file, transfer abandoned Then you can cancel a single file transfer with Ctrl/C. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Thanks your advice, actually, this ftp has a GUI interface, so I'm considering the downloading part in another process or thread, whick is s a tricky part for me to design. -- http://mail.python.org/mailman/listinfo/python-list
Re: why cannot assign to function call
scsoce wrote: I have a function return a reference, and want to assign to the reference, simply like this: def f(a) return a b = 0 * f( b ) = 1* but the last line will be refused as can't assign to function call. In my thought , the assignment is very nature, but why the interpreter refused to do that ? Because, as in most languages, it's not even clear what you might mean by this syntax. It doesn't have any meaning; assignments are made to variables, not the results of function calls. -- Erik Max Francis m...@alcyone.com http://www.alcyone.com/max/ San Jose, CA, USA 37 18 N 121 57 W AIM, Y!M erikmaxfrancis Only love is worth the risk -- Oleta Adams -- http://mail.python.org/mailman/listinfo/python-list
Get a list of functions in a file
I'm putting some utility functions in a file and then building a simple shell interface to them. Is their some way I can automatically get a list of all the functions in the file? I could wrap them in a class and then use attributes, but I'd rather leave them as simple functions. Thanks, Basu -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill orphaned threads at program exit
On 28 Dic, 18:47, Roy Smith r...@panix.com wrote: In article b133b978-fe63-4893-bb33-8c96bfb59...@v5g2000prm.googlegroups.com, Giampaolo Rodola' gne...@gmail.com wrote: Hi, I know that it's not possible to kill threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. You don't say how you're creating your threads, so I'll assume you're using threading.Thread(). After creating each thread, and before calling start() on it, call setDaemon(True). Apparently it doesn't make any difference. A curious thing is that by putting a print 1 as last instruction the pending threads get killed and the program exits (Windows XP sp3 32 bit). --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
[issue4705] python3.0 -u: unbuffered stdout
Antoine Pitrou pit...@free.fr added the comment: pitrou's patch changes PyFile_FromFd() behaviour for a text file opened with buffering=0: /* As a convenience, when buffering == 0 on a text file, we open the underlying binary stream in unbuffered mode and wrap it with a text stream in line-buffered mode. */ Why changing PyFile_FromFd() and not io.open() directly? I must admit I'm a bit lazy, and changing io.open() means changing a fundamental public API, as Guido said on python-dev, so more discussion and some parts of the patches delayed to 3.1. If someone else wants to do it, please don't hesitate... Note: I prefer Py_UnbufferedStdoutFlag=1 instead of Py_UnbufferedStdoutFlag++ (for -u command line option). Well, I minimally changed the existing code. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4705 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4759] bytearray.translate() should support None first argument
Antoine Pitrou pit...@free.fr added the comment: Looks like there's a problem: bytearray().translate(None, None) Traceback (most recent call last): File stdin, line 1, in module TypeError: Type NoneType doesn't support the buffer API bytearray().translate(None, None) Erreur de segmentation Also, the patch should probably be backported to trunk. -- versions: +Python 2.7 -Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4759 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4759] bytearray.translate() should support None first argument
Georg Brandl ge...@python.org added the comment: You're right (but the segfault isn't introduced by the patch). Fixed segfault in 3.0 and 2.6 in r67975 and r67977. Applied path in 3k and trunk in r67974 and r67976. -- assignee: pitrou - georg.brandl resolution: - accepted status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4759 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4489] shutil.rmtree is vulnerable to a symlink attack
Mart Sõmermaa m...@mrts.pri.ee added the comment: A shameless copy of the Perl fix for the bug http://bugs.debian.org/286922 looks like the evident solution. Somebody has to examine the fix though, I'm afraid I'm not currently able to do it. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4489 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4731] suggest change to Failed to find the necessary bits to build these modules message
Georg Brandl ge...@python.org added the comment: Done in r67978. -- nosy: +georg.brandl resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4731 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4705] python3.0 -u: unbuffered stdout
STINNER Victor victor.stin...@haypocalc.com added the comment: Why changing PyFile_FromFd() and not io.open() directly? I must admit I'm a bit lazy, and changing io.open() means changing a fundamental public API, as Guido said on python-dev, so more discussion and some parts of the patches delayed to 3.1. You're right, and PyFile_FromFd() is also a fundamental public API. Since TextIOWrapper doesn't support real unbuffered buffer (only pseudo line buffer: unbuffered raw buffer and line buffering for TextIOWrapper), I prefer to change only stdout/stderr instead of PyFile_FromFd(). My new patch only changes initstdio() using pitrou's code. Should we also change stdin? Added file: http://bugs.python.org/file12477/unbufferedstdout-2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4705 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4701] range objects becomes hashable after attribute access
Nick Coghlan ncogh...@gmail.com added the comment: enumerate can be added to the list of builtin types which isn't initialised correctly, as can the callable+sentinel iterator return from the 2-argument version of iter() and the default sequence iterator returned by iter() when given a type with both __len__ and __getitem__ methods, but no __iter__ method. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4701 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4701] range objects becomes hashable after attribute access
Nick Coghlan ncogh...@gmail.com added the comment: Copied from python-dev post: Perhaps the path of least resistance is to change PyObject_Hash to be yet another place where PyType_Ready will be called implicitly if it hasn't been called already? That approach would get us back to the Python 2.x status quo where calling PyType_Ready was only absolutely essential if you wanted to correctly inherit a slot from a type other than object itself. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4701 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4705] python3.0 -u: unbuffered stdout
Antoine Pitrou pit...@free.fr added the comment: Le dimanche 28 décembre 2008 à 12:19 +, STINNER Victor a écrit : STINNER Victor victor.stin...@haypocalc.com added the comment: Why changing PyFile_FromFd() and not io.open() directly? I must admit I'm a bit lazy, and changing io.open() means changing a fundamental public API, as Guido said on python-dev, so more discussion and some parts of the patches delayed to 3.1. You're right, and PyFile_FromFd() is also a fundamental public API. Well, open() is fundamental as in part of the built-ins and used pervasively. PyFile_FromFd(), on the other hand, is a relic of the 2.x C file handling API. Let's see what others have to say about this. Should we also change stdin? I don't know, but python -h only talks about stderr/stdout. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4705 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4444] unittest - use contexts to assert exceptions
Antoine Pitrou pit...@free.fr added the comment: I've committed an improved patch, with tests and doc, in r67979 and r67981. Thanks! -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4489] shutil.rmtree is vulnerable to a symlink attack
Antoine Pitrou pit...@free.fr added the comment: The Perl patch is here: http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=36;filename=etch_03_fix_file_path;att=1;bug=286922 It is a recursive implementation of rmtree. What it does is 1) get the inode of the path 2) unlink it altogether if not a dir 3) otherwise, chdir to it 4) check that '.' still has the same inode, otherwise bail out. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4489 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4489] shutil.rmtree is vulnerable to a symlink attack
Antoine Pitrou pit...@free.fr added the comment: Mmmh, the problem with Perl's approach is that it changes the current working directory (calls to chdir()), which is process-specific and not thread-specific. Currently, no function in shutil changes the current working directory, which is a nice behaviour and should IMO be preserved. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4489 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4761] create Python wrappers for openat() and others
New submission from Antoine Pitrou pit...@free.fr: Very recent POSIX versions have introduced a set of functions named openat(), unlinkat(), etc. (*) which allow to access files relatively to a directory pointed to by a file descriptor (rather than the process-wide current working directory). They are necessary to implement thread-safe directory traversal without any symlink attacks such as in #4489. Providing Python wrappers for these functions would help creating higher-level abstractions for secure directory traversal on platforms that support it. (*) http://www.opengroup.org/onlinepubs/9699919799/functions/openat.html “The purpose of the openat() function is to enable opening files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to open(), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the openat() function it can be guaranteed that the opened file is located relative to the desired directory.” -- components: Extension Modules, Library (Lib) messages: 78407 nosy: loewis, pitrou priority: normal severity: normal status: open title: create Python wrappers for openat() and others type: feature request versions: Python 2.7, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4761 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4705] python3.0 -u: unbuffered stdout
Antoine Pitrou pit...@free.fr added the comment: It seems the name field of the TextIOWrapper object isn't set in create_stdio() (the char *name parameter isn't used). Otherwise, the patch looks good. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4705 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1034053] unittest.py patch: add skipped test functionality
Antoine Pitrou pit...@free.fr added the comment: Pupeno's patch looks good to me. Additional candy would be a decorator to flag skipped tests (e.g. @skipped_test or @skipped_test(A message)), but we can do that later. -- stage: - patch review type: - feature request versions: +Python 2.7, Python 3.1 -Python 2.4, Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1034053 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2153] unittest.py modernization
Antoine Pitrou pit...@free.fr added the comment: Will take a look. -- versions: +Python 2.7 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2153 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4034] traceback attribute error
Antoine Pitrou pit...@free.fr added the comment: One possibility would be to only allow deleting the tb_frame attribute (setting it to NULL), not setting it to an arbitrary object. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4034 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4060] PyUnicode_DecodeUTF16(..., byteorder=0) gets it wrong on Mac OS X/PowerPC
Benjamin Peterson benja...@python.org added the comment: Applied the patch in r67982. -- nosy: +benjamin.peterson resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4060 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4728] Endianness and universal builds problems
Benjamin Peterson benja...@python.org added the comment: I applied the patch for #4060 in r67982. I would still like to know what difference an Intel machine makes in the installers, though. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4728 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4750] tarfile keeps excessive dir structure in compressed files
anatoly techtonik techto...@gmail.com added the comment: 7zip can decompress both, but it still creates dist/ directory when decompressing file that is made with Python. I've noticed this bug with extra path component is actual with tar + gzip under windows. If they are executed separately and windows path with backslashes is used - directory prefix is not stripped. I.e. this creates archive with invalid header: {{{ tar -cf dist\create_tar_sep.tar package gzip -f9 dist\create_tar_sep.tar }}} This command is ok: {{{ tar -cf dist\create_tar_sep.tar package gzip -f9 dist/create_tar_sep.tar }}} ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4750 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2153] unittest.py modernization
Antoine Pitrou pit...@free.fr added the comment: Committed in r67985, thanks! -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2153 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com