Portland area Code Sprint on April 9-10
XP / PYTHON CODE SPRINT XPDX will be hosting a code sprint on April 9-10, 2005 in downtown Portland, Oregon. We're all meeting in one big room, where we'll code and talk smack until beer-thirty. Come pair with long-time XPers to learn their techniques while working on nifty Python projects. If you're intending to attend at least part of the sprint, please email Arlo Belshee ([EMAIL PROTECTED]). You can also add your name to the Sprint wiki, at http://c2.com/cgi/wiki?XpCodeSprint . We've currently got about 20 confirmed attendees from Oregon, Washington, and California. There's no headcount limit; come on down and join us for a weekend of coding, learning, and fun. If you can't make it for the whole weekend, just tell Arlo which day you can make it for. Many of the attendees are new to Python. Some are experts. So feel welcome regardless of your skill level. Also, Python integrates well with other common languages, allowing us to easily blend in work in a number of different areas. There will probably be projects in a number of different languages, such as: * Pure Python * Python and C++, via boost.org's boost::python interoperability template library * Python and Java, via Jython * And probably some Smalltalk, just because This is not a pure XP Sprint. Please feel free to come if you've never even heard of the practice. Many of us will be learning it this weekend. Also, if you have no interest in XP, come anyway. There will be a lot of Python coding and a variety of interesting topics. There are several potential projects for you to work on. If any of these catch your eye, come to the sprint ready to plow into it. If they don't, come on down with your own pet project - or even with no project at all. Someone'll grab you as a pair partner. http://pythoncard.sourceforge.net/ http://moinmoin.wikiwikiweb.de/, or MoinMoin plugins. http://scons.sourceforge.net/ http://ipodder.sourceforge.net/index.php Agile programming infrastructure. Some (as yet poorly defined) set of integrated tools to allow unit testing, automated build, automated smoke testing, release control, SCM, and other necessary activities. How about a rocket telemetry data analysis or visualization tool for http://psas.pdx.edu/? We could even provide live hardware. Scope, a simpler automated test framework for C++ that takes advantage of the features of that language. --- LOCATION AND LOGISTICS Critical Path Software his kindly invited us to use a floor of its downtown facilities for this sprint. The office is at 711 SW Alder St. in downtown Portland. It is about a block from Pioneer Courthouse Square, so is an easy MAX ride from many places in the city. The code sprint will run on April 9th and 10th. We will start each day at 10:00, and run until evening. Saturday night, several of us will probably troop on down to one of the local beer establishments. Arlo Belshee is organizing this event. If you have questions, you may contact him via email at [EMAIL PROTECTED] Arlo -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Release 0.27 of Task Coach
Hi all, I am pleased to announce release 0.27 of Task Coach. This release adds one feature: - Tasks can have a budget. You can set a time budget for tasks. If you also track effort for that task you can tack how much of the budget is still left. What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://taskcoach.niessink.com https://sourceforge.net/projects/taskcoach/ A binary installer is available for Windows XP, in addition to the source distribution. Thanks, Frank -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
monitoring folder in python
Is it possible to monitor a folder in the python?My question is if I put any file in it that particular folder my script should monitor the folder and read the file name.If so what function can I use? Thanx in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: How to merge two binary files into one?
Grant Edwards wrote: For large files, something like this is probably a better idea: Or with the little-used shutil module, and keeping your nomenclature and block size of 65536 import shutil fout = file('C', 'wb') for n in ['A', 'B']: fin = file(n, 'rb') shutil.copyfileobj(fin, fout, 65536) fin.close() fout.close() Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
EOL created by .write or .encode
Why is that some of my files written out by outF.write(outtext.encode('utf-8')) has ascii 10 as EOL, while others has ascii 13 as EOL? both of these files's EOL are originally all ascii 10. If i remove the EOL after the tt below in the place string, then this doesn't happen. findreplace = [ (ur'/body', ur'''tt /body'''), ] ... inF = open(filePath,'rb') s=unicode(inF.read(),'utf-8') inF.close() for couple in findreplace: outtext=s.replace(couple[0],couple[1]) s=outtext outF = open(tempName,'wb') outF.write(outtext.encode('utf-8')) outF.close() thanks. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list
Re: copying a file in the python script
Raghul a écrit : hi I am having a problem. I want to copy a file from the folder and paste it or move it to another folder. Is it possible in python? Actually I need to implement this in the zope for my site. When I click any file it should move or copied to another folder in the same machine using zope. Thanks in advance. Hello. try this : import shutil shutil.copyfile(srcfile, dstfile) if you want to move, just use this after import os os.remove(srcfile) Bye Fouff -- http://mail.python.org/mailman/listinfo/python-list
Good day
The message cannot be represented in 7-bit ASCII encoding and has been sent as a binary attachment. -- http://mail.python.org/mailman/listinfo/python-list
Re: re module non-greedy matches broken
* lothar [EMAIL PROTECTED] wrote: no - in the non-greedy regex 1st-patnot-1st-pat*?follow-pat 1st-pat, not-1st-pat and follow-pat are arbitrarily complex patterns. The not is the problem. Regex patterns are expressed positive by definition (meaning, you can say, what you expect, but not what you don't expect). In other words, regexps were invented to define (uh... regular) sets, nothing more (especially you can't define non-sets). So the usual way is to define the set you've called 'not-1st-pat*?' and describe it as regex. Modern regular expression engines (which are no longer regular by the way ;-) allow shortcuts like negative lookahead assertions and the like. I want to make clear, that it isn't, that nobody _wants_ to give an advice how to express your pattern in general. The point is, that there's no real syntax for it. It depends on how your 1st-pat and follow-pat look like. Chances are, that's even not expressable in one regex (depends on the complexity and kind of the set they define). Each pattern you write is special to the particular use case. Said that, there are some common patterns on how to write some specific forms of regexes. I also suggest Friedl's book. Look for the C-comment-example, where your problem (more or less) is discussed execessively. Though I really recommend to read the book from start to end. It's more like a story, but a good one ;-) with character classes and negative character classes you do not need non-greediness anyway. AFAICS one needs non-greedy regexps very very rarely at all. I'm playing with regular expressions for about ten years now and I've actually used them, say, two or three times -- and only for quick hacks. I've never actually _needed_ them. nd -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorator Base Class: Needs improvement.
Ron_Adam wrote: Ok, that post may have a few(dozen?) problems in it. I got glitched by idles not clearing variables between runs, so it worked for me because it was getting values from a previous run. This should work better, fixed a few things, too. The decorators can now take more than one argument. The function and arguments lists initialize correctly now. Ron: I've followed your attempts to understand decorators with interest, and have seen you engage in conversation with many luminaries of the Python community, so I hesitate at this point to interject my own remarks. In a spirit of helpfulness, however, I have to ask whether your understanding of decorators is different from mine because you don't understand them or because I don't. You have several times mentioned the possibility of a decorator taking more than one argument, but in my understanding of decorators this just wouldn't make sense. A decorator should (shouldn't it) take precisely one argument (a function or a method) and return precisely one value (a decorated function or method). It doesn't work with functions with more than one variable. It seems tuples don't unpack when given to a function as an argument. Any way to force it? class Decorator(object): [...] Perhaps we need to get back to basics? Do you understand what I mean when I say a decorator should take one function as its argument and it should return a function? regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to merge two binary files into one?
I'm so glad that this this problem has so many recipes. On Apr 5, 2005 1:57 PM, Andrew Dalke [EMAIL PROTECTED] wrote: Grant Edwards wrote: For large files, something like this is probably a better idea: Or with the little-used shutil module, and keeping your nomenclature and block size of 65536 import shutil fout = file('C', 'wb') for n in ['A', 'B']: fin = file(n, 'rb') shutil.copyfileobj(fin, fout, 65536) fin.close() fout.close() Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert database rows from CSV file
Dennis Lee Bieber wrote: On Mon, 4 Apr 2005 15:54:37 -0700, 3c273 [EMAIL PROTECTED] declaimed the following in comp.lang.python: Thanks for the link, but this is the step I am trying to save (for someone else). Every time he goes to run a report, he must stop and import any new csv files. Since the files are generated by a Python script, I thought I That information wasn't supplied in the original message. Your original post implied that the data source /was/ the CSV file... Show us the code segment that is writing the CSV file, and we can probably show you the DB-API equivalent for writing a new record to the table. For short however: aCustomer = Customer1 theWidget = Widget1 aQuantity = 1000 # I'm presuming the table only has the three columns, since you didn't list fields cursor.execute( INSERT INTO Table1 Values (%s, %s, %s) , (aCustomer, theWidget, aQuantity)) Beware, however, that the parameter markers (%s in the example above) will depend on which database module you use - some modules will expect ?, for example. This depends on the module's paramstyle. Also, don't forget to commit the changes! regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorator Maker is working. What do you think?
Ron_Adam wrote: Ok... it's works! :) So what do you think? Not much. As long as You do not present any nontrivial examples like Guidos MultiMethod decorator or an implementation of the dispatching case decorator I proposed that would benefit from factoring into pre- and postprocessing the pattern has only limited use and worse it suggests a misnomer: it obscures the semantics that is clearly functional/OO not procedural. Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: the bugs that try men's souls
Sean McIlroy wrote: later Wow again. I had a real V8 moment when I looked at your solution (smacking my forhead, groaning ruefully, etc). You were right: my intention was simply to hide the trivial cases from view; I completely missed the fact that I was now testing for membership in a different set. I should have remembered that python plays fair, and looked a little harder to find my mistake. Thanks again, Sean You're most welcome, I'm glad the solution was the right one. Its the kind of bug you can stare at mindlessly for hours without spotting it, but which will often be reasonably transparent to someone with a fresh perspective on the code. I had a doozy myself the other night, writing a mergesort for python's deque class (I can't believe it doesnt come with one!) the method would yield a queue with the right elements in it, but in a seemingly arbitrary order. Turns out, there was a sign that needed to be a = sign. GRRR. I bet if I'd posted to this group it would have been spotted in about 3 seconds flat :) - Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Gnuplot.py and, _by far_, the weirdest thing I've ever seen on my computer
syd wrote: I don't even know where to begin. This is just bizarre. I just picked up the Gnuplot.py module (a light interface to gnuplot commands) and was messing around with it today. I've got a tiny script, but it only works from the command line about half the time! In the python interpreter, 100%. Ipython, 100%. I'm not kidding. Nothing strange about it. When run standalone, the python interpreter quits and cleans up after itself, possibly deleting temp files before gnuplot gets a chance to use them. You can put a time.sleep(5) before exiting, or even safer, a full safety check: while 1: if os.path.isfile(your_plot_filename): break time.sleeep(1) Best, f -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorator Base Class: Needs improvement.
Steve Holden wrote: You have several times mentioned the possibility of a decorator taking more than one argument, but in my understanding of decorators this just wouldn't make sense. A decorator should (shouldn't it) take precisely one argument (a function or a method) and return precisely one value (a decorated function or method). Yes. I think this sould be fixed into the minds of the people exacly this way You state it: When writing @decorator(x,y) def f(): not the so called decorator function but decorator(x,y) is the decorating function and decorator(x,y) is nothing but a callable object that takes f as parameter. A little correcture of Your statement: it is NOT nessacary that a function or method will be returned from a decorator. def decorator(x,y): def inner(func): return x+y return inner @decorator(1,2) def f():pass f 3 This is perfectly valid allthough not very usefull ;) Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
Hello NG, (Win XP) I have successfully installed pyqt, but not qtext, which I need to run Eric3. The PyQT demo files run fine. I've downloaded QScintilla, compiled via MS-VC, but (I suppose I need the SIG), to translate or provide the Python interface with pyd Files. Eric complains, that qtext is not found. Has anyone success with getting this to work and how? Many thanks in advance for possible answers, You haven't said which version of PyQt you are using. I guess it's the non-commercial version based on Qt v2 - QScintilla (and therefore eric) requires Qt v3. Phil -- http://mail.python.org/mailman/listinfo/python-list
Placing Toplevel over the parent ?
When calling a dialog box using the Toplevel widget, how do I place it over the calling parent ? Currently when I call the dialog it appears to the side of the calling parent. Pete -- http://mail.python.org/mailman/listinfo/python-list
How to read a wxTreeCtrl
Hi, I want to read a wxTreeCtrl from the root since I want to store all the information in it in a python dictionary. I know that the methods I have to use are ItemHasChildren, GetFirstChild and GetNextChild and I have been success in getting the first node in this manner: while child.IsOk(): print wx.TreeCtrl.GetItemText ( self, child ) if wx.TreeCtrl.ItemHasChildren ( self, child ): (child, cookie) = wx.TreeCtrl.GetNextChild( self, child, cookie ) else: (child, cookie) = wx.TreeCtrl.GetNextChild( self, child, cookie ) my problem is that each one of this nodes has others children whose has its values. How can I read more that one level? Thanks in advance, Daniel del Pozo -- http://mail.python.org/mailman/listinfo/python-list
Re: monitoring folder in python
Raghul wrote: Is it possible to monitor a folder in the python?My question is if I put any file in it that particular folder my script should monitor the folder and read the file name.If so what function can I use? Thanx in advance If you do not want to poll (check for changes yourself regularly), here are some pointers: In Windows: With the win32 extensions, it's quite simple: http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html In Linux: http://www.edoceo.com/creo/inotify/ http://www.student.lu.se/~nbi98oli/dnotify.html http://www.lambda-computing.com/projects/dnotify/ Don't know of any Python extensions for the above, so you might have to write your own if you want to use them from Python. Also, you probably need to reconfigure and compile a new kernel. Have tested inotify myself and it seems to work, you also get the filename with the event. Only problem is it don't support monitoring a directory recursive (subdirectories) like in Windows with ReadDirectoryChangesW. -- http://mail.python.org/mailman/listinfo/python-list
Re: StopIteration in the if clause of a generator expression
On Apr 5, 2005 2:04 AM, Raymond Hettinger [EMAIL PROTECTED] wrote: [Steven Bethard] So do I read this right in preferring [x for y in z] over list(x for y in z) Yes! Why? (Serious question. I'm sure that you have a good reason - I just can't figure out what it is.) The generator expression has the advantage of not leaking references into the enclosing namespace. What's advantage of the list comp? -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 09:17:05 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: Hello NG, (Win XP) I have successfully installed pyqt, but not qtext, which I need to run Eric3. The PyQT demo files run fine. I've downloaded QScintilla, compiled via MS-VC, but (I suppose I need the SIG), to translate or provide the Python interface with pyd Files. Eric complains, that qtext is not found. Has anyone success with getting this to work and how? Many thanks in advance for possible answers, You haven't said which version of PyQt you are using. I guess it's the non-commercial version based on Qt v2 - QScintilla (and therefore eric) requires Qt v3. Phil Hello John and Phil, thank you for your answers. I have: PyQt 3.13 Qt v2.3 Non-commercial Edition I compiled: qscintilla-1.62-gpl-1.5.1\ and the results seems ok qmake qscintilla.pro nmake for the qmake, I downloaded: Qt 3.3.4 Evaluation I installed also SIP. sip-4.2.1 What steps are missing? thank you again -- Franz Steinhäusler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 09:17:05 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: Hello NG, (Win XP) I have successfully installed pyqt, but not qtext, which I need to run Eric3. The PyQT demo files run fine. I've downloaded QScintilla, compiled via MS-VC, but (I suppose I need the SIG), to translate or provide the Python interface with pyd Files. Eric complains, that qtext is not found. Has anyone success with getting this to work and how? Many thanks in advance for possible answers, You haven't said which version of PyQt you are using. I guess it's the non-commercial version based on Qt v2 - QScintilla (and therefore eric) requires Qt v3. Phil Hello John and Phil, thank you for your answers. I have: PyQt 3.13 Qt v2.3 Non-commercial Edition I compiled: qscintilla-1.62-gpl-1.5.1\ and the results seems ok qmake qscintilla.pro nmake for the qmake, I downloaded: Qt 3.3.4 Evaluation I installed also SIP. sip-4.2.1 What steps are missing? If you are using the evaluation version of Qt then you need the evaluation version of PyQt. This already includes SIP and QScintilla. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: DIY Spam Filter in Python
Damien Wyart [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... * [EMAIL PROTECTED] (Peter Ballard) in comp.lang.python: Source code, and a bit of documentation, is at: http://members.ozemail.com.au/~pballard/diyspamfilter.html BTW, 2 of the 3 files are links, so missing from the tar archive... Sigh. Murphy's Law strikes again. The tar file is fixed now. -- Peter -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to distinguish between system environment variables and the user ones?
To a environment variable in Windows, can python know if it is a system environment variable or a current-user environment variable? -- -- http://mail.python.org/mailman/listinfo/python-list
Re: setup distributed computing for two computer only
Heiko Wundram wrote: Am Montag, 4. April 2005 21:27 schrieb [EMAIL PROTECTED]: snip Google for: Python Remote Objects ^^^ what Heiko said :) This is, assuming that the 'function' on the other computer is implemented in Python too. --Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: StopIteration in the if clause of a generator expression
Simon Brunning wrote: On Apr 5, 2005 2:04 AM, Raymond Hettinger [EMAIL PROTECTED] wrote: [Steven Bethard] So do I read this right in preferring [x for y in z] over list(x for y in z) Yes! Why? (Serious question. I'm sure that you have a good reason - I just can't figure out what it is.) The generator expression has the advantage of not leaking references into the enclosing namespace. What's advantage of the list comp? The list comprehension is about 15-20% faster according to timeit.py: C:\Python24\Lib..\python.exe timeit.py -s t = range(1000) [ x for x in t] 1 loops, best of 3: 116 usec per loop C:\Python24\Lib..\python.exe timeit.py -s t = range(1000) list(x for x in t) 1000 loops, best of 3: 144 usec per loop C:\Python24\Lib..\python.exe timeit.py -s t = range(10) [ x for x in t] 10 loops, best of 3: 13.9 msec per loop C:\Python24\Lib..\python.exe timeit.py -s t = range(10) list(x for x in t) 10 loops, best of 3: 16.3 msec per loop Alternatively you could just regard the list comprehension as having less clutter on the screen so it may be clearer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Change between Python 2.3 and 2.4 under WinXP
On Tue, 05 Apr 2005 01:53:25 +0200, Martin v. Löwis [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: I'm not aware of any other tool that solves that specific problem. notepad does a fine job at creating batch files, IMO. Of course, it is not all that clear what the OP actually wanted. [...] Hi, here I am again, the OP :) I think, I considered the problem more complicated as it is in fact. Maybe a batch file (py23.bat: c:\python23\python.exe should be enough) thanks again! -- Franz Steinhäusler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Super Newbie Question
To reply to many of your messages (I'm using Google right now due to lack of a better newsreader at the moment), the issue with the temporary file is that when I write something new to it, if the old contents of the file was larger, not all of it will be overwritten. So, the truncate() method will work very well. Thank you Mr. Neuhauser, Mr. Ewing, and all others. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple thread-safe counter?
Paul Rubin http://[EMAIL PROTECTED] writes: Tim Peters [EMAIL PROTECTED] writes: The GIL is your friend here: import itertools f = itertools.count().next Thanks, I was hoping something like this would work but was not sure I could rely on it. A similar thing can be done with xrange. But either way sucks if you call it often enough to exceed the size of a Python short int (platform C long). The obvious way with an explicit mutex doesn't have that problem. Xrange, of course :). I don't need to exceed the size of a short int, so either of these should work fine. I wonder what measures the Pypy implementers will take (if any) to make sure these things keep working, but for now I won't worry about it. Well, for now we don't support threads. Easy! Cheers, mwh (no, really, this is for the future) -- Two things I learned for sure during a particularly intense acid trip in my own lost youth: (1) everything is a trivial special case of something else; and, (2) death is a bunch of blue spheres. -- Tim Peters, 1 May 1998 -- http://mail.python.org/mailman/listinfo/python-list
Re: setup distributed computing for two computer only
Am Dienstag, 5. April 2005 11:22 schrieb Irmen de Jong: Python Remote Objects ^^^ what Heiko said :) *biggrin* -- --- Heiko. listening to: Tool - Lateralus - 1 The Grudge.mp3 see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ pgpKv3ALoPbZi.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 10:14:48 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: On Tue, 5 Apr 2005 09:17:05 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: What steps are missing? If you are using the evaluation version of Qt then you need the evaluation version of PyQt. This already includes SIP and QScintilla. Phil Hello Phil, Ok, new begin. I installed PyQt 3.14.1 Evaluation now. If I want to start for example aclock.py, I get: ImportError: No module named qt Is there any dll missing? Or doesn't it fit with Qt 3.3.4 Evaluation Any hints? -- Franz Steinhäusler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ -- http://mail.python.org/mailman/listinfo/python-list
Python Google Server
I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to 'localhost:8000'. It will let you browse the internet using google's cache. Obviously you'll miss images, javascript, css files, etc. See the world as google sees it ! (This is actually an 'inventive' short term measure to get round a restrictive internet policy at work :-) I'll probably put it in the Python Cookbook as it's quite fun (so if line lengths or indentation is mangled here, try there). Tested on Windows XP, with Python 2.3 and IE. # Copyright Michael Foord, 2004 2005. # Released subject to the BSD License # Please see http://www.voidspace.org.uk/documents/BSD-LICENSE.txt # For information about bugfixes, updates and support, please join the Pythonutils mailing list. # http://voidspace.org.uk/mailman/listinfo/pythonutils_voidspace.org.uk # Comments, suggestions and bug reports welcome. # Scripts maintained at http://www.voidspace.org.uk/python/index.shtml # E-mail [EMAIL PROTECTED] import google import BaseHTTPServer import shutil from StringIO import StringIO import urlparse __version__ = '0.1.0' This is a simple implementation of a server that fetches web pages from the google cache. It lets you explore the internet from your browser, using the google cache. Run this script and then set your browser proxy settings to localhost:8000 Needs google.py (and a google license key). See http://pygoogle.sourceforge.net/ and http://www.google.com/apis/ cached_types = ['txt', 'html', 'htm', 'shtml', 'shtm', 'cgi', 'pl', 'py'] google.setLicense(google.getLicense()) googlemarker = '''iGoogle is not affiliated with the authors of this page nor responsible for its content./i/font/center/td/tr/table/td/tr/table\nhr\n''' markerlen = len(googlemarker) class googleCacheHandler(BaseHTTPServer.BaseHTTPRequestHandler): server_version = googleCache/ + __version__ cached_types = cached_types googlemarker = googlemarker markerlen = markerlen def do_GET(self): f = self.send_head() if f: self.copyfile(f, self.wfile) f.close() def send_head(self): Common code for GET and HEAD commands. This sends the response code and MIME headers. Return value is either a file object (which has to be copied to the outputfile by the caller unless the command was HEAD, and must be closed by the caller under all circumstances), or None, in which case the caller has nothing further to do. print self.path url = urlparse.urlparse(self.path)[2] dotloc = url.find('.') + 1 if dotloc and url[dotloc:] not in self.cached_types: return None # not a cached type - don't even try thepage = google.doGetCachedPage(self.path) headerpos = thepage.find(self.googlemarker) if headerpos != -1: # remove the google header pos = self.markerlen + headerpos thepage = thepage[pos:] f = StringIO(thepage) self.send_response(200) self.send_header(Content-type, 'text/html') self.send_header(Content-Length, str(len(thepage))) self.end_headers() return f def copyfile(self, source, outputfile): shutil.copyfileobj(source, outputfile) def test(HandlerClass = googleCacheHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass) if __name__ == '__main__': test() -- http://mail.python.org/mailman/listinfo/python-list
passing dictionary objects with soap
Hi! all, How can i return dictionary type element from a soap server to a client. What should be the entry message section of a wsdl file. Regards VK Hug the REALITY ;-) Disclaimer The facts expressed here belong to everybody, the opinions to me. The distinction is yours to draw... __ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/ -- http://mail.python.org/mailman/listinfo/python-list
Re: monitoring folder in python
A straw-man solution in Python that monitors a directory for changes (Linux only): #!/usr/bin/env python2 import sys import os if sys.platform not in (linux2,): sys.exit(%s only runs on Linux % os.path.basename(sys.argv[0])) # TODO: we should check that kernel version = 2.4.19 # e.g. with 'uname -r' import fcntl import signal TESTDIRECTORY = . def notify(directory, handler): fd = os.open(directory, os.O_RDONLY) fcntl.fcntl(fd, fcntl.F_NOTIFY, fcntl.DN_ACCESS|fcntl.DN_MODIFY|fcntl.DN_CREATE) signal.signal(signal.SIGIO, handler) def handler(signum, frame): print Something happened; signal =, signum if __name__ == __main__: notify(TESTDIRECTORY, handler) try: signal.pause() # sleep until signal received except KeyboardInterrupt: pass With Python 2.4 one could bind e.g. to signal.SIGRTMIN instead of the default SIGIO and get additional info, as suggested by the C example in Documentation/dnotify.txt (look in the Linux src tree). But then I am note sure you can access a siginfo structure directly from Python. With the example above, one would probably write the handler so that it rescans the directory when called to detect what actually changed. Davide -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 10:14:48 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: On Tue, 5 Apr 2005 09:17:05 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: What steps are missing? If you are using the evaluation version of Qt then you need the evaluation version of PyQt. This already includes SIP and QScintilla. Phil Hello Phil, Ok, new begin. I installed PyQt 3.14.1 Evaluation now. If I want to start for example aclock.py, I get: ImportError: No module named qt Is there any dll missing? Or doesn't it fit with Qt 3.3.4 Evaluation Any hints? What version of Python do you have installed? The binary is built against v2.4. BTW, your email address is bouncing messages. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
[EMAIL PROTECTED] wrote: lol ,cool hack!! make a slashdot article about it!! I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to 'localhost:8000'. It will let you browse the internet using google's cache. Obviously you'll miss images, javascript, css files, etc. See the world as google sees it ! (This is actually an 'inventive' short term measure to get round a restrictive internet policy at work :-) I'll probably put it in the Python Cookbook as it's quite fun (so if line lengths or indentation is mangled here, try there). Tested on Windows XP, with Python 2.3 and IE. # Copyright Michael Foord, 2004 2005. # Released subject to the BSD License # Please see http://www.voidspace.org.uk/documents/BSD-LICENSE.txt # For information about bugfixes, updates and support, please join the Pythonutils mailing list. # http://voidspace.org.uk/mailman/listinfo/pythonutils_voidspace.org.uk # Comments, suggestions and bug reports welcome. # Scripts maintained at http://www.voidspace.org.uk/python/index.shtml # E-mail [EMAIL PROTECTED] import google import BaseHTTPServer import shutil from StringIO import StringIO import urlparse __version__ = '0.1.0' This is a simple implementation of a server that fetches web pages from the google cache. It lets you explore the internet from your browser, using the google cache. Run this script and then set your browser proxy settings to localhost:8000 Needs google.py (and a google license key). See http://pygoogle.sourceforge.net/ and http://www.google.com/apis/ cached_types = ['txt', 'html', 'htm', 'shtml', 'shtm', 'cgi', 'pl', 'py'] google.setLicense(google.getLicense()) googlemarker = '''iGoogle is not affiliated with the authors of this page nor responsible for its content./i/font/center/td/tr/table/td/tr/table\nhr\n''' markerlen = len(googlemarker) class googleCacheHandler(BaseHTTPServer.BaseHTTPRequestHandler): server_version = googleCache/ + __version__ cached_types = cached_types googlemarker = googlemarker markerlen = markerlen def do_GET(self): f = self.send_head() if f: self.copyfile(f, self.wfile) f.close() def send_head(self): Common code for GET and HEAD commands. This sends the response code and MIME headers. Return value is either a file object (which has to be copied to the outputfile by the caller unless the command was HEAD, and must be closed by the caller under all circumstances), or None, in which case the caller has nothing further to do. print self.path url = urlparse.urlparse(self.path)[2] dotloc = url.find('.') + 1 if dotloc and url[dotloc:] not in self.cached_types: return None # not a cached type - don't even try thepage = google.doGetCachedPage(self.path) headerpos = thepage.find(self.googlemarker) if headerpos != -1: # remove the google header pos = self.markerlen + headerpos thepage = thepage[pos:] f = StringIO(thepage) self.send_response(200) self.send_header(Content-type, 'text/html') self.send_header(Content-Length, str(len(thepage))) self.end_headers() return f def copyfile(self, source, outputfile): shutil.copyfileobj(source, outputfile) def test(HandlerClass = googleCacheHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass) if __name__ == '__main__': test() -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 11:43:38 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: [...] Or doesn't it fit with Qt 3.3.4 Evaluation Any hints? What version of Python do you have installed? The binary is built against v2.4. Oh sorry, I think, there was a mix between Python2.3 and Python2.4 somewhere in the registry. (it took the .pyd files from Python23 directory). I don't understand exactly (replaced some Python23 with Python24 with regedit), and, cool, it is working (also with eric (before I had installed 3.5.1 (there was an error), and now with eric 3.6.2), all is fine. thank you very much BTW, your email address is bouncing messages. Hm, sorry, I don't understand, what you mean. Phil best regards -- Franz Steinhäusler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorator Base Class: Needs improvement.
On 5 Apr 2005 00:54:25 -0700, Kay Schluehr [EMAIL PROTECTED] wrote: Steve Holden wrote: You have several times mentioned the possibility of a decorator taking more than one argument, but in my understanding of decorators this just wouldn't make sense. A decorator should (shouldn't it) take precisely one argument (a function or a method) and return precisely one value (a decorated function or method). I agree from an English language point of view. I.e., a verber is something that does the verbing, so a decorator ought to be the thing that does the decorating, which is the function/callable(s) resulting on stack from the evaluation of the @-line. In the case of a single @deco name, the evaluation is trivial, and the difference between the @-expression and the resulting callable might be overlooked. Full-fledged general expressions after the '@' are for some reason disallowed, but it is handy to allow attribute access and calling in the syntax, so the relevant Grammar rules are: From the 2.4 Grammar, the key part seems to be decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorators: decorator+ funcdef: [decorators] 'def' NAME parameters ':' suite and further on dotted_name: NAME ('.' NAME)* So the Python Grammar's name for the @-expression is just plain decorator which conflicts with my English-based reading of the word ;-/ So it appears the intent is to call the entire @-line the decorator and I guess to have a name for what evaluating the @-line returns on the stack, we could call it the decorating callable since it is what takes the function parameter as its first parameter and decorates the function and returns the decorated function. But I don't like it, English-wise. I would rather call the @-line the decorator expression and what it evaluates to the decorator. Can we change the grammar with s/decorator/decorator_expr/ ? Yes. I think this sould be fixed into the minds of the people exacly this way You state it: I think we may be agreeing in principle but with different words ;-) When writing @decorator(x,y) def f(): not the so called decorator function but decorator(x,y) is the ^--(the result of evaluating) decorating function and decorator(x,y) is nothing but a callable object ^--(the result of evaluating) that takes f as parameter. A little correcture of Your statement: it is NOT nessacary that a function or method will be returned from a decorator. Yes, in fact it could even perversely be colluding with a known succeeding decorator callable to pass info strangely, doing strange things, e.g., trick = ['spam', 'eggs'] def choose_name(tup): ... nx, f = tup ... f.func_name = trick[nx] ... return f ... def namedeco(nx=1): ... return lambda f, nx=nx:(nx, f) ... @choose_name ... @namedeco() ... def foo(): pass ... foo function eggs at 0x02EE8E64 @choose_name ... @namedeco(0) ... def foo(): pass ... foo function spam at 0x02EE8DF4 I.e., namedeco evaluates to the lambda as decorator function, and that passes a perverse (nx, f) tuple on to choose_name, instead of a normal f. def decorator(x,y): def inner(func): return x+y return inner @decorator(1,2) def f():pass f 3 This is perfectly valid allthough not very usefull ;) Perhaps even less useful, the final decorator can return something arbitrary, as only the name in the def matters at that point in the execution (as a binding target name), so: def dumbdeco(f): return 'something dumb' ... @dumbdeco ... def foo(): pass ... foo 'something dumb' Hm, maybe some use ... def keydeco(name): ... return lambda f: (name, f) ... @keydeco('pooh_foo') ... def foo(): pass ... @keydeco('tigger_bar') ... def bar(): pass ... dict([foo, bar]) {'pooh_foo': function foo at 0x02EE8DBC, 'tigger_bar': function bar at 0x02EE8DF4} ... nah ;-) Anyway, I think a different name for what comes after the @ and the callable that that (very limited) expression is supposed to return would clarify things. My conceptual model is @decorator_expression # = decorator def decorating_target(...): ... Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
it works on opera and firefox on linux, but you cant search in the cached google! it would be more usefull if you could somehow search only in the cache instead of putting the straight link. maybe you could put a magic url to search in the cache, like search:search terms [EMAIL PROTECTED] wrote: I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to 'localhost:8000'. It will let you browse the internet using google's cache. Obviously you'll miss images, javascript, css files, etc. See the world as google sees it ! (This is actually an 'inventive' short term measure to get round a restrictive internet policy at work :-) I'll probably put it in the Python Cookbook as it's quite fun (so if line lengths or indentation is mangled here, try there). Tested on Windows XP, with Python 2.3 and IE. # Copyright Michael Foord, 2004 2005. # Released subject to the BSD License # Please see http://www.voidspace.org.uk/documents/BSD-LICENSE.txt # For information about bugfixes, updates and support, please join the Pythonutils mailing list. # http://voidspace.org.uk/mailman/listinfo/pythonutils_voidspace.org.uk # Comments, suggestions and bug reports welcome. # Scripts maintained at http://www.voidspace.org.uk/python/index.shtml # E-mail [EMAIL PROTECTED] import google import BaseHTTPServer import shutil from StringIO import StringIO import urlparse __version__ = '0.1.0' This is a simple implementation of a server that fetches web pages from the google cache. It lets you explore the internet from your browser, using the google cache. Run this script and then set your browser proxy settings to localhost:8000 Needs google.py (and a google license key). See http://pygoogle.sourceforge.net/ and http://www.google.com/apis/ cached_types = ['txt', 'html', 'htm', 'shtml', 'shtm', 'cgi', 'pl', 'py'] google.setLicense(google.getLicense()) googlemarker = '''iGoogle is not affiliated with the authors of this page nor responsible for its content./i/font/center/td/tr/table/td/tr/table\nhr\n''' markerlen = len(googlemarker) class googleCacheHandler(BaseHTTPServer.BaseHTTPRequestHandler): server_version = googleCache/ + __version__ cached_types = cached_types googlemarker = googlemarker markerlen = markerlen def do_GET(self): f = self.send_head() if f: self.copyfile(f, self.wfile) f.close() def send_head(self): Common code for GET and HEAD commands. This sends the response code and MIME headers. Return value is either a file object (which has to be copied to the outputfile by the caller unless the command was HEAD, and must be closed by the caller under all circumstances), or None, in which case the caller has nothing further to do. print self.path url = urlparse.urlparse(self.path)[2] dotloc = url.find('.') + 1 if dotloc and url[dotloc:] not in self.cached_types: return None # not a cached type - don't even try thepage = google.doGetCachedPage(self.path) headerpos = thepage.find(self.googlemarker) if headerpos != -1: # remove the google header pos = self.markerlen + headerpos thepage = thepage[pos:] f = StringIO(thepage) self.send_response(200) self.send_header(Content-type, 'text/html') self.send_header(Content-Length, str(len(thepage))) self.end_headers() return f def copyfile(self, source, outputfile): shutil.copyfileobj(source, outputfile) def test(HandlerClass = googleCacheHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass) if __name__ == '__main__': test() -- http://mail.python.org/mailman/listinfo/python-list
Python IDE like NetBeans/Delphi IDE
Hi ! I search for an IDE that working in Windows, and knows these functions: A.) Automatic name searching/showing/extending on classes with keypressing (like Netbeans, or Delphi Ctrl+Space). B.) Debugging: breakpoints, step on lines (code), watch variables. Or A and B both. Please help me. Thanx: ft -- http://mail.python.org/mailman/listinfo/python-list
Re: playing with pyGoogle - strange codec error
Brian Blazer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Everything works fine until I get to r.snippet. Here is the error: UnicodeEncodeError: 'ascii' codec can't encode character '\ua9' in position 119: ordinal not in range(128) You have a character there (the copyright sign) that isn't in the ASCII set. If you have anything other than plain ASCII, you need to consider encoding. This reference might help: http://diveintopython.org/xml_processing/unicode.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Change between Python 2.3 and 2.4 under WinXP
Martin v. Löwis wrote: Of course, it is not all that clear what the OP actually wanted. For all we know, he wanted to alternate quickly (with batch file or similary) between python23 and python24... Maybe off-topic for this thread, but I noticed that when installing 2.4.1 that 2.4.0 is automatically removed. Does 2.4 do the same thing to 2.3 versions? -- http://mail.python.org/mailman/listinfo/python-list
Re: copying a file in the python script
If you are moving the file to another directory on the same hard drive (e.g. same filesystem) you can use os.rename(old, new) and the file doesn't have to be copied at all. This is more efficient. If you are copying to another filesystem, you must use shutil.copy and os.remove (or os.unlink). Larry Bates Raghul wrote: hi I am having a problem. I want to copy a file from the folder and paste it or move it to another folder. Is it possible in python? Actually I need to implement this in the zope for my site. When I click any file it should move or copied to another folder in the same machine using zope. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE like NetBeans/Delphi IDE
Take a look at ActiveState: http://www.activestate.com/Products/ActivePythonFamily/?_x=1 or for something more general: http://www.eclipse.org/ Larry Bates [EMAIL PROTECTED] wrote: Hi ! I search for an IDE that working in Windows, and knows these functions: A.) Automatic name searching/showing/extending on classes with keypressing (like Netbeans, or Delphi Ctrl+Space). B.) Debugging: breakpoints, step on lines (code), watch variables. Or A and B both. Please help me. Thanx: ft -- http://mail.python.org/mailman/listinfo/python-list
check interpreter version before running script
Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. Whatever I do, I need it to work on Linux, Mac and Windows. I thought of sys.version... but getting info out of it seems awkward to me. First 5 chars are '2.4.1' in string format have to split it up and convert it to ints to do proper checking, etc. It doesn't seem that sys.version was built with this type of usage in mind. So, what is the *best* most correct way to go about this? Thanks, rbt -- http://mail.python.org/mailman/listinfo/python-list
Re: copying a file in the python script
Larry Bates wrote: If you are moving the file to another directory on the same hard drive (e.g. same filesystem) you can use os.rename(old, new) and the file doesn't have to be copied at all. This is more efficient. If you are copying to another filesystem, you must use shutil.copy and os.remove (or os.unlink). Or use shutil.move() which implements the strategy you describe. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE like NetBeans/Delphi IDE
On Tue, 05 Apr 2005 14:07:14 +0200, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I search for an IDE that working in Windows, and knows these functions: A.) Automatic name searching/showing/extending on classes with keypressing (like Netbeans, or Delphi Ctrl+Space). B.) Debugging: breakpoints, step on lines (code), watch variables. Or A and B both. What about Boa Constructor for A.)? I personally don't like the debugger so much, IMHO Hap Debugger is better and is similar to Visual Studio Debugger. You can also try DrPython (the development debugger is apparantly in process). -- Franz Steinhäusler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: check interpreter version before running script
rbt wrote: Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. I like import os try: os.walk except AttributeError: # implement fallback No need to remember in which version the desired feature came to be. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: check interpreter version before running script
Le Tue, 05 Apr 2005 08:57:12 -0400, rbt a écrit : Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. I thought of sys.version... but getting info out of it seems awkward to me. First 5 chars are '2.4.1' in string format have to split it up and convert it to ints to do proper checking, etc. It doesn't seem that sys.version was built with this type of usage in mind. So, what is the *best* most correct way to go about this? try: from os import walk as os_walk except ImportError: os_walk = None # raise some exception or implement a fallback solution # use os_walk instead of os.walk Thanks, rbt -- http://mail.python.org/mailman/listinfo/python-list
Re: Eric3 under WinXP
On Tue, 5 Apr 2005 11:43:38 +0100 (BST), Phil Thompson [EMAIL PROTECTED] wrote: [...] Or doesn't it fit with Qt 3.3.4 Evaluation Any hints? What version of Python do you have installed? The binary is built against v2.4. Oh sorry, I think, there was a mix between Python2.3 and Python2.4 somewhere in the registry. (it took the .pyd files from Python23 directory). I don't understand exactly (replaced some Python23 with Python24 with regedit), and, cool, it is working (also with eric (before I had installed 3.5.1 (there was an error), and now with eric 3.6.2), all is fine. thank you very much BTW, your email address is bouncing messages. Hm, sorry, I don't understand, what you mean. Email to your address bounces with mailbox full errors. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Super Newbie Question
Joey C. wrote: To reply to many of your messages (I'm using Google right now due to lack of a better newsreader at the moment), the issue with the temporary file is that when I write something new to it, if the old contents of the file was larger, not all of it will be overwritten. That's not likely true, unless you're doing something unusual here. Are you somehow terminating the process before it closes the file (and not using flush())? Or are you opening the file in some kind of update mode (with a +) instead of just using w? Or something else? Or are you just assuming that what you describe will happen, but haven't actually tried it? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: raw sockets please
ionel wrote: anyone got any idea how the get raw sockets working on win32 ? (on python 2.4) No, but I'm certain this has been asked and answered many times in the past. Maybe you could use Google Groups and search the list archives, posting here only when you get insufficient results (and telling us that you've already checked the archives, and why the answers there were not sufficient)... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Placing Toplevel over the parent ?
Pete Moscatt wrote: When calling a dialog box using the Toplevel widget, how do I place it over the calling parent ? Currently when I call the dialog it appears to the side of the calling parent. What framework? What versions? What platform? -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
vegetax wrote: it works on opera and firefox on linux, but you cant search in the cached google! it would be more usefull if you could somehow search only in the cache instead of putting the straight link. maybe you could put a magic url to search in the cache, like search:search terms Thanks for the report. I've also tried it with firefox on windows. Yeah - google search results aren't cached !! Perhaps anything in a google domain ought to pass straight through. That could be done by testing the domain and using urllib2 to fetch the page. Have just tested the following which works. Add the follwoing two lines to the start of the code : import urllib2 txheaders = { 'User-agent' : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)' } Then change the start of the send_head method to this : def send_head(self): Only GET implemented for this. This sends the response code and MIME headers. Return value is a file object, or None. print 'Request :', self.path # traceback to sys.stdout url_tuple = urlparse.urlparse(self.path) url = url_tuple[2] domain = url_tuple[1] if domain.find('.google.') != -1: # bypass the cache for google domains req = urllib2.Request(self.path, None, txheaders) return urllib2.urlopen(req) [EMAIL PROTECTED] wrote: I've hacked together a 'GoogleCacheServer'. It is based on SimpleHTTPServer. Run the following script (hopefully google groups won't mangle the indentation) and set your browser proxy settings to 'localhost:8000'. It will let you browse the internet using google's cache. Obviously you'll miss images, javascript, css files, etc. See the world as google sees it ! [snip..] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE like NetBeans/Delphi IDE
More specifically, check out the pydev plugin for Eclipse. pydev.sourceforge.net M. Larry Bates wrote: Take a look at ActiveState: http://www.activestate.com/Products/ActivePythonFamily/?_x=1 or for something more general: http://www.eclipse.org/ Larry Bates [EMAIL PROTECTED] wrote: Hi ! I search for an IDE that working in Windows, and knows these functions: A.) Automatic name searching/showing/extending on classes with keypressing (like Netbeans, or Delphi Ctrl+Space). B.) Debugging: breakpoints, step on lines (code), watch variables. Or A and B both. Please help me. Thanx: ft -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to distinguish between system environment variables and the user ones?
could ildg wrote: To a environment variable in Windows, can python know if it is a system environment variable or a current-user environment variable? Not just by using the os.environ approach. You would have to resort to the pywin32 extensions. Check the Python Cookbook using Google for environment variable recipes and you'll get a good start on it. You'll also require a bit of Win32-specific knowledge, since this entire concept is not a cross-platform one. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: check interpreter version before running script
rbt wrote: Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. Whatever I do, I need it to work on Linux, Mac and Windows. Why does this have to occur before running the script? Can't you just do it as the first thing the script does on startup? That is the usual Best Practice approach. I thought of sys.version... but getting info out of it seems awkward to me. First 5 chars are '2.4.1' in string format have to split it up and convert it to ints to do proper checking, etc. It doesn't seem that sys.version was built with this type of usage in mind. So, what is the *best* most correct way to go about this? Use sys.version_info instead. As it's a tuple, you can just slice-and-dice as needed, and compare subsets of it with other tuples. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: check interpreter version before running script
F. Petitjean wrote: Le Tue, 05 Apr 2005 08:57:12 -0400, rbt a écrit : Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. I thought of sys.version... but getting info out of it seems awkward to me. First 5 chars are '2.4.1' in string format have to split it up and convert it to ints to do proper checking, etc. It doesn't seem that sys.version was built with this type of usage in mind. So, what is the *best* most correct way to go about this? try: from os import walk as os_walk except ImportError: os_walk = None # raise some exception or implement a fallback solution # use os_walk instead of os.walk Thanks, rbt You may be interested in this... http://www.jorendorff.com/articles/python/path/ as an alternative to the os.path functions... Martin -- http://mail.python.org/mailman/listinfo/python-list
start python web programming
I should implement a simple http/database page, based on python. I read some texts and it´s strange how python deal with html output. It´s something like Servlet... is there any diferent way to do that? Something like just bussiness code, applied in an MVC framework, or just like it. Thanks and sorry about my english.-- André Nobre[EMAIL PROTECTED]-- http://mail.python.org/mailman/listinfo/python-list
Re: Python IDE like NetBeans/Delphi IDE
Dnia Tue, 05 Apr 2005 14:07:14 +0200, [EMAIL PROTECTED] napisa(a): Hi ! I search for an IDE that working in Windows, and knows these functions: A.) Automatic name searching/showing/extending on classes with keypressing (like Netbeans, or Delphi Ctrl+Space). B.) Debugging: breakpoints, step on lines (code), watch variables. Or A and B both. Please help me. Check those: Eclipse + pydev plugin (free, stable, good integration with SVN plugin, pylint, debugger, refactoring) PythonWin (free, stable, fast, good debugger) WingIDE (commercial, slower than PythonWin but has many features) -- JZ -- http://mail.python.org/mailman/listinfo/python-list
Re: boring the reader to death (wasRe: Lambda: the Ultimate DesignFlaw
Donn Cave wrote: That's an odd thing to say. Poetry is verbose, florid? Python is Dutch. Ha. I'm vaguely dutch, whatever that means. I would say if there is a sister word for Programming in the english language, it isn't Poetry and it surely isn't Prose. It's Dialectic. I appreciate the idea of Code Poetry, and I find more than a few coders out there with more than a rudimentary appreciation of Poetry as well, but I don't like the analogy. No slight to Poetry is intended. Rather, I intend it as a compliment. Code has an almost entirely practical purpose, Malbol et al excluded. Poetry, except in cases of extraordinarily bad poetry, may have little practical purpose. Now dialectic. I like that word. And I think the art of programming is somewhere in the Late-Medeival period right now. From Merriam Webster, meanings 1,5,6 seem rather sympathetic to texts used in the creation of software: Dialectic 1. LOGIC 5. Any systematic reasoning, exposition, or argument that juxtaposes opposed or contradictory ideas and usually seeks to resolve their conflict/an intellectual exchange of ideas 6 : the dialectical tension or opposition between two interacting forces or elements One way to look at Code is as a textual abstraction of a design. Having been flattened from brain-space into a two dimension matrix of latin glyphs, certain semantic/meta-data is typically omitted. Thus a classical programming problem in many languages: The Write-only-code syndrom. You wrote it, it runs, but you're afraid even to touch it yourself. Python is stronger than other languages I have used. When I go back to Python code I've written long enough ago to have forgotten everything about, I am more able to pick it up and work with it than I am with other less agile languages. I'm not merely talking about pedantic details of literal code-readability, I'm talking about the ability to intuit design from implementation, and the orthogonality of the design of the system to the to the faculty of human reason. (In not so many words: Python fits my brain.) Warren -- http://mail.python.org/mailman/listinfo/python-list
Re: How to merge two binary files into one?
On 2005-04-05, Andrew Dalke [EMAIL PROTECTED] wrote: Grant Edwards wrote: For large files, something like this is probably a better idea: Or with the little-used shutil module, and keeping your nomenclature and block size of 65536 I knew I should have looked through shutil to see if there was already something like that. -- Grant Edwards grante Yow! MMM-MM!! So THIS is at BIO-NEBULATION! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
Another change - change the line `dotloc = url.find('.') + 1` to `dotloc = url.rfind('.') + 1` This makes it find the last '.' in the url Best Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: Change between Python 2.3 and 2.4 under WinXP
rbt [EMAIL PROTECTED] writes: Martin v. Löwis wrote: Of course, it is not all that clear what the OP actually wanted. For all we know, he wanted to alternate quickly (with batch file or similary) between python23 and python24... Maybe off-topic for this thread, but I noticed that when installing 2.4.1 that 2.4.0 is automatically removed. Does 2.4 do the same thing to 2.3 versions? No. 2.4 and 2.3 (and other versions) can coexist. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Class, object question.
Hello folks, The question I am having is something like this. # ignore the precursing . I am using them for easy message formatting from point import * Class vector(point): ..def __init___(self, point1, point2): ..self.i = point2.get_x() - point1.get_x() ..self.j = point2.get_y() - point1.get_y() ..self.k = point2.get_z() - point1.get_z() # methods of vector. Defined here. What I am wondering is if I have a 2nd init or something similar to create a vector. Such as what follows and if I can how do I go about implementing it? Class vector(point): ..def __init___(self, point1, point2): ..self.i = point2.get_x() - point1.get_x() ..self.j = point2.get_y() - point1.get_y() ..self.k = point2.get_z() - point1.get_z() . ..def __init___(self, i, j, k): ..self.i = i ..self.j = j ..self.k = k That way I can define a vector either using 2 points or if I have the vector data itself? Thanks in advance Jeff -- http://mail.python.org/mailman/listinfo/python-list
SSL and Proxy problem with urllib2 ?
using a proxy and https/SSL together I get the following SSL error : File dscore.pyo, line 2257, in UrlOpenEx File ClientCookie\_urllib2_support.pyo, line 572, in open File ClientCookie\_urllib2_support.pyo, line 472, in http_response File ClientCookie\_urllib2_support.pyo, line 589, in error File urllib2.pyo, line 304, in _call_chain File ClientCookie\_urllib2_support.pyo, line 181, in http_error_302 File ClientCookie\_urllib2_support.pyo, line 566, in open File urllib2.pyo, line 324, in open File urllib2.pyo, line 304, in _call_chain File ClientCookie\_urllib2_support.pyo, line 807, in https_open File ClientCookie\_urllib2_support.pyo, line 656, in do_open File httplib.pyo, line 712, in endheaders File httplib.pyo, line 597, in _send_output File httplib.pyo, line 564, in send File httplib.pyo, line 985, in connect File socket.pyo, line 73, in ssl sslerror: (1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol') using python 2.3.5 any Ideas about the problem? Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest vs py.test?
Roy Smith [EMAIL PROTECTED] writes: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Bengt Richter) Is there a package that is accessible without svn? That seems to be its weak point right now. Fortunately, you can get pre-built svn clients for many platforms (http://subversion.tigris.org/project_packages.html#binary-packages), and from there you just have to run a single command (svn get URL). wget -r should work fine! Cheers, mwh -- All obscurity will buy you is time enough to contract venereal diseases. -- Tim Peters, python-dev -- http://mail.python.org/mailman/listinfo/python-list
unknown protocol error in httplib using HTTPS
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani [EMAIL PROTECTED] User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.python Subject: unknown protocol error in httplib using HTTPS Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 48 Message-ID: [EMAIL PROTECTED] Date: Sun, 21 Dec 2003 18:44:53 +0530 NNTP-Posting-Host: 152.69.162.185 X-Trace: news.oracle.com 1072013963 152.69.162.185 (Sun, 21 Dec 2003 05:39:23 PST) NNTP-Posting-Date: Sun, 21 Dec 2003 05:39:23 PST I'm using Python 2.3.3 to do HTTPS using the httplib module. Here's the code: from httplib import HTTPSConnection con = HTTPSConnection('www-proxy', 80) con.set_debuglevel(1) con.request('GET', 'https://nexus.passport.com:443/rdr/pprdr.asp') res = con.getresponse() print res.status, res.reason print res.read() Here, www-proxy is the HTTPS proxy server that I have to go through (I can't connect directly). I'm trying to GET https://nexus.passport.com:443/rdr/pprdr.asp; via the proxy, but I'm getting a unknown protocol error in return: File test.py, line 9, in ? con.request('GET', 'https://nexus.passport.com:443/rdr/pprdr.asp') File c:\python23\lib\httplib.py, line 718, in request self._send_request(method, url, body, headers) File c:\python23\lib\httplib.py, line 739, in _send_request self.endheaders() File c:\python23\lib\httplib.py, line 712, in endheaders self._send_output() File c:\python23\lib\httplib.py, line 597, in _send_output self.send(msg) File c:\python23\lib\httplib.py, line 564, in send self.connect() File c:\python23\lib\httplib.py, line 985, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File c:\python23\lib\socket.py, line 73, in ssl return _realssl(sock, keyfile, certfile) socket.sslerror: (1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol') What's the problem here? I just want to use SSL over my HTTPS proxy using httplib. Any help. Thanks! Manish -- http://mannu.livejournal.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest vs py.test?
Peter Hansen [EMAIL PROTECTED] writes: Raymond Hettinger wrote: [Peter Hansen] This is pretty, but I *want* my tests to be contained in separate functions or methods. In py.test, those would read: def test1(): assert a == b def test2(): raises(Error, func, args) Enclosing classes are optional. So basically py.test skips the import statement, near as I can tell, at the cost of requiring a utility to be installed in the PATH. Where was all that weight that unittest supposedly has? For PyPy we wanted to do some things that the designers of unittest obviously hadn't expected[1], such as formatting tracebacks differently. This was pretty tedious to do[2], involving things like accessing __variables, defining subclasses of certain classes, defining subclasses of other classes so the previous subclasses would actually get used, etc. I've not programmed in Java, but I imagine this is what it feels like all the time... (Not to knock unittest too much, we did manage to get the customizations we needed done, but it wasn't fun). Cheers, mwh [1] this in itself is hardly a criticism: there are many special things about PyPy. [2] *this* is the criticism. -- Well, you pretty much need Microsoft stuff to get misbehaviours bad enough to actually tear the time-space continuum. Luckily for you, MS Internet Explorer is available for Solaris. -- Calle Dybedahl, alt.sysadmin.recovery -- http://mail.python.org/mailman/listinfo/python-list
Re: IronPython 0.7 released!
Does the Python community think Microsoft's embrace is a good or bad thing? James wrote: http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742 -- http://mail.python.org/mailman/listinfo/python-list
cross platform printing
Alan Isaac [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'd like to try personal financial management using Python. I just found PyCheckbook, but it does not support check printing. Is there a Python check printing application kicking around? OK, I'll assume silence means no, so new question: What is the current best practice for cross platform printing of PostScript files from Python? Same question for PDF. (I'm aware of URL:http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html.) Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: pagecrawling websites with Python
Swaroop, Thanks for the reply, I'll take a look at HarvestMan and see if we can use it directly, or get some ideas from the source code. :) Doug -- http://mail.python.org/mailman/listinfo/python-list
Re: change extensions
Bob Then wrote: how can i change all files from one extension to another within a direcory? Using Jason Orendorff's path.py module: # change all .py files in '.' to extension .new from path import path for f in path('.').files(): if f.endswith('.py'): f.rename(f.splitext()[0] + '.new') Don't try the above in a folder containing useful Python files! ;-) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Python MySQL
Hi all, I've got a weird problem. I was running Python 2.3 and MySQLdb and had everything running fine. Cutting to the chase: After upgrading to 2.4 (and latest modules) the MySQLdb functions in Python can connect to the database, do queries and do inserts. Or rather, it seems to do inserts. If I just run in the Python command line and manually connect to the database and do an insert and then a query on what I just inserted the info is there. However when I use SQLyog to look at the database the info isn't there. When I close down Python, restart, reconnect and query the info isn't there. Info inserted from SQLyog is persistant. Has anyone had any problems like this before? thanks, jason -- http://mail.python.org/mailman/listinfo/python-list
RE: change extensions
That approach works, but so does this one. import os, glob input_file_list = glob.glob('*.txt') for in_file in input_file_list: name = in_file.split('.') os.rename(in_file, str(name[0]) + '.' + 'text')) # I could have put the text extension with the period but if you use a variable (string) for the extension then you can't -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Hansen Sent: Tuesday, April 05, 2005 10:35 AM To: python-list@python.org Subject: Re: change extensions Bob Then wrote: how can i change all files from one extension to another within a direcory? Using Jason Orendorff's path.py module: # change all .py files in '.' to extension .new from path import path for f in path('.').files(): if f.endswith('.py'): f.rename(f.splitext()[0] + '.new') Don't try the above in a folder containing useful Python files! ;-) -Peter -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
authentication in zope server Python
Hi I am trying to execute a sample python script using zope server.The problem is I need to execute a python script in the linux machine. When I call that function through the zope server,It shows me the error regarding authentication that is 'access denied for myfunction' In my function just I am copying a file from one location to another location in the same machine. Thanx in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest vs py.test?
Michael Hudson wrote: Peter Hansen [EMAIL PROTECTED] writes: Where was all that weight that unittest supposedly has? For PyPy we wanted to do some things that the designers of unittest obviously hadn't expected[1], such as formatting tracebacks differently. This was pretty tedious to do[2], I'd agree with that! The guts of unittest I find to be somewhat opaque, and not straightforward to extend. Trying to do so here has also proven tedious, though ultimately feasible, as you say the PyPy folks have found. Which, in the end, is precisely why I just use the simplest vanilla approach that I can, no different than anything done, for example, in the excellent chapter on testing in http://www.diveintopython.org or other examples of using unittest. unitttest is surely not the be all and end all of Python unit testing frameworks... but it's one of the batteries included in the standard distribution, and it's pretty trivial to get started using it, unless maybe you try to go by the documentation instead of by the examples... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Change between Python 2.3 and 2.4 under WinXP
rbt said unto the world upon 2005-04-05 08:39: Martin v. Löwis wrote: Of course, it is not all that clear what the OP actually wanted. For all we know, he wanted to alternate quickly (with batch file or similary) between python23 and python24... Maybe off-topic for this thread, but I noticed that when installing 2.4.1 that 2.4.0 is automatically removed. Does 2.4 do the same thing to 2.3 versions? Hi, on a different thread http://groups.google.ca/groups?hl=enlr=safe=offselm=42353d7d%240%2419431%249b622d9e%40news.freenet.de Martin said that only one 2.4 version at a time is supported due to there being only one python24.dll. But the msi install process now informs you of this (thanks Martin :-) Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: change extensions
On Apr 5, 2005 10:43 AM, Jeffrey Maitland [EMAIL PROTECTED] wrote: That approach works, but so does this one. import os, glob input_file_list = glob.glob('*.txt') for in_file in input_file_list: name = in_file.split('.') os.rename(in_file, str(name[0]) + '.' + 'text')) you should really use in_file.splitext - your script renames myfile.with.lots.of.dots.txt to myfile.text instead of myfile.with.lots.of.dots.text . If you *really* wanted to use split(), it oughta be ''.join(in_file.split('.')[:-1]) , but why not use the built-in? Peace Bill Mill bill.mill at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MySQL
[EMAIL PROTECTED] wrote: Hi all, I've got a weird problem. I was running Python 2.3 and MySQLdb and had everything running fine. Cutting to the chase: After upgrading to 2.4 (and latest modules) the MySQLdb functions in Python can connect to the database, do queries and do inserts. Or rather, it seems to do inserts. If I just run in the Python command line and manually connect to the database and do an insert and then a query on what I just inserted the info is there. However when I use SQLyog to look at the database the info isn't there. When I close down Python, restart, reconnect and query the info isn't there. Info inserted from SQLyog is persistant. Has anyone had any problems like this before? thanks, jason I suspect you are forgetting to commit your changes to the database, so they are being rolled back when you close your connection. regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MySQL
[EMAIL PROTECTED] wrote: Hi all, I've got a weird problem. I was running Python 2.3 and MySQLdb and had everything running fine. Cutting to the chase: After upgrading to 2.4 (and latest modules) the MySQLdb functions in Python can connect to the database, do queries and do inserts. Or rather, it seems to do inserts. If I just run in the Python command line and manually connect to the database and do an insert and then a query on what I just inserted the info is there. However when I use SQLyog to look at the database the info isn't there. When I close down Python, restart, reconnect and query the info isn't there. Info inserted from SQLyog is persistant. Has anyone had any problems like this before? thanks, jason I suspect you are forgetting to commit your changes to the database, so they are being rolled back when you close your connection. regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert database rows from CSV file
Dennis Lee Bieber [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mon, 4 Apr 2005 15:54:37 -0700, 3c273 [EMAIL PROTECTED] declaimed the following in comp.lang.python: Thanks for the link, but this is the step I am trying to save (for someone else). Every time he goes to run a report, he must stop and import any new csv files. Since the files are generated by a Python script, I thought I That information wasn't supplied in the original message. Your original post implied that the data source /was/ the CSV file... Show us the code segment that is writing the CSV file, and we can probably show you the DB-API equivalent for writing a new record to the table. For short however: aCustomer = Customer1 theWidget = Widget1 aQuantity = 1000 # I'm presuming the table only has the three columns, since you didn't list fields cursor.execute( INSERT INTO Table1 Values (%s, %s, %s) , (aCustomer, theWidget, aQuantity)) Ah.. Many thanks. This is what I was looking for. Louis -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert database rows from CSV file
Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dennis Lee Bieber wrote: On Mon, 4 Apr 2005 15:54:37 -0700, 3c273 [EMAIL PROTECTED] declaimed the following in comp.lang.python: Thanks for the link, but this is the step I am trying to save (for someone else). Every time he goes to run a report, he must stop and import any new csv files. Since the files are generated by a Python script, I thought I That information wasn't supplied in the original message. Your original post implied that the data source /was/ the CSV file... Show us the code segment that is writing the CSV file, and we can probably show you the DB-API equivalent for writing a new record to the table. For short however: aCustomer = Customer1 theWidget = Widget1 aQuantity = 1000 # I'm presuming the table only has the three columns, since you didn't list fields cursor.execute( INSERT INTO Table1 Values (%s, %s, %s) , (aCustomer, theWidget, aQuantity)) Beware, however, that the parameter markers (%s in the example above) will depend on which database module you use - some modules will expect ?, for example. This depends on the module's paramstyle. Also, don't forget to commit the changes! regards Steve Thanks for the heads-up. I think I'm well on my way now. Louis -- http://mail.python.org/mailman/listinfo/python-list
Re: check interpreter version before running script
Josef Meile wrote: What's about: import sys print sys.version_info (2, 1, 3, 'final', 0) Python 1.5.2 (#1, Mar 3 2001, 01:35:43) [GCC 2.96 2731 (Red Hat Linux 7.1 2 on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam import sys sys.version_info Traceback (innermost last): File stdin, line 1, in ? AttributeError: version_info ...which the OP may have known, since they suggested sys.version, which *is* availible in pre-2.0. My own messy solution involves a shell script installer which runs a 1.5-safe Python script which installs a needs-2.2 Python script. But I needed an installer for other reasons. This would be ugly for a single script. djo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
Fuzzyman wrote: Add the follwoing two lines to the start of the code : import urllib2 txheaders = { 'User-agent' : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)' } Then change the start of the send_head method to this : def send_head(self): Only GET implemented for this. This sends the response code and MIME headers. Return value is a file object, or None. print 'Request :', self.path # traceback to sys.stdout url_tuple = urlparse.urlparse(self.path) url = url_tuple[2] domain = url_tuple[1] if domain.find('.google.') != -1: # bypass the cache for google domains req = urllib2.Request(self.path, None, txheaders) return urllib2.urlopen(req) Doesnt work,the browsers keeps asking me to save the page. this one works =) def send_head(self): print 'Request :', self.path #| traceback| to| sys.stdout url_tuple = urlparse.urlparse(self.path) url = url_tuple[2] domain = url_tuple[1] if domain.find('.google.') != -1: # bypass the cache for google domains req = urllib2.Request(self.path, None, txheaders) self.send_response(200) self.send_header(Content-type, 'text/html') self.end_headers() return urllib2.urlopen(req) dotloc = url.rfind('.') + 1 -- http://mail.python.org/mailman/listinfo/python-list
Real ython Poetry [was: Re: boring the reader to death...]
Scott David Daniels wrote: Sunnan wrote: ...Because what is boring? The opposite of dense, tense, intense. Utterly predictable; it's like the combination of all my prejudices. Even before I knew, I thought Bet Python separates statements from expressions. Python is for terse, pithy prose; Python is not for poetry. --Scott David Daniels [EMAIL PROTECTED] I though that too, until Michael Spencer sent me the following executable Python limerick, which I declared the PyCon limerick competition and read as a part of my closing address: # Freely re-distributable under Poetic License* # Voice only the alphanumeric tokens from itertools import repeat for feet in [3,3,2,2,3]: print .join(DA-DA-DUM for dummy in [None] for foot in repeat(metric, feet)) *thanks to Peter Hansen regards Steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
Of course - sorry. Thanks for the fix. Out of interest - why are you using this... just for curiosity, or is it helpful ? Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: Web application toolkit recommendation?
On Apr 05, 2005, at 02:01, Stewart Midwinter wrote: I don't want to hear anything about Zope - it's way too complex for my needs or desires. Other than that, fire away! I have an inexplicable attraction to CherryPy. Perhaps something to do with its name 8^) http://www.cherrypy.org/ http://www.cherrypy.org/wiki/CherryPyTutorial Cheers -- PA, Onnay Equitursay http://alt.textdrive.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: re module non-greedy matches broken
lothar wrote: with respect to the documentation, the module is broken. nope. the module does not necessarily deliver a minimal length match for a non-greedy pattern. it isn't supposed to: a regular expression describes a *set* of matching strings, and the engine is free to return any string from that set. Python's engine returns the *first* string it finds that belongs to the set. if you use a non-greedy operator, the engine will return the first non-greedy match it finds, not the overall shortest non-greedy match. if you don't want to understand how regular expressions work, don't use them. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Change between Python 2.3 and 2.4 under WinXP
Martin v. Löwis wrote: I'm not aware of any other tool that solves that specific problem. notepad does a fine job at creating batch files, IMO. have you used exemaker? have you compared the behaviour of the resulting executables to batch files using different environments, shells, and OS versions? or are you just guessing here? /F -- http://mail.python.org/mailman/listinfo/python-list
regexp weirdness (bug?)
Here's the session log: _re_pair=(?(plus).|-) _re1=((?Pplus\+)+_re_pair) _re2=(((?Pplus\+))+_re_pair) _re3=((?:(?Pplus\+))+_re_pair) _re4=(%s)%_re3 import re print [re.match(_re, +a) and 'match' for _re in [_re1, _re2, _re3, _re4]] ['match', None, 'match', None] this is not the supposed behaivour. all theese patterns should match, right? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
[EMAIL PROTECTED] writes: (This is actually an 'inventive' short term measure to get round a restrictive internet policy at work :-) If that means what I think, you're better off setting up a url-rewriting proxy server on some other machine, that uses SSL on the browser side. There's one written in perl at: http://www.jmarshall.com/tools/cgiproxy/ Presumably you're surfing through some oppressive firewall, and the SSL going into the proxy prevents the firewall from logging all the destination URL's going past it (and the content too, for that matter). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MySQL
Okay, I had the brilliant idea right after posting to google the newsgroups on this. db = MySQLdb.connect(user=database_user,passwd=database_password) db.autocommit(True) --- One little line! There ya go. Works like a champ. I swear I was pulling my hair out yesterday over this. -- http://mail.python.org/mailman/listinfo/python-list
Re: terminating an inactive process
if you have pywin32 then check out a download from MS download called script-o-matic2. it will write some boilerplate code that is usefull for killing processes. its wmi based but works nicely. i have a script that i run on my home computer if you want a sample. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Google Server
The difficulty is 'on some other machine'... there's a fantastic python CGI proxy called approx - http://www.voidspace.org.uk/python/cgi.shtml#approx The trouble is the current policy is 'whitelist only'... so I need the proxy installed on a server that is *on the whitelist*... which will take a little time to arrange. Best Regards, Fuzzy http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
os.path query functions behavior incorrect?
The docs for os.path.exists(), isdir(), and the like, do not describe behavior when an I/O error occurs. Testing on Windows XP SP2 with Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32, on a machine with no a: drive, c: is a hard disk with a top level directory named path but without a top level directory named foo, and d: is a CD drive (with no disc inserted): import os print os.path.exists(c:\\) True print os.path.isdir(c:\\) True print os.path.isdir(c:\\boost) True print os.path.isdir(c:\\foo) False OK, that meets my expectations. But now: print os.path.exists(a:\\) False print os.path.isdir(a:\\) False print os.path.exists(d:\\) True print os.path.isdir(d:\\) True These to me are I/O errors that should result in an exception. Doing a command line dir a:\ reports The system cannot find the path specified. Dir d:\ reports The device is not ready. So are these os.path functions specified and implemented incorrectly? Should they instead throw exceptions for the above examples? If they are specified and implemented correctly, what is the rationale for this behavior? Thanks, --Beman -- http://mail.python.org/mailman/listinfo/python-list
Re: re module non-greedy matches broken
a non-greedy match - as implicitly defined in the documentation - is a match in which there is no proper substring in the return which could also match the regex. you are skirting the issue as to why a matcher should not be able to return a non-greedy match. there is no theoretical reason why it can not be done. André Malo [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] * lothar [EMAIL PROTECTED] wrote: no - in the non-greedy regex 1st-patnot-1st-pat*?follow-pat 1st-pat, not-1st-pat and follow-pat are arbitrarily complex patterns. The not is the problem. Regex patterns are expressed positive by definition (meaning, you can say, what you expect, but not what you don't expect). In other words, regexps were invented to define (uh... regular) sets, nothing more (especially you can't define non-sets). So the usual way is to define the set you've called 'not-1st-pat*?' and describe it as regex. Modern regular expression engines (which are no longer regular by the way ;-) allow shortcuts like negative lookahead assertions and the like. I want to make clear, that it isn't, that nobody _wants_ to give an advice how to express your pattern in general. The point is, that there's no real syntax for it. It depends on how your 1st-pat and follow-pat look like. Chances are, that's even not expressable in one regex (depends on the complexity and kind of the set they define). Each pattern you write is special to the particular use case. -- http://mail.python.org/mailman/listinfo/python-list
Re: re module non-greedy matches broken
give an re to find every innermost table element: innertabdoc = table border=0 cellspacing=0 cellpadding=0 trtd table border=0 cellspacing=0 cellpadding=0 trtd an/a /td/tr /table /td/tr /table table border=0 cellspacing=0 cellpadding=0 trtd table border=0 cellspacing=0 cellpadding=0 trtd /td td table border=0 cellspacing=0 cellpadding=0 trtd py/p td z/td /td/tr /table /td/tr /table /td/tr trtd table border=0 cellspacing=0 cellpadding=0 trtd /td/tr /table /td/tr /table give an re to find every pre element directly followed by an a element: preadoc = pre a ir/i n /pre pre bl/b y /prea href=#n1/a pre r /pre pre f fontg/font z /pre pre m ib/i u ic/i v /prea href=#n2/a pre u /pre John Ridley [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Could you post some real-world examples of the problems you are trying to deal with, please? Trying to come up with general solutions for arbitrarily complex patterns is a bit to hard for me :) -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp weirdness (bug?)
* Sergey Schetinin wrote: Here's the session log: _re_pair=(?(plus).|-) _re1=((?Pplus\+)+_re_pair) _re2=(((?Pplus\+))+_re_pair) _re3=((?:(?Pplus\+))+_re_pair) _re4=(%s)%_re3 import re print [re.match(_re, +a) and 'match' for _re in [_re1, _re2, _re3, _re4]] ['match', None, 'match', None] this is not the supposed behaivour. all theese patterns should match, right? No, I suppose they shouldn't compile. _re_pair should be (?P=plus). nd -- http://mail.python.org/mailman/listinfo/python-list
Re: re module non-greedy matches broken
a non-greedy match is implicitly defined in the documentation to be one such that there is no proper substring in the return which could also match the regex. the documentation implies the module will return a non-greedy match. the module does not return a non-greedy match. Fredrik Lundh [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] lothar wrote: with respect to the documentation, the module is broken. nope. the module does not necessarily deliver a minimal length match for a non-greedy pattern. it isn't supposed to: a regular expression describes a *set* of matching strings, and the engine is free to return any string from that set. Python's engine returns the *first* string it finds that belongs to the set. if you use a non-greedy operator, the engine will return the first non-greedy match it finds, not the overall shortest non-greedy match. if you don't want to understand how regular expressions work, don't use them. /F -- http://mail.python.org/mailman/listinfo/python-list