# Path: ermesms/lib/singletonmixin.py
# class Singleton(object):
#     __metaclass__ = MetaSingleton
# 
#     def getInstance(cls, *lstArgs):
#         """
#         Call this to instantiate an instance or retrieve the existing instance.
#         If the singleton requires args to be instantiated, include them the first
#         time you call getInstance.
#         """
#         if cls._isInstantiated():
#             if len(lstArgs) != 0:
#                 raise SingletonException, 'If no supplied args, singleton must already be instantiated, or __init__ must require no args'
#         else:
#             if cls._getConstructionArgCountNotCountingSelf() > 0 and len(lstArgs) <= 0:
#                 raise SingletonException, 'If the singleton requires __init__ args, supply them on first instantiation'
#             instance = cls.__new__(cls)
#             instance.__init__(*lstArgs)
#             cls.cInstance = instance
#         return cls.cInstance
#     getInstance = classmethod(getInstance)
# 
#     def _isInstantiated(cls):
#         return hasattr(cls, 'cInstance')
#     _isInstantiated = classmethod(_isInstantiated)
# 
#     def _getConstructionArgCountNotCountingSelf(cls):
#         try:
#             return cls.__init__.im_func.func_code.co_argcount - 1
#         except AttributeError:
#             return 0
#     _getConstructionArgCountNotCountingSelf = classmethod(_getConstructionArgCountNotCountingSelf)
# 
#     def _forgetClassInstanceReferenceForTesting(cls):
#         """
#         This is designed for convenience in testing -- sometimes you
#         want to get rid of a singleton during test code to see what
#         happens when you call getInstance() under a new situation.
# 
#         To really delete the object, all external references to it
#         also need to be deleted.
#         """
#         try:
#             delattr(cls,'cInstance')
#         except AttributeError:
#             # run up the chain of base classes until we find the one that has the instance
#             # and then delete it there
#             for baseClass in cls.__bases__:
#                 if issubclass(baseClass, Singleton):
#                     baseClass._forgetClassInstanceReferenceForTesting()
#     _forgetClassInstanceReferenceForTesting = classmethod(_forgetClassInstanceReferenceForTesting)
# 
# Path: ermesms/errors/StopError.py
# class StopError(Exception):
#     """Indica l'interruzione di invio da parte dell'utente"""
# 
#     def __init__(self):
#         """Costruttore standard."""
#         Exception.__init__(self)
# 
#     def __str__(self):
#         return u"Invio interrotto per richiesta dell'utente"


import re
import time
import pycurl
from cStringIO import StringIO
from ermesms.lib.singletonmixin import Singleton
from ermesms.errors.StopError import StopError
        if arg1 == pycurl.INFOTYPE_DATA_IN: debugData = 'DataIn'
        if arg1 == pycurl.INFOTYPE_DATA_OUT: debugData = 'DataOut'
        if arg1 == pycurl.INFOTYPE_TEXT: debugData = 'Text'
        if arg1 == pycurl.INFOTYPE_HEADER_IN: debugData = 'HeaderIn'
        if arg1 == pycurl.INFOTYPE_HEADER_OUT: debugData = 'HeaderOut'
        if arg1 == pycurl.INFOTYPE_SSL_DATA_IN: debugData = 'SSLIn'
        if arg1 == pycurl.INFOTYPE_SSL_DATA_OUT: debugData = 'SSLOut'
        if not self.debugDataOld == debugData:
            if self.debugDataOld: fdebug.write('\n</'+self.debugDataOld+'>\n')
            fdebug.write('<'+debugData+'>\n')
            self.debugDataOld = debugData
        fdebug.write(arg2)
        fdebug.close()

    def ePerform(self, stop = None, saver = None):
        """Funzione che sostituisce il normale perform per permettere lo
        stop dell'invio e salvare i dati in debug mode"""
        if stop: raise StopError()
        if self.debug == 'On':
            self.curl.setopt(pycurl.VERBOSE, 1)
            self.curl.setopt(pycurl.DEBUGFUNCTION, self.debugFunction)
        else:
            self.curl.setopt(pycurl.VERBOSE, 0)
        if not saver and self.debug == 'On':
            saver = StringIO()
            saverwrite = saver.write
        elif not saver and not self.debug: saverwrite = self.doNothing
        else: saverwrite = saver.write
        self.curl.setopt(pycurl.WRITEFUNCTION, saverwrite)
        self.curl.perform()

# Path: ermesms/lib/singletonmixin.py
# class Singleton(object):
#     __metaclass__ = MetaSingleton
# 
#     def getInstance(cls, *lstArgs):
#         """
#         Call this to instantiate an instance or retrieve the existing instance.
#         If the singleton requires args to be instantiated, include them the first
#         time you call getInstance.
#         """
#         if cls._isInstantiated():
#             if len(lstArgs) != 0:
#                 raise SingletonException, 'If no supplied args, singleton must already be instantiated, or __init__ must require no args'
#         else:
#             if cls._getConstructionArgCountNotCountingSelf() > 0 and len(lstArgs) <= 0:
#                 raise SingletonException, 'If the singleton requires __init__ args, supply them on first instantiation'
#             instance = cls.__new__(cls)
#             instance.__init__(*lstArgs)
#             cls.cInstance = instance
#         return cls.cInstance
#     getInstance = classmethod(getInstance)
# 
#     def _isInstantiated(cls):
#         return hasattr(cls, 'cInstance')
#     _isInstantiated = classmethod(_isInstantiated)
# 
#     def _getConstructionArgCountNotCountingSelf(cls):
#         try:
#             return cls.__init__.im_func.func_code.co_argcount - 1
#         except AttributeError:
#             return 0
#     _getConstructionArgCountNotCountingSelf = classmethod(_getConstructionArgCountNotCountingSelf)
# 
#     def _forgetClassInstanceReferenceForTesting(cls):
#         """
#         This is designed for convenience in testing -- sometimes you
#         want to get rid of a singleton during test code to see what
#         happens when you call getInstance() under a new situation.
# 
#         To really delete the object, all external references to it
#         also need to be deleted.
#         """
#         try:
#             delattr(cls,'cInstance')
#         except AttributeError:
#             # run up the chain of base classes until we find the one that has the instance
#             # and then delete it there
#             for baseClass in cls.__bases__:
#                 if issubclass(baseClass, Singleton):
#                     baseClass._forgetClassInstanceReferenceForTesting()
#     _forgetClassInstanceReferenceForTesting = classmethod(_forgetClassInstanceReferenceForTesting)
# 
# Path: ermesms/errors/StopError.py
# class StopError(Exception):
#     """Indica l'interruzione di invio da parte dell'utente"""
# 
#     def __init__(self):
#         """Costruttore standard."""
#         Exception.__init__(self)
# 
#     def __str__(self):
#         return u"Invio interrotto per richiesta dell'utente"


# Path: ermesms/ConnectionManager.py
import re
import time
import pycurl
from cStringIO import StringIO
from ermesms.lib.singletonmixin import Singleton
from ermesms.errors.StopError import StopError

        if arg1 == pycurl.INFOTYPE_DATA_IN: debugData = 'DataIn'
        if arg1 == pycurl.INFOTYPE_DATA_OUT: debugData = 'DataOut'
        if arg1 == pycurl.INFOTYPE_TEXT: debugData = 'Text'
        if arg1 == pycurl.INFOTYPE_HEADER_IN: debugData = 'HeaderIn'
        if arg1 == pycurl.INFOTYPE_HEADER_OUT: debugData = 'HeaderOut'
        if arg1 == pycurl.INFOTYPE_SSL_DATA_IN: debugData = 'SSLIn'
        if arg1 == pycurl.INFOTYPE_SSL_DATA_OUT: debugData = 'SSLOut'
        if not self.debugDataOld == debugData:
            if self.debugDataOld: fdebug.write('\n</'+self.debugDataOld+'>\n')
            fdebug.write('<'+debugData+'>\n')
            self.debugDataOld = debugData
        fdebug.write(arg2)
        fdebug.close()

    def ePerform(self, stop = None, saver = None):
        """Funzione che sostituisce il normale perform per permettere lo
        stop dell'invio e salvare i dati in debug mode"""
        if stop: raise StopError()
        if self.debug == 'On':
            self.curl.setopt(pycurl.VERBOSE, 1)
            self.curl.setopt(pycurl.DEBUGFUNCTION, self.debugFunction)
        else:
            self.curl.setopt(pycurl.VERBOSE, 0)
        if not saver and self.debug == 'On':
            saver = StringIO()
            saverwrite = saver.write
        elif not saver and not self.debug: saverwrite = self.doNothing
        else: saverwrite = saver.write
        self.curl.setopt(pycurl.WRITEFUNCTION, saverwrite)
        self.curl.perform()

        if self.debug == 'On':