# Path: pydal/_compat.py
# PY2 = sys.version_info[0] == 2
#     def implements_bool(cls):
#     def implements_iterator(cls):
#     def to_bytes(obj, charset="utf-8", errors="strict"):
#     def to_native(obj, charset="utf8", errors="strict"):
#     def to_bytes(obj, charset="utf-8", errors="strict"):
#     def to_native(obj, charset="utf8", errors="strict"):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
# def to_unicode(obj, charset="utf-8", errors="strict"):
#     class metaclass(meta):
# 
# Path: pydal/helpers/serializers.py
# class Serializers(object):
#     def _json_parse(self, o):
#     def __getattr__(self, name):
#     def json(self, value):
#     def yaml(self, value):


import copy
import marshal
import struct
import threading
import time
import traceback
            import types
from .._compat import (
    PY2,
    exists,
    copyreg,
    implements_bool,
    iterkeys,
    itervalues,
    iteritems,
    to_bytes,
    long,
)
from .._globals import THREAD_LOCAL
from .serializers import serializers
    @staticmethod
    def try_create_web2py_filesystem(db):
        if db._uri not in DatabaseStoredFile.web2py_filesystems:
            if db._adapter.dbengine not in ("mysql", "postgres", "sqlite"):
                raise NotImplementedError(
                    "DatabaseStoredFile only supported by mysql, potresql, sqlite"
                )
            sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content BLOB, PRIMARY KEY(path));"
            if db._adapter.dbengine == "mysql":
                sql = sql[:-1] + " ENGINE=InnoDB;"
            db.executesql(sql)
            DatabaseStoredFile.web2py_filesystems.add(db._uri)

    def __init__(self, db, filename, mode):
        if db._adapter.dbengine not in ("mysql", "postgres", "sqlite"):
            raise RuntimeError(
                "only MySQL/Postgres/SQLite can store metadata .table files"
                + " in database for now"
            )
        self.db = db
        self.filename = filename
        self.mode = mode
        DatabaseStoredFile.try_create_web2py_filesystem(db)
        self.p = 0
        self.data = b""
        if mode in ("r", "rw", "rb", "a", "ab"):
            query = "SELECT content FROM web2py_filesystem WHERE path='%s'" % filename
            rows = self.db.executesql(query)
            if rows:
                self.data = to_bytes(rows[0][0])

# Path: pydal/_compat.py
# PY2 = sys.version_info[0] == 2
#     def implements_bool(cls):
#     def implements_iterator(cls):
#     def to_bytes(obj, charset="utf-8", errors="strict"):
#     def to_native(obj, charset="utf8", errors="strict"):
#     def to_bytes(obj, charset="utf-8", errors="strict"):
#     def to_native(obj, charset="utf8", errors="strict"):
# def with_metaclass(meta, *bases):
#         def __new__(cls, name, this_bases, d):
# def to_unicode(obj, charset="utf-8", errors="strict"):
#     class metaclass(meta):
# 
# Path: pydal/helpers/serializers.py
# class Serializers(object):
#     def _json_parse(self, o):
#     def __getattr__(self, name):
#     def json(self, value):
#     def yaml(self, value):


# Path: pydal/helpers/classes.py
import copy
import marshal
import struct
import threading
import time
import traceback
            import types
from .._compat import (
    PY2,
    exists,
    copyreg,
    implements_bool,
    iterkeys,
    itervalues,
    iteritems,
    to_bytes,
    long,
)
from .._globals import THREAD_LOCAL
from .serializers import serializers

    @staticmethod
    def try_create_web2py_filesystem(db):
        if db._uri not in DatabaseStoredFile.web2py_filesystems:
            if db._adapter.dbengine not in ("mysql", "postgres", "sqlite"):
                raise NotImplementedError(
                    "DatabaseStoredFile only supported by mysql, potresql, sqlite"
                )
            sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content BLOB, PRIMARY KEY(path));"
            if db._adapter.dbengine == "mysql":
                sql = sql[:-1] + " ENGINE=InnoDB;"
            db.executesql(sql)
            DatabaseStoredFile.web2py_filesystems.add(db._uri)

    def __init__(self, db, filename, mode):
        if db._adapter.dbengine not in ("mysql", "postgres", "sqlite"):
            raise RuntimeError(
                "only MySQL/Postgres/SQLite can store metadata .table files"
                + " in database for now"
            )
        self.db = db
        self.filename = filename
        self.mode = mode
        DatabaseStoredFile.try_create_web2py_filesystem(db)
        self.p = 0
        self.data = b""
        if mode in ("r", "rw", "rb", "a", "ab"):
            query = "SELECT content FROM web2py_filesystem WHERE path='%s'" % filename
            rows = self.db.executesql(query)
            if rows:
                self.data = to_bytes(rows[0][0])

            elif exists(filename):