# Path: src/petmail/eventual.py
# def eventually(cb, *args, **kwargs):
#     """This is the eventual-send operation, used as a plan-coordination
#     primitive. The callable will be invoked (with args and kwargs) in a later
#     reactor turn. Doing 'eventually(a); eventually(b)' guarantees that a will
#     be called before b.
# 
#     Any exceptions that occur in the callable will be logged with log.err().
#     If you really want to ignore them, be sure to provide a callable that
#     catches those exceptions.
# 
#     This function returns None. If you care to know when the callable was
#     run, be sure to provide a callable that notifies somebody.
#     """
#     _theSimpleQueue.append(cb, args, kwargs)


from twisted.python import log, failure
from twisted.internet import reactor, defer, protocol
from twisted.application import service
from twisted.protocols import basic
from twisted.web.client import Agent, ResponseDone
from twisted.web.http_headers import Headers
from .eventual import eventually
        self.res._stop_eventsource()

class ReconnectingEventSource(service.MultiService,
                              protocol.ReconnectingClientFactory):
    def __init__(self, baseurl, connection_starting, handler):
        service.MultiService.__init__(self)
        # we don't use any of the basic Factory/ClientFactory methods of
        # this, just the ReconnectingClientFactory.retry, stopTrying, and
        # resetDelay methods.

        self.baseurl = baseurl
        self.connection_starting = connection_starting
        self.handler = handler
        # IService provides self.running, toggled by {start,stop}Service.
        # self.active is toggled by {,de}activate. If both .running and
        # .active are True, then we want to have an outstanding EventSource
        # and will start one if necessary. If either is False, then we don't
        # want one to be outstanding, and will initiate shutdown.
        self.active = False
        self.connector = Connector(self)
        self.es = None # set we have an outstanding EventSource
        self.when_stopped = [] # list of Deferreds

    def isStopped(self):
        return not self.es

    def startService(self):
        service.MultiService.startService(self) # sets self.running
        self._maybeStart()


# Path: src/petmail/eventual.py
# def eventually(cb, *args, **kwargs):
#     """This is the eventual-send operation, used as a plan-coordination
#     primitive. The callable will be invoked (with args and kwargs) in a later
#     reactor turn. Doing 'eventually(a); eventually(b)' guarantees that a will
#     be called before b.
# 
#     Any exceptions that occur in the callable will be logged with log.err().
#     If you really want to ignore them, be sure to provide a callable that
#     catches those exceptions.
# 
#     This function returns None. If you care to know when the callable was
#     run, be sure to provide a callable that notifies somebody.
#     """
#     _theSimpleQueue.append(cb, args, kwargs)


# Path: src/petmail/eventsource.py
from twisted.python import log, failure
from twisted.internet import reactor, defer, protocol
from twisted.application import service
from twisted.protocols import basic
from twisted.web.client import Agent, ResponseDone
from twisted.web.http_headers import Headers
from .eventual import eventually

        self.res._stop_eventsource()

class ReconnectingEventSource(service.MultiService,
                              protocol.ReconnectingClientFactory):
    def __init__(self, baseurl, connection_starting, handler):
        service.MultiService.__init__(self)
        # we don't use any of the basic Factory/ClientFactory methods of
        # this, just the ReconnectingClientFactory.retry, stopTrying, and
        # resetDelay methods.

        self.baseurl = baseurl
        self.connection_starting = connection_starting
        self.handler = handler
        # IService provides self.running, toggled by {start,stop}Service.
        # self.active is toggled by {,de}activate. If both .running and
        # .active are True, then we want to have an outstanding EventSource
        # and will start one if necessary. If either is False, then we don't
        # want one to be outstanding, and will initiate shutdown.
        self.active = False
        self.connector = Connector(self)
        self.es = None # set we have an outstanding EventSource
        self.when_stopped = [] # list of Deferreds

    def isStopped(self):
        return not self.es

    def startService(self):
        service.MultiService.startService(self) # sets self.running
        self._maybeStart()


    def stopService(self):