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 received this message because you are subscribed to the Google Groups "Paste Users" group.
To post to this group, send email to paste...@googlegroups.com.
To unsubscribe from this group, send email to paste-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/paste-users?hl=en.
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
> To unsubscribe from this group, send email to paste-users...@googlegroups.com.
---------- Forwarded message ----------
From: Paul Davis <paul.jos...@gmail.com>
Date: Sat, Jul 31, 2010 at 12:05 PM
Subject: Re: [Paste] Re: 'wsgi.output' in environ?
To: Graham Dumpleton <graham.d...@gmail.com>
One of the first sentences of my notes was something along the lines
of "Its 2010 and its about time that WSGI focus on being HTTP
compliant and leave the constraints of CGI behind."
I hadn't at all researched the various embedded implementations to
figure out if it was viable yet. Though I'm a tad confused on how
these embeddings support the write callable without being able to
access the read side of the socket.
> So, some things should simply never be a part of the WSGI
> specification as they destroy the promise of portability that WSGI has
> brought.
I agree that we should minimize the surface area to make it as easy to
implement as possible. I'm not tied to any of this at all. It was just
a fun little by product of how I rearranged the write callable action.
> 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.
One of the ideas I've had simmering for a bit was to figure out how to
write a series of wsgi apps that exercise the entire WSGI
specification. That way you could just run it behind your favorite
server to check the validity of its implementation. Basically,
wsgiref.validator, but in reverse.
> 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
>
http://jeffkreeftmeijer.com/2010/experimenting-with-node-js/
This was a fun little experiment at one point, but now that the
traffic has died down its lost its effectiveness. Right when it hit
Hacker News there were probably 40-50 cursors floating around showing
everyone's mouse movements.
Benoit Chesneau (the other Gunicorn developer) made a quick example
and short movie of websockets using the WSGI hacks.
http://www.vimeo.com/10111929
http://github.com/benoitc/gunicorn/tree/master/examples/websocket/
Its not as amusing as the communal mouse cursors, but it should do the
trick in showing the client code for such things. The spec is a bit
dense, but the basic premise is to have a bidirectional channel open
to the browser to avoid the current state of the art that is long poll
et al.
Paul Davis
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.
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
> I can imagine an incoming WebSocket message (first message or laterThat's a pretty interesting idea. Though it breaks the server
> 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.
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".