当前位置: 首页>>代码示例>>Python>>正文


Python client.SimpleXMLElement类代码示例

本文整理汇总了Python中pysimplesoap.client.SimpleXMLElement的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLElement类的具体用法?Python SimpleXMLElement怎么用?Python SimpleXMLElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SimpleXMLElement类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_issue46

    def test_issue46(self):
        """Example for sending an arbitrary header using SimpleXMLElement"""

        # fake connection (just to test xml_request):
        client = SoapClient(
            location="https://localhost:666/",
            namespace='http://localhost/api'
        )

        # Using WSDL, the equivalent is:
        # client['MyTestHeader'] = {'username': 'test', 'password': 'test'}

        headers = SimpleXMLElement("<Headers/>")
        my_test_header = headers.add_child("MyTestHeader")
        my_test_header['xmlns'] = "service"
        my_test_header.marshall('username', 'test')
        my_test_header.marshall('password', 'password')

        try:
            client.methodname(headers=headers)
        except:
            open("issue46.xml", "wb").write(client.xml_request)
            self.assert_('<soap:Header><MyTestHeader xmlns="service">'
                            '<username>test</username>'
                            '<password>password</password>'
                         '</MyTestHeader></soap:Header>' in client.xml_request.decode(),
                         "header not in request!")
开发者ID:smartylab,项目名称:pysimplesoap,代码行数:27,代码来源:issues_test.py

示例2: test_issue69

 def test_issue69(self):
     """Boolean value not converted correctly during marshall"""
     span = SimpleXMLElement('<span><name>foo</name></span>')
     span.marshall('value', True)
     d = {'span': {'name': str, 'value': bool}}
     e = {'span': {'name': 'foo', 'value': True}}
     self.assertEqual(span.unmarshall(d), e)
开发者ID:smartylab,项目名称:pysimplesoap,代码行数:7,代码来源:issues_test.py

示例3: test_issue78

    def test_issue78(self):
        "Example for sending an arbitrary header using SimpleXMLElement and WSDL"
        
        # fake connection (just to test xml_request):
        client = SoapClient(wsdl='http://dczorgwelzijn-test.qmark.nl/qmwise4/qmwise.asmx?wsdl')

        # Using WSDL, the easier form is but this doesn't allow for namespaces to be used.
        # If the server requires these (buggy server?) the dictionary method won't work
        # and marshall will not marshall 'ns:username' style keys
        # client['MyTestHeader'] = {'username': 'test', 'password': 'test'}

        namespace = 'http://questionmark.com/QMWISe/'
        ns = 'qmw'
        header = SimpleXMLElement('<Headers/>', namespace=namespace, prefix=ns)
        security = header.add_child("Security")
        security['xmlns:qmw']=namespace
        security.marshall('ClientID','NAME',ns=ns)
        security.marshall('Checksum','PASSWORD',ns=ns)
        client['Security']=security

        try:
            client.GetParticipantList()
        except:
            #open("issue78.xml", "wb").write(client.xml_request)
            print client.xml_request
            header="""<soap:Header><qmw:Security xmlns:qmw="http://questionmark.com/QMWISe/"><qmw:ClientID>NAME</qmw:ClientID><qmw:Checksum>PASSWORD</qmw:Checksum></qmw:Security></soap:Header>"""
            self.assert_(header in client.xml_request, "header not in request!")
开发者ID:KongJustin,项目名称:pysimplesoap,代码行数:27,代码来源:issues_tests.py

示例4: getClient

def getClient(codeClient):
    client = SoapClient(location="http://aboweb.com/aboweb/ClientService?wsdl",trace=False)
    client['wsse:Security'] = {
           'wsse:UsernameToken': {
                'wsse:Username': '[email protected]',
                'wsse:Password': 'pYsIJKF18hj0SvS3TwrQV3hWzD4=',
                # 'wsse:Password': 'tRPTUOP+QQYzVcxYZeQXsiTJ+dw=',
                }
            }
    params = SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><ges:getClient xmlns:ges="http://www.gesmag.com/"><codeClient>'+codeClient+'</codeClient></ges:getClient>');
    result = client.call("getClient",params)
    xml = SimpleXMLElement(client.xml_response)
    return xml.children().children().children()
开发者ID:patsykakaz,项目名称:PNP,代码行数:13,代码来源:webservices.py

示例5: test_issue47_raw

    def test_issue47_raw(self):
        "Same example (clarizen), with raw headers (no wsdl)!"
        client = SoapClient(location="https://api.clarizen.com/v1.0/Clarizen.svc", namespace='http://clarizen.com/api', trace=False)
            
        headers = SimpleXMLElement("<Headers/>", namespace="http://clarizen.com/api", prefix="ns1")
        session = headers.add_child("Session")
        session['xmlns'] = "http://clarizen.com/api"
        session.marshall('ID', '1234')

        client.location = "https://api.clarizen.com/v1.0/Clarizen.svc"
        client.action = "http://clarizen.com/api/IClarizen/Logout"
        try:
            client.call("Logout", headers=headers)
        except:
            open("issue47_raw.xml", "wb").write(client.xml_request)
            self.assert_("""<soap:Header><ns1:Session xmlns="http://clarizen.com/api"><ID>1234</ID></ns1:Session></soap:Header>""" in client.xml_request,
                        "Session header not in request!")
开发者ID:KongJustin,项目名称:pysimplesoap,代码行数:17,代码来源:issues_tests.py

示例6: create_tra

def create_tra(service=SERVICE,ttl=2400):
    "Crear un Ticket de Requerimiento de Acceso (TRA)"
    tra = SimpleXMLElement(
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<loginTicketRequest version="1.0">'
        '</loginTicketRequest>')
    tra.add_child('header')
    # El source es opcional. Si falta, toma la firma (recomendado).
    #tra.header.addChild('source','subject=...')
    #tra.header.addChild('destination','cn=wsaahomo,o=afip,c=ar,serialNumber=CUIT 33693450239')
    tra.header.add_child('uniqueId',str(date('U')))
    tra.header.add_child('generationTime',str(date('c',date('U')-ttl)))
    tra.header.add_child('expirationTime',str(date('c',date('U')+ttl)))
    tra.add_child('service',service)
    return tra.as_xml()
开发者ID:AndresVillan,项目名称:pyafipws,代码行数:15,代码来源:wsaa.py

示例7: create_tra

def create_tra(service=None, ttl=2400, cert=None):
    "Create a Access Request Ticket (TRA)"
    # Base TRA squeleton (Ticket de Requerimiento de Acceso)
    tra = SimpleXMLElement(
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<loginTicketRequest version="1.0">'
        '</loginTicketRequest>')
    tra.add_child('header')
    # get the source from the certificate subject, ie "CN=empresa, O=dna, C=py"
    if cert:
        crt = xmlsec.x509_parse_cert(cert)
        tra.header.add_child('source', crt.get_subject().as_text())
    tra.header.add_child('destination', 'C=py, O=dna, OU=sofia, CN=wsaatest')
    d = int(time.mktime(datetime.datetime.now().timetuple()))
    tra.header.add_child('uniqueId', str(d))
    date = lambda ts: datetime.datetime.fromtimestamp(ts).isoformat()
    tra.header.add_child('generationTime', str(date(d-ttl)))
    tra.header.add_child('expirationTime', str(date(d+ttl)))
    tra.add_child('service', service)
    return tra.as_xml()
开发者ID:AmineCherrai,项目名称:pysimplesoap,代码行数:20,代码来源:wsaa_py.py

示例8: crudas

xmlsec.lxml = None                  # deshabilitar lxml y usar c14n.py

# Por el momento se utilizan llamadas crudas (RAW) y no se parsea el WSDL
##client = SoapClient(wsdl=wsdl, cache="cache")

# Instancio el cliente para consumir el webservice
client = SoapClient(LOCATION, ACTION,
                    namespace="DGI_Modernizacion_Consolidado", 
                    ns="dgi", 
                    soap_ns="soapenv", trace=True)

# si se usa el WSDL, se puede consultar client.help("EFACRECEPCIONSOBRE")

# construir los parámetros de la llamada al webservice (requerimiento):
param = SimpleXMLElement(
    """<dgi:WS_PersonaGetActEmpresarial.Execute xmlns:dgi="DGI_Modernizacion_Consolidado" />""", 
    namespace="DGI_Modernizacion_Consolidado", prefix="dgi")
rut = param.add_child("Rut", "210475730011", ns=True)

# agregar seguridad WSSE (mensaje firmado digitalmente para autenticacion)
#     usar el certificado unico asociado al RUT emisor emitidos por la 
#     Administración Nacional de Correos (CA: autoridad certificadora actual)

plugin = BinaryTokenSignature(certificate="certificado.crt",
                              private_key="private.key", 
                              password=None,
                              cacert="CorreoUruguayoCA.crt",
                              )
client.plugins += [plugin]

# llamar al método remoto
开发者ID:emezeta,项目名称:py_efactura_uy,代码行数:31,代码来源:consulta_rut.py

示例9: SoapClient

# Instancio el cliente para consumir el webservice
client = SoapClient(LOCATION, ACTION,
                    namespace="http://dgi.gub.uy", 
                    ns="dgi", 
                    soap_ns="soapenv", trace=True)

# si se usa el WSDL, se puede consultar client.help("EFACRECEPCIONSOBRE")

# Procedimiento tentativo:
# ========================

# leer los datos del comprobante
# NOTA: se podría usar más SimpleXMLElement para armar el xml pythonicamente

cfe = SimpleXMLElement(open("dgicfe_uy.xml").read())
caratula = cfe("DGICFE:Caratula")

# establecer la fecha actual
setattr(caratula, "DGICFE:Fecha", 
                  datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S-03:00"))#utcnow().strftime("%Y-%m-%dT%H:%M:%S"))

# leer el certificado (PEM) del emisor y agregarlo 
cert_lines = open("certificado.crt").readlines()
cert_pem =  ''.join([line for line in cert_lines
                          if not line.startswith("---")])
setattr(caratula, "DGICFE:X509Certificate", cert_pem)

# preparar la plantilla para la info de firma con los namespaces padres (CFE)
plantilla = SimpleXMLElement(xmlsec.SIGN_ENV_TMPL)
plantilla["xmlns:DGICFE"] = plantilla["xmlns:ns0"] = "http://cfe.dgi.gub.uy"
开发者ID:emezeta,项目名称:py_efactura_uy,代码行数:30,代码来源:prueba.py

示例10: open

import xml.dom.minidom
from pysimplesoap.client import SoapClient, SimpleXMLElement
from pysimplesoap.wsse import BinaryTokenSignature
from pysimplesoap import xmlsec


fechacfe = lambda *x: datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S-03:00")

LOCATION = "https://efactura.dgi.gub.uy:6443/ePrueba/ws_eprueba?wsdl"
ACTION = "http://dgi.gub.uyaction/"


with open("documento.xml") as f:
    dataCFE = f.read()

cfe = SimpleXMLElement(dataCFE)

caratula = cfe("DGICFE:Caratula")
setattr(caratula, "DGICFE:Fecha", fechacfe())


# leer el certificado (PEM) del emisor y agregarlo
cert_lines = open("certificado.crt").readlines()
cert_fmt = [line for line in cert_lines if not line.startswith("---")]
cert_pem =  ''.join(cert_fmt)
setattr(caratula, "DGICFE:X509Certificate", cert_pem)


cfeXML = cfe("ns0:CFE")

# preparar la plantilla para la info de firma con los namespaces padres (CFE)
开发者ID:emezeta,项目名称:py_efactura_uy,代码行数:31,代码来源:prueba_simple.py


注:本文中的pysimplesoap.client.SimpleXMLElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。