Re: [2.4.2/Linux] Getting Python to fork?
On 2008-02-04, Christian Heimes [EMAIL PROTECTED] wrote: Jon Ribbens wrote: Why? I don't think you do. Neither does BSD daemon.c or glibc daemon.c The problem is well documented at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 OK I understand what is being said here, although it seems a bit unlikely (daemon process opens a tty), but what is puzzling me is why, if it's so necessary, does neither Linux nor *BSD do this in their daemon() functions? It would seem surprising if the operating system authors don't know how to make a daemon process in their own OS ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.4.2/Linux] Getting Python to fork?
On 2008-02-04, Gilles Ganault [EMAIL PROTECTED] wrote: I need to launch a Python script, and fork it so that the calling script can resume with the next step will the Python script keeps running. I tried those two, but they don't work, as the calling script is stuck until the Python script ends: This should work I believe: if os.fork(): os._exit(0) os.setsid() os.chdir(/) fd = os.open(/dev/null, os.O_RDWR) os.dup2(fd, 0) os.dup2(fd, 1) os.dup2(fd, 2) if fd 2: os.close(fd) # do stuff Although bear in mind it's pretty UNIX-y. -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.4.2/Linux] Getting Python to fork?
On 2008-02-04, Rolf van de Krol [EMAIL PROTECTED] wrote: To create a deamon, you indeed need to fork two times. For more information and a working example see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 . I'm quite sure this works, because I used it several times to create a deamon. That doesn't mean it works. That just means it hasn't failed while you were watching. (Not that I am saying it's necessarily wrong, I'm just saying that it worked when I tried it is a very bad way of deciding if something is correct code.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Regarding coding style
On 2008-03-07, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: 2. You should use two spaces after a sentence-ending period. For heavens sake, why? I've always been obstructed by the double blanks but tolerated them. Now, that i read that it actually is a recommendation, i need to ask about the purpose. Like many things of this nature, the purpose is to follow the rules of correct English usage. Well, no, it's to follow a particular person's choice out of the many and various competing rules of correct English usage. Personally, I dislike double spaces after sentences, but it is not wrong to put them there any more than it is wrong not to put them there. Consistency is far more important (hence the rule, I presume). -- http://mail.python.org/mailman/listinfo/python-list
Re: Finally had to plonk google gorups.
On 2008-04-16, Grant Edwards [EMAIL PROTECTED] wrote: But that's not a battle you can win, so I broke down and joined all the other people that just killfile everything posted via google.groups. I did the same about an hour ago. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Success stories
On 2008-04-23, Mark Wooding [EMAIL PROTECTED] wrote: Python is actually one of the few to define one but not the other. (The other one I can think of is Acorn's BBC BASIC, for whatever that's worth; it too lacks `++'.) You should've added it in Termite Basic then :-p -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting expirty data on a cookie
On 2008-04-25, David [EMAIL PROTECTED] wrote: Another note: 'expires' is apprantly a legacy attribute for early Netscape browsers. The RFC and python source comments suggest that you use 'Max-Age' instead. Theoretically, yes. In practice, no. *Nobody* uses the new-style cookies, everyone uses Netscape ones. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is None = 0
On 2008-04-25, Martin v. Löwis [EMAIL PROTECTED] wrote: None is smaller than anything. According to Tim Peters, this is not true. See http://bugs.python.org/issue1673405 -- http://mail.python.org/mailman/listinfo/python-list
Re: Why can't timedeltas be divided?
On 2008-04-27, Martin v. Löwis [EMAIL PROTECTED] wrote: sorry for bringing up such an old thread, but this seems important to me -- up to now, there are thousands [1] of python programs that use hardcoded time calculations. Would you like to work on a patch? Last time I brought up this sort of thing, it seemed fairly unanimous that the shortcomings of the datetime module were 'deliberate' and would not be fixed, patch or no patch. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why can't timedeltas be divided?
On 2008-04-27, Martin v. Löwis [EMAIL PROTECTED] wrote: Last time I brought up this sort of thing, it seemed fairly unanimous that the shortcomings of the datetime module were 'deliberate' and would not be fixed, patch or no patch. Ok, so then if the answer to my question is yes, the first step should be to discuss it on python-dev. Yes, that's where it was decided that the datetime module was fine that way it is and must not be changed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why can't timedeltas be divided?
On 2008-04-27, webograph [EMAIL PROTECTED] wrote: On 2008-04-27 14:18, Jon Ribbens wrote: Yes, that's where it was decided that the datetime module was fine that way it is and must not be changed. could you give me some pointers to that discussion? Well, http://bugs.python.org/issue1673409 seems very closely related. As does the thread starting at http://mail.python.org/pipermail/python-dev/2007-March/071776.html nevertheless, i fail to see such problems when dividing timedeltas -- after all, `delta2 / 5 == delta1` works, so why should not `delta2 / delta1 == 5`? I used very similar arguments for the changes I wanted, and they weren't appreciated ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to store config or preferences in a multi-platform way.
On 2008-05-01, Ivan Illarionov [EMAIL PROTECTED] wrote: IMO .ini-like config files are from the stone age. The modern approach is to use YAML (http://www.yaml.org). You mean YAML isn't a joke!? It's so ludicrously overcomplicated, and so comprehensively and completely fails to achieve its stated main goal of being readable by humans, that I had assumed it was an April Fool along the lines of Intercal or brainf***. I certainly wouldn't recommend it as being suitable for, well, anything at all. Or were you trolling and I missed the joke? ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to store config or preferences in a multi-platform way.
On 2008-05-01, Ivan Illarionov [EMAIL PROTECTED] wrote: I used XML files before for this purpose and found YAML much easier and better suitable for the task. Please explain why don't like YANL so much? Because even the examples in the spec itself are unreadable gibberish. The PyYAML library is over 300kB! These are rather big clues that it's unsuitable for the purpose for which it was designed. It's certainly unsuitable for use as a configuration file format, where it is overkill by several orders of magnitude. !!str a1 foo: !!str bar a2 baz : *a1 !tag:yaml.org,2002:str foo : !!bar baz This is supposed to be human readable? PS. Your reply remind me of early days of Python when Perl programmers said exacly the same thing about Python. I think I would suffer irony overload if I saw a Perl programmer criticising Python for being hard to read ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: 16bit hash
On 2007-06-27, Robin Becker [EMAIL PROTECTED] wrote: Is the any way to get an efficient 16bit hash in python? int(md5.new(s).hexdigest()[:4], 16) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why PHP is so much more popular for web-development
On 2007-07-26, Steve Holden [EMAIL PROTECTED] wrote: That sounds trivial to ameliorate (at least somewhat) by putting your uploads in a directory whose name is known only to you (let's say it's a random 20-letter string). The parent directory can be protected to not allow reading the subdirectory names. But you have to admit that's security by obscurity. Um, no? -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to protect my new commercial software.
On 2007-12-18, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-12-18, Jan Claeys [EMAIL PROTECTED] wrote: No, it's only copyrighted when you _publish_ it. Interesting. So, in Europe, if somebody steals something you wrote before you get it published, they're free to do with it as they please? No, I believe the above comment is false. The Berne Convention of 1887 makes copyright automatic as soon as a work is written or recorded. Thus, most of Europe has had automatic copyright for a very long time, and all of it does now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Python to fork?
On 2008-02-04, Bernard [EMAIL PROTECTED] wrote: #Fork and commit suicide if os.fork(): sys.exit(0) I'm pretty sure that should be os._exit(0) #What to do in parent process This is now the child process. sys.stdin = open('/dev/null') sys.stdout = open('/dev/null', 'w') sys.stderr = open('/dev/null', 'w') I think that's changing Python's idea of stdin etc but not the operating system's idea of them. You won't be closing the original file descriptors, and if you run any subprocesses they will end up with the original stdin/out/err. Unless sys.stdin is more magic than I'm aware of. -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.4.2/Linux] Getting Python to fork?
On 2008-02-04, Christian Heimes [EMAIL PROTECTED] wrote: Although bear in mind it's pretty UNIX-y. IIRC you have to fork a second time after you have changed the working dir and created a new session group. Why? I don't think you do. Neither does BSD daemon.c or glibc daemon.c -- http://mail.python.org/mailman/listinfo/python-list
Re: Iteration for Factorials
On 2007-10-23, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Yuk. Reminds me of one of the Hitachi processors that has a single depth hardware link register that tells a subroutine where it was called from. That's how ARM processors work, and they're everywhere these days. -- http://mail.python.org/mailman/listinfo/python-list
Re: count pages in a pdf
On 2007-11-27, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: is it possible to parse a pdf file in python? for starters, i would like to count the number of pages in a pdf file. i see there is a project called ReportLab, but it seems to be a pdf generator... i can't tell if i would be able to parse a pdf file programmically. http://pybrary.net/pyPdf/ -- http://mail.python.org/mailman/listinfo/python-list
Re: why isn't Unicode the default encoding?
In article [EMAIL PROTECTED], Martin v. Löwis wrote: In any case, it doesn't matter what encoding the document is in: read(2) always returns two bytes. It returns *up to* two bytes. Sorry to be picky but I think it's relevant to the topic because it illustrates how it's difficult to change the definition of file.read() to return characters instead of bytes (if the file is ready to read, there will always be one or more bytes available (or EOF), but there won't always be one or more characters available). -- http://mail.python.org/mailman/listinfo/python-list
Re: How do clients(web browser) close a python CGI program that is not responding?
In article [EMAIL PROTECTED], Sullivan WxPyQtKinter wrote: Hi,there. Sometimes a python CGI script tries to output great quantities of HTML responce or in other cases, it just falls into a dead loop. How could my client close that CGI script running on the server? I tried to use the STOP button in the web browser button, but it does not work. It depends on what CGI framework you're using. If the user hits 'stop', the client browser should close its connection and your web server should close the pipe to your CGI process. I'd expect you to get a SIGPIPE when next trying to output data. In addition, how could I configure that if a CGI program do not finish its task in 20sec or so, it will be automatically terminated? Do you mean a specific CGI, or all CGIs in general? If it's in general then you need to see if your web server can be configured to do that. If it's a specific CGI, check out signal.alarm() or resource.setrlimit(resource.RLIMIT_CPU, ...). Apache has a RLimitCPU directive, but be careful with it since it may well not do what you expect. -- http://mail.python.org/mailman/listinfo/python-list
Re: Difference between 'is' and '=='
In article [EMAIL PROTECTED], Roy Smith wrote: This may even be useful. What if you were trying to emulate SQL's NULL? NULL compares false to anything, even itself. Strictly speaking, comparing NULL to anything gives NULL, not False. -- http://mail.python.org/mailman/listinfo/python-list
Re: overloading constructor in python?
In article [EMAIL PROTECTED], Alex Martelli wrote: I guess in python we use two idioms to cover most of the uses of mulltiple constructors: ... and classmethods. OK, _three_ idioms. Oh, and factory functions. Among the idioms we use are the following... Nobody expects the Spanglish inquisition... -- http://mail.python.org/mailman/listinfo/python-list
Re: File writing success
On 2007-05-11, HMS Surprise [EMAIL PROTECTED] wrote: If file writing has no return value (http://docs.python.org/lib/bltin- file-objects.html), how do you know if the write was successful? Because no exception was thrown? Although bear in mind that some errors might not become apparent until you close or flush the file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Select hangs after some reads
In article [EMAIL PROTECTED], Steve Holden wrote: Of course, if the client forces the TCP PSH flag true then the receiver is guaranteed to debuffer the stream up to that point - this is how FTP clients work, for example. I don't think that's right. You are confusing the PSH flag (which is basically unused in Unix networking I think) and the URG flag (which is extremely rarely used, but is indeed used by FTP to get abort requests to 'jump the queue' as it were). -- http://mail.python.org/mailman/listinfo/python-list
Re: Select hangs after some reads
In article [EMAIL PROTECTED], Steve Holden wrote: I don't think that's right. You are confusing the PSH flag (which is basically unused in Unix networking I think) and the URG flag (which is extremely rarely used, but is indeed used by FTP to get abort requests to 'jump the queue' as it were). Nope. I'm sorry, but you're definitely mistaken. The URG flag indicates that a packet contains out-of-band data, whihc is what you describe above. out-of-band is just way the sockets interface slightly mis-describes it. Either way, it causes (in Unix) the FTP server process to receive a SIGURG; the signal handler sets a flag and the data-transfer loop stops. The PSH flag indicates that the data stream must be flushed right through to the other end. That's sort-of true, but irrelevant. The PSH flag, when received, means that the networking layer should unbuffer any data and ensure it is released to the receiving application. *However*, BSD sockets never wait before allowing the application to receive incoming data, so the incoming PSH flag is unnecessary and ignored. In addition, the sockets interface simply doesn't provide a method for applications to set the PSH flag on output. The networking system simply sets the PSH flag by default whenever the output buffer empties. This is essential for interactive protocols such as FTP: without it the server has no way to know that the client has sent a complete command, and vice versa. I'm afraid that's completely wrong. The FTP server knows it has received a complete command because it sees the CRLF sequence in the data stream. I must admit it's refreshingly unusual to find someone who is more familiar with TCP/IP as described theoretically in the 1981 RFCs than the realities of the sockets interface ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: help() on stdout.closed
In article [EMAIL PROTECTED], Pekka Karjalainen wrote: from sys import stdout help (stdout.closed) If I do this, it gives me help on the bool object. stdout.closed is a bool. What were you expecting it to show you? -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to wrap a whole script in try..except?
In article [EMAIL PROTECTED], Hari Sekhon wrote: I want to wrap a whole script in try ... except. What is the best way of doing this? You could do this maybe: import sys def excepthook(exc_type, exc_value, tb): import modules_needed_to_notify_exception ... sys.excepthook = excepthook import modules_needed_by_script ... -- http://mail.python.org/mailman/listinfo/python-list
Re: OS specific command in Python
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action. Try exec() and execfile() from the standard library (IIRC) Ths os.spawn...() functions are likely to be better suited to what he wants to do. ssh [EMAIL PROTECTED] .etc When you connect (via ssh or telnet) to a remote machine, you need to type (manually) your username and your password. Programming that is never easy. Indeed, so it is much easier to use public-key authentication with an unencrypted private key, that way you don't have to type any passwords. See the AUTHORIZED_KEYS FILE FORMAT section of the 'sshd' man page, and the 'ssh-keygen' command. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sudoko solver
In article [EMAIL PROTECTED], Rony Steelandt wrote: Yes, this is on windows using winzip It says the zip file is not a valid zipfile Works fine for me on Windows. Try deleting the file you downloaded, clearing your browser cache, and trying again. On the other hand, when you run it it immediately pops up a huge dialog saying that there is a new version available, 404 File Not Found, and a huge pile of HTML source. The game itself seems to work though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fork You.. Forking and threading..
In article [EMAIL PROTECTED], rh0dium wrote: if os.fork() == 0: os.setsid sys.stdout = open(/dev/null, 'w') sys.stdin = open(/dev/null, 'r') I don't know if it's the cause of your problem, but you're not doing the backgrounding right, it should be: if os.fork(): os._exit(0) os.setsid() os.chdir(/) fd = os.open(/dev/null, os.O_RDWR) os.dup2(fd, 0) os.dup2(fd, 1) os.dup2(fd, 2) if fd 2: os.close(fd) # do stuff -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I avoid abusing lists?
In article [EMAIL PROTECTED], Thomas Nelson wrote: This is exactly what I want to do: every time I encounter this kind of value in my code, increment the appropriate type by one. Then I'd like to go back and find out how many of each type there were. This way I've written seems simple enough and effective, but it's very ugly and I don't think it's the intended use of lists. Does anyone know a cleaner way to have the same funtionality? How about this: map = {} def increment(value): map[value] = map.get(value, 0) + 1 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/env python 2.4?
In article [EMAIL PROTECTED], Stargaming wrote: from sys import version_info if version_info[0] 2 or version_info[1] 4: raise RuntimeError(You need at least python2.4 to run this script) That'll fail when the major version number is increased (i.e. Python 3.0). You want: if sys.hexversion 0x020400f0: ... error ... -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/env python 2.4?
In article [EMAIL PROTECTED], Sion Arrowsmith wrote: Jon Ribbens [EMAIL PROTECTED] wrote: if sys.hexversion 0x020400f0: ... error ... Readability counts. if sys.version_info (2, 4): ... error ... Maybe you should suggest a patch to the Python documentation then ;-) The formula I mentioned is the one suggested in the official Python documentation ( http://docs.python.org/lib/module-sys.html#l2h-5143 ) as being the way to check the Python version. -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/env python 2.4?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: I don't see any problem with:: if version_info[0] = 2 and version_info[1] 4: raise RuntimeError() What if the version number is 1.5? -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/env python 2.4?
In article [EMAIL PROTECTED], Gabriel Genellina wrote: Uh... I never thought it was an implied formula there - that F0 had to come from 1.5 = 15 = 0xF. I think it should be stated much more clearly. I'm not sure what you're saying. You are correct that the documentation is rather vague. The 'f0' comes from 'final release' I think. -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a string/list/generator/comprehension incantation.
In article [EMAIL PROTECTED], Steven W. Orr wrote: Now I want something that's going to give me a string whose value is the set of all of the first letters of months. Order is not important. .join(set(m[0] for m in calendar.month_abbr[1:])) And for extra credit, I need the string whose value is the set of all of the letters of months minus the first letter. .join(set(.join(m[1:] for m in calendar.month_abbr[1:]))) Those are the ways that are obvious to me anyway, maybe there are better ways. If you actually want a set not a string, remove the outer-most .join(). -- http://mail.python.org/mailman/listinfo/python-list
Re: need an alternative to getattr()
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: import heading1 import heading2 While True: heading = get_next_heading(file_ptr) # This func will return heading1, then heading2(on next call) if heading = : break getattr(heading, process)(file_ptr) # The problem, as you would have noticed, is that the first # argument to getattr is a string!! Is there an alternatice to getattr() that will solve my problem, or is there another way to do it. globals()[heading].process(file_ptr) or sys.modules[heading].process(file_ptr) but note that, unless you are checking 'heading' against a 'known good configuration keywords' list beforehand, you are trusting the author of the configuration file. -- http://mail.python.org/mailman/listinfo/python-list
Re: IP address
In article [EMAIL PROTECTED], Lad wrote: I have a website written in Python and I would like to login every visitor's IP address. In other words, if a visitor come to my Python application, this application will record his IP. Depending on what CGI framework you're using, something like: os.environ[REMOTE_ADDR] -- http://mail.python.org/mailman/listinfo/python-list
Re: list index()
On 2007-08-31, Erik Max Francis [EMAIL PROTECTED] wrote: I say the 'oll' in troll like the 'ol' in frolic, and pronounce roll and role similarly. My accent is probably from the East Midlands of the UK, but is not pronounced. _Troll_ and _frolic_ aren't pronounced with the same o sound in any accent I've ever heard of. Welcome to England! Which you pronounce _boat_ and _bot_ the same way, too? No. HTH HAND. -- http://mail.python.org/mailman/listinfo/python-list
Re: smtp debugging methods
On 2007-09-14, Sean Nakasone [EMAIL PROTECTED] wrote: I'm having trouble with sending smtp mail. It's hanging after the smtplib.SMTP() line. It doesn't works from home but not from work. What's the best way to debug this? # Here's the error server = smtplib.SMTP(smtp.gmail.com,465) smtp.gmail.com port 465 is SSL only. Try port 587 instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: add without carry
In article [EMAIL PROTECTED], Bruno Desthuilliers wrote: Hugh wrote: Sorry, here's an example... 5+7=12 added without carrying, 5+7=2 i.e the result is always less than 10 I've been thinking some more about this and my brain is starting to work something out... No need to think too long to come up with the most possibly QD solution: res = int(str(5 + 7)[-1]) Am I missing something subtle in the question or is there some reason that nobody has posted the correct solution: (a + b) % 10 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: Lawrence D'Oliveiro wrote: So I think the default for the second argument to cgi.escape should be changed to True. Or alternatively, the second argument should be removed altogether, and quotes should always be escaped. you're confused: cgi.escape(s) is designed to be used for ordinary text, cgi.escape(s, True) is designed for attributes. if you use the code the way it's intended to be used, it works perfectly fine. He's not confused, he's correct; the author of cgi.escape is the confused one. The optional extra parameter is completely unnecessary and achieves nothing except to make it easier for people to end up with bugs in their code. Making cgi.escape always escape the '' character would not break anything, and would probably fix a few bugs in existing code. Yes, those bugs are not cgi.escape's fault, but that's no reason not to be helpful. It's a minor improvement with no downside. One thing that is flat-out wrong, by the way, is that cgi.escape() does not encode the apostrophe (') character. This is essentially identical to the quote character in HTML, so any code which escaping one should always be escaping the other. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Georg Brandl wrote: Attributes can be quoted with either single or double quotes. That's what the HTML spec says. cgi.escape doesn't correctly allow for that. Ergo, cgi.escape is broken. QED. A function is broken if its implementation doesn't match the documentation. Or if the design, as described in the documentation, is flawed in some way. As a courtesy, I've pasted it below. [...] Now, do you still think cgi.escape is broken? Yes. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: Making cgi.escape always escape the '' character would not break anything, and would probably fix a few bugs in existing code. Yes, those bugs are not cgi.escape's fault, but that's no reason not to be helpful. It's a minor improvement with no downside. the improvement with no downside would bloat down the output for everyone who's using the function in the intended way, By a miniscule degree. That is a very weak argument by any standard. and will also break unit tests. Er, so change the unit tests at the same time? One thing that is flat-out wrong, by the way, is that cgi.escape() does not encode the apostrophe (') character. it's intentional, of course: I noticed. That doesn't mean it isn't wrong. you're supposed to use if you're using cgi.escape(s, True) to escape attributes. again, punishing people who actually read the docs and understand them is not a very good way to maintain software. In what way is anyone being punished? Deliberately retaining flaws and misfeatures that can easily be fixed without damaging backwards-compatibility is not a very good way to maintain software either. btw, you're both missing that cgi.escape isn't good enough for general use anyway, I'm sorry, I didn't realise this was a general thread about any and all inadequacies of Python's cgi module. since it doesn't deal with encodings at all. Why does it need to? cgi.escape is (or should be) dealing with character strings, not byte sequences. I must admit, internationalisation is not my forte, so if there's something I'm missing here I'd love to hear about it. By the way, if you could try and put across your proposed arguments as to why you don't favour this suggested change without the insults and general rudeness, it would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: maybe you haven't done software long enough to understand that software works better if you use it the way it was intended to be used, but that's no excuse for being stupid. So what's your excuse? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: If you're really serious about making things easier to use, shouldn't you look at the whole picture? HTML documents are byte streams, so any transformation from internal character data to HTML must take both escaping and encoding into account. Ever heard of modular programming? I would suggest that you do indeed take a step back and look at the whole picture - it's the whole picture that needs to take escaping and encoding into account. There's nothing to say that cgi.escape should take them both into account in the one function, and in fact as you yourself have already commented, good reasons for it not to, in that it would make it excessively complicated. If you and Lawrence have a hard time remembering how to use the existing cgi.escape function, despite it's utter simplicity, surely it would make your life even easier if there was an alternative API that would handle both the easy part (escaping) and the hard part (encoding) ? You seem to be arguing that because, in an ideal world, it would be better to throw away the 'cgi' module completely and start again, it is not worth making minor improvements in what we already have. I would suggest that this is, to put it mildly, not a good argument. I've already explained that, but since you're convinced that your use case is more important than other use cases, and you don't care about things like stability and respect for existing users of an API, nor the cost for others to update their code and unit tests, I don't see much need to repeat myself. You are merely compounding your bad manners. All of your above allegations are outright lies. I am not sure if you are simply not understanding the simple points I am making, or are deliberately trying to mislead people for some bizarre reason of your own. Breaking things just because you think you can simply isn't the Python way of doing things. Your hyperbole is growing more extravagant. To begin with, you were claiming that the suggested change would make things (minisculely) less efficient, now you're claiming it will break unspecified things. What precisely do you think it would break? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: (still waiting for the jon's enhanced escape proposal, btw, but I guess it's easier to piss on others than to actually contribute something useful). Well, yes, you certainly seem to be good at the pissing on others part, even if you have to lie to do it. You have had the enhanced escape proposal all along - it was the post which started this thread! If you are referring to your strawman argument about encodings, you have yet to show that it's relevant. If it'll make you any happier, here's the code for the 'cgi.escape' equivalent that I usually use: _html_encre = re.compile([\'+]) _html_encodes = { : amp;, : lt;, : gt;, \: quot;, ': #39;, +: #43; } def html_encode(raw): return re.sub(_html_encre, lambda m: _html_encodes[m.group(0)], raw) -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Duncan Booth wrote: It is generally a principle of Python that new releases maintain backward compatability. An incompatible change such proposed here would probably break many tests for a large number of people. Why is the suggested change incompatible? What code would it break? I agree that it would be a bad idea if it did indeed break backwards compatibility - but it doesn't. There should be a one-stop shop where I can take my unicode text and convert it into something I can safely insert into a generated html page; I disagree. I think that doing it in one is muddled thinking and liable to lead to bugs. Why not keep your output as unicode until it is ready to be output to the browser, and encode it as appropriate then? Character encoding and character escaping are separate jobs with separate requirements that are better off handled by separate code. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: There's nothing to say that cgi.escape should take them both into account in the one function so what exactly are you using cgi.escape for in your code ? To escape characters so that they will be treated as character data and not control characters in HTML. What precisely do you think it would break? existing code, and existing tests. I'm sorry, that's not good enough. How, precisely, would it break existing code? Can you come up with an example, or even an explanation of how it *could* break existing code? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Georg Brandl wrote: I'm sorry, that's not good enough. How, precisely, would it break existing code? Can you come up with an example, or even an explanation of how it *could* break existing code? Is that so hard to see? If cgi.escape replaced ' with an entity reference, code that expects it not to do so would break. Sorry, that's still not good enough. Why would any code expect such a thing? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Duncan Booth wrote: I guess you've never seen anyone write tests which retrieve some generated html and compare it against the expected value. If the page contains any unescaped quotes then this change would break it. You're right - I've never seen anyone do such a thing. It sounds like a highly dubious and very fragile sort of test to me, of very limited use. I'm talking about encoding certain characters as entity references. It doesn't matter whether its the character ampersand or right double quote, they both want to be converted to entities. Same operation. This is that muddled thinking I was talking about. They are *not* the same operation. You want to encode , for example, because it must always be encoded to prevent it being treated as an HTML control character. This has nothing to do with character encodings. You might sometimes want to escape right double quote because it may or may not be available in the character encoding you using to output to the browser. Yes, this might sometimes seem a bit similar to the escaping described above, because one of the ways you could avoid the character encoding issue would be to use numeric entities, but it is actually a completely separate issue and is none of the business of cgi.escape. By your argument, cgi.escape should in fact escape *every single* character as a numeric entity, and even that wouldn't work properly since , #, ; and the digits might not be in their usual positions in the output encoding. Right now the only way the Python library gives me to do the entity escaping properly has a side effect of encoding the string. I should be able to do the escaping without having to encode the string at the same time. I'm getting lost here - the opposite of what you say above is true. cgi.escape does the escaping properly (modulo failing to escape quotes) without encoding. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Max M wrote: I'm sorry, that's not good enough. How, precisely, would it break existing code? Can you come up with an example, or even an explanation of how it *could* break existing code? Some examples are: - Possibly any code that tests for string equality in a rendered html/xml page. Testing is a prefered development tool these days. Testing is good, but only if done correctly. - Code that generates cgi.escaped() markup and (rightfully) for some reason expects the old behaviour to be used. That's begging the question again (an example of code that would break is code that would break). - 3. party code that parses/scrapes content from cgi.escaped() markup. (you could even break Java code this way :-s ) I'm sorry, I don't understand that one. What is party code? Code that is scraping content from web sites already has to cope with entities etc. Your comment about Java is a little ironic given that I persuaded the Java Struts people to make the exact same change we're talking about here, back in 2002 (even if it did take 11 months) ;-) If you cannot think of other examples for yourself where your change would introduce breakage, you are certainly not an experienced enough programmer to suggest changes in the standard lib! I'll take my own opinion on that over yours, thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Max M wrote: Oh ... because you cannot see a use case for that *documented* behaviour, it must certainly be wrong? No, but if nobody else can find one either, that's a clue that maybe it's safe to change. Here's a point for you - the documentation for cgi.escape says that the characters , and are converted, but not what they are converted to. Even by your own argument, therefore, code is not entitled to rely on the output of cgi.escape being any particular exact string. This funktion which is correct by current documentation will be broken by you change. def hasSomeWord(someword): import urllib f = urllib.open('http://www.example.com/cgi_escaped_content') content = f.read() f.close() return '%s' % someword in content: That function is broken already, no change required. I find it amazing that you cannot understand this. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: I'm sorry, that's not good enough. How, precisely, would it break existing code? ('owdo Mr. Ribbens!) Good afternoon Mr Glover ;-) URI= 'http://www.oreilly.com/' html= cgi.escape(text) html= html.replace('O\'Reilly', 'a href=%sO\'Reilly/a' % URI) Sure this may be rare, but it's what the documentation says, and changing it may not only fix things but also subtly break things in ways that are hard to detect. I'm not sure about subtly break things, but you're right that the above code would break. I could argue that it's broken already, (since it's doing a plain-text search on HTML data) but given real-world considerations it's reasonable enough that I won't be that pedantic ;-) I personally think the entire function should be deprecated, firstly because it's insufficient in some corner cases (apostrophes as you pointed out, and XHTML CDATA), and secondly because it's in the wrong place: HTML-escaping is nothing to do with the CGI interface. A good template library should deal with escaping more smoothly and correctly than cgi.escape. (It may be able to deal with escape-or-not-bother and character encoding issues automatically, for example.) I agree that in most situations you should probably be using a template library, but sometimes a simple CGI-and-manual-HTML system suffices, and I think (a fixed version of) cgi.escape should exist at a low level of the web application stack. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: Sorry, that's still not good enough. that's not up to you to decide, though. It's up to me to decide whether or not an argument is good enough to convince me, thank you very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Filip Salomonsson wrote: Here's a point for you - the documentation for cgi.escape says that the characters , and are converted, but not what they are converted to. If the documentation isn't clear enough, that means the documentation should be fixed. Incorrect - documentation can and frequently does leave certain behaviours undefined. This is deliberate and (among other things) is to allow for the behaviour to change in future versions without breaking backwards-compatibility. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: It's up to me to decide whether or not an argument is good enough to convince me, thank you very much. not if you expect anyone to take anything you say seriously. Now you're just being ridiculous. In this thread you have been rude, evasive, insulting, vague, hypocritical, and have failed to answer substantive points in favour of sarcastic and erroneous sniping - I'd suggest it's you that needs to worry about being taken seriously. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Brian Quinlan wrote: Now you're just being ridiculous. In this thread you have been rude, evasive, insulting, vague, hypocritical, and have failed to answer substantive points in favour of sarcastic and erroneous sniping - I'd suggest it's you that needs to worry about being taken seriously. Actually, at least in the context of this mailing list, Fredrik doesn't have to worry about that at all. Why? Because he is one of the most prolific contributers to the Python language and libraries I would have hoped that people don't treat that as a licence to be obnoxious, though. I am aware of Fredrik's history, which is why I was somewhat surprised and disappointed that he was being so rude and unpleasant in this thread. He is not living up to his reputation at all. Maybe he's having a bad day ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Georg Brandl wrote: Here's a point for you - the documentation for cgi.escape says that the characters , and are converted, but not what they are converted to. It says to HTML-safe sequences. That's reasonably clear without the need to reproduce the exact replacements for each character. If anyone doesn't know what is meant by this, he shouldn't really write apps using the cgi module before doing a basic HTML course. So would you like to expliain the difference between #34; and quot; , or do you need to go on a basic HTML course first? -- http://mail.python.org/mailman/listinfo/python-list
Re: QuoteSQL
In article [EMAIL PROTECTED], Lawrence D'Oliveiro wrote: You're proposing two separate functions: 1) quoting of non-wildcard specials 2) quoting of wildcard specials Lawrence, you're wrong in this thread for the same reason you were right in the cgi.escape thread. Escaping general characters for string literals is a different operation from escaping wildcards from pattern matches, and for a good reason. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Steve Holden wrote: I would have hoped that people don't treat that as a licence to be obnoxious, though. I am aware of Fredrik's history, which is why I was somewhat surprised and disappointed that he was being so rude and unpleasant in this thread. He is not living up to his reputation at all. Maybe he's having a bad day ;-) I generally find that Fredrik's rudeness quotient is satisfactorily biased towards discouraging ill-informed comment. It's a pity he's being rude when presented with well-informed comment then. As far as rudeness goes, I've found your approach to this discussion to be pretty obnoxious, and I'm generally know as someone with a high tolerance for idiotic behaviour. Why do you say that? I have confined myself to simple logical arguments, and been frankly very restrained when presented with rudeness and misunderstanding from other thread participants. In what way should I have modified my postings? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: the same documentation tells people what function to use if they want to quote *every-thing* that might need to be quoted, so if people did actually understand everything that was written in a reasonably clear way, this thread wouldn't even exist. The fact that you don't understand that that's not true is the reason you've been getting into such a muddle in this thread. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Steve Holden wrote: Why do you say that? I have confined myself to simple logical arguments, and been frankly very restrained when presented with rudeness and misunderstanding from other thread participants. In what way should I have modified my postings? Please allow me to apologise. I have clearly been confusing you with someone else. A review of your contributions to the thread confirms your asertion. Oh, ok! You had me worried for a minute there ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: It's a pity he's being rude when presented with well-informed comment then. since when is the output of [snip code] well-informed? heck, it doesn't even pass the turing test ;-) Since when did that bear any resemblance to what I have said? Are you going to grow up and start addressing the substantial points raised, rather than making puerile sarcastic remarks? An apology from you would not go amiss. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: the same documentation tells people what function to use if they want to quote *every-thing* that might need to be quoted, so if people did actually understand everything that was written in a reasonably clear way, this thread wouldn't even exist. The fact that you don't understand that that's not true is the reason you've been getting into such a muddle in this thread. it's a fact that it's not true that the documentation points to the function that it points to ? exactly what definitions of the words fact and true are you using here ? You misunderstand again. The second half of the sentence is the untrue bit (if people did ... understand ... this thread wouldn't even exist), not the first. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: This has nothing to do with character encodings. it has *everything* to do with encoding of existing data into HTML so it can be safely transported to, and recreated by, an HTML-aware client. I can't tell if you're disagreeing or not. You escape the character as the sequence of characters lt;, for example, because otherwise the HTML user agent will treat it as the start of a tag and not as character data. You will notice that the character encoding is utterly irrelevant to this. does the word information set mean anything to you? You would appear to be talking about either game theory, or XML, neither of which have anything to do with HTML. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Brian Quinlan wrote: A summary of this pointless argument: Your summary seems pretty reasonable, but please note that later on, the thread was not about cgi.escape escaping (or not) quote characters (as described in your summary), but about Fredrik arguing, somewhat incoherently, that it should have to take character encodings into consideration. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: I know the answer. I'm pretty sure everyone else who's actually read my posts to this thread might have figured it out by now, too. But since you're still trying to win the debate, long after it's over, I think it's safest to end this thread right now. *plonk* It's sad to see a grown man throw his toys out of his pram, just because he's losing an argument... -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Brian Quinlan wrote: Your summary seems pretty reasonable, but please note that later on, the thread was not about cgi.escape escaping (or not) quote characters (as described in your summary), but about Fredrik arguing, somewhat incoherently, that it should have to take character encodings into consideration. And, of course, about you telling people that their explanations are not good enough :-) I guess, if you mean the part of the thread which went it'll break existing code, what existing code? existing code but what existing code? i dunno, just, er, code ok *how* will it break it? i dunno, it just will? BTW, I am curious about how you do unit testing. The example that I used in my summary is a very common pattern but would break in cgi.escape changed it's semantics. What do you do instead? To be honest I'm not sure what *sort* of code people test this way. It just doesn't seem appropriate at all for web page generating code. Web pages need to be manually viewed in web browsers, and validated, and checked for accessibility. Checking they're equal to a particular string just seems bizarre (and where does that string come from anyway?) -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: Jon Ribbens wrote: does the word information set mean anything to you? You would appear to be talking about either game theory, or XML, neither of which have anything to do with HTML. I notice that yet again you've snipped the substantial point and failed to answer it, presumably because you don't know how. you see no connection between XML's concept of information set and HTML? (hint: what's XHTML?) I am perfectly well aware of what XHTML is. If you're trying to make a point, please get to it, rather than going off on irrelevant tangents. What do XML Information Sets have to do with escaping control characters in HTML? -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Fredrik Lundh wrote: What do XML Information Sets have to do with escaping control characters in HTML? figure out the connection, and you'll have the answer to your substantial point. If you don't know the answer, you can say so y'know. There's no shame in it. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Brian Quinlan wrote: Well, there are dozens (hundreds?) of templating systems for Python. I know, I wrote one of them ;-) t = Template(test.html) t['foo'] = 'Brian - Hi!' assert str(t) == 'pBrian -gt; Hi/p' So how would you test our template system? What I don't get is why you are testing the above code like that at all. Surely if the template system somehow became so broken that it couldn't even do trivial replacements, you would notice immediately as all your web pages would go totally wrong. Maybe, which is why I'm asking you how you do it. Some of our web applications contain 100s of script generated pages. Testing each one by hand after making a change would be completely impossible. So we use HTTP scripting for testing purposes i.e. send this request, grab the results, verify that the test in the element with id=username equals Brian Quinlan, etc. The test also validates that each page is well formed. We also view each page at some point but not every time a developer makes a change that might (i.e. everything) affect the entire system. Ah, ok, that sounds more sensible. But something as specialised and complicated as that can surely cope with un-encoding HTML entities? Incidentally, the company I work for, www.sitemorse.com, does automated web site testing - and it's all done in Python! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Brian Quinlan wrote: If, in the example that I showed, the less-than character was not correctly escaped, then it might not manifest itself frequently in a typical application because the less-than character is seldom used in English prose. OK, but effectively what you're talking about here is testing the 'cgi.escape' function itself - said test of course being part and parcel of the cgi package and therefore easily updatable if the cgi.escape function changes. Also, assuming that single case was trivial to test without a test harness, how many web pages do I have to look at to be reasonably confident that *every* feature works correctly? It depends on how many features you have! My templating system, for example, has sections and replacements, and that's it. Replacements can be unencoded, html-encoded or url-encoded. That's approximately 4 things to test ;-) Plus, the templating code basically never changes so doesn't need regression testing. -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
In article [EMAIL PROTECTED], Gabriel G wrote: By example, I do not validate a page. I validate that all methods that make up pieces of a page, build them the way they should - these are our unit tests. Then, it's up to the templating library to join all the pieces into the final html page. That sounds sensible to me - and also likely to be the sort of tests that are not going to get broken by changes to cgi.escape ;-) I validated the original html against the corresponding dtd some time ago (using the w3c validator), and ocasionally when things looks wrong on a browser, but most of the time the html generated pages are not validated nor checked as a whole. That's possibly a mistake, but obviously that depends on details of how your overall methodology works that I have no information about. -- http://mail.python.org/mailman/listinfo/python-list
Re: Computer Language Popularity Trend
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: http://xahlee.org/lang_traf/index.html Careful there with the sweeping generalizations and quick judgments about languages :) I just read PHP as a language is rather dry and business-like, and fell off my chair. -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI - mod_python
In article [EMAIL PROTECTED], Paul Boddie wrote: it is a kind of nooby question. Is there a way to transfer a CGI python script to mod_python without rewriting the code? Had you used WebStack [1] to begin with, this migration would involve changing a few lines of glue code. Or Jonpy ;-) http://jonpy.sf.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw strings and escaping
In article [EMAIL PROTECTED], Matthew Warren wrote: I would expect this to work, rawstring=r'some things\new things\some other things\' But it fails as the last backslash escapes the single quote. String constants in Python are weird - raw strings doubly so. In a raw string, backslashes are not special - unless followed by a quote character, when they simultaneously escape the quote and also insert a literal backslash. I presume there was originally some reason for this bizarre behaviour - it'd be interesting to know what it is/was, if anyone knows? -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw strings and escaping
In article [EMAIL PROTECTED], Duncan Booth wrote: I presume there was originally some reason for this bizarre behaviour - it'd be interesting to know what it is/was, if anyone knows? See the FAQ for the explanation: http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash The idea is that if you use raw strings for regular expressions you can write things like: pattern = r'[\']' if the raw string simply ignored the backslash altogether it would be much harder to write regular expressions that contain both sorts of quotes. Well, hardly *much* harder: pattern = rfoo Personally, I think that raw strings behaving as they do is unexpected, unintuitive and unnecessary, but it's obviously too late to change it now anyway ;-) I think standard strings accepting backslash followed by an unexpected character is also a mistake, but again it's too late to fix now. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.5 excitement (was Re: Java Developer Exploring Python)
In article [EMAIL PROTECTED], Aahz wrote: On that front, I think that pysqlite is much more important because it finally gets rid of the excuse for using Berkeley for simple database purposes. Apologies if I'm being obtuse, but how does including the pysqlite wrapper module change anything? You still need to download and install SQLite, so what's the point of including a wrapper for something you may or may not have? Why is pysqlite included, for example, and not MySQL-Python or postgresql or whatever? -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.5 excitement (was Re: Java Developer Exploring Python)
In article [EMAIL PROTECTED], Chris Lambacher wrote: At least on windows. PySqlite is statically linked with the sqlite library. This can be done because it is quite small. OK, well that makes sense, but why not on any other platform? -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.5 excitement (was Re: Java Developer Exploring Python)
In article [EMAIL PROTECTED], Fredrik Lundh wrote: Apologies if I'm being obtuse, but how does including the pysqlite wrapper module change anything? You still need to download and install SQLite I'm pretty sure the distributors will do this for you, just as they've included zlib, dbm, tcl/tk, openssl, and many other standard libraries over the years. The distributors? Que? I guess I just don't get why the inclusion of the pysqlite wrapper is so exciting if all it's doing is changing the situation from Python does not come with a DB, but you can install extra software to provide one to Python does not come with a DB, but you can install extra software to provide one. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.5 excitement (was Re: Java Developer Exploring Python)
In article [EMAIL PROTECTED], Fredrik Lundh wrote: these days, most end users get their Python either with their OS, or by downloading a prebuilt installer. Oh, ok. I've just never heard such people referred to as the distributors before. It sounds like some sort of TV series! ;-) I guess I just don't get why the inclusion of the pysqlite wrapper is so exciting if all it's doing is changing the situation from Python does not come with a DB, but you can install extra software to provide one to Python does not come with a DB, but you can install extra software to provide one. I assume you stopped reading at just as they've included zlib, dbm, tcl/tk, openssl, and many other standard libraries over the years. I'll assume you didn't read my post properly then, since I did no such thing. Never mind, it was just meant to be an innocuous question, and I'm certainly not disagreeing with the decision to include pysqlite. -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking for EOF in stream
In article [EMAIL PROTECTED], Gabriel Genellina wrote: So this is the way to check for EOF. If you don't like how it was spelled, try this: if data==: break How about: if not data: break ? ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple content-types break cgi.py
In article [EMAIL PROTECTED], Janto Dreijer wrote: The Nokia Java SDK allows one to define multiple content-types in a single HTTP header field. I'm not sure if it's standard, but it's happening from some Java-enabled phones. The only reference to this bug I can find dates back to 1999: http://tinyurl.com/3ahc3r It's not a bug - sending multiple content-types is just totally broken. What would such a header even be supposed to mean? It's like saying this is an apple orange. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple content-types break cgi.py
In article [EMAIL PROTECTED], Janto Dreijer wrote: It's not a bug - sending multiple content-types is just totally broken. What would such a header even be supposed to mean? It's like saying this is an apple orange. Hmmm. Thanks! I suspected as much. Rough inspection suggests that calling connection.setRequestProperty(Content-Type, application/x-www- form-urlencoded); on the Nokia 6230 would actually cause the value to be *appended* and not set. If that method is inherited from java.net.URLConnection, then if the phone is behaving as you suggest, its Java library is bugged and behaving contrary to Sun's Java documentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommended FastCGI module?
In article [EMAIL PROTECTED], John Nagle wrote: The JonPy version: http://jonpy.sourceforge.net/fcgi.html Last revised in 2004. I'd recommend my one, but it's just possible I'm not impartial ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommended FastCGI module?
In article [EMAIL PROTECTED], John Nagle wrote: Jon Ribbens wrote: The JonPy version: http://jonpy.sourceforge.net/fcgi.html Last revised in 2004. I'd recommend my one, but it's just possible I'm not impartial ;-) Does it work with current Pythons? (2.4, 2.5)? I'm mainly concerned about the abandonware problem with some of them. Yes, I use it myself in my day job, where we have recently upgraded to Python 2.5. jonpy itself hasn't been revised for a while because there have been no revisions I felt necessary. There may be a new version released in the next couple of months, but there won't be any major changes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database module multithreading
In article [EMAIL PROTECTED], John Nagle wrote: As for some modules not being maintained, it really is sad that MySQLdb is kind of behind. If you're running Windows and need MySQL, you're either stuck with Python 2.4 Looks like that's changed: http://sourceforge.net/project/showfiles.php?group_id=22307package_id=15775 -- http://mail.python.org/mailman/listinfo/python-list
Re: Database module multithreading
In article [EMAIL PROTECTED], John Nagle wrote: Is the egg packaging gimmick considered mainstream Python, or just some wierd idea from the Peak people? It seems to complicate installation without adding much value. I don't know, but stock Python 2.5 seems to stick mysterious '.egg' files in the site-packages directory when you install things. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database module multithreading
In article [EMAIL PROTECTED], Gabriel Genellina wrote: I don't know, but stock Python 2.5 seems to stick mysterious '.egg' files in the site-packages directory when you install things. Which stock Python? Not the one from www.python.org... Yes, the one from www.python.org. -- http://mail.python.org/mailman/listinfo/python-list
Re: Database module multithreading
In article [EMAIL PROTECTED], Gabriel Genellina wrote: I don't know, but stock Python 2.5 seems to stick mysterious '.egg' files in the site-packages directory when you install things. Which stock Python? Not the one from www.python.org... Yes, the one from www.python.org. Those .egg must come from other installed packages... My mistake, they are .egg-info. And they certainly do come from stock Python 2.5 from www.python.org and not anything else. They are installed by distutils/command/install_egg_info, which is automatically called by 'python setup.py install'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
In article [EMAIL PROTECTED], John Nagle wrote: On Unix a quick shortcut would be to simply read the output of 'tail - f file' command... tail -f just checks the file size once a second. It's not doing anything exciting. That's not actually always true these days. *BSD, at least, use 'kqueue' to avoid busy-wait on tail -f. -- http://mail.python.org/mailman/listinfo/python-list
Flask import problem with Python 3 and __main__.py
Flask suggests the following file layout: runflaskapp.py flaskapp/ __init__.py runflaskapp.py contains: from flaskapp import app app.run(debug=True) flaskapp/__init__.py contains: from flask import Flask app = Flask(__name__) Running this with 'python3 runflaskapp.py' works fine. However it seems to me that a more Python3onic way of doing this would be to rename 'runflaskapp.py' as 'flaskapp/__main__.py' and then run the whole thing as 'python3 -m flaskapp'. Unfortunately this doesn't work: $ python3 -m flaskapp * Running on http://127.0.0.1:5000/ * Restarting with reloader Traceback (most recent call last): File /home/username/src/flaskapp/__main__.py, line 1, in module from flaskapp import app ImportError: No module named 'flaskapp' Does anyone know why and how to fix it? -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask import problem with Python 3 and __main__.py
On 2014-08-26, Terry Reedy tjre...@udel.edu wrote: On 8/26/2014 12:03 PM, Jon Ribbens wrote: Flask suggests the following file layout: runflaskapp.py flaskapp/ __init__.py runflaskapp.py contains: from flaskapp import app app.run(debug=True) flaskapp/__init__.py contains: from flask import Flask app = Flask(__name__) Unless there is something else in flaskapp, this seems senseless. Why not runflaskapp.py: from flask import Flask app = Flask(__name__) app.run(debug=True) Because that's not how Flask apps work. I am showing a minimal test case, obviously for any real app not only would __init__.py contain more code, but there would be other files inside flaskapp/ too. Then when deployed, 'runflaskapp.py' would either be changed or go away entirely and the web server would just be pointed at 'flaskapp'. Running this with 'python3 runflaskapp.py' works fine. You are either giving this in directory 'x' containing runflaskapp.py or given a longer pathname. In either case, directory 'x' get prepended to sys.path, so that 'import flaskapp' finds flaskapp in x. Well, as I understand it actually the empty string is in sys.path, which is taken by Python to mean 'the current directory'. However it seems to me that a more Python3onic way of doing this would be to rename 'runflaskapp.py' as 'flaskapp/__main__.py' and then run the whole thing as 'python3 -m flaskapp'. In what directory? In the same directory as above, i.e. the one containing 'flaskapp'. It clearly does find 'flaskapp' initially, otherwise I would get a different error message /usr/bin/python3: No module named flaskapp. Unfortunately this doesn't work: Because x does not get added to sys.path. No, but the current directory does (effectively). Or put flaskapp in site_packages, which is on the import search path . That's no use for development though. The important part of my question is why is running __main__.py from inside flaskapp/ somehow different to running runflaskapp.py from the parent directory? It's probably a fairly Flask-specific question. -- https://mail.python.org/mailman/listinfo/python-list
Re: Flask and Python 3
On 2014-09-23, Juan Christian juan0christ...@gmail.com wrote: if __name__ == '__main__': app.run(port = 8000) app.run(port=8000, debug=True) might've made the problem easier to find. -- https://mail.python.org/mailman/listinfo/python-list
Lazy-evaluation lists/dictionaries
I have a need, in a Python C extension I am writing, for lists and dictionaries with lazy evaluation - by which I mean that at least some of the values in the lists/dictionaries are proxy objects which, rather than returning as themselves, should return the thing they are a proxy for when retrieved. This is because retrieving the proxied objects is expensive and only a small minority of them will actually be accessed, so retrieving them all before they are actually accessed is massively inefficient. With object attributes, this can be easily done with the descriptor protocol and having properties which look like simple objects but actually cause a method to be invoked when they are accessed. However there doesn't seem to be any equivalent way of doing this for retrieving items from lists or dictionaries - unfortunately, the method implementations of list() and dict() are full of direct accesses to the underlying data pointers rather than indirecting through obj-tp_as_mapping-mp_subscript or whatever. Is there any better way to do this other than simply re-implementing these types from scratch, emulating all their methods and operations? (i.e. using UserList/UserDict). I was under the impression that that sort of thing was supposed to have gone since Python 2.2 or so. -- https://mail.python.org/mailman/listinfo/python-list
Re: Lazy-evaluation lists/dictionaries
On 2014-10-26, Terry Reedy tjre...@udel.edu wrote: On 10/26/2014 10:14 AM, Jon Ribbens wrote: Is there any better way to do this other than simply re-implementing these types from scratch, emulating all their methods and operations? (i.e. using UserList/UserDict). I was under the impression that that sort of thing was supposed to have gone since Python 2.2 or so. We considered dropping UserDict and UserList for 3.0 but kept them in collections for cases in which subclassing does not work. It seems on further investigation to be hard/impossible to subclass Python classes from C extensions. I've gone with subclassing dict, and reimplementing most of its methods. It helps that I only need it to be read-only. It's a pity there's no protocol for 'dynamic' lists/dicts though. -- https://mail.python.org/mailman/listinfo/python-list
Re: Lazy-evaluation lists/dictionaries
On 2014-10-26, Tim Delaney timothy.c.dela...@gmail.com wrote: On 27 October 2014 01:14, Jon Ribbens jon+use...@unequivocal.co.uk wrote: I have a need, in a Python C extension I am writing, for lists and dictionaries with lazy evaluation - by which I mean that at least some of the values in the lists/dictionaries are proxy objects which, rather than returning as themselves, should return the thing they are a proxy for when retrieved. This is because retrieving the proxied objects is expensive and only a small minority of them will actually be accessed, so retrieving them all before they are actually accessed is massively inefficient. Why not put proxy objects into the list/dict? That's precisely what I am doing. The point is that when they are retrieved they need to be resolved into the genuine objects. Have a look at the weakref module for an API that may be suitable for such proxy objects (if you used the same API, that would also allow you to transparently use weakrefs in your lists/dicts). Hmm, the idea behind that appears to be to create a proxy that emulates every possible method of every conceivable type. My method of only emulating the list and dict methods seems to be somewhat simpler for my purpose ;-) -- https://mail.python.org/mailman/listinfo/python-list