/usr/lib/python2.7/dist-packages/zeep/utils.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 78 79 80 81 82 83 84 85 86 87 88 | import cgi
import inspect
from lxml import etree
from zeep.exceptions import XMLParseError
from zeep.ns import XSD
def qname_attr(node, attr_name, target_namespace=None):
value = node.get(attr_name)
if value is not None:
return as_qname(value, node.nsmap, target_namespace)
def as_qname(value, nsmap, target_namespace=None):
"""Convert the given value to a QName"""
if ':' in value:
prefix, local = value.split(':')
# The xml: prefix is always bound to the XML namespace, see
# https://www.w3.org/TR/xml-names/
if prefix == 'xml':
namespace = 'http://www.w3.org/XML/1998/namespace'
else:
namespace = nsmap.get(prefix)
if not namespace:
raise XMLParseError(
"No namespace defined for %r (%r)" % (prefix, value))
# Workaround for https://github.com/mvantellingen/python-zeep/issues/349
if not local:
return etree.QName(XSD, 'anyType')
return etree.QName(namespace, local)
if target_namespace:
return etree.QName(target_namespace, value)
if nsmap.get(None):
return etree.QName(nsmap[None], value)
return etree.QName(value)
def findall_multiple_ns(node, name, namespace_sets):
result = []
for nsmap in namespace_sets:
result.extend(node.findall(name, namespaces=nsmap))
return result
def get_version():
from zeep import __version__ # cyclic import
return __version__
def get_base_class(objects):
"""Return the best base class for multiple objects.
Implementation is quick and dirty, might be done better.. ;-)
"""
bases = [inspect.getmro(obj.__class__)[::-1] for obj in objects]
num_objects = len(objects)
max_mro = max(len(mro) for mro in bases)
base_class = None
for i in range(max_mro):
try:
if len({bases[j][i] for j in range(num_objects)}) > 1:
break
except IndexError:
break
base_class = bases[0][i]
return base_class
def detect_soap_env(envelope):
root_tag = etree.QName(envelope)
return root_tag.namespace
def get_media_type(value):
"""Parse a HTTP content-type header and return the media-type"""
main_value, parameters = cgi.parse_header(value)
return main_value
|