Exemplo n.º 1
0
def test_dc_close_events(tmpdir):
    ctx = ffi.gc(
        capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    evlog = EventLogger(ctx)
    evlog.set_timeout(5)
    set_context_callback(
        ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
    p = tmpdir.join("hello.db")
    lib.dc_open(ctx, p.strpath.encode("ascii"), ffi.NULL)
    capi.lib.dc_close(ctx)

    def find(info_string):
        while 1:
            ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
            data2 = ev[2]
            if info_string in data2:
                return
            else:
                print("skipping event", *ev)

    find("disconnecting inbox-thread")
    find("disconnecting sentbox-thread")
    find("disconnecting mvbox-thread")
    find("disconnecting SMTP")
    find("Database closed")
Exemplo n.º 2
0
    def __init__(self, db_path, logid=None, eventlogging=True):
        """ initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param logid: an optional logging prefix that should be used with
                      the default internal logging.
        :param eventlogging: if False no eventlogging and no context callback will be configured
        """
        self._dc_context = ffi.gc(
            lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
            _destroy_dc_context,
        )
        if eventlogging:
            self._evlogger = EventLogger(self._dc_context, logid)
            deltachat.set_context_callback(self._dc_context, self._process_event)
            self._threads = IOThreads(self._dc_context, self._evlogger._log_event)
        else:
            self._threads = IOThreads(self._dc_context)

        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")
        if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
            raise ValueError("Could not dc_open: {}".format(db_path))
        self._configkeys = self.get_config("sys.config_keys").split()
        self._imex_completed = threading.Event()
Exemplo n.º 3
0
def dc_account_init(account):
    # send all FFI events for this account to a plugin hook
    def _ll_event(ctx, evt_name, data1, data2):
        assert ctx == account._dc_context
        ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
        account._pm.hook.ac_process_ffi_event(account=account,
                                              ffi_event=ffi_event)

    deltachat.set_context_callback(account._dc_context, _ll_event)
Exemplo n.º 4
0
    def __init__(self, db_path, logid=None):
        """ initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param logid: an optional logging prefix that should be used with
                      the default internal logging.
        """
        self._dc_context = ffi.gc(
            lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
            _destroy_dc_context,
        )
        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")
        if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
            raise ValueError("Could not dc_open: {}".format(db_path))
        self._evhandler = EventHandler(self._dc_context)
        self._evlogger = EventLogger(self._dc_context, logid)
        deltachat.set_context_callback(self._dc_context, self._process_event)
        self._threads = IOThreads(self._dc_context)
Exemplo n.º 5
0
    def __init__(self, db_path, logid=None):
        """ initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param logid: an optional logging prefix that should be used with
                      the default internal logging.
        """
        self._dc_context = ffi.gc(
            lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
            _destroy_dc_context,
        )
        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")
        if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
            raise ValueError("Could not dc_open: {}".format(db_path))
        self._evhandler = EventHandler(self._dc_context)
        self._evlogger = EventLogger(self._dc_context, logid)
        deltachat.set_context_callback(self._dc_context, self._process_event)
        self._threads = IOThreads(self._dc_context)
        self._configkeys = self.get_config("sys.config_keys").split()
def test_dc_close_events():
    ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL)
    evlog = EventLogger(ctx)
    evlog.set_timeout(5)
    set_context_callback(
        ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
    capi.lib.dc_close(ctx)

    def find(info_string):
        while 1:
            ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
            data2 = ev[2]
            if info_string in data2:
                return
            else:
                print("skipping event", *ev)

    find("disconnecting INBOX-watch")
    find("disconnecting sentbox-thread")
    find("disconnecting mvbox-thread")
    find("disconnecting SMTP")
    find("Database closed")
Exemplo n.º 7
0
    def __init__(self, db_path, logid=None, os_name=None, debug=True):
        """ initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param logid: an optional logging prefix that should be used with
                      the default internal logging.
        :param os_name: this will be put to the X-Mailer header in outgoing messages
        :param debug: turn on debug logging for events.
        """
        self._dc_context = ffi.gc(
            lib.dc_context_new(lib.py_dc_callback, ffi.NULL,
                               as_dc_charpointer(os_name)),
            _destroy_dc_context,
        )
        self._evlogger = EventLogger(self, logid, debug)
        self._threads = IOThreads(self._dc_context, self._evlogger._log_event)

        # register event call back and initialize plugin system
        def _ll_event(ctx, evt_name, data1, data2):
            assert ctx == self._dc_context
            self.pluggy.hook.process_low_level_event(account=self,
                                                     event_name=evt_name,
                                                     data1=data1,
                                                     data2=data2)

        self.pluggy = get_plugin_manager()
        self.pluggy.register(self._evlogger)
        deltachat.set_context_callback(self._dc_context, _ll_event)

        # open database
        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")
        if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
            raise ValueError("Could not dc_open: {}".format(db_path))
        self._configkeys = self.get_config("sys.config_keys").split()
        atexit.register(self.shutdown)
Exemplo n.º 8
0
    def __init__(self,
                 db_path,
                 logid=None,
                 eventlogging=True,
                 os_name=None,
                 debug=True):
        """ initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param logid: an optional logging prefix that should be used with
                      the default internal logging.
        :param eventlogging: if False no eventlogging and no context callback will be configured
        :param os_name: this will be put to the X-Mailer header in outgoing messages
        :param debug: turn on debug logging for events.
        """
        self._dc_context = ffi.gc(
            lib.dc_context_new(lib.py_dc_callback, ffi.NULL,
                               as_dc_charpointer(os_name)),
            _destroy_dc_context,
        )
        if eventlogging:
            self._evlogger = EventLogger(self._dc_context, logid, debug)
            deltachat.set_context_callback(self._dc_context,
                                           self._process_event)
            self._threads = IOThreads(self._dc_context,
                                      self._evlogger._log_event)
        else:
            self._threads = IOThreads(self._dc_context)

        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")
        if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
            raise ValueError("Could not dc_open: {}".format(db_path))
        self._configkeys = self.get_config("sys.config_keys").split()
        self._imex_events = Queue()
        atexit.register(self.shutdown)
Exemplo n.º 9
0
def test_callback_None2int():
    ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL)
    set_context_callback(ctx, lambda *args: None)
    capi.lib.dc_close(ctx)
    clear_context_callback(ctx)