[Python] SOAP & SOAP with attachment

2012-06-07 Per discussione Filadelfo Fiamma
Buongiorno a tutti,

è ormai un certo periodo di tempo che utilizzo "Suds" come client soap per
python, trovandomi molto bene e avendo pochi problemi!
Sarei adesso interessato ad utilizzare SOAP with attachment, mio malgrado
ho scoperto che Suds non supporta, in modo esplicito, quest'estensione.
Non perdendomi d'animo ho trovato una discussione su stackoverflow in cui
si parla proprio di questo problema:

http://stackoverflow.com/questions/6601107/how-to-send-a-file-through-soap-in-python

Un tizio ha scritto una sorta di wrapper in grado di gestire i file
allegati (
https://d-feet.fedorahosted.org/suds/attachment/ticket/350/soap_attachments.2.py
 ).
Facendo una prova, ho da subito riscontrato un problema in merito alla riga
75 del sopracitato link, client.location() non è un metodo valido, ho però
sostituito quest'istruzione con client.options.location, che sembra essere
ciò che si vuole ottenere da quel fantomatico metodo..

In seguito ho testato un servizio di esempio (
http://soapclient.com/xml/soapresponder.wsdl ), non ottenendo errori ma
ottenendo una risposta non attesa: il wsdl stesso..

Chiedo, se qualcuno si è già addentrato in queste problematiche,
gentilmente un piccolo aiuto per capire dove ho sbagliato o meno!

mi permetto di postare di seguito il codice  che ho usato, grazie
anticipatamente a tutti!

#
http://stackoverflow.com/questions/6601107/how-to-send-a-file-through-soap-in-python
import re
import uuid
import mimetypes
from suds.client import Client
def with_soap_attachment(suds_method, attachment_data, *args, **kwargs):
""" Add an attachment to a suds soap request.
attachment_data is assumed to contain a list:
  ( , ,  )
The attachment content is only required list element.
"""

from suds.transport import Request
# Suds doesn't currently support SOAP Attachments, so we have to build
our
# own attachment support, using parts of the suds library
MIME_DEFAULT = 'text/plain'
attachment_transfer_encoding = '8bit'
soap_method = suds_method.method
if len(attachment_data) == 3:
data, attachment_id, attachment_mimetype = attachment_data
elif len(attachment_data) == 2:
data, attachment_id = attachment_data
attachment_mimetype = MIME_DEFAULT
elif len(attachment_data) == 1:
data = attachment_data
attachment_mimetype = MIME_DEFAULT
attachment_id = uuid.uuid4()
# Generate SOAP XML appropriate for this request
soap_client = suds_method.clientclass(kwargs)
binding = soap_method.binding.input
soap_xml = binding.get_message(soap_method, args, kwargs)

# Prepare MIME headers & boundaries
boundary_id = 'uuid:%s' % uuid.uuid4()
root_part_id ='uuid:%s' % uuid.uuid4()
request_headers = {
  'Content-Type': '; '.join([
  'multipart/related',
  'type="text/xml"',
  'start="<%s>"' % root_part_id,
  'boundary="%s"' % boundary_id,
]),
}
soap_headers = '\n'.join([
  'Content-Type: text/xml; charset=UTF-8',
  'Content-Transfer-Encoding: 8bit',
  'Content-Id: <%s>' % root_part_id,
  '',
])
attachment_headers = '\n'.join([
  'Content-Type: %s' % attachment_mimetype,
  'Content-Transfer-Encoding: %s' % attachment_transfer_encoding,
  'Content-Id: <%s>' % attachment_id,
  '',
])
# Build the full request
request_text = '\n'.join([
  '',
  '--%s' % boundary_id,
  soap_headers,
  str(soap_xml),
  '--%s' % boundary_id,
  attachment_headers,
  data,
  '--%s--' % boundary_id
])
# Stuff everything into a request object
headers = suds_method.client.options.headers.copy()
headers.update(request_headers)
request = Request(suds_method.client.options.location, request_text)
#print str(request_text)+''
request.headers = headers
#print str(request.headers)+''
# Send the request
response = suds_method.client.options.transport.send(request)
return response


if __name__ == '__main__':
infile = 'C:/Documents and
Settings/filo/Desktop/test_soap_with_attachment.py'
f = open(infile,'rb')
data_file = f.read().encode("base64")
data_file_type = mimetypes.guess_type(infile)[0]
(filename,ext) = infile.split('.')
 url =  "http://soapclient.com/xml/soapresponder.wsdl";
cl = Client(url,location=url)
 identifier = with_soap_attachment(cl.service.Method1, [data_file, '1',
data_file_type],"ciao","ciao")
 print identifier.message
-- 

FF
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python


Re: [Python] messaggi di errore con le gtk

2012-06-07 Per discussione Matteo Perini

Il 06/06/2012 15:31, Matteo Perini ha scritto:


Credo che il tutto sia dovuto al fatto che l'errore, se c'è, si 
manifesta immediatamente al lancio del programma (e quindi questo non 
arrivi a completarsi).




Ho risolto cambiando l'ordine in cui venivano eseguite delle parti codice.
Grazie comunque.
Ciao
Matteo
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python


[Python] visualizzare immagine su schermo separato

2012-06-07 Per discussione Matteo Perini

Ciao a tutti.
Rieccomi con una nuova richiesta ;-)

Come da oggetto avrei bisogno di visualizzare alcune immagini 
(fullscreen e senza bordi) in sequenza su un secondo monitor.
Attualmente riesco nel mio intento solo su linux richiamando un altro 
software in un ciclo:


subprocess.Popen(['xloadimage','-display',':0.1','-fullscreen','nomefile.png'])

e non ho nessun problema.

Come posso far andare le cose anche su windows??
Qualcuno potrebbe indicarmi qualche libreria python che supporti il 
doppio monitor?

Ho cercato on-line e ho trovato
-wxpython
-tkinter
-pygame
-pyglet
-PIL
ma non ho trovato riferimenti per quanto riguarda il "separate screen"

In alternativa potrei richiamare qualcosa tipo xloadimage però per 
windows (non ho trovato nulla di simile per adesso; qualche idea?)
Sarei anche disposto a scrivermi qualche riga in altri linguaggi ma 
vorrei essere sicuro che il tempo impiegato dia i frutti sperati.

Qualche consiglio?
Grazie
Matteo P

___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python