# Path: src/petmail/database.py
# class DBError(Exception):
# class ObservableDatabase:
# def get_schema(version):
# def serialize(row):
#     def __init__(self, connection):
#     def subscribe(self, table, observer):
#     def unsubscribe(self, table, observer):
#     def execute(self, sql, values=None):
#     def insert(self, sql, values, table=None, tags={}):
#     def update(self, sql, values, table=None, id=None, tags={}):
#     def delete(self, sql, values, table, id, tags={}):
#     def commit(self):
# def get_db(dbfile, stderr=sys.stderr):
# def make_observable_db(dbfile, stderr=sys.stderr):
#     VERSION = 1
# 
# Path: src/petmail/util.py
# def equal(a, b):
#     # not vulnerable to timing attack
#     return hashlib.sha256(a).digest() == hashlib.sha256(b).digest()
# 
# def make_nonce():
#     return base64.b32encode(os.urandom(32)).strip("=").lower()
# 
# Path: src/petmail/errors.py
# class CommandError(Exception):
#     def __init__(self, msg):
#         self.msg = msg


import json, collections
from pkg_resources import resource_string, resource_filename
from twisted.application import service, strports
from twisted.web import server, static, resource, http
from .database import Notice
from .util import equal, make_nonce
from .errors import CommandError
        # this is ignored by clients, but can keep the connection open in the
        # face of firewall/NAT timeouts. It also helps unit tests, since
        # apparently twisted.web.client.Agent doesn't consider the connection
        # to be established until it sees the first byte of the reponse body.
        self.request.write(": %s\n\n" % comment)

    def sendEvent(self, data, name=None, id=None, retry=None):
        if name:
            self.request.write("event: %s\n" % name.encode("utf-8"))
            # e.g. if name=foo, then the client web page should do:
            # (new EventSource(url)).addEventListener("foo", handlerfunc)
            # Note that this basically defaults to "message".
        if id:
            self.request.write("id: %s\n" % id.encode("utf-8"))
        if retry:
            self.request.write("retry: %d\n" % retry) # milliseconds
        for line in data.splitlines():
            self.request.write("data: %s\n" % line.encode("utf-8"))
        self.request.write("\n")

    def stop(self):
        self.request.finish()

# note: no versions of IE (including the current IE11) support EventSource

class EventChannel(resource.Resource):
    def __init__(self, db, agent, dispatcher, esid):
        resource.Resource.__init__(self)
        self.db = db
        self.agent = agent

# Path: src/petmail/database.py
# class DBError(Exception):
# class ObservableDatabase:
# def get_schema(version):
# def serialize(row):
#     def __init__(self, connection):
#     def subscribe(self, table, observer):
#     def unsubscribe(self, table, observer):
#     def execute(self, sql, values=None):
#     def insert(self, sql, values, table=None, tags={}):
#     def update(self, sql, values, table=None, id=None, tags={}):
#     def delete(self, sql, values, table, id, tags={}):
#     def commit(self):
# def get_db(dbfile, stderr=sys.stderr):
# def make_observable_db(dbfile, stderr=sys.stderr):
#     VERSION = 1
# 
# Path: src/petmail/util.py
# def equal(a, b):
#     # not vulnerable to timing attack
#     return hashlib.sha256(a).digest() == hashlib.sha256(b).digest()
# 
# def make_nonce():
#     return base64.b32encode(os.urandom(32)).strip("=").lower()
# 
# Path: src/petmail/errors.py
# class CommandError(Exception):
#     def __init__(self, msg):
#         self.msg = msg


# Path: src/petmail/web.py
import json, collections
from pkg_resources import resource_string, resource_filename
from twisted.application import service, strports
from twisted.web import server, static, resource, http
from .database import Notice
from .util import equal, make_nonce
from .errors import CommandError

        # this is ignored by clients, but can keep the connection open in the
        # face of firewall/NAT timeouts. It also helps unit tests, since
        # apparently twisted.web.client.Agent doesn't consider the connection
        # to be established until it sees the first byte of the reponse body.
        self.request.write(": %s\n\n" % comment)

    def sendEvent(self, data, name=None, id=None, retry=None):
        if name:
            self.request.write("event: %s\n" % name.encode("utf-8"))
            # e.g. if name=foo, then the client web page should do:
            # (new EventSource(url)).addEventListener("foo", handlerfunc)
            # Note that this basically defaults to "message".
        if id:
            self.request.write("id: %s\n" % id.encode("utf-8"))
        if retry:
            self.request.write("retry: %d\n" % retry) # milliseconds
        for line in data.splitlines():
            self.request.write("data: %s\n" % line.encode("utf-8"))
        self.request.write("\n")

    def stop(self):
        self.request.finish()

# note: no versions of IE (including the current IE11) support EventSource

class EventChannel(resource.Resource):
    def __init__(self, db, agent, dispatcher, esid):
        resource.Resource.__init__(self)
        self.db = db
        self.agent = agent

        self.dispatcher = dispatcher