File: xmlrpc_test.py

package info (click to toggle)
kamailio 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 56,100 kB
  • sloc: ansic: 552,832; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (51 lines) | stat: -rw-r--r-- 1,699 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import xmlrpclib, httplib, sys

# Usage:  python xmlrpc_test.py command [params...]
#
# python script for sending an xmlrpc command to ser's xmlrpc module.
# Note: it uses a re-defined transport class that does not depend on the
# server side closing the connection (it can be used to send multiple
# commands without closing the connections and it will work without any
# special workarounds in the ser.cfg xmlrpc route).
#
# Credits: the transport class comes from ser_ctl, heavily trimmed to a very
# basic version (the ser_ctl version is much more complex, supports
# authentication, ssl a.s.o). See
# http://git.sip-router.org/cgi-bin/gitweb.cgi?p=ser;a=blob;f=ser_ctl/serctl/serxmlrpc.py#l73 for the original (better) version.
#
#
# History:
# --------
#  2009-07-13  initial version (andrei)
#


XMLRPC_SERVER = "127.0.0.1"
XMLRPC_PORT = 5060

class Transport:
	def __init__(self):
		self.conn=httplib.HTTPConnection(XMLRPC_SERVER, str(XMLRPC_PORT));

	def _http_request(self, uripath, body, host):
		self.conn.request("POST", uripath, body, {})

	def request(self, host, uripath, body, verbose=0):
		self._http_request(uripath, body, host)
		response=self.conn.getresponse()
		if response.status != 200:
			raise xmlrpclib.ProtocolError(host+uripath, response.status,
							response.reason, response.msg)
		data=response.read()
		parser, unmarshaller=xmlrpclib.getparser()
		parser.feed(data)
		parser.close()
		return unmarshaller.close()

if len(sys.argv) < 2:
	sys.exit("Usage: "+sys.argv[0]+" rpc_command [args...]");
transport=Transport()
c=xmlrpclib.ServerProxy("http://" + XMLRPC_SERVER+ ":" + str(XMLRPC_PORT),
						transport)
res=getattr(c, sys.argv[1])(*sys.argv[2:])
print res;