-from docutils.core import publish_string;
-import posix
-import select
-import sys
-import xmlrpclib
-import xml.parsers.expat
-from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
-
-def write(s):
- # no comment
- sys.stdout.write(s)
- sys.stdout.flush()
-
-def debug(s):
- print >>sys.stderr, __name__ + ':DEBUG:' + s
- sys.stderr.flush()
-
-def rpc_read(processor):
- acc = ''
- ret = None
- while True:
- line = sys.stdin.readline()
- if line is None: continue
- if len(line) == 0: sys.exit(posix.EX_OK)
-# debug('read line: ' + line)
- acc += line
- try:
- ret = processor(acc)
-# debug('processed: ' + acc)
-# debug('got back: ' + ret.__class__.__name__)
- return ret
- except xml.parsers.expat.ExpatError:
-# debug('request invalid or incomplete: ' + acc)
- pass
- return None
-
-def rpc_call(cmd, **kwargs):
- call = xmlrpclib.dumps(sum(kwargs.items(), ()), cmd)
- write(call + '\n')
- resp = rpc_read(lambda resp: resp)
-
-class SimpleStdinOutXMLRPCHandler(SimpleXMLRPCDispatcher):
-
- def __init__(self, allow_none=False, encoding=None):
- # see http://bugs.debian.org/470645
- if SimpleXMLRPCDispatcher.__init__.func_code.co_argcount == 1:
- # python2.4 and before only took one argument
- SimpleXMLRPCDispatcher.__init__(self)
- else:
- SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)