<commit_before>#
# ElementSOAP
# $Id: //modules/elementsoap/elementsoap/ElementSOAP.py#4 $
#
# a simple SOAP library based on element trees
#
# history:
# 2003-11-16 fl   created (using bits and pieces from various sources)
# 2003-11-18 fl   added fault handling
# 2003-11-22 fl   added qname handling, decoder stub
# 2003-11-23 fl   handle type attributes, decode basic types
#
# Copyright (c) 2003 by <NAME>.  All rights reserved.
#
# <EMAIL>
# http://www.pythonware.com
#

##
# This module provides helper classes for SOAP client implementations.
##

from elementtree import ElementTree
from elementtree import XMLTreeBuilder
from elementtree.ElementTree import Element, QName, SubElement, tostring
from HTTPClient import HTTPClient, HTTPError

# --------------------------------------------------------------------

def sanitycheck():
    # check that we have a version of ElementTree without the
    # "duplicate namespace prefix" bug
    elem = Element("doc")
    subelem = Element("tag")
    subelem.attrib["{url1}key"] = QName("{url2}value")
    elem.append(subelem)
    elem.append(subelem)
    try:
        ElementTree.fromstring(tostring(elem))
    except:
        import warnings
        warnings.warn(
            "This library requires ElementTree 1.2a5 or newer",
            RuntimeWarning
            )

sanitycheck()

# --------------------------------------------------------------------

# SOAP 1.1 namespaces
NS_SOAP_ENV = "{http://schemas.xmlsoap.org/soap/envelope/}"
NS_SOAP_ENC = "{http://schemas.xmlsoap.org/soap/encoding/}"
NS_XSI = "{http://www.w3.org/1999/XMLSchema-instance}"
NS_XSD = "{http://www.w3.org/1999/XMLSchema}"


soap_namespaces = {NS_SOAP_ENV[1:-1] : 'SOAP-ENV',
                   NS_SOAP_ENC[1:-1] : 'SOAP-ENC',
                   NS_XSI[1:-1]      : 'xsi',
                   NS_XSD[1:-1]      : 'xsd'
                   }

ElementTree._namespace_map.update(soap_namespaces)



##
# SOAP fault exception.
#
# @param faultcode SOAP fault code.
# @param faultstring SOAP fault description.
# @param faultactor SOAP fault actor.
# @param detail SOAP detail structure (an Element structure).

class SoapFault(Exception):

    ##
    # SOAP fault code.

    faultcode = None

    ##
    # SOAP fault description.

    faultstring = None

    ##
    # SOAP fault actor.

    faultactor = None

    ##
    # SOAP fault detail.  This is either None or an Element structure.

    detail = None

    def __init__(self, faultcode, faultstring, faultactor, detail):
        Exception.__init__(self, faultcode, faultstring, faultactor, detail)
        self.faultcode = faultcode
        self.faultstring = faultstring
        self.faultactor = faultactor
        self.detail = detail

##
# SOAP request factory.
#
# @param request SOAP request URL.
# @return A SOAP request element structure.
# @defreturn Element

def SoapRequest(request):
    # create a SOAP request element
    request = Element(request)
##     request.set(
##         NS_SOAP_ENV + "encodingStyle",
##         "http://schemas.xmlsoap.org/soap/encoding/"
##         )
    return request

##
# SOAP element factory.  This creates a value element, and appends
# it to a parent element.
#
# @param parent The parent element (usually a SOAP request element
#     another SOAP element).
# @param name Element name.
# @param type Element type.  Use None for untyped objects, a string
#     for types in the standard XML Schema namespace, or a QName.
# @param text Element value.
# @return A SOAP value element.
# @defreturn Element

def SoapElement(parent, name, type=None, text=None):
    # add a typed SOAP element to a request structure
    elem = SubElement(parent, name)
    if type:
        #if not isinstance(type, QName):
        #    type = QName("http://www.w3.org/1999/XMLSchema", type)
        #elem.set(NS_XSI + "type", type)
        elem.set("xsi:type", type)
    elem.text = text
    print "SoapElement", tostring(elem)
    return elem

##
# Base class for SOAP service proxies.
#
# @param url Optional service URL.  If omitted, the URL defaults to
#    the default URL for this service (as defined by the <b>url</b>
#    class attribute).

class SoapService:

    def __init__(self, url=None):
        self.__client = HTTPClient(url or self.url)

    ##
    # Calls a remote SOAP method.
    #
    # @param action The SOAP action string.<commit_msg>removed an old print<commit_after>#
# ElementSOAP
# $Id: //modules/elementsoap/elementsoap/ElementSOAP.py#4 $
#
# a simple SOAP library based on element trees
#
# history:
# 2003-11-16 fl   created (using bits and pieces from various sources)
# 2003-11-18 fl   added fault handling
# 2003-11-22 fl   added qname handling, decoder stub
# 2003-11-23 fl   handle type attributes, decode basic types
#
# Copyright (c) 2003 by <NAME>.  All rights reserved.
#
# <EMAIL>
# http://www.pythonware.com
#

##
# This module provides helper classes for SOAP client implementations.
##

from elementtree import ElementTree
from elementtree import XMLTreeBuilder
from elementtree.ElementTree import Element, QName, SubElement, tostring
from HTTPClient import HTTPClient, HTTPError

# --------------------------------------------------------------------

def sanitycheck():
    # check that we have a version of ElementTree without the
    # "duplicate namespace prefix" bug
    elem = Element("doc")
    subelem = Element("tag")
    subelem.attrib["{url1}key"] = QName("{url2}value")
    elem.append(subelem)
    elem.append(subelem)
    try:
        ElementTree.fromstring(tostring(elem))
    except:
        import warnings
        warnings.warn(
            "This library requires ElementTree 1.2a5 or newer",
            RuntimeWarning
            )

sanitycheck()

# --------------------------------------------------------------------

# SOAP 1.1 namespaces
NS_SOAP_ENV = "{http://schemas.xmlsoap.org/soap/envelope/}"
NS_SOAP_ENC = "{http://schemas.xmlsoap.org/soap/encoding/}"
NS_XSI = "{http://www.w3.org/1999/XMLSchema-instance}"
NS_XSD = "{http://www.w3.org/1999/XMLSchema}"


soap_namespaces = {NS_SOAP_ENV[1:-1] : 'SOAP-ENV',
                   NS_SOAP_ENC[1:-1] : 'SOAP-ENC',
                   NS_XSI[1:-1]      : 'xsi',
                   NS_XSD[1:-1]      : 'xsd'
                   }

ElementTree._namespace_map.update(soap_namespaces)



##
# SOAP fault exception.
#
# @param faultcode SOAP fault code.
# @param faultstring SOAP fault description.
# @param faultactor SOAP fault actor.
# @param detail SOAP detail structure (an Element structure).

class SoapFault(Exception):

    ##
    # SOAP fault code.

    faultcode = None

    ##
    # SOAP fault description.

    faultstring = None

    ##
    # SOAP fault actor.

    faultactor = None

    ##
    # SOAP fault detail.  This is either None or an Element structure.

    detail = None

    def __init__(self, faultcode, faultstring, faultactor, detail):
        Exception.__init__(self, faultcode, faultstring, faultactor, detail)
        self.faultcode = faultcode
        self.faultstring = faultstring
        self.faultactor = faultactor
        self.detail = detail

##
# SOAP request factory.
#
# @param request SOAP request URL.
# @return A SOAP request element structure.
# @defreturn Element

def SoapRequest(request):
    # create a SOAP request element
    request = Element(request)
##     request.set(
##         NS_SOAP_ENV + "encodingStyle",
##         "http://schemas.xmlsoap.org/soap/encoding/"
##         )
    return request

##
# SOAP element factory.  This creates a value element, and appends
# it to a parent element.
#
# @param parent The parent element (usually a SOAP request element
#     another SOAP element).
# @param name Element name.
# @param type Element type.  Use None for untyped objects, a string
#     for types in the standard XML Schema namespace, or a QName.
# @param text Element value.
# @return A SOAP value element.
# @defreturn Element

def SoapElement(parent, name, type=None, text=None):
    # add a typed SOAP element to a request structure
    elem = SubElement(parent, name)
    if type:
        #if not isinstance(type, QName):
        #    type = QName("http://www.w3.org/1999/XMLSchema", type)
        #elem.set(NS_XSI + "type", type)
        elem.set("xsi:type", type)
    elem.text = text
    return elem

##
# Base class for SOAP service proxies.
#
# @param url Optional service URL.  If omitted, the URL defaults to
#    the default URL for this service (as defined by the <b>url</b>
#    class attribute).

class SoapService:

    def __init__(self, url=None):
        self.__client = HTTPClient(url or self.url)

    ##
    # Calls a remote SOAP method.
    #
    # @param action The SOAP action string.
{'fraction_non_alphanumeric': 0.13433866697363878, 'fraction_numerical': 0.015425348221480372, 'mean_word_length': 2.5738379267791034, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4026820', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2570, 'n_words': 801}