# Path: stagehand/toolbox/utils.py
# def tostr(value, encoding=None, desperate=True, coerce=False, fs=False):
#     """
#     Convert (if necessary) the given value to a unicode string.
# 
#     :param value: the value to be converted to a unicode string
#     :param encoding: the character set to first try to decode as; if None, will
#                      use the system default (from the locale).
#     :type encoding: str
#     :param desperate: if True and decoding to the given (or default) charset
#                       fails, will also try utf-8 and latin-1 (in that order),
#                       and if those fail, will decode as the preferred charset,
#                       replacing unknown characters with \\\\uFFFD.
#     :type desperate: bool
#     :param coerce: if True, will coerce numeric types to a unicode string; if
#                    False, such values will be returned untouched.
#     :type coerce: bool
#     :param fs: indicates value is a file name or other environment string; if True,
#                the encoding (if not explicitly specified) will be the encoding
#                given by ``sys.getfilesystemencoding()`` and the error handler
#                used will be ``surrogateescape`` if supported.
#     :type fs: bool
#     :returns: the value as a unicode string, or the original value if coerce is
#               False and the value was not a bytes or string.
#     """
#     if isinstance(value, str):
#         # Nothing to do.
#         return value
#     elif isinstance(value, (int, float)):
#         return str(value) if coerce else value
#     elif not isinstance(value, (bytearray, bytes)):
#         # Need to coerce this value.  Try the direct approach.
#         try:
#             return str(value)
#         except UnicodeError:
#             # Could be that value.__repr__ returned a non-unicode and
#             # non-8bit-clean string.  Be a bit more brute force about it.
#             return tostr(repr(value), desperate=desperate)
# 
#     errors = 'strict'
#     if fs:
#         if not encoding:
#             encoding = sys.getfilesystemencoding()
#         errors = 'surrogateescape'
# 
#     # We now have a bytes object to decode.
#     for c in (encoding or ENCODING, 'utf-8', 'latin-1'):
#         try:
#             return value.decode(c, errors)
#         except UnicodeError:
#             pass
#         if not desperate:
#             raise UnicodeError("Couldn't decode value to unicode (and not desperate enough to keep trying)")
# 
#     return value.decode(encoding or ENCODING, 'replace')


import sys
import os
import time
import re
import logging
import math
import copyreg
import pickle
import struct
import _weakref
import threading
import functools
import string
import sqlite3 as sqlite
import asyncio
            import io
    import _objectrow
from .utils import tostr
# it under the terms of the GNU Lesser General Public License version
# 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# -----------------------------------------------------------------------------
__all__ = [
    'Database', 'QExpr', 'DatabaseError', 'DatabaseReadOnlyError',
    'split_path', 'ATTR_SIMPLE', 'ATTR_SEARCHABLE', 'ATTR_IGNORE_CASE',
    'ATTR_INDEXED', 'ATTR_INDEXED_IGNORE_CASE', 'ATTR_INVERTED_INDEX',
    'RAW_TYPE'
]

# python imports


BYTES_TYPE = bytes
UNICODE_TYPE = str

# get logging object
log = logging.getLogger('db')


# Path: stagehand/toolbox/utils.py
# def tostr(value, encoding=None, desperate=True, coerce=False, fs=False):
#     """
#     Convert (if necessary) the given value to a unicode string.
# 
#     :param value: the value to be converted to a unicode string
#     :param encoding: the character set to first try to decode as; if None, will
#                      use the system default (from the locale).
#     :type encoding: str
#     :param desperate: if True and decoding to the given (or default) charset
#                       fails, will also try utf-8 and latin-1 (in that order),
#                       and if those fail, will decode as the preferred charset,
#                       replacing unknown characters with \\\\uFFFD.
#     :type desperate: bool
#     :param coerce: if True, will coerce numeric types to a unicode string; if
#                    False, such values will be returned untouched.
#     :type coerce: bool
#     :param fs: indicates value is a file name or other environment string; if True,
#                the encoding (if not explicitly specified) will be the encoding
#                given by ``sys.getfilesystemencoding()`` and the error handler
#                used will be ``surrogateescape`` if supported.
#     :type fs: bool
#     :returns: the value as a unicode string, or the original value if coerce is
#               False and the value was not a bytes or string.
#     """
#     if isinstance(value, str):
#         # Nothing to do.
#         return value
#     elif isinstance(value, (int, float)):
#         return str(value) if coerce else value
#     elif not isinstance(value, (bytearray, bytes)):
#         # Need to coerce this value.  Try the direct approach.
#         try:
#             return str(value)
#         except UnicodeError:
#             # Could be that value.__repr__ returned a non-unicode and
#             # non-8bit-clean string.  Be a bit more brute force about it.
#             return tostr(repr(value), desperate=desperate)
# 
#     errors = 'strict'
#     if fs:
#         if not encoding:
#             encoding = sys.getfilesystemencoding()
#         errors = 'surrogateescape'
# 
#     # We now have a bytes object to decode.
#     for c in (encoding or ENCODING, 'utf-8', 'latin-1'):
#         try:
#             return value.decode(c, errors)
#         except UnicodeError:
#             pass
#         if not desperate:
#             raise UnicodeError("Couldn't decode value to unicode (and not desperate enough to keep trying)")
# 
#     return value.decode(encoding or ENCODING, 'replace')


# Path: stagehand/toolbox/db.py
import sys
import os
import time
import re
import logging
import math
import copyreg
import pickle
import struct
import _weakref
import threading
import functools
import string
import sqlite3 as sqlite
import asyncio
            import io
    import _objectrow
from .utils import tostr

# it under the terms of the GNU Lesser General Public License version
# 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# -----------------------------------------------------------------------------
__all__ = [
    'Database', 'QExpr', 'DatabaseError', 'DatabaseReadOnlyError',
    'split_path', 'ATTR_SIMPLE', 'ATTR_SEARCHABLE', 'ATTR_IGNORE_CASE',
    'ATTR_INDEXED', 'ATTR_INDEXED_IGNORE_CASE', 'ATTR_INVERTED_INDEX',
    'RAW_TYPE'
]

# python imports


BYTES_TYPE = bytes
UNICODE_TYPE = str

# get logging object
log = logging.getLogger('db')


SCHEMA_VERSION = 0.2