\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/alt/python35/lib64/python3.5/site-packages/playhouse/

Viewing File: berkeleydb.py

import ctypes
import datetime
import decimal
import sys

from peewee import ImproperlyConfigured
from peewee import sqlite3
from playhouse.sqlite_ext import *

sqlite3_lib_version = sqlite3.sqlite_version_info

# Peewee assumes that the `pysqlite2` module was compiled against the
# BerkeleyDB SQLite libraries.
try:
    from pysqlite2 import dbapi2 as berkeleydb
except ImportError:
    import sqlite3 as berkeleydb

berkeleydb.register_adapter(decimal.Decimal, str)
berkeleydb.register_adapter(datetime.date, str)
berkeleydb.register_adapter(datetime.time, str)


class BerkeleyDatabase(SqliteExtDatabase):
    def __init__(self, database, pragmas=None, cache_size=None, page_size=None,
                 multiversion=None, *args, **kwargs):
        super(BerkeleyDatabase, self).__init__(
            database, pragmas=pragmas, *args, **kwargs)
        if multiversion:
            self._pragmas.append(('multiversion', 'on'))
        if page_size:
            self._pragmas.append(('page_size', page_size))
        if cache_size:
            self._pragmas.append(('cache_size', cache_size))

    def _connect(self, database, **kwargs):
        if not PYSQLITE_BERKELEYDB:
            message = ('Your Python SQLite driver (%s) does not appear to '
                       'have been compiled against the BerkeleyDB SQLite '
                       'library.' % berkeleydb)
            if LIBSQLITE_BERKELEYDB:
                message += (' However, the libsqlite on your system is the '
                            'BerkeleyDB implementation. Try recompiling '
                            'pysqlite.')
            else:
                message += (' Additionally, the libsqlite on your system '
                            'does not appear to be the BerkeleyDB '
                            'implementation.')
            raise ImproperlyConfigured(message)

        conn = berkeleydb.connect(database, **kwargs)
        conn.isolation_level = None
        self._add_conn_hooks(conn)
        return conn

    def _set_pragmas(self, conn):
        # `multiversion` is weird. It checks first whether another connection
        # from the BTree cache is available, and then switches to that, which
        # may have the handle of the DB_Env. If that happens, then we get
        # an error stating that you cannot set `multiversion` despite the
        # fact we have not done any operations and it's a brand new conn.
        if self._pragmas:
            cursor = conn.cursor()
            for pragma, value in self._pragmas:
                if pragma == 'multiversion':
                    try:
                        cursor.execute('PRAGMA %s = %s;' % (pragma, value))
                    except berkeleydb.OperationalError:
                        pass
                else:
                    cursor.execute('PRAGMA %s = %s;' % (pragma, value))
            cursor.close()

    @classmethod
    def check_pysqlite(cls):
        try:
            from pysqlite2 import dbapi2 as sqlite3
        except ImportError:
            import sqlite3
        conn = sqlite3.connect(':memory:')
        try:
            results = conn.execute('PRAGMA compile_options;').fetchall()
        finally:
            conn.close()
        for option, in results:
            if option == 'BERKELEY_DB':
                return True
        return False

    @classmethod
    def check_libsqlite(cls):
        # Checking compile options is not supported.
        if sys.platform.startswith('win'):
            library = 'libsqlite3.dll'
        elif sys.platform == 'darwin':
            library = 'libsqlite3.dylib'
        else:
            library = 'libsqlite3.so'

        try:
            libsqlite = ctypes.CDLL(library)
        except OSError:
            return False

        return libsqlite.sqlite3_compileoption_used('BERKELEY_DB') == 1


if sqlite3_lib_version < (3, 6, 23):
    # Checking compile flags is not supported in older SQLite versions.
    PYSQLITE_BERKELEYDB = False
    LIBSQLITE_BERKELEYDB = False
else:
    PYSQLITE_BERKELEYDB = BerkeleyDatabase.check_pysqlite()
    LIBSQLITE_BERKELEYDB = BerkeleyDatabase.check_libsqlite()