Source code for poste

# coding: utf-8

"""
Abstract
========

A module to send ``raccomandate``, ``telegrammi`` and ``letters``
throught Italian Mail Service poste-online_.

A simple and tipical example could be as simple as::

    # Create a client for each type of letter
    xol = poste.ROLClient(username=USERNAME, password=PASSWORD)

    # Create a recipient and a Sender
    destinatario = poste.Destinatario(**self.addr)
    mittente = poste.Mittente(**MITTENTE)

    # send a document and confirm
    xol_submit = xol.invia('mydocument.pdf', destinatario, mittente)
    result = xol.conferma(xol_submit=self.xol_submit, autoconfirm=True)

Three different clients are available:

* :class:`poste.ROLClient`: client to send ``raccomandate``

* :class:`poste.LOLClient`: client to send letters

* :class:`poste.TOLClient`: client to send telegrams

Test :class:`poste.xol.ROLSubmit`

API
====

All of these clients accept

.. autoclass:: poste.ROLClient
   :members:

.. autoclass:: poste.LOLClient
   :members:

.. autoclass:: poste.TOLClient
   :members:

.. automodule:: poste.xol
   :members:

.. _poste-online: http://www.posta-online.it

"""
import logging

from poste.tol import *
from poste.xol import *
from poste.webservice import *
from utils import *

[docs]class PosteSoapClientError(Exception): def __init__(self, result): super(PosteSoapClientError, self).__init__() try: self.servizio_enquiry = result.ServizioEnquiryResponse except: pass self.ceresult = result.CEResult self.cer_code = self.ceresult._Code self.cer_type = self.ceresult._Type self.cer_description = self.ceresult._Description def __str__(self): return self.cer_description
[docs]class ValidationError(Exception): def __init__(self, msg, obj=None): ## repr รจ necessario nel caso il testo abbia delle lettere accentate super(ValidationError, self).__init__(repr(msg)) self.obj = obj
[docs]class RemoteValidationError(ValidationError): def __init__(self, result, id_richiesta): """ :param result: remote result :param id_richiesta: id_richiesta """ super(Exception, self).__init__() self.id_richiesta = id_richiesta try: self.servizio_enquiry = result.ServizioEnquiryResponse except: pass self.ceresult = result.CEResult self.cer_code = self.ceresult._Code self.cer_type = self.ceresult._Type try: self.cer_description = result.ServizioEnquiryResponse[0].StatoLavorazione._Descrizione except: self.cer_description = self.ceresult._Description def __str__(self): return self.cer_description
[docs]class RecipientValidationError(ValidationError): pass
[docs]class RemoteRecipientValidationError(RemoteValidationError): pass
def debug(active=False, filename =None): """activate eactivate debug. Very basic aimed at silencing suds Warn: You may be better off configuring it by yourself :param active: boolean :param filename: filename where to log suds """ if filename: logging.basicConfig(filename=filename, level=logging.DEBUG) if active: logging.basicConfig(level=logging.DEBUG) logging.getLogger('suds.client').setLevel(logging.DEBUG) logging.getLogger('suds.transport').setLevel(logging.DEBUG) # MUST BE THIS? logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG) logging.getLogger('suds.wsdl').setLevel(logging.DEBUG) logging.getLogger('suds.resolver').setLevel(logging.DEBUG) logging.getLogger('suds.xsd.query').setLevel(logging.DEBUG) logging.getLogger('suds.xsd.basic').setLevel(logging.DEBUG) logging.getLogger('suds.binding.marshaller').setLevel(logging.DEBUG) else: logging.basicConfig(level=logging.ERROR) logging.getLogger('suds').setLevel(logging.ERROR) logging.getLogger('suds.client').setLevel(logging.ERROR) logging.getLogger('suds.transport').setLevel(logging.ERROR) # MUST BE THIS? logging.getLogger('suds.xsd.schema').setLevel(logging.ERROR) logging.getLogger('suds.wsdl').setLevel(logging.ERROR) logging.getLogger('suds.resolver').setLevel(logging.ERROR) logging.getLogger('suds.xsd.query').setLevel(logging.ERROR) logging.getLogger('suds.xsd.basic').setLevel(logging.ERROR) logging.getLogger('suds.binding.marshaller').setLevel(logging.ERROR)