[Python-Dev] switching on -3 from within a program?
With a minor modification to the Makefile I was able to get mod_wsgi
v2.3 to work with python2.6rc1.
I promptly got a warning in my apache log files on the depcrecated use
of 'sha' in the paste's cookie module, good! And easily fixed.
After that I was looking for a way to switch on the -3 warnings from
within my code to have extra warnings show up in my apache log file.
After reading some documentation I tried from the python2.6 prompt:
import sys
sys.py3kwarning = True
x = { 'abc': 1 }; x.has_key('abc')
which does not give a warning (starting python2.6 with the -3 option of
course does).
Is there anyway to switch this on from within a program with a Python
statement?
If not, would I need to make a small C-extension module (to be imported
as the first module) that sets Py_Py3WarningFlag or something else at
the C level, or would that better be done by mod_wsgi's C code.
Regards
Anthon
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] switching on -3 from within a program?
Anthon van der Neut wrote:
import sys
sys.py3kwarning = True
x = { 'abc': 1 }; x.has_key('abc')
which does not give a warning (starting python2.6 with the -3 option of
course does).
> Is there anyway to switch this on from within a program with a Python
> statement?
That doesn't work because "sys.py3kwarning = True" doesn't change the
global C variable Py_Py3kWarningFlag. IIRC there is no API to change the
flag from Python code.
If not, would I need to make a small C-extension module (to be imported
as the first module) that sets Py_Py3WarningFlag or something else at
the C level, or would that better be done by mod_wsgi's C code.
I suggest that you introduce a new config option that sets
Py_Py3kWarningFlag to 1.
Christian
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] switching on -3 from within a program?
On Tue, Sep 16, 2008 at 10:32 AM, Anthon van der Neut
<[EMAIL PROTECTED]> wrote:
> With a minor modification to the Makefile I was able to get mod_wsgi
> v2.3 to work with python2.6rc1.
> I promptly got a warning in my apache log files on the depcrecated use
> of 'sha' in the paste's cookie module, good! And easily fixed.
>
> After that I was looking for a way to switch on the -3 warnings from
> within my code to have extra warnings show up in my apache log file.
>
> After reading some documentation I tried from the python2.6 prompt:
>
> import sys
> sys.py3kwarning = True
> x = { 'abc': 1 }; x.has_key('abc')
>
> which does not give a warning (starting python2.6 with the -3 option of
> course does).
>
> Is there anyway to switch this on from within a program with a Python
> statement?
> If not, would I need to make a small C-extension module (to be imported
> as the first module) that sets Py_Py3WarningFlag or something else at
> the C level, or would that better be done by mod_wsgi's C code.
You could also utilize a nifty ctypes trick:
import ctypes
def engage_py3k_warning():
flag = ctypes.c_int.in_dll(ctypes.pythonapi, "Py_Py3kWarningFlag")
flag.value = 1
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] ',' precedence in documentation]
On Tue, 16 Sep 2008 10:50:45 am Greg Ewing wrote: > Steven D'Aprano wrote: > > I was confused about the role of commas, and totally gobsmacked > > when I discovered that commas make tuples everywhere except when > > following an except statement. > > Um... you've never written a function call with more than > one argument before? :-) Of course I had. If somebody had asked me, I probably would have guessed that there was some sort of special case in the parser for function calls. I didn't say my mental model was a good model, but it was the only one I had. I have no doubt that there are others out there who are confused about the role of commas. -- Steven ___ Python-Dev mailing list [email protected] http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
I've tried to modify my existing asyncore-based code but I'm encountering a lot of different problems I didn't manage to fix. It seems that playing with the do_handshake_on_connect flag doesn't make any difference. I guess that without some kind of documentation describing how to deal with non-blocking "ssl-wrapped" sockets I won't get too far. I try to ask two questions in case the answers may help me in some way: 1 - What pending() method is supposed to do (it's not documented)? 2 - By reading ssl.py code I noticed that when do_handshake_on_connect flag is False the do_handshake() method is never called. Is it supposed to be manually called when dealing with non-blocking sockets? In the meanwhile I noticed something in the ssl.py code which seems to be wrong: def recv (self, buflen=1024, flags=0): if self._sslobj: if flags != 0: raise ValueError( "non-zero flags not allowed in calls to sendall() on %s" % self.__class__) while True: try: return self.read(buflen) except SSLError, x: if x.args[0] == SSL_ERROR_WANT_READ: continue else: raise x else: return socket.recv(self, buflen, flags) I don't know the low levels but that while statement which continues in case of SSL_ERROR_WANT_READ seems to be wrong (blocking), at least when dealing with non-blocking sockets. I think the proper way of doing recv() here is letting SSL_ERROR_WANT_READ propagate and let the upper application (e.g. asyncore) deal with it. Hope this helps, --- Giampaolo http://code.google.com/p/pyftpdlib/downloads/list On 15 Set, 04:50, Bill Janssen <[EMAIL PROTECTED]> wrote: > Hi, Giampaolo. > > If you look a bit further in Lib/test/test_ssl.py, you'll see a > non-blocking use of the "do_handshake" method. Basically, the flag > "do_handshake_on_connect" says whether you want this to happen > automatically and blockingly (True), or whether you want to do it > yourself (False). In the test suite, the function > "testNonBlockingHandshake" does the async client-side handshake; the > server side logic is just the same, only it would happen in the server's > "handle new connection" code -- you'd have to add a state variable, and > bind handlers for "read_event" and "write_event", which would consult > the state variable to see whether they had finished the handshake yet. > > I just made the server do it automatically to make life easier. > > The hard part isn't really doing the non-blocking, it's trying to figure > out how to use asyncore correctly, IMO. > > Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > I'm interested in using the ssl module with asyncore but since there's > > no real documentation about how using ssl module with non-blocking > > If you'd like to contribute a doc patch, that would be great. > > Here's what it current says for do_handshake_on_connect: > > The parameter do_handshake_on_connect specifies whether to do the SSL > handshake automatically after doing a socket.connect(), or whether the > application program will call it explicitly, by invoking the > SSLSocket.do_handshake() method. Calling SSLSocket.do_handshake() > explicitly gives the program control over the blocking behavior of the > socket I/O involved in the handshake. > > and here's what the docs for do_handshake() says: > > SSLSocket.do_handshake()¦ Perform a TLS/SSL handshake. If this is used > with a non-blocking socket, it may raise SSLError with an arg[0] of > SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, in which case it must be > called again until it completes successfully. For example, to simulate > the behavior of a blocking socket, one might write: > > while True: > try: > s.do_handshake() > break > except ssl.SSLError, err: > if err.args[0] == ssl.SSL_ERROR_WANT_READ: > select.select([s], [], []) > elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: > select.select([], [s], []) > else: > raise > > Bill > ___ > Python-Dev mailing list > [EMAIL PROTECTED]://mail.python.org/mailman/listinfo/python-dev > Unsubscribe:http://mail.python.org/mailman/options/python-dev/python-dev2-garchiv... ___ Python-Dev mailing list [email protected] http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] ssl module, non-blocking sockets and asyncore integration
Sorry, ignore my 2nd question, I see now that you already gave a very clear answer in your first message. I change my question: how am I supposed to know when the SSL hanshake is completed? When pending() returns False? If so I'd recommend to document the method. --- Giampaolo http://code.google.com/p/pyftpdlib/ On 17 Set, 03:24, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > I've tried to modify my existing asyncore-based code but I'm > encountering a lot of different problems I didn't manage to fix. > It seems that playing with the do_handshake_on_connect flag doesn't > make any difference. > I guess that without some kind of documentation describing how to deal > with non-blocking "ssl-wrapped" sockets I won't get too far. > I try to ask two questions in case the answers may help me in some > way: > > 1 - What pending() method is supposed to do (it's not documented)? > 2 - By reading ssl.py code I noticed that when do_handshake_on_connect > flag is False the do_handshake() method is never called. Is it > supposed to be manually called when dealing with non-blocking sockets? > > In the meanwhile I noticed something in the ssl.py code which seems to > be wrong: > > def recv (self, buflen=1024, flags=0): > if self._sslobj: > if flags != 0: > raise ValueError( > "non-zero flags not allowed in calls to sendall() > on %s" % > self.__class__) > while True: > try: > return self.read(buflen) > except SSLError, x: > if x.args[0] == SSL_ERROR_WANT_READ: > continue > else: > raise x > else: > return socket.recv(self, buflen, flags) > > I don't know the low levels but that while statement which continues > in case of SSL_ERROR_WANT_READ seems to be wrong (blocking), at least > when dealing with non-blocking sockets. I think the proper way of > doing recv() here is letting SSL_ERROR_WANT_READ propagate and let the > upper application (e.g. asyncore) deal with it. > > Hope this helps, > > --- Giampaolohttp://code.google.com/p/pyftpdlib/downloads/list > > On 15 Set, 04:50, Bill Janssen <[EMAIL PROTECTED]> wrote: > > > > > Hi, Giampaolo. > > > If you look a bit further in Lib/test/test_ssl.py, you'll see a > > non-blocking use of the "do_handshake" method. Basically, the flag > > "do_handshake_on_connect" says whether you want this to happen > > automatically and blockingly (True), or whether you want to do it > > yourself (False). In the test suite, the function > > "testNonBlockingHandshake" does the async client-side handshake; the > > server side logic is just the same, only it would happen in the server's > > "handle new connection" code -- you'd have to add a state variable, and > > bind handlers for "read_event" and "write_event", which would consult > > the state variable to see whether they had finished the handshake yet. > > > I just made the server do it automatically to make life easier. > > > The hard part isn't really doing the non-blocking, it's trying to figure > > out how to use asyncore correctly, IMO. > > > Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > > I'm interested in using the ssl module with asyncore but since there's > > > no real documentation about how using ssl module with non-blocking > > > If you'd like to contribute a doc patch, that would be great. > > > Here's what it current says for do_handshake_on_connect: > > > The parameter do_handshake_on_connect specifies whether to do the SSL > > handshake automatically after doing a socket.connect(), or whether the > > application program will call it explicitly, by invoking the > > SSLSocket.do_handshake() method. Calling SSLSocket.do_handshake() > > explicitly gives the program control over the blocking behavior of the > > socket I/O involved in the handshake. > > > and here's what the docs for do_handshake() says: > > > SSLSocket.do_handshake()¦ Perform a TLS/SSL handshake. If this is used > > with a non-blocking socket, it may raise SSLError with an arg[0] of > > SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, in which case it must be > > called again until it completes successfully. For example, to simulate > > the behavior of a blocking socket, one might write: > > > while True: > > try: > > s.do_handshake() > > break > > except ssl.SSLError, err: > > if err.args[0] == ssl.SSL_ERROR_WANT_READ: > > select.select([s], [], []) > > elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: > > select.select([], [s], []) > > else: > > raise > > > Bill > > ___ > > Python-Dev mailing list > > [EMAIL PROTECTED]://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe:http://mail.python.org/mailman/options/pyth
