本文整理汇总了Python中xmlrpclib.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xml_dumps
def test_xml_dumps():
"""
Test the `ipalib.rpc.xml_dumps` function.
"""
f = rpc.xml_dumps
params = (binary_bytes, utf8_bytes, unicode_str, None)
# Test serializing an RPC request:
data = f(params, API_VERSION, b'the_method')
(p, m) = loads(data)
assert_equal(m, u'the_method')
assert type(p) is tuple
assert rpc.xml_unwrap(p) == params
# Test serializing an RPC response:
data = f((params,), API_VERSION, methodresponse=True)
(tup, m) = loads(data)
assert m is None
assert len(tup) == 1
assert type(tup) is tuple
assert rpc.xml_unwrap(tup[0]) == params
# Test serializing an RPC response containing a Fault:
fault = Fault(69, unicode_str)
data = f(fault, API_VERSION, methodresponse=True)
e = raises(Fault, loads, data)
assert e.faultCode == 69
assert_equal(e.faultString, unicode_str)
示例2: makedict
def makedict(xmlnodes):
nodelist = []
for node in xmlnodes[0].childNodes:
#print job.childNodes
newdict = {}
for attr in node.childNodes:
if not attr.hasChildNodes():
element_data = ''
else:
element_data = attr.childNodes[0].data
# print attr.nodeName, element_data
attr_type = attr.getAttribute('type')
if attr_type == 'bool':
element_data = bool(element_data)
elif attr_type == 'int':
element_data = int(element_data)
elif attr_type == 'float':
element_data = float(element_data)
elif attr_type == 'dict':
attrdict = {}
for x,y in xmlrpclib.loads(element_data)[0]:
attrdict.update({x:y})
element_data = attrdict
elif attr_type == 'list':
# load list data using xmlrpc marshalling
element_data = list(xmlrpclib.loads(element_data)[0])
newdict.update({attr.nodeName:element_data})
nodelist.append(newdict)
return nodelist
示例3: test_xmlrequests
def test_xmlrequests(self):
data = (
'<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>'
)
response = self.client.post(self.rpc_path, data, "text/xml")
self.assertEqual(response.status_code, 200)
xmlrpclib.loads(response.content) # this will throw an exception with bad data
示例4: test_kwargs
def test_kwargs(self):
xml = dumps((1, 2), 'kwargstest')
ret = self.dispatcher.dispatch(xml)
out, name = loads(ret)
self.assertFalse(out[0])
ret = self.dispatcher.dispatch(xml, c=1)
out, name = loads(ret)
self.assertTrue(out[0])
xml = dumps((1,),'requestargtest')
ret = self.dispatcher.dispatch(xml, request=True)
out, name = loads(ret)
self.assertTrue(out[0])
xml = """<?xml version='1.0'?>
<methodCall>
<methodName>withoutargstest</methodName>
<params>
</params>
</methodCall>
"""
ret = self.dispatcher.dispatch(xml, request='fakerequest')
out, name = loads(ret)
self.assertTrue(out[0])
示例5: test_kwargs
def test_kwargs(self):
xml = dumps((1, 2), 'kwargstest')
ret = self.dispatcher.dispatch(xml)
out, name = loads(ret)
self.assertFalse(out[0])
ret = self.dispatcher.dispatch(xml, c=1)
out, name = loads(ret)
self.assertTrue(out[0])
示例6: test_bad_xml_input
def test_bad_xml_input(self):
request = Request.blank("/", method="POST", body="<foo")
response = request.get_response(self.app)
self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, response.body)
try:
xmlrpclib.loads(response.body)
except xmlrpclib.Fault, e:
self.assertEquals(repr(e), "<Fault -32700: 'Not well formed.'>")
示例7: wrap
def wrap(self, func, *p, **kw):
try:
try:
parms, method = xmlrpclib.loads(request.body)
except:
parms, method = xmlrpclib.loads(urllib.unquote_plus(request.body))
rpcresponse = xmlrpclib.dumps((func(p[0], *parms),), methodresponse=1)
except xmlrpclib.Fault, fault:
rpcresponse = xmlrpclib.dumps(fault)
示例8: test_datetime_before_1900
def test_datetime_before_1900(self):
# same as before but with a date before 1900
dt = datetime.datetime(1, 02, 10, 11, 41, 23)
s = xmlrpclib.dumps((dt,))
(newdt,), m = xmlrpclib.loads(s, use_datetime=1)
self.assertEqual(newdt, dt)
self.assertEqual(m, None)
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
self.assertEqual(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
示例9: main
def main(argv):
output_python=False
if argv[0] == '-p':
output_python=True
argv.pop(0)
host, methodname = argv[:2]
respxml = do_scgi_xmlrpc_request(host, methodname, convert_params_to_native(argv[2:]))
if not output_python:
print respxml
else:
print xmlrpclib.loads(respxml)[0][0]
示例10: test_dump_bare_date
def test_dump_bare_date(self):
# This checks that an unwrapped datetime.date object can be handled
# by the marshalling code. This can't be done via test_dump_load()
# since the unmarshaller produces a datetime object
d = datetime.datetime(2005, 02, 10, 11, 41, 23).date()
s = xmlrpclib.dumps((d,))
(newd,), m = xmlrpclib.loads(s, use_datetime=1)
self.assertEquals(newd.date(), d)
self.assertEquals(newd.time(), datetime.time(0, 0, 0))
self.assertEquals(m, None)
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
self.assertEquals(newdt, xmlrpclib.DateTime('20050210T00:00:00'))
示例11: test_dump_bare_datetime
def test_dump_bare_datetime(self):
# This checks that an unwrapped datetime.date object can be handled
# by the marshalling code. This can't be done via test_dump_load()
# since with use_datetime set to 1 the unmarshaller would create
# datetime objects for the 'datetime[123]' keys as well
dt = datetime.datetime(2005, 02, 10, 11, 41, 23)
s = xmlrpclib.dumps((dt,))
(newdt,), m = xmlrpclib.loads(s, use_datetime=1)
self.assertEqual(newdt, dt)
self.assertEqual(m, None)
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
self.assertEqual(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
示例12: render_POST
def render_POST(self, request):
request.content.seek(0, 0)
request.setHeader("content-type", "text/xml")
try:
if self.useDateTime:
args, functionPath = xmlrpclib.loads(request.content.read(),
use_datetime=True)
else:
# Maintain backwards compatibility with Python < 2.5
args, functionPath = xmlrpclib.loads(request.content.read())
except Exception, e:
f = Fault(self.FAILURE, "Can't deserialize input: %s" % (e,))
self._cbRender(f, request)
示例13: test_dump_bare_time
def test_dump_bare_time(self):
# This checks that an unwrapped datetime.time object can be handled
# by the marshalling code. This can't be done via test_dump_load()
# since the unmarshaller produces a datetime object
t = datetime.datetime(2005, 02, 10, 11, 41, 23).time()
s = xmlrpclib.dumps((t,))
(newt,), m = xmlrpclib.loads(s, use_datetime=1)
today = datetime.datetime.now().date().strftime("%Y%m%d")
self.assertEquals(newt.time(), t)
self.assertEquals(newt.date(), datetime.datetime.now().date())
self.assertEquals(m, None)
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
self.assertEquals(newdt, xmlrpclib.DateTime('%sT11:41:23'%today))
示例14: test_it_with_invalid_body
def test_it_with_invalid_body(self):
config = self.config
config.include('pyramid_rpc.xmlrpc')
config.add_xmlrpc_endpoint('rpc', '/api/xmlrpc')
app = config.make_wsgi_app()
app = TestApp(app)
resp = app.post('/api/xmlrpc', content_type='text/xml',
params='<')
try:
xmlrpclib.loads(resp.body)
except xmlrpclib.Fault:
exc = sys.exc_info()[1] # 2.5 compat
self.assertEqual(exc.faultCode, -32700)
else: # pragma: no cover
raise AssertionError
示例15: render
def render(self, request):
request.content.seek(0, 0)
args, functionPath = xmlrpclib.loads(request.content.read())
try:
function = self._getFunction(functionPath)
except Fault, f:
self._cbRender(f, request)