Tofu ([info]thetofu) wrote,
@ 2005-11-30 20:54:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
twisted command line xmlrpc client
Here is a command line xmlrpc client for my and your enjoyment.




from twisted.web.xmlrpc import Proxy
from twisted.internet import reactor, stdio
from twisted.protocols import basic
import sys

   

class Shell(basic.LineReceiver):
    from os import linesep as delimiter

    def __init__(self, proxy):
        self.proxy = proxy
       
    def connectionMade(self):
        self.transport.write('>>> ')

    def printValue(self, value):
        print repr(value)
        # go to command line again
        self.transport.write('\n')
        self.transport.write('>>> ')

    def printError(self, error):
        print 'error', error
        # go to command line again
        self.transport.write('\n')
        self.transport.write('>>> ')

    def lineReceived(self, line):
        args = []
        tline = line.replace(')','').replace(';','').replace('\'','')
        m = tline.split('(')
        method = m.pop(0)
        args = m[0].split(',')
       
        self.proxy.callRemote(method,*args).addCallbacks(self.printValue, self.printError)
        self.sendLine('Echo: ' + line)
       



if len(sys.argv)==2:
    proxy = Proxy(sys.argv[1])
    stdio.StandardIO(Shell(proxy))

    reactor.run()
else:
    print " Usage : %s proxyURL " % sys.argv[0]




(Post a new comment)


[info]thetofu
2005-12-01 12:59 pm UTC (link)
The command line parsing needs to be a regular expression. It was done quick. :)

(Reply to this)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…