figuring out how much data was sent so far via XML-RPC?

Fredrik Lundh fredrik at pythonware.com
Tue Mar 7 08:07:58 CET 2006


Ratko Jagodic wrote:

> I am currently using XML-RPC for a very convenient quick-and-dirty way of
> sending some files (base64 encoded).
> The files can be bigger sometimes (10-20mb) and I was wondering if there is
> a way to see how much data was sent already and how much still needs to be
> sent (like a progress bar).

some "monkey overriding" might help:

# start

import xmlrpclib

class MyConnection:
    def __init__(self, conn):
        self.conn = conn
    def send(self, data):
        # split send up in pieces
        for i in range(0, len(data), 100):
            print "(%d of %d)" % (i, len(data)),
            self.conn.send(data[i:i+100])
        print
    def __getattr__(self, key):
        # delegate everything else
        return getattr(self.conn, key)

class MyTransport(xmlrpclib.Transport):
    def make_connection(self, host):
        conn = xmlrpclib.Transport.make_connection(self, host)
        return MyConnection(conn)

server = xmlrpclib.ServerProxy(
    "http://effbot.org/rpc/echo.cgi", transport=MyTransport()
    )

x = server.echo(10000*"*")

print type(x), len(x)

# this prints
# (0 of 10148) (100 of 10148) (200 of 10148) ... /snip/
# <type 'str'> 10000

</F>






More information about the Python-list mailing list