Re: what is the difference between the two kinds of brackets?
Paul Hankin pamail.com wrote: If everything else is equal, use tuples. Interesting point of view - mine is just the opposite. I wonder if its the philosophical difference between: Anything not expressly allowed is forbidden and Anything not expressly forbidden is allowed ? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: logging module - restricted mode error
Vinay Sajip [EMAIL PROTECTED] writes: On 16 Oct, 04:14, Paul Rudin [EMAIL PROTECTED] wrote: I'm occasionally seeing tracebacks like this: Traceback (most recent call last): File logging/__init__.py, line 744, in emit File logging/__init__.py, line 630, in format File logging/__init__.py, line 421, in format RuntimeError: instance.__dict__ not accessible in restricted mode I'm not sure what it means. Googling leads me to http://docs.python.org/lib/restricted.html but that says that those modules were disabled in 2.3 and I'm running 2.5.1. In any case I'm not using them (although it could be that one of the 3rd party modules I'm using does something.) Could someone please explain what this error means? Can you say a little bit more about the execution environment? For example, are you running under mod_python? If so, which version? I'm not running under mod_python - but this is using cherrypy. I also do some passing of pickled objects between two python processes, which I guess could be relevant. When googling, did you search for the exact text of the error message? For example, did you see the following post? http://mail-archives.apache.org/mod_mbox/httpd-python-dev/200404.mbox/[EMAIL PROTECTED] I hadn't noticed that particularly, but I'm still a little unclear as to what's going on. That thread dates from 3 years ago and it seems to imply that mod python is using restricted mode (in the sense of the the rexec module), which won't run in 2.5 will it? One parts that says: Restricted mode is a strange beast, in that there isn't really anything like a restricted mode flag, but it looks at a pointer somwhere (don't remember now), and if it's not what is expected, it concludes that it's in restricted mode. So this behaviour is actually a sign of a bug where an object is created in one subinterpreter but is running in another... These bugs can be hard to track down. What exactly is meant by a subinterpreter? Python running in a subprocess? -- http://mail.python.org/mailman/listinfo/python-list
Re: Selection error...
cursor.execute(SELECT id from templinks where url=%s, (URL,) ) Yes i already try this before ask. URL.decode('latin-1').encode('utf-8') to transcode it into utf-8. i know this but how do you know the html encoding's a latin-1 ? Html encoding is to be iso-8859-9 or ascii or cp1254 ... For this reason URL.decode('latin-1').encode('utf-8') must give me error. I'm trying now and whet it finished i write the result here. Thank you very much for your helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
On Sat, 20 Oct 2007 14:04:06 -0700, llothar [EMAIL PROTECTED] tried to confuse everyone with this message: I love math. I respect Math. I'm nothing but a menial servant to Mathematics. Programming and use cases are not maths. Many mathematics are the worst programmers i've seen because they want to solve things and much more often you just need heuristics. Once they are into exact world they loose there capability to see the factor of relevance in algorithms. And they almost never match the mental model that the average user has about a problem. I'm, not sure that I'm getting your point, but are you trying to argue that _not_ knowing mathemathics makes you a better programmer? Or maybe that learning math is useless to a programmer? This must be the most ignorant post I've seen this week. The *best* programmers I've seen actually had mathematic education. The programmers who don't know math are the ones who end up on DailyWTF. -- |Don't believe this - you're not worthless ,gr-.ru |It's us against millions and we can't take them all... | ue il | |But we can take them on! | @ma | | (A Wilhelm Scream - The Rip)|__| -- http://mail.python.org/mailman/listinfo/python-list
Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away
On Oct 20, 10:46 pm, rbe [EMAIL PROTECTED] wrote: On Oct 15, 5:22 am, Mike Kent [EMAIL PROTECTED] wrote: Conference page // with links to program details // (updated Friday 10/12) http://www.sigapl.org/apl2007.html... At APL2007, I'll be announcing the release of the APEX APL compiler, version 0.0.0, under GPL Version 2. If you can't wait until then, you can download it for Dyalog Linux atwww.snakeisland.com. Bob Congratulations on your compiler. I looked through your pages and came across this [This article originally appeared in the ACM SIGAPL Quote Quad, vol. 21, no.1, September 1990.] The APL character set has contributed, more than any other facet of the language, to its lack of acceptance in the computing community at large. The character set is a metaproblem -- not a problem in and of itself, but a creator of other recurring problems of hardware, software, ergonomics, and psychology. The adoption of new, ASCII-base dialects of APL, such as J, is suggested as one solution to the character set problem. This is also the reason for why I will not be downloading your new compiler until there will be a J version of it, something I hope will be coming soon. I can not use the APL character set at all. It is too mixed up with my national characters. -- http://mail.python.org/mailman/listinfo/python-list
Shed Skin Python-to-C++ compiler 0.0.24, 0.0.25
Hi all, I've just released Shed Skin 0.0.25. Together with the (unannounced) 0.0.24 release, there have been some interesting changes. Most importantly perhaps, Shed Skin now caches (most) 1-length strings, which can improve performance dramatically for string-intensive programs. I also performed a long-overdue rewrite of the virtual function detection code, which should work much more reliably now, at least for relatively simple cases :) 0.0.24: -1-length string caching 0.0.25 -improved detection of virtual functions -further set optimizations -fix for extension modules and certain default arguments -exhaustive checking of C++ keywords -fix for some combinations of arguments to min, max -several minor bug fixes As always, I could really use more help in pushing Shed Skin forward. Let me know if you'd like to help out, but are not sure where to begin. The Shed Skin homepage: http://mark.dufour.googlepages.com Thanks, Mark. -- One of my most productive days was throwing away 1000 lines of code - Ken Thompson -- http://mail.python.org/mailman/listinfo/python-list
Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away
Gosi [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Oct 20, 10:46 pm, rbe [EMAIL PROTECTED] wrote: On Oct 15, 5:22 am, Mike Kent [EMAIL PROTECTED] wrote: Conference page // with links to program details // (updated Friday 10/12) http://www.sigapl.org/apl2007.html... At APL2007, I'll be announcing the release of the APEX APL compiler, version 0.0.0, under GPL Version 2. If you can't wait until then, you can download it for Dyalog Linux atwww.snakeisland.com. Bob Congratulations on your compiler. I looked through your pages and came across this [This article originally appeared in the ACM SIGAPL Quote Quad, vol. 21, no.1, September 1990.] The APL character set has contributed, more than any other facet of the language, to its lack of acceptance in the computing community at large. The character set is a metaproblem -- not a problem in and of itself, but a creator of other recurring problems of hardware, software, ergonomics, and psychology. The adoption of new, ASCII-base dialects of APL, such as J, is suggested as one solution to the character set problem. This is also the reason for why I will not be downloading your new compiler until there will be a J version of it, something I hope will be coming soon. I can not use the APL character set at all. It is too mixed up with my national characters. witch ones? -- wade ward [EMAIL PROTECTED] Der Katze tritt die Treppe hoch; Der Kater tritt sie krumm.% % De Teufel geit um; er bringt de menschen allet dumm. schau, schau -- http://mail.python.org/mailman/listinfo/python-list
Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away
Gosi wrote: .. I can not use the APL character set at all. It is too mixed up with my national characters. What about a unicode version of APL? Honestly, I cannot use J because it mixes with all the characters I use... ;) -Veli-Matti -- http://mail.python.org/mailman/listinfo/python-list
Visibility of symbols between extension modules
Hi all, I have been learning to write extension modules using the C API that python provides, and have hit a minor roadblock that is turning out to be major headache. My project essentially is organized as follows, foo | - | || bar_foo baz _foo basically does some init stuff, nothing much. Thats where the problem starts. The handler variable which is initialized in _foo isn't visible to others. One solution that worked was calling the initializing function in each of the module's PyMODINIT_FUNC. Debugging through the interpreter I found out the it loads all the .so's and executes PyMODINIT_FUNCs. But by doing so, the routine to initialize the handle gets executed three times, something which i find to be sort of unclean. The definition of the variable is included in a header and the sources of the other modules include this master header, So I do have that variable in scope, but its not initialized. _foo does the job of declaring that variable. I did my share of RTFM and found CObjects as a potential alternative. But I feel its use rather complicated for a single variable that goes out of scope. Is there any other way to solve this, or is my approach itself borked =(?, What am I missing? Thanks for your help -- Sudharshan S http://www.sudharsh.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Selection error...
2007/10/21, Abandoned [EMAIL PROTECTED]: cursor.execute(SELECT id from templinks where url=%s, (URL,) ) Yes i already try this before ask. URL.decode('latin-1').encode('utf-8') to transcode it into utf-8. i know this but how do you know the html encoding's a latin-1 ? Try using chardet to detect the encoding Html encoding is to be iso-8859-9 or ascii or cp1254 ... For this reason URL.decode('latin-1').encode('utf-8') must give me error. I'm trying now and whet it finished i write the result here. Thank you very much for your helps. -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
I'm, not sure that I'm getting your point, but are you trying to argue that _not_ knowing mathemathics makes you a better programmer? No but it doesn't help you very much either. They are just different skills. Or maybe that learning math is useless to a programmer? No and at least the mathematical idea of building a universe on a basic set of axioms is pretty exciting for a programmer. But it's the idea not the real wisdom (I never had to use any serious maths in my 25 years of programming) that you need as a programmer This must be the most ignorant post I've seen this week. The *best* programmers I've seen actually had mathematic education. Depends. I would call Knuth as one of the worst programmers. Look at his total failures on literature programming. Software Engineering is something very different. Having a dead - i mean end of development line software like TeX - and then trying to base a theory about software engineering (which is based on changes) is so absolutely stupid ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
llothar wrote: Depends. I would call Knuth as one of the worst programmers. Look at his total failures on literature programming. Software Engineering is something Umm, the term is literate programmer and there is evidence that it is not a failure. very different. Having a dead - i mean end of development line software like TeX - and Based on what do you call it dead end. It's used, it's outlasted many other flashes in the pan, it does what its users require. You will need evidence for such a claim. then trying to base a theory about software engineering (which is based on changes) base a theory on what? There's a clause missing here. is so absolutely stupid ... Is that a technical evaluation? It looks like random inflammatory comments without basis in logic or evidence. Can stupidity be absolute? What is the metric of stupidity? How would you disprove that assertion? Oh, wait, there wasn't an assertion. The sentence was incomplete. What are you asserting? A theory based on what, exactly, is so absolutely stupid? -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away
Hello, Can we please have a little trimming of newsgroups? Fortran's character set is a nice safe subset of seven-bit ASCII. Veli-Matti wrote: Gosi wrote: .. I can not use the APL character set at all. It is too mixed up with my national characters. What about a unicode version of APL? Honestly, I cannot use J because it mixes with all the characters I use... ;) -Veli-Matti -- Dan Nagle Purple Sage Computing Solutions, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Splitting URLs
I'm trying to split a URL into components. For example: URL = 'http://steve:[EMAIL PROTECTED]:82/dir + \ 'ectory/file.html;params?query#fragment' (joining the strings above with plus has no significance, it's just to avoid word-wrapping) If I split the URL, I would like to get the following components: scheme = 'http' netloc = 'steve:[EMAIL PROTECTED]:82' username = 'steve' password = 'secret' hostname = 'www.domain.com.au' port = 82 path = '/directory/file.html' parameters = 'params' query = 'query' fragment = 'fragment' I can get *most* of the way with urlparse.urlparse: it will split the URL into a tuple: ('http', 'steve:[EMAIL PROTECTED]:82', '/directory/file.html', 'params', 'query', 'fragment') If I'm using Python 2.5, I can split the netloc field further with named attributes. Unfortunately, I can't rely on Python 2.5 (for my sins I have to support 2.4). Before I write code to split the netloc field by hand (a nuisance, but doable) I thought I'd ask if there was a function somewhere in the standard library I had missed. This second question isn't specifically Python related, but I'm asking it anyway... I'd also like to split the domain part of a HTTP netloc into top level domain (.au), second level (.com), etc. I don't need to validate the TLD, I just need to split it. Is splitting on dots sufficient, or will that miss some odd corner case of the HTTP specification? (If it does, I might decide to live with the lack... it depends on how odd the corner is, and how much work it takes to fix.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
Lew wrote: very different. Having a dead - i mean end of development line software like TeX - and Based on what do you call it dead end. It's used, it's outlasted many other flashes in the pan, it does what its users require. You will need evidence for such a claim. According to wikipedia the last version is from december 2002. That level of activity could be considered dead. It would for almost any other software. Tex has some absolute over it, so I am not sure normal software practices apply. But you could argue based on that. Arne -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
llothar wrote: I'm, not sure that I'm getting your point, but are you trying to argue that _not_ knowing mathemathics makes you a better programmer? No but it doesn't help you very much either. They are just different skills. Many things within programming have a foundation in mathematics and mathematical logic. Or maybe that learning math is useless to a programmer? No and at least the mathematical idea of building a universe on a basic set of axioms is pretty exciting for a programmer. But it's the idea not the real wisdom (I never had to use any serious maths in my 25 years of programming) that you need as a programmer Depends obvious a bot on what you consider serious math. Expression evaluation, floating point characteristics, relational database theory, simulation, optimum location, encryption etc. are all based on mathematics of different levels. This must be the most ignorant post I've seen this week. The *best* programmers I've seen actually had mathematic education. Depends. I would call Knuth as one of the worst programmers. Look at his total failures on literature programming. Software Engineering is something very different. I think you will find it very difficult to write a piece of code that are not heavily influenced by Knuth. Arne -- http://mail.python.org/mailman/listinfo/python-list
Re: logging module - restricted mode error
On 21 Oct, 07:50, Paul Rudin [EMAIL PROTECTED] wrote: Can you say a little bit more about the execution environment? For example, are you running under mod_python? If so, which version? I'm not running under mod_python - but this is using cherrypy. I also do some passing of pickled objects between two python processes, which I guess could be relevant. When googling, did you search for the exact text of the error message? For example, did you see the following post? http://mail-archives.apache.org/mod_mbox/httpd-python-dev/200404.mbox/[EMAIL PROTECTED] I hadn't noticed that particularly, but I'm still a little unclear as to what's going on. That thread dates from 3 years ago and it seems to imply that mod python is using restricted mode (in the sense of the the rexec module), which won't run in 2.5 will it? One parts that says: Restricted mode is a strange beast, in that there isn't really anything like a restricted mode flag, but it looks at a pointer somwhere (don't remember now), and if it's not what is expected, it concludes that it's in restricted mode. So this behaviour is actually a sign of a bug where an object is created in one subinterpreter but is running in another... These bugs can be hard to track down. What exactly is meant by a subinterpreter? Python running in a subprocess? I'm no mod_python expert: I just wondered whether you might be hitting the same problem. The way I read it, the restricted mode referred to in that post is not in the rexec sense, but based on some more obscure heuristic to do with multiple interpreters. Anyway: I don't think it's specifically a logging problem, except that logging does introspect (look at LogRecord.__dict__) and this raises the error. But in that, it's no different to lots of other stdlib and third party modules. Vinay -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
For the love of the Perl, Python, Lisp, Java and functional programmers, please just give an abstract of what you've written and link to it? -Rudolf -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
Arne Vajhøj wrote: Lew wrote: very different. Having a dead - i mean end of development line software like TeX - and Based on what do you call it dead end. It's used, it's outlasted many other flashes in the pan, it does what its users require. You will need evidence for such a claim. According to wikipedia the last version is from december 2002. That level of activity could be considered dead. It would for almost any other software. Tex has some absolute over it, so I am not sure normal software practices apply. But you could argue based on that. No, you present good evidence that TeX is a dead end. It still doesn't support the claim llothar wrote: Depends. I would call Knuth as one of the worst programmers. Plenty of brilliant programmers have written software that is no longer used (except in legacy use cases). Good software, too. I suppose what I was reacting to was the notion that TeX was a dead end at the time Knuth came up with it, and that that somehow invalidated the accomplishment of coming up with TeX. The fact that it is still in use even five years after cessation of development does mitigate the dead end assessment at least potentially. -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
OMouse wrote: For the love of the Perl, Python, Lisp, Java and functional programmers, please just give an abstract of what you've written and link to it? I expect you'll be ignored on that. Xah Lee reposts and reposts these essays from years agone. I don't even read his posts, just the responses. -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
On 21 Okt., 21:39, Arne Vajhøj [EMAIL PROTECTED] wrote: That level of activity could be considered dead. For me at least 2% of the total line count should be changed to call it non dead. I don't say it it not used anymore for users it might be not dead but this is not the point under discussion here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
llothar wrote: On 21 Okt., 21:39, Arne Vajhøj [EMAIL PROTECTED] wrote: That level of activity could be considered dead. For me at least 2% of the total line count should be changed to call it non dead. I don't say it it not used anymore for users it might be not dead but this is not the point under discussion here. No, there are two points - not whether Tex is dead, but whether it's a dead end (which do you mean?), and whether in any way that says anything about Knuth's ability as a programmer. Evidence is that TeX development is dead. There is not yet firm evidence that Tex is a dead end (or even what that means), and there has been none (nor, I expect, is there any) that any of that reflects on Knuth's skill as a programmer. The switch from asserting dead end to asserting dead is sort of an interesting rhetorical device. Just pick one or the other, or if you prefer, assert both, but please be clear. Should we just accept that you meant, less than 2% of total line count changed? Per year? Per century? What if the code is perfect and has no need of change? Is it (a) dead (end)? (Who uses line count as a metric of anything any more?) -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
Depends obvious a bot on what you consider serious math. Expression evaluation, floating point characteristics, relational database theory, simulation, optimum location, encryption etc. are all based on mathematics of different levels. Thats not i call serious maths. You just need a very little understanding here for all this concepts. A extended high school degress should be well enough (based on our education system in Germany - don't know how much math you do in a US high schoool). A little bit set theory and of course boolean algebra (on a very low level but unfortunately not teached in school). But where do you need the way to prove mathematical theorems and this is what i call as serious math. You don't need to prove anything you just need to use it. (In 95% of all programming, except some embedded programming with DSP's or numeric.) Depends. I would call Knuth as one of the worst programmers. Look at his total failures on literature programming. Software Engineering is something very different. I think you will find it very difficult to write a piece of code that are not heavily influenced by Knuth. Well programming in the small like sort algorithms for sure. But not for his great discoveries but for one of the first man who was paid for this by this university employee. But in the field of software enginering as i said before he completely failed. And for me programming is just another word for software engineering these days. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
llothar wrote: Well programming in the small like sort algorithms for sure. But not for his great discoveries but for one of the first man who was paid for this by this university employee. What a curious thesis. But in the field of software enginering as i said before he completely failed. As you said, but for which you provided absolutely no evidence, and the counter evidence that Arne provided is that he has not completely failed for any useful value of failed. Statements of absolute only need one counterexample. /The Art of Programming/ is arguably the most significant contribution to the field of software engineering. By any reasonable assessment, on the basis of that one work alone Knuth was a success. Your rhetorical tack of unfounded assertions and inflammatory characterizations, not to say complete disregard for the reality of the situation, do not make a cogent case, much less a convincing one. I am afraid that your conclusion is quite mistaken. Knuth is, if anything, a huge success in the field of software engineering, whether you rate it as making a contribution to the art, or as being paid to perform the art. -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Re: General module name clash problem?
I hope, i get it right now. :-) So i worked out an extreme not-module-name-clashing-example. Type 'python start.py' at root. Thanks, jipjip root.tar.gz Description: GNU Zip compressed data -- http://mail.python.org/mailman/listinfo/python-list
Endless GIL and thread confusion
Can someone clarify the steps needed to make access to the interpreter safe from multiple threads? I've been reading the docs for days and I still find them very confusing and misleading. For example does the PyGILState_Ensure() function lock the GIL or just create the thread state? Is thread supposed to call it once on creation and then the release function before exiting or is this the preferred mechanism to handle the locking? Most of the confusion stems from this segment in the documentation. ...when threads are created from C, they don't have the global interpreter lock, nor is there a thread state data structure for them. Such threads must bootstrap themselves into existence, by first creating a thread state data structure, then acquiring the lock, and finally storing their thread state pointer, before they can start using the Python/C API. When they are done, they should reset the thread state pointer, release the lock, and finally free their thread state data structure. Beginning with version 2.3, threads can now take advantage of the PyGILState_*() functions to do all of the above automatically. Anyway, currently my code looks like this: void foobar(...) { PyGILState state = PyGILState_Ensure(); // make python calls PyGILState_Release(state); } void blablah(...) { PyGILState state = PyGILState_Ensure(); // make python calls PyGILState_Release(state); } My python Initialization code looks like this void init_python(char* progname, char* bindir) { Py_SetProgramName(progname); PyEval_InitThreads(); Py_InitializeEx(0); char* argv[] = {progname, bindir}; PySys_SetArgv(2, argv); } calling foobar() or blablah() from the main thread works as expected, but if the second thread calls them it locks up in the call to PyGILState_Ensure(). I have tried adding a call to PyEval_ReleaseLock() in the init_python function to make sure that the main thread is not holding the GIL, but this causes the application to segfault when it is calling Py_Finalize() so it is clear that this is not correct. Please advice. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
compiler module bug?
Hello, I am experiencing a problem with the compiler module. Is this a bug, or am I doing something wrong? so I have the following code: from compiler import parse, parseFile filename='blah.py' if False: # turn this to false, to get it to work ast = parse(open(filename).read()) # this line gives a syntax error else: ast = parseFile(filename) # this line works print ast the documentation, here http://docs.python.org/lib/module- compiler.html says that the two lines with parse and parseFile are equivalent. the file I am trying to parse is simply: def main(): a=10 # comment at the end of the file it seems like a comment at the end breaks the parse command, but not parseFile. Is this reproducible by others? am I doing something wrong? thanks, Brian Blais -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Problem Converting Word to UTF8 Text File
Hi all, I'm trying to copy a bunch of microsoft word documents that have unicode characters into utf-8 text files. Everything works fine at the beginning. The word documents get converted and new utf-8 text files with the same name get created. And then I try to copy the data and I keep on getting TypeError: coercing to Unicode: need string or buffer, instance found. I'm probably copying the word document wrong. What can I do? Thanks, Patrick import os, codecs, glob, shutil, win32com.client from win32com.client import Dispatch input = 'C:\\text_samples\\source\\*.doc' output_dir = 'C:\\text_samples\\source\\output' FileFormat=win32com.client.constants.wdFormatText for doc in glob.glob(input): doc_copy = shutil.copy(doc,output_dir) WordApp = Dispatch(Word.Application) WordApp.Visible = 1 WordApp.Documents.Open(doc) WordApp.ActiveDocument.SaveAs(doc, FileFormat) WordApp.ActiveDocument.Close() WordApp.Quit() for doc in glob.glob(input): txt_split = os.path.splitext(doc) txt_doc = txt_split[0] + '.txt' txt_doc = codecs.open(txt_doc,'w','utf-8') shutil.copyfile(doc,txt_doc) -- http://mail.python.org/mailman/listinfo/python-list
Re: Visibility of symbols between extension modules
En Sun, 21 Oct 2007 08:21:50 -0300, Sudharshan S [EMAIL PROTECTED] escribi�: I have been learning to write extension modules using the C API that python provides, and have hit a minor roadblock that is turning out to be major headache. My project essentially is organized as follows, foo | - | || bar_foo baz What is foo? a directory? And bar/_foo/baz, source files in C? Each one defining a module object, or is there a single module - foo perhaps? _foo basically does some init stuff, nothing much. Thats where the problem starts. The handler variable which is initialized in _foo isn't visible to others. One solution that worked was calling the initializing function in each of the module's PyMODINIT_FUNC. Debugging through the interpreter I found out the it loads all the .so's and executes PyMODINIT_FUNCs. But by doing so, the routine to initialize the handle gets executed three times, something which i find to be sort of unclean. Ah, ok, after rereading it I see you have three modules. The definition of the variable is included in a header and the sources of the other modules include this master header, So I do have that variable in scope, but its not initialized. _foo does the job of declaring that variable. Is it a global C variable, or a module attribute? If you want it to be available to other Python code, it should be a module attribute. In this case, you retrieve the value using PyObject_GetAttrString as with any other object. If it's a global C variable, once it's assigned it should be visible to all (but decades of warning against using global variables can't be wrong...) The single most common error using the Python API is getting wrong the reference counts. If you lose a reference, your object may be garbage collected. If you leak a reference, it will never be freed. Maybe this is what happens here. I did my share of RTFM and found CObjects as a potential alternative. But I feel its use rather complicated for a single variable that goes out of scope. Is there any other way to solve this, or is my approach itself borked =(?, What am I missing? Perhaps if you explain a bit more what you want to do someone can give some advice. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Error when python script run as cgi script
Hi, I'm running a python script which if I run from the command line as root runs fine. But if I run it through the web-browser as a cgi script gives the following error Error in X11: unable to start device PNG. Now I should say that this python script is calling fucntions in R (a scripting languange used in statistics) using the python module RPy, so this I dunno if this is entirely a Python question, because as far as I can see the error is being thrown by R. But then as I say, when the script is run by the root user from the command line everything goes off without a hitch. So I dunno is there some way to run a CGI script as root, maybe thats a bad idea because of security? But any ideas would be welcome. -Thanks. -- http://mail.python.org/mailman/listinfo/python-list
errors while building a program with Python
Hi, I'm trying to build a program (MixMinion) with Python 2.5.1, MSVS 2003 SP1 and Windows XP Home SP2 but I'm getting a couple of errors. Here are the two errors I am getting: (1) .\contrib\OpenSSL\lib\Builder5\ssleay32.lib : fatal error LNK1136: invalid or corrupt file (2) error: command 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe' failed with exit status 1136 Here is the terminal output log: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Ownercd C:\MixMinion\Mixminion-0.0.8alpha3 C:\MixMinion\Mixminion-0.0.8alpha3python setup.py build Host is little-endian C:\Python25\Lib\config\Makefile running build running build_py creating build\lib.win32-2.5 creating build\lib.win32-2.5\mixminion copying lib\mixminion\benchmark.py - build\lib.win32-2.5\mixminion copying lib\mixminion\BuildMessage.py - build\lib.win32-2.5\mixminion copying lib\mixminion\ClientAPI.py - build\lib.win32-2.5\mixminion copying lib\mixminion\ClientDirectory.py - build \lib.win32-2.5\mixminion copying lib\mixminion\ClientMain.py - build\lib.win32-2.5\mixminion copying lib\mixminion\ClientUtils.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Common.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Config.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Crypto.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Filestore.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Fragments.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Main.py - build\lib.win32-2.5\mixminion copying lib\mixminion\MMTPClient.py - build\lib.win32-2.5\mixminion copying lib\mixminion\NetUtils.py - build\lib.win32-2.5\mixminion copying lib\mixminion\Packet.py - build\lib.win32-2.5\mixminion copying lib\mixminion\ScheduleUtils.py - build \lib.win32-2.5\mixminion copying lib\mixminion\ServerInfo.py - build\lib.win32-2.5\mixminion copying lib\mixminion\SExpression.py - build\lib.win32-2.5\mixminion copying lib\mixminion\test.py - build\lib.win32-2.5\mixminion copying lib\mixminion\testSupport.py - build\lib.win32-2.5\mixminion copying lib\mixminion\ThreadUtils.py - build\lib.win32-2.5\mixminion copying lib\mixminion\TLSConnection.py - build \lib.win32-2.5\mixminion copying lib\mixminion\__init__.py - build\lib.win32-2.5\mixminion creating build\lib.win32-2.5\mixminion\server copying lib\mixminion\server\DNSFarm.py - build \lib.win32-2.5\mixminion\server copying lib\mixminion\server\EventStats.py - build \lib.win32-2.5\mixminion\serv er copying lib\mixminion\server\HashLog.py - build \lib.win32-2.5\mixminion\server copying lib\mixminion\server\MMTPServer.py - build \lib.win32-2.5\mixminion\serv er copying lib\mixminion\server\Modules.py - build \lib.win32-2.5\mixminion\server copying lib\mixminion\server\PacketHandler.py - build \lib.win32-2.5\mixminion\s erver copying lib\mixminion\server\Pinger.py - build\lib.win32-2.5\mixminion \server copying lib\mixminion\server\ServerConfig.py - build \lib.win32-2.5\mixminion\se rver copying lib\mixminion\server\ServerKeys.py - build \lib.win32-2.5\mixminion\serv er copying lib\mixminion\server\ServerMain.py - build \lib.win32-2.5\mixminion\serv er copying lib\mixminion\server\ServerQueue.py - build \lib.win32-2.5\mixminion\ser ver copying lib\mixminion\server\__init__.py - build \lib.win32-2.5\mixminion\server creating build\lib.win32-2.5\mixminion\directory copying lib\mixminion\directory\DirCGI.py - build \lib.win32-2.5\mixminion\direc tory copying lib\mixminion\directory\Directory.py - build \lib.win32-2.5\mixminion\di rectory copying lib\mixminion\directory\DirFormats.py - build \lib.win32-2.5\mixminion\d irectory copying lib\mixminion\directory\DirMain.py - build \lib.win32-2.5\mixminion\dire ctory copying lib\mixminion\directory\ServerInbox.py - build \lib.win32-2.5\mixminion\ directory copying lib\mixminion\directory\ServerList.py - build \lib.win32-2.5\mixminion\d irectory copying lib\mixminion\directory\__init__.py - build \lib.win32-2.5\mixminion\dir ectory running build_ext building 'mixminion._minionlib' extension creating build\temp.win32-2.5 creating build\temp.win32-2.5\Release creating build\temp.win32-2.5\Release\src C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / nologo /Ox /MD /W3 /GX /DNDEBUG -DMM_L_ENDIAN=1 -I.\contrib\OpenSSL\include -I. \contrib\op enssl\include -Isrc -IC:\Python25\include -IC:\Python25\PC /Tcsrc/ crypt.c /Fobui ld\temp.win32-2.5\Release\src/crypt.obj crypt.c C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / nologo /Ox /MD /W3 /GX /DNDEBUG -DMM_L_ENDIAN=1 -I.\contrib\OpenSSL\include -I. \contrib\op enssl\include -Isrc -IC:\Python25\include -IC:\Python25\PC /Tcsrc/ aes_ctr.c /Fob uild\temp.win32-2.5\Release\src/aes_ctr.obj aes_ctr.c C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c / nologo /Ox /MD /W3 /GX /DNDEBUG -DMM_L_ENDIAN=1
Re: Dealing with funny characters
Diez B. Roggisch wrote: No, no, that's wrong. MySQL and the Python interface to it understand Unicode. You don't want to convert data to UTF-8 before putting it in a database; the database indexing won't work. I doubt that indexing has anything to do with it whatsoever. Of course it does. ORDER BY, LIKE, TRIM, and other SQL expressions that do more than an equal comparison need to know the actual data representation. If you were to convert to UTF-8 or UCS-2 in the Python program and send the resulting byte string to MySQL, with MySQL thinking it was storing ASCII or a BLOB, many SQL functions won't work right. A database is not a file system; a database looks at the data. Here's how to do it right. First, tell MySQL, before you create your MySQL tables, that the tables are to be stored in Unicode: ALTER database yourdatabasename DEFAULT CHARACTER SET utf8; You can also do this on a table by table basis, or even for single fields, but you'll probably get confused if you do. Then, when you connect to the database in Python, use something like this: db = MySQLdb.connect(host=localhost, use_unicode = True, charset = utf8, user=username, passwd=password, db=database) That tells MySQLdb to talk to the database in Unicode, and it tells the database (via charset) that you're talking Unicode. You confuse unicode with utf-8 here. ... pontification deleted But due to e.g. environmental settings, opened connections will deliver the contents in e.g. latin1. Which of course will lead to problems if you try to return data from the table with the topmost chines first names. ??? So you can alter the encoding the connection delivers and expects byte-strings in. In mysql, this can be done explcit using cursor.execute(set names encoding) Or - as you said - as part of a connection-string. db = MySQLdb.connect(host=localhost, use_unicode = True, charset = utf8, user=username, passwd=password, db=database) But there is more to it. If the DB-API supports it, then the API itself will decode the returned strings, using the specified encoding, so that the user will only deal with real unicode-objects, greatly reducing the risk of mixing byte-strings with unicode-objects. That's what the use_unicod-parameter is for: it makes the API accept and deliver unicod-objects. But it would do so even if the charset-parameter was latin1. Yes, and that's taken care of if the connection is set up as above. For legacy reasons, there are both unicode and charset parameters to connect, and they can be set in incompatible ways. Also, you need MySQL 5 or later to get full Unicode support. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Converting Word to UTF8 Text File
En Sun, 21 Oct 2007 13:35:43 -0300, [EMAIL PROTECTED] escribi�: Hi all, I'm trying to copy a bunch of microsoft word documents that have unicode characters into utf-8 text files. Everything works fine at the beginning. The word documents get converted and new utf-8 text files with the same name get created. And then I try to copy the data and I keep on getting TypeError: coercing to Unicode: need string or buffer, instance found. I'm probably copying the word document wrong. What can I do? Always remember to provide the full traceback. Where do you get the error? In the last line: shutil.copyfile? If the file already contains the text in utf-8, and you just want to make a copy, use shutil.copy as before. (or, why not tell Word to save the file using the .txt extension in the first place?) for doc in glob.glob(input): txt_split = os.path.splitext(doc) txt_doc = txt_split[0] + '.txt' txt_doc = codecs.open(txt_doc,'w','utf-8') shutil.copyfile(doc,txt_doc) copyfile expects path names as arguments, not a codecs-wrapped-file-like-object -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
Is there a C++ version of the C Python API packaged with python 2.5? Stargaming has already mentioned the fine points; the first answer is: yes, the API packaged python 2.5 can be used with C++. It is a C++ version of the same API as it adds proper extern C declarations around all prototypes, and it was specifically cleaned up (ten years ago) to work with C++. This API does not make use of many of the C++ features, including classes, templates, or overloading. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: compiler module bug?
En Sun, 21 Oct 2007 13:36:46 -0300, Brian Blais [EMAIL PROTECTED] escribi�: I am experiencing a problem with the compiler module. Is this a bug, or am I doing something wrong? I think it's a well-known fact... it seems like a comment at the end breaks the parse command, but not parseFile. Is this reproducible by others? The comment itself is not a problem; but the last line in the source must end in a newline. See the py_compile/compileall modules as an example. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Visibility of symbols between extension modules
Hi, On Sun, 2007-10-21 at 13:43 -0300, Gabriel Genellina wrote: En Sun, 21 Oct 2007 08:21:50 -0300, Sudharshan S [EMAIL PROTECTED] escribi�: What is foo? a directory? And bar/_foo/baz, source files in C? Each one defining a module object, or is there a single module - foo perhaps? Sorry, let me explain things a bit, foo is a directory with an __init__.py to tell the interpreter that foo is a package and bar, _foo, baz are shared extension objects, with their sources as bar.c, _foo.c and baz.c, each with its own PyMODINIT_FUNC function. Is it a global C variable, or a module attribute? If you want it to be available to other Python code, it should be a module attribute. In this case, you retrieve the value using PyObject_GetAttrString as with any other object. If it's a global C variable, once it's assigned it should be visible to all (but decades of warning against using global variables can't be wrong...) The single most common error using the Python API is getting wrong the reference counts. If you lose a reference, your object may be garbage collected. If you leak a reference, it will never be freed. Maybe this is what happens here. Its not a module attribute, Just a good old C structure. I thought I couldnt use Py_INCREF on non-PyObjects. After a gdb session, I found that my variable say spam, is initialised when the _foo.so is loaded but the moment baz.so or something get loaded, it becomes NULL again, although its still in the current scope. (found that on my backtrace). I hope I am right with the loading of .so part. Is that how python works, bringing all the symbols in the different modules in a common namespace?. If so why is spam losing its value. I also found that the interpreter calls init functions of all the modules the moment I do a import foo. I also suspect my setup script is kinda doing something wrong. Perhaps if you explain a bit more what you want to do someone can give some advice. Well, my code should tell everything. But a word of request, try not to laugh at it. http://projects.openmoko.org/plugins/scmsvn/viewcvs.php/python-gsmd/?root=python-openmoko It would be great if anyone could take a look and guide me out of this. The variable in question is lgsmh defined in _pygsmd.c. I really feel I am missing something very trivial yet important thing. Thanks for all the help.. -- Sudharshan S http://www.sudharsh.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list
Re: errors while building a program with Python
En Sun, 21 Oct 2007 13:52:43 -0300, [EMAIL PROTECTED] escribi�: I'm trying to build a program (MixMinion) with Python 2.5.1, MSVS 2003 SP1 and Windows XP Home SP2 but I'm getting a couple of errors. Here are the two errors I am getting: (1) .\contrib\OpenSSL\lib\Builder5\ssleay32.lib : fatal error LNK1136: invalid or corrupt file Ensure that your downloaded files are not corrupt. You could try to download and compile OpenSSL yourself but this may be a bit tricky; I think it would be a lot better to ask this directly on the MixMinion dev list. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: compiler module bug?
On Oct 21, 2007, at Oct 21:1:15 PM, Gabriel Genellina wrote: En Sun, 21 Oct 2007 13:36:46 -0300, Brian Blais [EMAIL PROTECTED] escribi�: I am experiencing a problem with the compiler module. Is this a bug, or am I doing something wrong? I think it's a well-known fact... it seems like a comment at the end breaks the parse command, but not parseFile. Is this reproducible by others? The comment itself is not a problem; but the last line in the source must end in a newline. See the py_compile/compileall modules as an example. I didn't see anything in that module which mentions this issue (perhaps I missed it). however, if the documentation states: parseFile( path) Return an abstract syntax tree for the Python source code in the file specified by path. It is equivalent to parse(open(path).read()). then, even if it is known problem, the docs are wrong. the two (parseFile(path) and parse(open(path).read())) are *not* the same: one can handle a file which doesn't end in a newline, another one can't handle the same file. Can one hack it like: filestr=open(filename).read() filestr+=\n before going to parse, or will that give problems? thanks, bb -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
Lew schrieb: I am afraid that your conclusion is quite mistaken. Knuth is, if anything, a huge success in the field of software engineering, whether you rate it as making a contribution to the art, or as being paid to perform the art. Well, sort of. Some of the code given is unreadable. (He obviously didn't take the structured programming thing to heart.) Worse, some of the code given is inscrutable, and remains unexplained (e.g. the code for the spectral test algorithm). Whole classes of algorithms were omitted. This is probably no fault of Knuth as a programmer, but simply a field that's moving faster than a single person can keep up with. These are small detractions from a large overall contribution. In particular, I find llothars characterization of TeX wrong: it is one of the least buggy typesetting programs ever written (not a small feat), and it *still* produces output that is as least as good as what other programs do, and in fact better than the vast majority. It also has downsides, most notably the markup language is pure horror. TeX's markup language is a dead end. TeX's algorithm isn't. Actually it has been extracted from the software and is available as a functional program, waiting to be embedded into a typesetting system with more modern qualities. Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: compiler module bug?
En Sun, 21 Oct 2007 14:33:00 -0300, Brian Blais [EMAIL PROTECTED] escribió: On Oct 21, 2007, at Oct 21:1:15 PM, Gabriel Genellina wrote: The comment itself is not a problem; but the last line in the source must end in a newline. then, even if it is known problem, the docs are wrong. the two (parseFile(path) and parse(open(path).read())) are *not* the same: one can handle a file which doesn't end in a newline, another one can't handle the same file. Feel free to submit a bug report to http://bugs.python.org Can one hack it like: filestr=open(filename).read() filestr+=\n The parseFile function does exactly that, along with this comment: # XXX The parser API tolerates files without a trailing newline, # but not strings without a trailing newline. Always add an extra # newline to the file contents, since we're going through the string # version of the API. The compile function in py_compile.py that I've menctioned earlier does the same but only when needed: f = open(file, 'U') codestring = f.read() f.close() if codestring and codestring[-1] != '\n': codestring = codestring + '\n' -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: compiler module bug?
On Oct 21, 2007, at Oct 21:2:05 PM, Gabriel Genellina wrote: The parseFile function does exactly that, along with this comment: thanks! bb -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
On Oct 20, 6:20 pm, Daniel Pitts [EMAIL PROTECTED] wrote: On Oct 20, 2:04 pm, llothar [EMAIL PROTECTED] wrote: I love math. I respect Math. I'm nothing but a menial servant to Mathematics. Programming and use cases are not maths. Many mathematics are the worst programmers i've seen because they want to solve things and much more often you just need heuristics. Once they are into exact world they loose there capability to see the factor of relevance in algorithms. And they almost never match the mental model that the average user has about a problem. I read somewhere that for large primes, using Fermat's Little Theorem test is *good enough* for engineers because the chances of it being wrong are less likely than a cosmic particle hitting your CPU at the exact instant to cause a failure of the same sort. This is the primary difference between engineers and mathematicians. Carmichael number are the ones who are making the problem , but they are very rare. There are 1,401,644 Carmichael numbers between 1 and 1018 (approximately one in 700 billion numbers.) http://en.wikipedia.org/wiki/Carmichael_number If you want to be sure use Miller-Rabin test. Slobodan Blazeski -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Converting Word to UTF8 Text File
Indeed, the shutil.copyfile(doc,txt_doc) was causing the problem for the reason you stated. So, I changed it to this: for doc in glob.glob(input): txt_split = os.path.splitext(doc) txt_doc = txt_split[0] + '.txt' txt_doc_dir = os.path.join(input_dir,txt_doc) doc_dir = os.path.join(input_dir,doc) shutil.copy(doc_dir,txt_doc_dir) However, I still cannot read the unicode from the Word file. If take out the first for-statement, I get a bunch of garbled text, which isn't helpful. I would save them all manually, but I want to figure out how to do it in Python, since I'm just beginning. My intuition says the problem is with FileFormat=win32com.client.constants.wdFormatText because it converts fine to a text file, just not a utf-8 text file. How can I modify this or is there another way to code this type of file conversion from *.doc to *.txt with unicode characters? Thanks On Oct 21, 7:02 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 21 Oct 2007 13:35:43 -0300, [EMAIL PROTECTED] escribi?: Hi all, I'm trying to copy a bunch of microsoft word documents that have unicode characters into utf-8 text files. Everything works fine at the beginning. The word documents get converted and new utf-8 text files with the same name get created. And then I try to copy the data and I keep on getting TypeError: coercing to Unicode: need string or buffer, instance found. I'm probably copying the word document wrong. What can I do? Always remember to provide the full traceback. Where do you get the error? In the last line: shutil.copyfile? If the file already contains the text in utf-8, and you just want to make a copy, use shutil.copy as before. (or, why not tell Word to save the file using the .txt extension in the first place?) for doc in glob.glob(input): txt_split = os.path.splitext(doc) txt_doc = txt_split[0] + '.txt' txt_doc = codecs.open(txt_doc,'w','utf-8') shutil.copyfile(doc,txt_doc) copyfile expects path names as arguments, not a codecs-wrapped-file-like-object -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Status on OSX
Hey guys, What is that status of Tkinter on OSX (10.4.10)? I have tried several installations (Python 2.4.4, 2.5 and 2.5.1) all from the official distro sites and others each version has the same major issue.Theproblem is simple to recreate, use any of the simple sample code available here: http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm The menu widgets never display...When I literally cut and paste this same code into a VMWare image (windows and linux) the same code executes as you'd expect it, all the widgets display and work properlyliterally the same code cut and pasted from OSX into windows/linux Vmware images, gets different results. -- Zenapse.org -- http://mail.python.org/mailman/listinfo/python-list
Re: errors while building a program with Python
On Oct 21, 1:31 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 21 Oct 2007 13:52:43 -0300, [EMAIL PROTECTED] escribi?: I'm trying to build a program (MixMinion) with Python 2.5.1, MSVS 2003 SP1 and Windows XP Home SP2 but I'm getting a couple of errors. Here are the two errors I am getting: (1) .\contrib\OpenSSL\lib\Builder5\ssleay32.lib : fatal error LNK1136: invalid or corrupt file Ensure that your downloaded files are not corrupt. You could try to download and compile OpenSSL yourself but this may be a bit tricky; I think it would be a lot better to ask this directly on the MixMinion dev list. -- Gabriel Genellina You are correct on all counts. I have already re-downloaded openssl and the curropution error went away. I originally thought the error was a python issue, hence my message here. Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: what is the difference between the two kinds of brackets?
Hendrik van Rooyen wrote: Paul Hankin pamail.com wrote: If everything else is equal, use tuples. Interesting point of view - mine is just the opposite. I wonder if its the philosophical difference between: Anything not expressly allowed is forbidden and Anything not expressly forbidden is allowed ? - Hendrik The latter is how I interpret any religious moral code--life is a lot more fun that way. Maybe that percolates to how I use python? James -- James Stroud UCLA-DOE Institute of Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with format string / MySQL cursor
En Sat, 20 Oct 2007 18:40:38 -0300, Dennis Lee Bieber [EMAIL PROTECTED] escribi�: On Fri, 19 Oct 2007 18:50:20 -0300, Gabriel Genellina [EMAIL PROTECTED] declaimed the following in comp.lang.python: If the MySQLdb adapter actually converts and inserts the arguments itself into the supplied SQL sentence, generating a new string for each call, this advantage -and many others- are cancelled, defeating the purpose of bound variables. Okay, I'm a bit behind the time... The book I keep on the floor next to my computer is the old brown/black version covering version 3.x and introducing ver 4.0 (my newer books are across the room in shelves behind the couch that take time to reach) It can't be fully blamed on the MySQLdb adapter... After crawling through too many reference books, it looks like MySQL itself didn't support prepared statements until sometime in the ver 4.1.x period -- I believe the MySQLdb adapter is still ver 3.x compatible, using the mysql_query(connection, SQL_string) call, rather than the half-dozen newer functions for separately binding parameters to prepared statements. Yes, if the database doesn't allow for prepared statements the poor adapter can't do much... Since, to my experience, db-api 2 doesn't expose the concepts of prepared statements to the user, about the only place using them would offer a true speed-up would be in the .executemany() call (and even then it would seem to depend upon which is more costly: formatting a properly [...] Some databases automatically cache SQL statements. I know DB2 does that, and I think Oracle does too (or is it the JDBC layer?). So it's not required that user code explicitely prepares SQL statements. Prepared statements have other advantages, apart from the speed gain when using repetitive queries: they help to keep the statement length below some size limit, they help to lower the cpu load on the server (by not having to parse and optimize the query again), and they avoid SQL injection (else, you have to rely on the quoting and escaping being well done, even on the DB-API adapter). If the api exposed them to the user, I could see a potential use for them: an application with, say, multiple forms (each of one or more DB tables)... By preparing and saving a set of statements for each form (parameterized select, update, insert, delete, say) during application startup (or conditionally on first entry to a form) one would only need to reference the prepared statements for the forms as the end-user navigates the forms. But DB-API 2.0 already allows that. PEP 249 says, when describing cursor.execute: A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times). So nothing special is required to enable prepared statements; the adapter is free to prepare and re-use queries if desired. BTW, the situation is similar to the re module: you can pre-compile your regular expressions, but it's not required, as the re module caches compiled expressions, reusing them later when the same r.e. is seen. {At least we're not discussing Firebird... 1000+ page book on it and the closest it comes to discussing a C-language API is to mention that the C header file defining the functions is included with the binary install... And for other APIs it just gives URLs} Nice book! :) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: Is there a C++ version of the C Python API packaged with python 2.5? Stargaming has already mentioned the fine points; the first answer is: yes, the API packaged python 2.5 can be used with C++. It is a C++ version of the same API as it adds proper extern C declarations around all prototypes, and it was specifically cleaned up (ten years ago) to work with C++. This API does not make use of many of the C++ features, including classes, templates, or overloading. Regards, Martin Well C++ implicitly includes OOP since that is the foundation of the language. I was more or less asking if there was an object oriented version of the Python embedded API or perhaps an OO wrapper. However it doesn't seem that way, so I may have to make my own. Thanks for the responses. -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting URLs
URL = 'http://steve:[EMAIL PROTECTED]:82/dir + \ 'ectory/file.html;params?query#fragment' If I split the URL, I would like to get the following components: scheme = 'http' netloc = 'steve:[EMAIL PROTECTED]:82' username = 'steve' password = 'secret' hostname = 'www.domain.com.au' port = 82 path = '/directory/file.html' parameters = 'params' query = 'query' fragment = 'fragment' I can get *most* of the way with urlparse.urlparse: it will split the URL into a tuple: ('http', 'steve:[EMAIL PROTECTED]:82', '/directory/file.html', 'params', 'query', 'fragment') If I'm using Python 2.5, I can split the netloc field further with named attributes. Unfortunately, I can't rely on Python 2.5 (for my sins I have to support 2.4). Before I write code to split the netloc field by hand (a nuisance, but doable) I thought I'd ask if there was a function somewhere in the standard library I had missed. there are some goodies in urllib for doing some of this splitting. Example code at the bottom of my reply (though it seems to choke on certain protocols such as mailto:; and ssh: because urlparse doesn't return the netloc properly) This second question isn't specifically Python related, but I'm asking it anyway... I'd also like to split the domain part of a HTTP netloc into top level domain (.au), second level (.com), etc. I don't need to validate the TLD, I just need to split it. Is splitting on dots sufficient, or will that miss some odd corner case of the HTTP specification? I believe that dots are the sanctioned separator, HOWEVER, you can have a non-qualified machine-name with local scope, so you can easily have NO TLD, such as http://user:[EMAIL PROTECTED]:8000/path/to/thing There's also the ambiguity of what TLD means if you use IP addresses: http://user:[EMAIL PROTECTED]:8000/path/to/thing Does that make the TLD 1? Other odd edge-cases that are usually allowable (but frowned upon, mostly used by spammers/phishers) include using a long-int as the domain-name, such as http://user:[EMAIL PROTECTED]:8000/path/to/thing In an attempt to play with these functions, I present the code below. -tkc import urlparse, urllib tests = ( 'http://steve:[EMAIL PROTECTED]:82/' 'directory/file.html;params?query#fragment', 'http://user:[EMAIL PROTECTED]/path/to/thing/', 'http://192.168.1.2/path/to/thing/', 'http://2130706433/path/to/thing/', 'http://localhost/path/to/thing/', 'http://user:[EMAIL PROTECTED]/path/to/thing/', 'telnet://[EMAIL PROTECTED]', 'ssh://[EMAIL PROTECTED]', 'gopher://wais.example.edu', 'svn+ssh://user:[EMAIL PROTECTED]/svn/here/there/', 'mailto:[EMAIL PROTECTED]', ) def is_ip_address(s): for i, part in enumerate(s.split('.')): try: assert 0 = int(i) = 255 except: return False return i == 3 def steve_parse(url): (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url) creds, host = urllib.splituser(netloc) username, password = urllib.splitpasswd(creds or '') host, port = urllib.splitport(host) if '.' in host and not is_ip_address(host): domain, tld = host.rsplit('.', 1) else: domain = host tld = '' return ( scheme, username, password, domain, tld, port, path, params, query, fragment) if __name__ == '__main__': for test in tests: print test (scheme, username, password, domain, tld, port, path, params, query, fragment) = steve_parse(test) print '\tScheme: ', scheme print '\tUsername: ', username print '\tPassword: ', password print '\tDomain: ', domain print '\tTLD: ', tld print '\tPort: ', port print '\tPath: ', path print '\tParams: ', params print '\tQuery: ', query print '\tFragment: ', fragment print '='*50 -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
Well C++ implicitly includes OOP since that is the foundation of the language. I was more or less asking if there was an object oriented version of the Python embedded API or perhaps an OO wrapper. However it doesn't seem that way, so I may have to make my own. I think you are misinterpreting what you are seeing. The Python C API *is* object-oriented. It has all features of object-orientation: classes, encapsulation, polymorphism, late binding, ... As for make your own: people have tried this before; there are multiple C++ wrappers around the Python C API available. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: using request variable in python web program
On 21 Okt, 21:59, sami [EMAIL PROTECTED] wrote: Thanks a ton Paul for the information. I am using CGI and my host (nearlyfreespeech.net) does not have django hosting - and being mainly a C/dekstop apps programmer I really don't want to learn the whole MVC concept and its implementation (and quirks) in django - I want to use abstractions only when I feel the need for them See the library reference for information on how to get the value of form/request parameters from the CGI environment: http://docs.python.org/lib/node561.html Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: using request variable in python web program
However, it shouldn't be too bad to set Django up, really, especially if people have taken some time to explain something very close to what you want to do using Django. Moreover, there's a Google group (django- users) where you could ask general questions, and I imagine that people will be quite happy to help you out. But I can totally understand that creating databases and installing various packages seems somewhat peripheral to a task which could arguably be done using a CGI script (as far as I can see). Thanks a ton Paul for the information. I am using CGI and my host (nearlyfreespeech.net) does not have django hosting - and being mainly a C/dekstop apps programmer I really don't want to learn the whole MVC concept and its implementation (and quirks) in django - I want to use abstractions only when I feel the need for them Since a django user made pyfacebook, hopefully someone on the forum will help out Thanks again Sami Paul P.S. I'm not too impressed by the lack of a common high-level Web API for Python, either. However, I've mostly ignored the discussions and stuck with my own API (WebStack) in the knowledge that if it doesn't work for me, at least I know how I might fix it. -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: I think you are misinterpreting what you are seeing. The Python C API *is* object-oriented. It has all features of object-orientation: classes, encapsulation, polymorphism, late binding, ... As for make your own: people have tried this before; there are multiple C++ wrappers around the Python C API available. Regards, Martin Could you emphasize a little more? I haven't worked much at all with the Python C API, so I may be misunderstanding. First of all, you say that the Python C API is object oriented, which is contradictory because it should read Python C++ API is object oriented. Perhaps this is a typo, or maybe you're referencing some C++ wrapper for the Python C API that you failed to mention the name of. You also mentioned that there are multiple C++ wrappers arround the Python C API Available... could you provide names for a few of the popular ones? Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
Could you emphasize a little more? I haven't worked much at all with the Python C API, so I may be misunderstanding. First of all, you say that the Python C API is object oriented, which is contradictory because it should read Python C++ API is object oriented. Perhaps this is a typo, or maybe you're referencing some C++ wrapper for the Python C API that you failed to mention the name of. No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. You also mentioned that there are multiple C++ wrappers arround the Python C API Available... could you provide names for a few of the popular ones? The most popular ones are Boost.Python, CXX, and PySTL. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. I disagree with this statement. C is not an object oriented language, and I've seen attempts to make it somewhat object oriented, however it failed miserably in readability and manageability overhead. However, this isn't the place to discuss such a thing so I've got nothing more to say than that. I do appreciate you taking the time to respond to my inquiry and offer a few C++ wrapper API's for the Python C API. Take care! -- http://mail.python.org/mailman/listinfo/python-list
parallel NumPy: PyMPI, myMPI or something else?
Hi! I am trying to find my way to a running parallel NumPy installation. Can you help me getting started wihtout losing my way several times? PyMPI and myMPI are apperently not too actively developed. Is this true? Are they mature enough so that they don't need any more updates? Have they been replaced by more recent modules? Then, if I have NumPy running with PyMPI or whatever, is NumPy already optimized for a MPI environment so that for example matrix multiplication, iterative solvers etc. are automatically distributed? Or do I have to split each problem myself to make use of the parallelism? Thank you Ken -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
llothar wrote: On 21 Okt., 22:45, Lew [EMAIL PROTECTED] wrote: Evidence is that TeX development is dead. Exactly and Knuths only contribution to software development was the theory of literate programming. As i said for me algorithms are not software development, this is programming in the small (something left for coding apes), not programming in the large. There are no problems anymore with programming the small, sure you can try to develop Judy Arrays or another more optimized sorting algorithm, but this has no real world effect. It is theoretical computer science - well a few people seem to like this. And as an evidence that this theory works (literate programming) - there is no easy prove about efficient workflow - was his TeX program where only some parts are handled like this. But drawing an conclusion from a developement dead project to other in development projects is just sorry: fucking stupid. No, I conclude that literate programming works from the prevalence of tools like Javadoc and Doxygen, and the Sun and MS coding standards documents. I see the direct benefits in my own work every day. Proposing a straw-man argument then knocking it down with mere purple prose like just sorry: [sic] fucking stupid is, sorry, just fucking stupid. See? No logic there at all. Thus proving that there's no logic there at all. Everythink in the real world says that literate programming is not useable. Rrr? Everythink does, eh? Maybe what the world needs instead is literate programmers, then. Cite some specifics, please? And remember, when you say everything that even one counter-example disproves. There is evidence that aspects of literate programming do work. Besides, that a theory is wrong is part of science, not a denigration of the scientist. Even a wrong theory, like Newtonian mechanics, advances the science (e.g., physics) and is evidence that the scientist (Isaac Newton) is a genius. Like Donald Knuth. Sure if you are an academic guy you can do endless post-mortem analysis you might find this amazing but it is just as worthless for the real world as a guy building a copy of the Eiffel tower from burned matches - a pure hobby. So you say, again with just rhetoric and complete lack of evidence or argument to support the outrageous assertion. Many people, myself included, have seen your so-called real world benefit significantly from academic results. Object-oriented programming is an example. The fertilization works both ways; check out how the science of computer graphics expanded thanks to LucasFilms. Try using reason, logic and evidence for your points instead of merely shouting obscenities, hm? -- Lew -- http://mail.python.org/mailman/listinfo/python-list
Problem with regexp and text injection
Hello, I want to create a script in python that search for .html files in the predefined directory and subdirectories. Then it checks if a specific snippet of code exists in the .html file, if not it injects/adds the code right below the string body otherwise bypasses the file. I wrote the first part, I managed to write search function and I'm trying to find my way out of regular expressions reading the manuals. However I don't know what kind of function and module to use in order to write this function, re.search(), re.string() or re.match() or maybe re.compile() ? I have not much programming experience. Programming is not my cup of tea. Can someone help by pointing me to a sample code with comments if possible. Regards, atma -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributed RVS, Darcs, tech love
On Oct 21, 3:11 pm, Lew [EMAIL PROTECTED] wrote: Try using reason, logic and evidence for your points instead of merely shouting obscenities, hm? You're expecting logic from someone who asserts that llothar wrote: only contribution to software development was the theory of literate programming. Good luck, mate. -o -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting URLs
On Sun, 21 Oct 2007 14:55:01 -0500, Tim Chase wrote: there are some goodies in urllib for doing some of this splitting. Example code at the bottom of my reply (though it seems to choke on certain protocols such as mailto:; and ssh: because urlparse doesn't return the netloc properly) It doesn't? That's... bad. But for my application, probably not important: I only care about HTTP. Thanks for the reply and sample code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
Martin v. Löwis [EMAIL PROTECTED] wrote: ... The most popular ones are Boost.Python, CXX, and PySTL. I think SIP is also pretty popular (see http://www.riverbankcomputing.co.uk/sip/). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On Sun, 21 Oct 2007 16:17:19 -0500, Robert Dailey wrote: On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. I disagree with this statement. C is not an object oriented language, and I've seen attempts to make it somewhat object oriented, however it failed miserably in readability and manageability overhead. However, this isn't the place to discuss such a thing so I've got nothing more to say than that. What he means is that the C API provides a complete, if boilerplate- heavy, interface to object oriented aspects of Python. I.e., you can write Python types completely in C, including all the OOPy stuff like inheritance and so on. You don't need a language with built-in support of OOP to do that. Now, a C++ API for CPython would necessarily be built on top of the C API, which carries some limitations relative to the OOP abilities of C++ itself. I suspect all you'll get from a C++ binding is a slightly more comfortable (to people who like C++) calling interface. It could help bring some unity to your extension code, and maybe get rid of a few typecasts and simplify function names. But you shouldn't expect anything like the ability to freely inherit between C++ and Python classes. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
Robert Dailey wrote: On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. I disagree with this statement. C is not an object oriented language, and I've seen attempts to make it somewhat object oriented, however it failed miserably in readability and manageability overhead. However, this isn't the place to discuss such a thing so I've got nothing more to say than that. Guess you haven't programmed in GTK+ on C, then. Very heavy in object-oriented programmin. C++'s OOP stuff is just pure syntactic sugar, nothing more, nothing less. Python's OO nature is a bit deeper, since we're talking a dynamic language. Scheme, another dynamic language, is not inherently OO or non-OO. You can use it in either fashion. I do appreciate you taking the time to respond to my inquiry and offer a few C++ wrapper API's for the Python C API. Take care! Any C++ version of the python API is by definition going to be a wrapper around the C version. Even the C version is a wrapper around the python object model. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with regexp and text injection
On Oct 21, 6:22 pm, Panagiotis Atmatzidis [EMAIL PROTECTED] wrote: Hello, I want to create a script in python that search for .html files in the predefined directory and subdirectories. Then it checks if a specific snippet of code exists in the .html file, if not it injects/adds the code right below the string body otherwise bypasses the file. I wrote the first part, I managed to write search function and I'm trying to find my way out of regular expressions reading the manuals. However I don't know what kind of function and module to use in order to write this function, re.search(), re.string() or re.match() or maybe re.compile() ? I have not much programming experience. Programming is not my cup of tea. Can someone help by pointing me to a sample code with comments if possible. Regards, atma import glob glob.glob(*.html) # returns a list of all filenames you are looking for - import re m = re.search(regular_expression_testing_for_string_of_code, string_with_contents_of_page) # checks if your snippet is there if m is None: new_contents = re.sub(r(?xis) body .*?, lambda m: m.group() + your_snippet_of_code, string_with_contents_of_page) # Add the snippet to the body. I use a function as the replacement in case your snippet has backreferences in it for some reason. If it doesn't, feel free to use r\0 + snippet_of_code. -- http://mail.python.org/mailman/listinfo/python-list
Re: what is the difference between the two kinds of brackets?
James Stroud [EMAIL PROTECTED] wrote: ... I wonder if its the philosophical difference between: Anything not expressly allowed is forbidden and Anything not expressly forbidden is allowed ? - Hendrik The latter is how I interpret any religious moral code--life is a lot more fun that way. Maybe that percolates to how I use python? FYI, in Security the first approach is also known as Default Deny, the second one as Default Permit. http://www.ranum.com/security/computer_security/editorials/dumb/ explains why default permit is THE very dumbest one of the six dumbest ideas in computer security which the article is all about. But then, the needs of Security are often antithetical to everything else we wish for -- security and convenience just don't mix:-( Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting URLs
there are some goodies in urllib for doing some of this splitting. Example code at the bottom of my reply (though it seems to choke on certain protocols such as mailto:; and ssh: because urlparse doesn't return the netloc properly) It doesn't? That's... bad. But for my application, probably not important: I only care about HTTP. This seems to be intentional, rather than a bug. In my python2.4/urlparse.py file, there's a uses_netloc list which clearly does not have 'mailto' in it. I can't give an explanation/justification for it, but it seems to me (IMHO) that there is a netloc involved in a mail address. Or maybe I have a semantic misunderstanding of what the netloc field means when returned from urlparse.urlparse However, since this is where the hostname appears in http, it makes me think that the hostname from a mailto URL should also appear in this result field. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Wrapping stdout in a codec
We want to wrap the stdout device in a codec in order to decode output transparently according to a particular code page (which might not be the system code page). However, codec.open requires a filename, and stdout may be a tty or otherwise anonymous. How can we accomplish this wrapping? Our application may be loaded into a Python program that has already set up stdout. TIA, Jon Peck -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with format string / MySQL cursor
Dennis Lee Bieber wrote: I should also add that I'm still using a somewhat older MySQLdb (one reason I haven't upgraded Python to 2.5 series -- finding trusted binary builds of the third-party stuff is a pain...) What, you don't trust the build from a World of Warcraft guild? John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel NumPy: PyMPI, myMPI or something else?
[EMAIL PROTECTED] wrote: Hi! I am trying to find my way to a running parallel NumPy installation. Can you help me getting started wihtout losing my way several times? PyMPI and myMPI are apperently not too actively developed. Is this true? Are they mature enough so that they don't need any more updates? Have they been replaced by more recent modules? The people who I know who use MPI and Python have been using mpi4py. I haven't used it myself, though. http://mpi4py.scipy.org/ Then, if I have NumPy running with PyMPI or whatever, is NumPy already optimized for a MPI environment so that for example matrix multiplication, iterative solvers etc. are automatically distributed? No. Or do I have to split each problem myself to make use of the parallelism? Pretty much. -- 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: Problem Converting Word to UTF8 Text File
En Sun, 21 Oct 2007 15:32:57 -0300, [EMAIL PROTECTED] escribi�: However, I still cannot read the unicode from the Word file. If take out the first for-statement, I get a bunch of garbled text, which isn't helpful. I would save them all manually, but I want to figure out how to do it in Python, since I'm just beginning. My intuition says the problem is with FileFormat=win32com.client.constants.wdFormatText because it converts fine to a text file, just not a utf-8 text file. How can I modify this or is there another way to code this type of file conversion from *.doc to *.txt with unicode characters? Ah! I thought you were getting the right file format. I can't test it now, but this KB document http://support.microsoft.com/kb/209186/en-us suggests you should use wdFormatUnicodeText when saving the document. What the MS docs call unicode when dealing with files, is in general utf16. In this case, if you want to convert to utf8, the sequence would be: f = open(original_filename, rb) udata = f.read().decode(utf16) f.close() f = open(new_filename, wb) f.write(udata.encode(utf8)) f.close() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with shelve/gdbm
En Fri, 19 Oct 2007 17:58:50 -0300, Douglas Applegate [EMAIL PROTECTED] escribi�: I am having a problem with shelve. The problem I think is really with gdbm. I'll write out a file using shelve/gdbm on an amd64 machine and then I'll try to read it in on a i386 machine. The result is a 'gdbm fatal: read error.' Reversing directions results in the same problem. Below are two small programs that get at the heart of the problem: Best to file a bug at http://bugs.python.org -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
RE: Wrapping stdout in a codec
On Behalf Of JKPeck otherwise anonymous. How can we accomplish this wrapping? Our application may be loaded into a Python program that has already set up stdout. Do you mean something like this? import sys class OutStreamEncoder(object): Wraps a stream with an encoder def __init__(self, outstream, encoding=None): self.out = outstream if not encoding: self.encoding = sys.getfilesystemencoding() else: self.encoding = encoding def write(self, obj): Wraps the output stream, encoding Unicode strings with the specified encoding if isinstance(obj, unicode): self.out.write(obj.encode(self.encoding)) else: self.out.write(obj) def __getattr__(self, attr): Delegate everything but write to the stream return getattr(self.out, attr) You can wrap sys.stdout easily: sys.stdout = OutStreamEncoder(sys.stdout) The code, with unit tests: http://www.ginstrom.com/code/streamencode.zip Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list
A near realtime fs mirror application (for backup, written in Python, by Linux inotify)
Hello: Recently I started an open source project cutils on the sourceforge: http://sourceforge.net/projects/crablfs/ The document can be found at: http://crablfs.sourceforge.net/#ru_data_man This project's mirrord/fs_mirror tool is a near realtime file system mirroring application across 2 or more hosts, something like MySQL's replication, but it's for the file system especially with a great amount of small files, such as the php scripts and images of a website or the (vitual) websites. There are several ways to use this tool. The simplest is to mirror a host's file system to another host for backup, and use the rotate function(in the future version) or rotate scripts to get a daily or hourly snapshot with the hard link. Or futhur more, you can use it this way: This graph should be displayed with monospaced fonts: +--+ | worker | -[mirrord] ---\ +--+ | .. | | +--+ | | worker | -[mirrord] ---\ +--+ | V [fs_mirror] | +--+ +--+ | worker | -[mirrord] --- | backup | +--+ +--+ | | [take_over]| | | V | +--+ | | rescue | --- NFS +--+ This is the multi to one backup, which is cost efficient. If one of the worker hosts fails, you can subsitute the failed worker with the rescue host, with the aid of any high available method, such as heartbeat project. By this way, you can use 1 or 2 hosts to support the HA of more than 3 servers. Or you can also use it as an IDS(Intrusion Detection System) like a realtime tripware, or you can make a mirror chain that a host B mirrors from A and be mirrored by C, etc ... I will also try to research a way to use it as a distributed implemetation with one write and multi-read model. mirrord/fs_mirror makes use of inotify, which is a function afforded by the recent Linux (from 2.6.12). It is a counterpart of FAM, since Linux FAM has stopped so long. Now it works for me, on a RHEL4 system and the LFS 6.2, I hope this tool can be useful to you too. Thanks. -- My Projects: http://sourceforge.net/projects/crablfs http://crablfs.sourceforge.net/ http://crablfs.sourceforge.net/#ru_data_man http://crablfs.sourceforge.net/tree.html http://cralbfs.sourceforge.net/sysadm_zh_CN.html My Blog: http://chowroc.blogspot.com/ http://hi.baidu.com/chowroc_z/ Looking for a space and platform to exert my originalities (for my projects)... -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
In article [EMAIL PROTECTED], Robert Dailey [EMAIL PROTECTED] wrote: Is there a C++ version of the C Python API packaged with python 2.5? It would be nice to have a OOP approach to embedding python in C++. It would also be a bonus if this C++ Python API cleaned up a lot of the messy code involved in embedding python. One other thing: you may get more advice from C++-sig and/or capi-sig; mail.python.org has the info for subscribing to those. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Carl Banks [EMAIL PROTECTED] wrote: Now, a C++ API for CPython would necessarily be built on top of the C API, which carries some limitations relative to the OOP abilities of C++ itself. It wouldn't have to be, although it'd be much more of a maintenance nightmare if it poked into the Python internals. But you shouldn't expect anything like the ability to freely inherit between C++ and Python classes. You can do this with Boost.Python. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Robert Dailey [EMAIL PROTECTED] wrote: On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. I disagree with this statement. C is not an object oriented language, and I've seen attempts to make it somewhat object oriented, however it failed miserably in readability and manageability overhead. However, this isn't the place to discuss such a thing so I've got nothing more to say than that. Object-oriented programming is a design choice, not a language feature. You can write straight procedural code in C++, and you can write object oriented code in C. Sure, C++ has some language features which facilitate object-oriented programming, but it doesn't magically make your code object-oriented. You can certainly write basic object-oriented code in C and hide most of the implementation in preprocessor macros if you so desire. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
[issue1267] Py3K cannot run as ``python -S``
Guido van Rossum added the comment: Do you have access to Windows? I believe it doesn't have dup(). :-( __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1267] Py3K cannot run as ``python -S``
Christian Heimes added the comment: Guido van Rossum wrote: Guido van Rossum added the comment: Do you have access to Windows? I believe it doesn't have dup(). :-( I've an old laptop with Win2k at my disposal but it has no VS yet. Can you point me to a set of instruction how to install VS 2003? I've just VS .NET 2005 available. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1267] Py3K cannot run as ``python -S``
Guido van Rossum added the comment: Do you have access to Windows? I believe it doesn't have dup(). :-( I've an old laptop with Win2k at my disposal but it has no VS yet. Can you point me to a set of instruction how to install VS 2003? I've just VS .NET 2005 available. Sorry, I'm as green as you when it comes to these. :-( But I believe I was mistaken about dup() not existing on Windows; dup() can't be used to duplicate sockets, but that's irrelevant here. So the dup()-based solution is fine. Alas, my family won't let me use the computer for more than a minute at a time today, so I won't be able to review any code... :-) __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1745035] DoS smtpd vulnerability
billiejoex added the comment: What does this do when a line longer than 4096 bytes is found? Does it report an error to the SMTP client? That's my only concern. Sorry for replying so late. No, it does not report the error and this is bad. I've searched through RFCs and I found that RFC 821 and RFC 2821 at chapter 4.2.2 say that a 500 Syntax error, command unrecognized response could be used to report errors such as command lines too long. Modified smtpd.py in attachment. It should be definitively fine for inclusion now. -- severity: normal - urgent type: - security Added file: http://bugs.python.org/file8586/smtpd.py _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1745035 _#! /usr/bin/env python An RFC 2821 smtp proxy. Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]] Options: --nosetuid -n This program generally tries to setuid `nobody', unless this flag is set. The setuid call will fail if this program is not run as root (in which case, use this flag). --version -V Print the version number and exit. --class classname -c classname Use `classname' as the concrete SMTP proxy class. Uses `PureProxy' by default. --debug -d Turn on debugging prints. --help -h Print this message and exit. Version: %(__version__)s If localhost is not given then `localhost' is used, and if localport is not given then 8025 is used. If remotehost is not given then `localhost' is used, and if remoteport is not given, then 25 is used. # Overview: # # This file implements the minimal SMTP protocol as defined in RFC 821. It # has a hierarchy of classes which implement the backend functionality for the # smtpd. A number of classes are provided: # # SMTPServer - the base class for the backend. Raises NotImplementedError # if you try to use it. # # DebuggingServer - simply prints each message it receives on stdout. # # PureProxy - Proxies all messages to a real smtpd which does final # delivery. One known problem with this class is that it doesn't handle # SMTP errors from the backend server at all. This should be fixed # (contributions are welcome!). # # MailmanProxy - An experimental hack to work with GNU Mailman # www.list.org. Using this server as your real incoming smtpd, your # mailhost will automatically recognize and accept mail destined to Mailman # lists when those lists are created. Every message not destined for a list # gets forwarded to a real backend smtpd, as with PureProxy. Again, errors # are not handled correctly yet. # # Please note that this script requires Python 2.0 # # Author: Barry Warsaw [EMAIL PROTECTED] # # TODO: # # - support mailbox delivery # - alias files # - ESMTP # - handle error codes from the backend smtpd import sys import os import errno import getopt import time import socket import asyncore import asynchat __all__ = [SMTPServer,DebuggingServer,PureProxy,MailmanProxy] program = sys.argv[0] __version__ = 'Python SMTP proxy version 0.2' class Devnull: def write(self, msg): pass def flush(self): pass DEBUGSTREAM = Devnull() NEWLINE = '\n' EMPTYSTRING = '' COMMASPACE = ', ' def usage(code, msg=''): print sys.stderr, __doc__ % globals() if msg: print sys.stderr, msg sys.exit(code) class SMTPChannel(asynchat.async_chat): COMMAND = 0 DATA = 1 def __init__(self, server, conn, addr): asynchat.async_chat.__init__(self, conn) self.__server = server self.__conn = conn self.__addr = addr self.__line = [] self.__in_buffer_len = 0 self.__state = self.COMMAND self.__greeting = 0 self.__mailfrom = None self.__rcpttos = [] self.__data = '' self.__fqdn = socket.getfqdn() self.__peer = conn.getpeername() print DEBUGSTREAM, 'Peer:', repr(self.__peer) self.push('220 %s %s' % (self.__fqdn, __version__)) self.set_terminator('\r\n') # Overrides base class for convenience def push(self, msg): asynchat.async_chat.push(self, msg + '\r\n') # Implementation of base class abstract method def collect_incoming_data(self, data): self.__line.append(data) self.__in_buffer_len += len(data) if self.__in_buffer_len 998: self.push('500 Line too long') self.__line = [] self.__in_buffer_len = 0 # Implementation of base class abstract method def found_terminator(self): line = EMPTYSTRING.join(self.__line) print DEBUGSTREAM, 'Data:', repr(line) self.__line = [] self.__in_buffer_len = 0 if self.__state == self.COMMAND: if not line: self.push('500 Error: bad syntax') return method =
[issue1745035] DoS smtpd vulnerability
Changes by billiejoex: Added file: http://bugs.python.org/file8587/smtpd.diff _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1745035 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1308] unicode(None) anomaly
New submission from James G. sack (jim): '2.5 (r25:51908, Apr 10 2007, 10:27:40) \n[GCC 4.1.2 20070403 (Red Hat 4.1.2-8)]' unicode(None) u'None' This doesn't seem right, ;-) Regards, ,,jim -- components: Unicode messages: 56628 nosy: jgsack severity: normal status: open title: unicode(None) anomaly type: behavior versions: Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1308 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1308] unicode(None) anomaly
Martin v. Löwis added the comment: What answer did you expect instead? -- nosy: +loewis __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1308 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1308] unicode(None) anomaly
James G. sack (jim) added the comment: (aside: Wow! that was a fast response to my posting!) I'm not really sure what makes the most sense, possibly: - an exception - u'' - None but not u'None'; not a string of length 4. That's quite unexpected! Regards, ..jim PS: I don't understand why I couldn't reply via email. I got an autoresponse You are not a registered user. Please register at: http://bugs.python.org/[EMAIL PROTECTED] ...before sending mail to the tracker. Unknown address: jgsack... I tried the registration, but that failed. I thought I _was_ registered. Oh, well. :-[ ..jim __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1308 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1267] Py3K cannot run as ``python -S``
Changes by Guido van Rossum: -- resolution: accepted - status: closed - open __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1267] Py3K cannot run as ``python -S``
Guido van Rossum added the comment: OK, checked in. You might want to compare what I checked in to your patch; I did a few style cleanups. I also moved the lseek() call into import.c, where it seems more appropriate. Committed revision 58587. -- resolution: - accepted status: open - closed __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1309] windows build fix
New submission from Christian Heimes: bytes_methods.c isn't in PCbuild/pythoncore.vcproj -- components: Windows files: py3k_pcbuild_bytes.patch messages: 56632 nosy: tiran severity: normal status: open title: windows build fix type: compile error versions: Python 3.0 Added file: http://bugs.python.org/file8588/py3k_pcbuild_bytes.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1309 __Index: PCbuild/pythoncore.vcproj === --- PCbuild/pythoncore.vcproj (Revision 58587) +++ PCbuild/pythoncore.vcproj (Arbeitskopie) @@ -440,8 +440,11 @@ RelativePath=..\Objects\boolobject.c /File File - RelativePath=..\Objects\bytesobject.c + RelativePath=..\Objects\bytes_methods.c /File +File +RelativePath=..\Objects\bytesobject.c +/File File RelativePath=..\Objects\cellobject.c /File ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1267] Py3K cannot run as ``python -S``
Christian Heimes added the comment: Guido van Rossum wrote: You might want to compare what I checked in to your patch; I did a few style cleanups. I also moved the lseek() call into import.c, where it seems more appropriate. Ah I see that you prefer to keep assignment and check against NULL/-1 on two separate lines. I had the lseek() in PyTokenizer_FindEncoding() because I prefer functions that restore their environment. I find it less surprising when it restores the position of the file descriptor. By the way I got Windows, VS 2003 and several SDKs installed in VMWare today. It's annoying and it takes hours. Most unit tests are passing. http://wiki.python.org/moin/Building_Python_with_the_free_MS_C_Toolkit __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1267 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1308] unicode(None) anomaly
James G. sack (jim) added the comment: Here's more: unicode(object) utype 'object' There seems to be an call to repr() somewhere in the process. This seems, at least to me, to violate the principle of least surprise, and I'm thinking that unicode(x) ought to return UnicodeDecodeError if x is not a string. Maybe this is argueable. If so, I'd like to be educated. :-) Regards, ..jim __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1308 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1286] fileinput, StringIO, and cStringIO do not support the with protocol
Alexandre Vassalotti added the comment: Do you have a use-case for this? In Py3k, I don't think adding support for the 'with' statement to StringIO makes any sense, since the close() method does nothing. -- nosy: +alexandre.vassalotti __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1286 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1310] tempfile breaks on Windows
New submission from Christian Heimes: tempfile breaks on Windows because exception objectss no longer support e[0]. The fix is simple and short: Index: Lib/tempfile.py === --- Lib/tempfile.py (Revision 58587) +++ Lib/tempfile.py (Arbeitskopie) @@ -201,7 +201,7 @@ del fp, fd return dir except (OSError, IOError) as e: -if e[0] != _errno.EEXIST: +if e.args[0] != _errno.EEXIST: break # no point trying more names in this directory pass -- components: Library (Lib) messages: 56638 nosy: tiran severity: normal status: open title: tempfile breaks on Windows type: behavior versions: Python 3.0 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1310 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com