>
> [..]
>
>> There's a branch of Twisted that implements this, hopefully it will
> >> eventually be merged:
> >> http://twistedmatrix.com/trac/ticket/3711
> >>
> >>
> > Is there anything that is currently holding this up? (ie. is the design
> > on
> > this branch what will end up in the system or could it change
> > dramatically?)
>
> There are a bunch of review comments in the ticket. You could just write
> your own until this is ready, I've done it a number of times and it's a
> pretty small piece of code.
>
I started writing one of my own today (basically a wrapper in render_GET
that calls an deferrable render_GET).
Something like this:
def _bg_GET(self, request):
# Do something slow
request.write(result)
return request
def render_GET(self, request):
d = deferToThread(self._bg_GET, request)
d.addCallback(lambda r: r.finish())
return NOT_DONE_YET
That seems to work, but I would like to
a) not use the deferToThread() and
b) do something that doesn't sacrifice too much performance.
At the end of the day, what I would really like is something in render_GET
that checks the return from calling the internal GET method and if it is a
deferred it adds a callback to finish the request, if not it simply returns
the result. (this would allow me to use deferToThread, inlineCallbacks, etc
as needed in my get methods)
Can you see any issues with doing something like this? (it seems almost too
simple so I expect that I must be missing something)
-Allen
(repost of email earlier today on twisted mailing list. suggested this may
be better place to discuss. sorry if you get this twice.)
We have a large client-server based application based on twisted. The
application has grown to the point where we would like to add a REST-based
API to the server side to allow for interfacing with a wider variety of
client applications. Over the weekend I started looking into twisted.web
and had a couple of basic questions:
1) Is there any method to stream a large request (ex: PUT or POST with file
upload) into the system or does the entire body have to be loaded into
memory as part of the request?
2) Has anyone used an existing URL Routing system (ex: Routes [1], Selector
[2]) and adapted it for use with Twisted? (I know I could use the twisted
preferred method of parent child hierarchies, but our application has a
better fit with the route-based method used by Pylons, Django, Rails, etc)
3) Is there a document anywhere that describes all the environment variables
the user can get from the request and how to get to them? (something like
the environ section of the WSGI PEP [3])
4) Are their any wrappers people have developed to make it a bit easier to
use deferreds (in particular inlinecallbacks) in the handlers for
twisted.web? (I am considering just writing a wrapper myself that provides
an interface similar to google app engine webapp [4] but wanted to check
first so I don't reinvent something)
Thanks,
Allen
[1] http://routes.groovie.org/index.html
[2] http://lukearno.com/projects/selector/
[3] http://www.python.org/dev/peps/pep-0333/#environ-variables
[4] http://code.google.com/appengine/docs/python/tools/webapp/
Dear Twistonistas,
I am using 10.0.0 for 2.5 on a Vista Home 'Premium' (yes, yes, I know).
I am accessing some page with getPage(certain_url,method='GET').
Accessing works for non-local urls. Accessing does not work for "http://localhost:8080/..." - windows error 10061: connection refused (abbreviated from partially localized error message).
This propably sounds like a firewall problem, but all three firewall profiles disabled, only the 'native' windows vista firewall installed, so it shouldn't be one, I hope.
When using a synchronous urllib.urlopen('http://localhost:8080/...') / read() pair, it works.
This makes me nervous somehow, I must admit. Perhaps you have any hint / idea what the problem might be? This would be most welcome!
Btw.: The line "127.0.0.1 localhost" is in the host file in \Windows\System32\drivers\etc.
Thank you very much in advance!
Jannico
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Hi to all, and since this is my first post, congratulations for the perfect
framework.
i have the following code
class SimpleServer(LineReceiver):
def connectionMade(self):
print 'Connection from: ', self.transport.client
def connectionLost(self, reason):
print self.transport.client, 'Disconnected'
def dataReceived(self, line):
"""Here the XML Parser"""
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = start_element
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data
p.Parse(line, 1)
I got the following error
--- <exception caught here> ---
File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
x86_64.egg/twisted/internet/selectreactor.py", line 146, in
_doReadOrWrite
why = getattr(selectable, method)()
File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
return self.protocol.dataReceived(data)
File "stdiodemo.py", line 419, in dataReceived
p.Parse(line, 1)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
The XML Message is coming in the form of:
POST /test/pcp/Listener HTTP/1.1
user-agent:hjahs
Host:127.0.0.1
Content-Length: 547
<pttv_control_message version="1.0-M4-SNAPSHOT" build="599"
xmlns="http://1270.0.01/pttv<http://www.google.com/url?sa=D&q=http://1270.0.01/pttv&usg=AFQjCNEPqmRku5kV…>">
<cmdReply>
<code>200</code>
<message>OK, found 5 session entries</message>
<sessionList>
<session>
<id>06d4d59bfdfe10139dd874</id>
<subscriberId>82</subscriberId>
<deviceClass>and</deviceClass>
</session>
</sessionList>
</cmdReply>
</pttv_control_message>
Please give me some hints.
How to parse the incoming XML and how to ommit the headers from the
beginning of the message?
Thanks in advance