本文整理匯總了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!")
示例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)
示例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!")
示例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()
示例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!")
示例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()
示例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()
示例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
示例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"
示例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)