# 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)


import os, sys
import sqlite3
from collections import defaultdict, namedtuple
from pkg_resources import resource_string
from .eventual import eventually

    def subscribe(self, table, observer):
        self.observers[table].append(observer)

    def unsubscribe(self, table, observer):
        self.observers[table].remove(observer)

    # database methods

    def execute(self, sql, values=None):
        if values:
            return self.conn.execute(sql, values)
        return self.conn.execute(sql)

    def insert(self, sql, values, table=None, tags={}):
        new_id = self.conn.execute(sql, values).lastrowid
        if table:
            c = self.conn.execute("SELECT * FROM `%s` WHERE id=?" % table,
                                  (new_id,))
            self.pending_notifications.append(Notice(table, "insert", new_id,
                                                     serialize(c.fetchone()),
                                                     tags))
        return new_id

    def update(self, sql, values, table=None, id=None, tags={}):
        self.conn.execute(sql, values)
        if table:
            c = self.conn.execute("SELECT * FROM `%s` WHERE id=?" % table,
                                  (id,))
            new_value = serialize(c.fetchone())

# 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/database.py
import os, sys
import sqlite3
from collections import defaultdict, namedtuple
from pkg_resources import resource_string
from .eventual import eventually


    def subscribe(self, table, observer):
        self.observers[table].append(observer)

    def unsubscribe(self, table, observer):
        self.observers[table].remove(observer)

    # database methods

    def execute(self, sql, values=None):
        if values:
            return self.conn.execute(sql, values)
        return self.conn.execute(sql)

    def insert(self, sql, values, table=None, tags={}):
        new_id = self.conn.execute(sql, values).lastrowid
        if table:
            c = self.conn.execute("SELECT * FROM `%s` WHERE id=?" % table,
                                  (new_id,))
            self.pending_notifications.append(Notice(table, "insert", new_id,
                                                     serialize(c.fetchone()),
                                                     tags))
        return new_id

    def update(self, sql, values, table=None, id=None, tags={}):
        self.conn.execute(sql, values)
        if table:
            c = self.conn.execute("SELECT * FROM `%s` WHERE id=?" % table,
                                  (id,))
            new_value = serialize(c.fetchone())

            if new_value: