From graham.dumpleton at gmail.com Sun Jun 3 08:06:21 2007 From: graham.dumpleton at gmail.com (Graham Dumpleton) Date: Sun, 3 Jun 2007 16:06:21 +1000 Subject: [Web-SIG] WSGI application object returning a string/buffer. Message-ID: <88e286470706022306t30cad62q8056d93c1cf9dce2@mail.gmail.com> The WSGI specification says: """When called by the server, the application object must return an iterable yielding zero or more strings. This can be accomplished in a variety of ways, such as by returning a list of strings, or by the application being a generator function that yields strings, or by the application being a class whose instances are iterable. Regardless of how it is accomplished, the application object must always return an iterable yielding zero or more strings.""" This requirement would be satisfied by an application object returning the response content using: # list of strings return ['s1','s2'] # tuple of strings return ('s1','s2') # generator yield 's1' yield 's2' One could also return any object which is iterable, provide it yields strings for each item. A consequence of this last option though is that the following are actually valid: # string return 's1s2' # buffer return buffer('s1s2') This is because when iterated over, the result is a string object for each item albeit where each string object is of length 1. Although string and buffer objects can be returned, one cannot however return a unicode object. Ie., the following will fail: # unicode (fails) return u's1s2' This fails because each item yield when iterated over is a unicode object. For the string and buffer return value, although it is technically legal by the specification, that it is also a requirement that data be flushed between each yielded item from a sequence means that each character is written back to the user one at a time. The result of this is that performance will suck something terrible. The question is, although returning a string object is technically allowed by the specification, should a good WSGI adapter actually allow it given that it is more than likely a programming mistake that someone has done it this way rather than return the string object enclosed in an array? The buffer object is a more problematic case, as they can't even be returned in an array as is, but would need to be converted to a string object first before being put in the array. Any comments or suggestion? Should I just process string and buffer objects as a sequence without complaint as required by specification, or disallow it based on probability that it isn't probably what the user meant to do anyway? Graham From pje at telecommunity.com Sun Jun 3 21:30:44 2007 From: pje at telecommunity.com (Phillip J. Eby) Date: Sun, 03 Jun 2007 15:30:44 -0400 Subject: [Web-SIG] WSGI application object returning a string/buffer. In-Reply-To: <88e286470706022306t30cad62q8056d93c1cf9dce2@mail.gmail.com > References: <88e286470706022306t30cad62q8056d93c1cf9dce2@mail.gmail.com> Message-ID: <20070603193046.B45583A40AC@sparrow.telecommunity.com> At 04:06 PM 6/3/2007 +1000, Graham Dumpleton wrote: >Should I just process string and buffer >objects as a sequence without complaint as required by specification, I'd say yes. It's trivial for someone to use wsgiref.validate to test their application, and it will tell them about this issue. You could, of course, provide an option to use wsgiref.validate automatically... From graham.dumpleton at gmail.com Mon Jun 4 00:32:21 2007 From: graham.dumpleton at gmail.com (Graham Dumpleton) Date: Mon, 4 Jun 2007 08:32:21 +1000 Subject: [Web-SIG] WSGI application object returning a string/buffer. In-Reply-To: <20070603193046.B45583A40AC@sparrow.telecommunity.com> References: <88e286470706022306t30cad62q8056d93c1cf9dce2@mail.gmail.com> <20070603193046.B45583A40AC@sparrow.telecommunity.com> Message-ID: <88e286470706031532nba823cs851acdaa4ccf9955@mail.gmail.com> On 04/06/07, Phillip J. Eby wrote: > At 04:06 PM 6/3/2007 +1000, Graham Dumpleton wrote: > >Should I just process string and buffer > >objects as a sequence without complaint as required by specification, > > I'd say yes. It's trivial for someone to use wsgiref.validate to > test their application, and it will tell them about this issue. Last time I looked the wsgiref.validate function will only complain about string being returned, not 'buffer'. > You could, of course, provide an option to use wsgiref.validate > automatically... It is trivial for someone to do it themselves in their WSGI application script file and a lot harder to add such an option as in inbuilt feature, plus would add a dependency on some third party package. Graham From sasch.pe at gmx.de Sat Jun 23 11:37:07 2007 From: sasch.pe at gmx.de (Sascha Peilicke) Date: Sat, 23 Jun 2007 11:37:07 +0200 Subject: [Web-SIG] Clientside Python Message-ID: <1182591427.15675.29.camel@schlepp> Hello, Hello, hopefully this is the right place, I would like to propose a new application area for Python. But lets start from the beginning. Python already started to conquer the server-side via all those cool frameworks (Django,Pylons,TurboGears,...), basically everything related to networks is available. But one thing is missing: client-side python-scripting in the web-browser! Think about it, there are basically only two languages usable for this purpose, VBScript, no option. JavaScript, the status quo but it is more a thing one has to work with and not want to work with. Like these guys from the MochiKit framework " ... make JavaScript suck less" and it really sucks! Wouldn't it be cool to have our favorite language at hand when developing a web-app? I am not sure about how difficult this task could be. The interpreter runs on every platform which can run a browser, it can be embedded in basically every kind of software. The thing to do would be creating a fully-compatible DOM-Implementation, XMLHttpRequest and some kind of wrapping middleware which acts as the interface for the specific browser. I tried to do some programmer's art: ----------- -------------- ------------------------ | Browser | | Middleware | | Python-Interpreter | | |===| (glue code)|==| DOM-Stack | ----------- -------------- | Reduced Standard-Lib | | XMLHttpRequest | | ... | ------------------------ Then the following will become possible then: ... ...
... Altough I see a slight problem: correct indentation, which is important for python code inside > ... >
> ... > > Altough I see a slight problem: correct indentation, which is important > for python code inside