Re: [Twisted-Python] zope.interface

2009-12-14 Thread Phil Mayers
Jared Gisin wrote:
 Is there a good document that explains why zope.interface is necessary 
 to the twisted project?

A counter-question: Is there a good document that explains why people 
care? It's just another dependency isn't it?

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] zope.interface

2009-12-14 Thread Tim Allen
On Mon, Dec 14, 2009 at 11:48:48AM +, Phil Mayers wrote:
 Jared Gisin wrote:
  Is there a good document that explains why zope.interface is necessary 
  to the twisted project?
 
 A counter-question: Is there a good document that explains why people 
 care? It's just another dependency isn't it?

Trying to remember back to when I was a Twisted newbie, I seem to
recall a pang of dismay at seeing the word zope, until I realised that
zope.interface was very small and self-contained and didn't have further
dependencies on the rest of Zope.

Another possibility might be that the worry comes from people using
systems that don't have good built-in dependency management. I don't
know where pip/easy_install are at these days, but Debian's apt and
Fedora's yum have numbed the painful memories of downloading some
interesting code off the 'net and discovering yet further dependencies
I would have to track down and install to get things working.

I'm not saying these are well-researched or compelling reasons, just
speculating about what might be going on.

It occurs to me that recent discussions about splitting Deferreds off
into their own library might consider zope.interface as a model. Has it
prospered, as separate library? Does anyone besides Zope and Twisted use
it? I don't know, but it might be worth finding out.


Tim.

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] zope.interface

2009-12-14 Thread David Ripton
On 2009.12.14 11:48:48 +, Phil Mayers wrote:
 Jared Gisin wrote:
  Is there a good document that explains why zope.interface is necessary 
  to the twisted project?
 
 A counter-question: Is there a good document that explains why people 
 care? It's just another dependency isn't it?

Sure.  But Twisted has a very small number of dependencies (I think
Python and Zope Interface are the only ones that are absolutely
required) so it does increase the total effort to install Twisted on an
OS without a good package manager by a noticable amount.

Zope Interface is a good library, and I think the Twisted team made the
right call when they decided to use it rather than continue to maintain
their own interface library.  It's not their fault that installing
Python dependencies on some operating systems is still way harder than
it should be.

It would be great if general Python installation and packaging tools
improved to the point where one could easily install Twisted and all its
dependencies on any supported OS using PyPI, as easily as we can on
Linux or BSD using the OS package manager, or as easily as we can
install Perl packages from CPAN, or as easily as we can run Java stuff
using Java Web Start, etc.  Enough smart people care about this problem
that I'm pretty sure it'll be solved over the next couple of years.
Which is too far away to save me from having to write big nasty custom
Windows and MacOS installers for my current game, but might mean that
this is the last time I ever have to do it.

-- 
David Riptondrip...@ripton.net

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] XMLRPC get IP address

2009-12-14 Thread exarkun

On 05:32 pm, landrevi...@deadtreepages.com wrote:
Hello,

I've looked through the mailing list and already found this reference 
to get
the IP address when using xmlrpc:

http://twistedmatrix.com/pipermail/twisted-python/2004-June/007987.html

But it is not working.

I have added this to my class that inherits from xmlrpc.XMLRPC

def render(self, request):
self.request = request
xmlrpc.XMLRPC.render(self, request)


Now when I call any function the log says:
2009-12-14 12:29:18-0500 [-]
/usr/local/lib/python2.6/dist-packages/Twisted-9.0.0-py2.6-linux- 
x86_64.egg/twisted/web/xmlrpc.py:148:
exceptions.UserWarning: Warning! request.finish called twice.

I have two XMLRPC classes, and one of them is a subHandler, but the
subhandler's render method never gets called as far as I've seen (so it
shouldnt be causing request.finish to be called twice)  and just to be 
sure
I added this to only the parent XMLRPC class.

Any ideas why this would cause request.finish to be called twice?

Make sure you return the result of calling xmlrpc.XMLRPC.render.

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] plugin system

2009-12-14 Thread César García
Guys, I'am new to twisted and I've read the documentation about the
plugin system and the components but I can't make it, I really do not
get it well, do you guys have any examples there to see if I can get
it :)

Thanks a lot

-- 
http://celord.blogspot.com/

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] zope.interface

2009-12-14 Thread Andrew Bennetts
Tim Allen wrote:
[...]
 It occurs to me that recent discussions about splitting Deferreds off
 into their own library might consider zope.interface as a model. Has it
 prospered, as separate library? Does anyone besides Zope and Twisted use
 it? I don't know, but it might be worth finding out.

I'm not sure that it has “prospered” exactly, but a Python 3 added its
Abstract Base Classes feature[1] to satisfy some (many?) of the same needs.
So in some sense the general idea has prospered, even if this particular
implementation hasn't taken over the world.

-Andrew.

[1] http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3119

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] complete producer/consumer example

2009-12-14 Thread Benjamin Rutt
How does the below example look as a complete producer/consumer example?  If
it's well received, perhaps we can add it to the online documentation at
http://twistedmatrix.com/documents/current/core/howto/producers.html in the
Further Reading section?  I always felt that the producer/consumer (a.k.a.
high volume streaming) docs lacked a real example that users could download
and run.

#!/sw/external/python-2.6.1/bin/python
Serve as a sample implementation of a twisted producer/consumer
system, with a simple TCP server which asks the user how many random
integers they want, and it sends the result set back to the user, one
result per line.

import random

from zope.interface import implements
from twisted.internet import interfaces, reactor
from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineReceiver

class Producer:
Send back the requested number of random integers to the client.
implements(interfaces.IPushProducer)
def __init__(self, proto, cnt):
self._proto = proto
self._goal = cnt
self._produced = 0
self._paused = False
def pauseProducing(self):
When we've produced data too fast, pauseProducing() will be
called (reentrantly from within resumeProducing's transport.write
method, most likely), so set a flag that causes production to pause
temporarily.
self._paused = True
print('pausing connection from %s' %
(self._proto.transport.getPeer()))
def resumeProducing(self):
self._paused = False
while not self._paused and self._produced  self._goal:
next_int = random.randint(0, 1)
self._proto.transport.write('%d\r\n' % (next_int))
self._produced += 1
if self._produced == self._goal:
self._proto.transport.unregisterProducer()
self._proto.transport.loseConnection()
def stopProducing(self):
pass

class ServeRandom(LineReceiver):
Serve up random data.
def connectionMade(self):
print('connection made from %s' % (self.transport.getPeer()))
self.transport.write('how many random integers do you want?\r\n')
def lineReceived(self, line):
cnt = int(line.strip())
producer = Producer(self, cnt)
self.transport.registerProducer(producer, True)
producer.resumeProducing()
def connectionLost(self, reason):
print('connection lost from %s' % (self.transport.getPeer()))
factory = Factory()
factory.protocol = ServeRandom
reactor.listenTCP(1234, factory)
print('listening on 1234...')
reactor.run()

Use on the client:

$ telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
how many random integers do you want?
5
431
7201
3289
9604
6659
Connection closed by foreign host.
$

Use on the server (observe how the server pauses production sometimes - this
happens when a large data set is requested by the client):

$ ./streaming.py
listening on 1234...
connection made from IPv4Address(TCP, '127.0.0.1', 54859)
connection lost from IPv4Address(TCP, '127.0.0.1', 54859)
connection made from IPv4Address(TCP, '127.0.0.1', 54864)
pausing connection from IPv4Address(TCP, '127.0.0.1', 54864)
pausing connection from IPv4Address(TCP, '127.0.0.1', 54864)
pausing connection from IPv4Address(TCP, '127.0.0.1', 54864)
pausing connection from IPv4Address(TCP, '127.0.0.1', 54864)
connection lost from IPv4Address(TCP, '127.0.0.1', 54864)
[...]

Thanks.
-- 
Benjamin Rutt
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] subprocess.Popen

2009-12-14 Thread Aníbal Pacheco
Hi list,

Is it possible to attach a callback to a process launched using
subprocess.Popen?, I want to receive a notification on process
termination.

many thanks!
anibal.-

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] subprocess.Popen

2009-12-14 Thread Tim Allen
On Tue, Dec 15, 2009 at 02:32:40AM -0200, Aníbal Pacheco wrote:
 Is it possible to attach a callback to a process launched using
 subprocess.Popen?, I want to receive a notification on process
 termination.

I don't believe Twisted has any special support for subprocess.Popen,
but you can do much the same things with Twisted's
reactor.spawnProcess().

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python