當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleXMLElement.add_child方法代碼示例

本文整理匯總了Python中pysimplesoap.client.SimpleXMLElement.add_child方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleXMLElement.add_child方法的具體用法?Python SimpleXMLElement.add_child怎麽用?Python SimpleXMLElement.add_child使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pysimplesoap.client.SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement.add_child方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_tra

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
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,代碼行數:17,代碼來源:wsaa.py

示例2: test_issue46

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
    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,代碼行數:29,代碼來源:issues_test.py

示例3: test_issue78

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
    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,代碼行數:29,代碼來源:issues_tests.py

示例4: create_tra

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
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,代碼行數:22,代碼來源:wsaa_py.py

示例5: test_issue47_raw

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
    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,代碼行數:19,代碼來源:issues_tests.py

示例6: crudas

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
# 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
ret = client.call("AWS_PERSONAGETACTEMPRESARIAL.Execute", param)
開發者ID:emezeta,項目名稱:py_efactura_uy,代碼行數:32,代碼來源:consulta_rut.py

示例7: cfe

# 需要導入模塊: from pysimplesoap.client import SimpleXMLElement [as 別名]
# 或者: from pysimplesoap.client.SimpleXMLElement import add_child [as 別名]
firma_xml = (xmlsec.SIGNATURE_TMPL % vars)
cfe("ns0:CFE").import_node(SimpleXMLElement(firma_xml))

# guardo el xml firmado para depuración
open("test.xml", "w").write(cfe.as_xml())
print cfe.as_xml()

# serializar CDATA según el ejemplo
cdata = xml.dom.minidom.CDATASection()
cdata.data = cfe.as_xml()

# construir los parámetros de la llamada al webservice (requerimiento):
param = SimpleXMLElement(
    """<dgi:WS_eFactura.EFACRECEPCIONSOBRE xmlns:dgi="http://dgi.gub.uy"/>""", 
    namespace="http://dgi.gub.uy", prefix="dgi")
data_in = param.add_child("Datain", ns=True)
data_in.add_child("xmlData", cdata, 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
ret = client.call("AWS_EFACTURA.EFACRECEPCIONSOBRE", param)
開發者ID:emezeta,項目名稱:py_efactura_uy,代碼行數:33,代碼來源:prueba.py


注:本文中的pysimplesoap.client.SimpleXMLElement.add_child方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。