Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
'wsgi.output' in environ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
eigenein  
View profile  
 More options Jul 29 2010, 7:06 pm
From: eigenein <eigen...@gmail.com>
Date: Thu, 29 Jul 2010 16:06:18 -0700 (PDT)
Local: Thurs, Jul 29 2010 7:06 pm
Subject: 'wsgi.output' in environ?
Hello,

In my project I need not only read from environ['wsgi.input'] but also
write in the opposite direction too. After some hours of goooogling I
supposed there is no any way to obtain output file object. So, I've
added just one line at httpserver.py:210

               ,'wsgi.output': self.wfile

and this did the trick.

Is there a better solution? Why there is 'wsgi.input' and no
'wsgi.output' and do not consider adding 'wsgi.output' to environ as
'wsgi.input' is?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Jul 29 2010, 10:41 pm
From: Ian Bicking <i...@colorstudy.com>
Date: Thu, 29 Jul 2010 21:41:04 -0500
Local: Thurs, Jul 29 2010 10:41 pm
Subject: Re: [Paste] 'wsgi.output' in environ?

On Thu, Jul 29, 2010 at 6:06 PM, eigenein <eigen...@gmail.com> wrote:
> In my project I need not only read from environ['wsgi.input'] but also
> write in the opposite direction too. After some hours of goooogling I
> supposed there is no any way to obtain output file object. So, I've
> added just one line at httpserver.py:210

>               ,'wsgi.output': self.wfile

> and this did the trick.

> Is there a better solution? Why there is 'wsgi.input' and no
> 'wsgi.output' and do not consider adding 'wsgi.output' to environ as
> 'wsgi.input' is?

Well, that's just not how it works.  Generally if you really need to push
stuff out you should use the start_response writer, like:

def app(environ, start_response):
    write = start_response(status, headers)
    write('hello ')
    write('world')

--
Ian Bicking  |  http://blog.ianbicking.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eigenein  
View profile  
 More options Jul 30 2010, 7:50 am
From: eigenein <eigen...@gmail.com>
Date: Fri, 30 Jul 2010 04:50:50 -0700 (PDT)
Local: Fri, Jul 30 2010 7:50 am
Subject: Re: 'wsgi.output' in environ?
The problem is that I need to pass some output file-like object to a
third-party code without writing any stuff myself (I'm embedding
mod_pywebsockets extension into project, so my code should provide
input and output file-like objects to the extension and give a control
to the extension code). In this case wfile fully satisfies me...

On Jul 30, 5:41 am, Ian Bicking <i...@colorstudy.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Jul 30 2010, 11:23 am
From: Ian Bicking <i...@colorstudy.com>
Date: Fri, 30 Jul 2010 10:23:14 -0500
Local: Fri, Jul 30 2010 11:23 am
Subject: Re: [Paste] Re: 'wsgi.output' in environ?

On Fri, Jul 30, 2010 at 6:50 AM, eigenein <eigen...@gmail.com> wrote:
> The problem is that I need to pass some output file-like object to a
> third-party code without writing any stuff myself (I'm embedding
> mod_pywebsockets extension into project, so my code should provide
> input and output file-like objects to the extension and give a control
> to the extension code). In this case wfile fully satisfies me...

You'll be fully out of the WSGI domain then, e.g., middleware won't work, or
testing frameworks.

Does the code want to write the entire HTTP response (headers and all)?

--
Ian Bicking  |  http://blog.ianbicking.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eigenein  
View profile  
 More options Jul 30 2010, 11:35 am
From: eigenein <eigen...@gmail.com>
Date: Fri, 30 Jul 2010 08:35:57 -0700 (PDT)
Local: Fri, Jul 30 2010 11:35 am
Subject: Re: 'wsgi.output' in environ?
Yes, the code want to write the entire response, and also the code
will not close connection immediately but will left connection opened
for a long time to be able to send data periodically (accordingly to
WebSockets protocol over an opened connection).

On Jul 30, 6:23 pm, Ian Bicking <i...@colorstudy.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Jul 30 2010, 11:41 am
From: Ian Bicking <i...@colorstudy.com>
Date: Fri, 30 Jul 2010 10:41:09 -0500
Local: Fri, Jul 30 2010 11:41 am
Subject: Re: [Paste] Re: 'wsgi.output' in environ?

That's going to interact rather poorly with WSGI, I'd suggest running that
server on an entirely separate port.

--
Ian Bicking  |  http://blog.ianbicking.org

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Graham Dumpleton  
View profile  
 More options Jul 30 2010, 9:47 pm
From: Graham Dumpleton <graham.dumple...@gmail.com>
Date: Fri, 30 Jul 2010 18:47:41 -0700 (PDT)
Local: Fri, Jul 30 2010 9:47 pm
Subject: Re: 'wsgi.output' in environ?
I recollect when I had a quick look at WebSockets it wasn't able to be
implemented on top of a standards conforming WSGI server. Even when
Google tried to do an implementation for Apache for Python using
mod_python they created an abomination because in the handler they
reached down into the connection layer to bypass the standard Apache
body processing.

To do WebSockets properly seems to require direct access to the actual
web server connection layer and cannot be done using higher level
abstractions that provide a more restrictive interface such as WSGI or
even mod_python.

Graham

On Jul 31, 1:41 am, Ian Bicking <i...@colorstudy.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Davis  
View profile  
 More options Jul 31 2010, 12:01 am
From: Paul Davis <paul.joseph.da...@gmail.com>
Date: Sat, 31 Jul 2010 00:01:00 -0400
Subject: Re: [Paste] Re: 'wsgi.output' in environ?
On Fri, Jul 30, 2010 at 9:47 PM, Graham Dumpleton

<graham.dumple...@gmail.com> wrote:
> I recollect when I had a quick look at WebSockets it wasn't able to be
> implemented on top of a standards conforming WSGI server. Even when
> Google tried to do an implementation for Apache for Python using
> mod_python they created an abomination because in the handler they
> reached down into the connection layer to bypass the standard Apache
> body processing.

> To do WebSockets properly seems to require direct access to the actual
> web server connection layer and cannot be done using higher level
> abstractions that provide a more restrictive interface such as WSGI or
> even mod_python.

> Graham

WebSockets definitely hates on the WSGI spec. For what its worth, I've
not seen anything in the Rack/Plack/Jack specs that deal with this
either.

In Gunicorn we added two undocumented features to allow for WebSocket
support. First, we place an object into the environ that represents
the underlying socket connection so applications can take control of
the actual I/O. Then we have an undocumented singleton variable that
applications can return so that the usual WSGI semantics are disabled.
This is obviously broke as all get out and no one should expect such
things to work in real life.

A secondary aspect of this was that I chatted with a Gunicorn user
about trying to get django-websockets working. Looking through the
code briefly I found that django-websockets was reaching deep and
pulling out a copy of the raw socket form the request which obviously
breaks lots of things. But I think this is a sign that the next WSGI
is going to have to support connection upgrades.

In the recent work I've been stewing over for a WSGI that works on
both 3.x and 2.x I wrote in a small bit based on my Gunicorn
experience. I'm was aiming to support the old write callable for
legacy support while removing the start_response callable that all
other WSGI-ish specs did away with. That coupled with the WebSocket
use case gave me the idea to have environ["wsgi.upgrade"] which is a
callable that returns some object that acts like a socket. There's a
wart on this, in that the only way I could think to let middleware and
server authors know if a connection was still HTTP or not was to have
an environ["wsgi.upgraded"] callable that returned a boolean. Not
optimal. There's also the question on whether the spec should allow a
connection to be downgraded after an upgrade (ie, resume HTTP
traffic). I've done zero research on whether this is expected
behavior, so it may be a non-issue.

Anyway, I've got some code and docs for this WSGI stuff I was working
on. I've spent the last few evenings staring at the WebOb sources
trying to figure out how in the world to crack into patching it to
work with what I've drafted out. I've given myself until Sunday before
I just push this stuff out to see what people think. I was hoping to
have something like webob support first to try and minimize bike
shedding, but webob turned out to be much bigger than I thought it
was.

Paul Davis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Graham Dumpleton  
View profile  
 More options Jul 31 2010, 1:02 am
From: Graham Dumpleton <graham.dumple...@gmail.com>
Date: Fri, 30 Jul 2010 22:02:58 -0700 (PDT)
Local: Sat, Jul 31 2010 1:02 am
Subject: Re: 'wsgi.output' in environ?

On Jul 31, 2:01 pm, Paul Davis <paul.joseph.da...@gmail.com> wrote:

Not at all. When something can't work on the majority of web hosting
mechanisms that support a WSGI interface, why would you shove it into
the WSGI specification itself.

You have to realise that hosting mechanisms such as mod_python,
mod_wsgi, mod_uwsgi, mod_fastcgi, mod_fcgid, mod_scgi, mod_ajp,
mod_cgi etc, aren't going to be able to support this concept as they
are based on an assumption that standard HTTP is used. Some of them
are even more constrained than that and don't even permit things that
technically should be possible with HTTP.

So, some things should simply never be a part of the WSGI
specification as they destroy the promise of portability that WSGI has
brought.

There has been a similar argument about adding asynchronous features
to WSGI. They want special hooks which they felt would help them do
what they needed. Problem was that outside of that one little feature,
they still had heaps of code which was dependent upon the specific
asynchronous framework being used, eg., Twisted, Tornado etc. If that
is going to be the case and you aren't going to have a system which
allows one to write the code to the interface once and have it work on
different frameworks, what is the point.

That all said, I am interested to learn more about WebSockets. When I
tried to look at it last time I couldn't find a good introductory
description of it and was stuck trying to work it out from the
specification and what Google had done with mod_python.

My reasons for wanting to know is that although mod_wsgi and
mod_python may not be adequate vehicles for implementing it for
Apache, I have been working on/thinking about some new stuff in
relation to Apache that might make writing custom Apache modules in
Python viable, whereby one is working with raw Apache APIs and not a
restricted high level API.

So, know of any resources that explain WebSockets in simple terms with
simple examples?

Graham


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eigenein  
View profile  
 More options Jul 31 2010, 7:38 am
From: eigenein <eigen...@gmail.com>
Date: Sat, 31 Jul 2010 04:38:47 -0700 (PDT)
Local: Sat, Jul 31 2010 7:38 am
Subject: Re: 'wsgi.output' in environ?
It seems I've got WebSockets to work properly with the described
wsgi.output hack, and mod_pywebsocket module and a couple of adapter
classes. The point I'm started at was two brief articles in Russian...
I've failed in attempts to google any better descriptions.
On Jul 31, 8:02 am, Graham Dumpleton <graham.dumple...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Fwd: [Paste] Re: 'wsgi.output' in environ?" by Paul Davis
Paul Davis  
View profile  
 More options Jul 31 2010, 12:05 pm
From: Paul Davis <paul.joseph.da...@gmail.com>
Date: Sat, 31 Jul 2010 12:05:53 -0400
Local: Sat, Jul 31 2010 12:05 pm
Subject: Fwd: [Paste] Re: 'wsgi.output' in environ?
And I managed to forget to include the list.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "'wsgi.output' in environ?" by Ian Bicking
Ian Bicking  
View profile  
 More options Jul 31 2010, 1:08 pm
From: Ian Bicking <i...@colorstudy.com>
Date: Sat, 31 Jul 2010 12:08:05 -0500
Local: Sat, Jul 31 2010 1:08 pm
Subject: Re: [Paste] Re: 'wsgi.output' in environ?

On Fri, Jul 30, 2010 at 11:01 PM, Paul Davis <paul.joseph.da...@gmail.com>wrote:

Huh, I'm surprised.  My basic understanding of WebSockets is that it works
kind of like:

You get a request with normal HTTP headers
Plus a bunch of special WebSocket negotiation stuff that everyone is
complaining about (special headers, and special response headers)
Then the socket has delimited messages (length+bytes I guess)?  They go in
both directions.

It doesn't seem like you should need (or even have) direct access to the
sockets, because it's not streaming and there's no parsing of the socket
itself (except for parsing the WebSocket messages, which the server can do
and is spec'd out).

I can imagine an incoming WebSocket message (first message or later
messages) could be represented as a WSGI request, just adding a connection
ID and cloning the HTTP headers each time.  Responses could be... well,
that's tricky, as there's no request/response pairing.  You could put in
something like environ['websockets.send_message']('a message to send').  But
then the actual WSGI response becomes meaningless.  So it's not a great
fit.  But at least it is always initiated by the client.

Implementing this without a WebSockets-aware server seems like a bad idea.
Anything not at the server level is going to be a nasty hack.

--
Ian Bicking  |  http://blog.ianbicking.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Davis  
View profile  
 More options Jul 31 2010, 4:17 pm
From: Paul Davis <paul.joseph.da...@gmail.com>
Date: Sat, 31 Jul 2010 16:17:26 -0400
Local: Sat, Jul 31 2010 4:17 pm
Subject: Re: [Paste] Re: 'wsgi.output' in environ?

I don't think streaming is the right word, but the effect is the same.
The websocket connection is a full duplex asynchronous message passing
channel. Ie, the client and server can both send messages whenever
they want. All the websocket spec is really doing is specifying the
HTTP upgrade (the special headers and response), the line protocol
after upgrade (the length delimited messages) and the JavaScript API
in the browser.

After that its basically a full tcp connection which means that
anything between the client code and webapp code needs to make sure
that the channel is unbuffered if applications are going to work
correctly.

> I can imagine an incoming WebSocket message (first message or later
> messages) could be represented as a WSGI request, just adding a connection
> ID and cloning the HTTP headers each time.  Responses could be... well,
> that's tricky, as there's no request/response pairing.  You could put in
> something like environ['websockets.send_message']('a message to send').  But
> then the actual WSGI response becomes meaningless.  So it's not a great
> fit.  But at least it is always initiated by the client.

That's a pretty interesting idea. Though it breaks the server
initiated message part of websockets. My orginal wsgi.upgrade was
basically to say "this connection is no longer HTTP and the app code
has taken responsibility for handling the connection". As Graham
pointed out, that could be shot down by the number of implementations
that wouldn't be able to handle it.

> Implementing this without a WebSockets-aware server seems like a bad idea.
> Anything not at the server level is going to be a nasty hack.

I definitely agree. For awhile I toyed around with the idea of making
the upgrade thing an optional but conventional  way to do websockets.
But then I had similar fears to what Graham voiced about that
splitting the wsgi server implementations up fairly drastically.

In the end I'm more worried about properly supporting HTTP. WebSockets
would be nice, but they're not exactly HTTP.

Paul Davis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Graham Dumpleton  
View profile  
 More options Jul 31 2010, 11:39 pm
From: Graham Dumpleton <graham.dumple...@gmail.com>
Date: Sat, 31 Jul 2010 20:39:58 -0700 (PDT)
Local: Sat, Jul 31 2010 11:39 pm
Subject: Re: 'wsgi.output' in environ?

On Aug 1, 6:17 am, Paul Davis <paul.joseph.da...@gmail.com> wrote:

In the past I have called it both ways streaming and technically the
HTTP protocol can support it without special tricks of upgrading the
protocol. All it means is that you need to use chunked request content
as well as chunked response content. Plus, implement your own message
boundary mechanism on top, which is effectively what WebSockets is
doing anyway.

The problem is that chunked request content is not supported by CGI,
FASTCGI, SCGI, AJP and certain other custom protocols, nor does WSGI
as a higher level API that can ride on these and other hosting
mechanisms.

So, even though I have described in the past how WSGI could support
chunked requests, and thus both way streaming, it doesn't help that
most WSGI implementations wouldn't be able to support it.

The main problem there is that implementations of protocols like CGI,
FASTCGI etc, assume that they can read all request content and send it
onto the application before they need to start reading the response
content. In other words, they cant be sending request content through
to the application and reading and returning response content at the
same time.

Graham


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bicking  
View profile  
 More options Aug 1 2010, 12:01 pm
From: Ian Bicking <i...@colorstudy.com>
Date: Sun, 1 Aug 2010 11:01:23 -0500
Local: Sun, Aug 1 2010 12:01 pm
Subject: Re: [Paste] Re: 'wsgi.output' in environ?

On Sat, Jul 31, 2010 at 3:17 PM, Paul Davis <paul.joseph.da...@gmail.com>wrote:

> > I can imagine an incoming WebSocket message (first message or later
> > messages) could be represented as a WSGI request, just adding a
> connection
> > ID and cloning the HTTP headers each time.  Responses could be... well,
> > that's tricky, as there's no request/response pairing.  You could put in
> > something like environ['websockets.send_message']('a message to send').
> But
> > then the actual WSGI response becomes meaningless.  So it's not a great
> > fit.  But at least it is always initiated by the client.

> That's a pretty interesting idea. Though it breaks the server
> initiated message part of websockets. My orginal wsgi.upgrade was
> basically to say "this connection is no longer HTTP and the app code
> has taken responsibility for handling the connection".

The server can only initiate a message, not a connection, so the ability to
save websockets.send_message (and use whatever queuing or task process you
had to send messages) would help.  In most applications you probably won't
even need another set of processes, as messages would be sent because of
something else, e.g., in a chat application a message will be sent out when
a message comes in (but across different sockets).  It does seem like an
asynchronous API would be helpful in this case, as there's no reason to
block the one client in order to send out a message to other clients...
though I suppose all websocket requests will in effect be asynchronous
because the WSGI response wouldn't mean anything.  I guess you also need
server-initiated close, since the request wouldn't close on its own (though
maybe require a 204 No Content response to indicate the application
understands web sockets, and otherwise simply abort).

--
Ian Bicking  |  http://blog.ianbicking.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »