I'm trying to get to grips with Xish; and theres this annoying little problem:
through a series of steps I'm getting at an Element who doesn't use the
default namespace anymore, only some other NS. I am trying to make this other
NS the default NS for serialization, but without much luck.
>>> from twisted.words.xish import domish
>>> e=domish.Element(("foons", "foo"), defaultUri="defuri",
>>> e.addElement(("foons", "bar"))
<twisted.words.xish.domish.Element object at 0x820840c>
u"<f:foo xmlns='defuri' xmlns:f='foons'><f:bar/></f:foo>"
I'd like the output to be something like "<foo><bar/></foo>" -- thats shorter
Am I making any sense? Probably I'm missing something pretty obvious...
Thanks in advance,
I'm looking for a simple way to check whatever a use with a specific name is
in a channel or not. How could I do this? Im connecting to irc by
subclassign the twisted.words.im.ircsupport.IRCProto class.
Thanks in advance!
>Date: Sat, 19 Apr 2008 11:47:38 -0700 (PDT)
>From: Andrew Francis <andrewfr_ice(a)yahoo.com>
>Subject: [Twisted-Python] Stackless Python Examples Re: InlineCallback
> Friendly ?
>Content-Type: text/plain; charset=iso-8859-1
--- Andrew Francis <andrewfr_ice(a)yahoo.com> wrote:
>Based on Jean-Paul's explanation, here are some code
>snippets showing how to handle other protocols with
>Stackless Python and Twisted. This is a continuation
>of the technique I used in "Adventures" to prevent the
>reactor from deadlocking.
>Currently I am rethinking the techniques - I believe
>there is a way to reduce spawning tasklets - not that
>tasklets are all that expensive....
I have been experimenting with a new technique for tasklets to interact with Twisted protocol instances (the following is essentially what I was pestering the Twisted Team about at PyCon 2008. Sorry guys)
I have been exploring situations where a tasklet rendezvoused with Twisted (as opposed to a Twisted spawning a tasklet to fulfill a request). A lot of WS-BPEL constructs take this form....
In the old system, I ran the server protocol instance in its own tasklet. This was to prevent the reactor from blocking and preventing other tasklets from issuing Twisted calls. In turn, the tasklet and protocol instance/tasklet communicated via a channel.
With this technique, I do not create an additional tasklet. Rather I pass back a deferred whose callback points to the reminder of the protocol instance's code.
Although I have not finished testing, this technique seems to be about 20% faster. Again, implementing this is fairly straightforward. Here is a sketch.
def __httpWrite__(self, status, message):
create a deferred
myDeferred = defer.Deferred()
we need a way for the protocol instance to tell tasklets that a
connect has been made. Easiest way, just hand the protocol
instance a reference
status, message = \
if status != http.OK:
myDeferred = None
if things went well, return a deferred
This is a Twisted way to circumvent blocking and waiting
def processReply(self, reply):
meanwhile, in the tasklet
deferred = someFunction(somePath)
# send a message
Although PyCon 2008 is over, I still plan to submit a paper that will better explain the various techniques in the "Adventures" talk. I am also writing simpler code to better illustrate the techniques and combine them with other tried-and-true techniques (i.e., Armstrong's blockOn).
I was going to use Deferred.setTimeout until I saw that it was
deprecated. Does anyone know why? I found it handy and I find that
case-per-case replacements tend to be complicated. Does anyone have any
ideas on how to replace it?
I have a queue containing read results from I/O, the get() method
returns a deferred fired when the data arrives (sort of like
defer.DeferredQueue). Since I need to be able to set a read timeout,
i.e. if the data doesn't arrive after a certain time, I need to raise an
exception and remove the deferred from the internal list; the defer's
timeout would have been handy here :-(.
I was thinking of doing something like this, if data isn't present in
the data internal list:
d = Deferred()
dc = reactor.callLater(self.timeout, self.__timeoutCallback, d)
Then a tuple containing the Deferred ("d"), the DelayedCall ("dc") is
then put in the internal waiting list. If the timeout doesn't expire
before the data arrives, then the DelayedCall is canceled, if it does
expire then the tuple is removed from the queue (potentially slow) and
an exception is raised.
Is there a better way of doing this? Any ideas?
I have to deal with flash players (I'm deeply ashamed for what I'm doing ;-), and their somewhat cumberstone constraints.
The main part of the communication is handled via an tcp socket using the amf protocol. But I have to handle "file uploads" via http POST multipart from client to server and sending it back to the flash player since flash only allows domain specific content - no content from the users' file system.
So my first attempt to solve this big mess was to create a tac like that:
import sys, os
from twisted.application import internet, service
# my custom backend factory subclassed from ServerFactory
from socketManager import SocketManager
from policySocketFactory import PolicySocketFactory
from twisted.web2 import server, channel, static
from twisted.application import service, strports
from fileupload import Toplevel
application = service.Application('backend')
# backend service - all client/server communication should go via that sockets
backendService = internet.TCPServer(8600, SocketManager())
# policy service
socketPolicyService = internet.TCPServer(8601, PolicySocketFactory('socket-policy.xml'))
# http service
site = server.Site(Toplevel())
fileUploadService = strports.service('tcp:8080', channel.HTTPFactory(site))
Authentication /Authorization is implemented in the backend service, so I'm searching for a solution to fire some sort of event in the fileUploadService to be handled in the backendService, and to restrict the file upload to already logged in users. I thought about using "inotify" for watching the upload directory, but I would prefer a twisted /pythonic solution. Perhaps someone could give me some advice about what would be a sane way to solve this 2 problems.
Thank you in advance,
Divmod's been talking to various hosting companies about potential
Twisted deals (and maybe even support). I wanted to get a gauge of
people's level of interest in the services we've been discussing.
We're currently looking at the following options:
* Dedicated hosts, with Twisted libs pre-installed on them
* Virtual hosts/"slices" with Twisted libs pre-installed on them
* Clouds that support uploading and running Twisted apps
* Potential support contracts where Divmod engineers provide
high-level assistance for paying customers
* Becoming a reseller and offering these services directly through Divmod
I've been approached privately by a few developers who use Twisted in
their projects at home and at work with questions about Twisted
hosting. They've been interested to know if 1) Divmod does Twisted
hosting, 2) anyone provides "out of the box" support for Twisted, and
3) who we recommend.
I know that as the years pass, I have less and less time to manage my
own systems responsibly. After 6 years, I'm closing down my colocated
boxes. When Twisted makes it to the cloud, I'll close down my virtual
hosts, too. I just don't have the time any more. All I need is
reliable uptime for my apps (most of them are just sites with dynamic
How many others on these lists feel that they would benefit from the
ease of pre-installed Twisted and/or support for Twisted apps in the
If you do, what kinds of apps (that you are currently running) do you
want to be able to run in such environments? Simple web sites? DNS
servers? Game servers? Chat applications? Web/data services apps?
And lastly, what hosting companies are your favorites? Where would you
be happiest, if they supported Twisted? Would you consider switching
to a hosting provider that *did* support Twisted?
Looking forward to hearing the people speak,