/usr/lib/python2.7/dist-packages/zeep/helpers.py is in python-zeep 2.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import datetime
from collections import OrderedDict
from lxml import etree
from zeep import xsd
from zeep.xsd.valueobjects import CompoundValue
def serialize_object(obj, target_cls=OrderedDict):
"""Serialize zeep objects to native python data structures"""
if isinstance(obj, list):
return [serialize_object(sub, target_cls) for sub in obj]
if isinstance(obj, (dict, CompoundValue)):
result = target_cls()
for key in obj:
result[key] = serialize_object(obj[key], target_cls)
return result
return obj
def create_xml_soap_map(values):
"""Create an http://xml.apache.org/xml-soap#Map value."""
Map = xsd.ComplexType(
xsd.Sequence([
xsd.Element(
'item',
xsd.AnyType(),
min_occurs=1,
max_occurs="unbounded"),
]),
qname=etree.QName('{http://xml.apache.org/xml-soap}Map'))
KeyValueData = xsd.Element(
'{http://xml.apache.org/xml-soap}KeyValueData',
xsd.ComplexType(
xsd.Sequence([
xsd.Element(
'key',
xsd.AnyType(),
),
xsd.Element(
'value',
xsd.AnyType(),
),
]),
),
)
return Map(item=[
KeyValueData(
xsd.AnyObject(xsd.String(), key),
xsd.AnyObject(guess_xsd_type(value), value)
) for key, value in values.items()
])
def guess_xsd_type(obj):
"""Return the XSD Type for the given object"""
if isinstance(obj, bool):
return xsd.Boolean()
if isinstance(obj, int):
return xsd.Integer()
if isinstance(obj, float):
return xsd.Float()
if isinstance(obj, datetime.datetime):
return xsd.DateTime()
if isinstance(obj, datetime.date):
return xsd.Date()
return xsd.String()
def Nil():
"""Return an xsi:nil element"""
return xsd.AnyObject(None, None)
|