コード例 #1
0
ファイル: __init__.py プロジェクト: pombredanne/pysophia
 def __init__(self, path, flags):
     if self._env is not None or self._db is not None:
         raise RuntimeError('object was already initialized')
     # initialize environment
     env = lib.sp_env()
     if env == ffi.NULL:
         raise MemoryError('could not allocate environment')
     # set db directory and flags
     _flags = ffi.cast('int', flags)
     _path = ffi.new('char[]', path)
     r = lib.sp_ctl(env, lib.SPDIR, _flags, _path)
     if r != 0:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     # open db
     db = lib.sp_open(env)
     if db == ffi.NULL:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     self._env = env
     self._db = db
コード例 #2
0
ファイル: __init__.py プロジェクト: pombredanne/pysophia
 def __init__(self, path, flags):
     if self._env is not None or self._db is not None:
         raise RuntimeError('object was already initialized')
     # initialize environment
     env = lib.sp_env()
     if env == ffi.NULL:
         raise MemoryError('could not allocate environment')
     # set db directory and flags
     _flags = ffi.cast('int', flags)
     _path = ffi.new('char[]', path)
     r = lib.sp_ctl(env, lib.SPDIR, _flags, _path)
     if r != 0:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     # open db
     db = lib.sp_open(env)
     if db == ffi.NULL:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     self._env = env
     self._db = db
コード例 #3
0
ファイル: __init__.py プロジェクト: pombredanne/pysophia
__all__ = ['Sophia', 'SophiaError', 'sophia_version']

from cffi import FFI
from pysophia._c_ffi import lib as libc
from pysophia._sophia_ffi import ffi, lib

# get version
major = ffi.new('uint32_t *')
minor = ffi.new('uint32_t *')
lib.sp_ctl(ffi.NULL, lib.SPVERSION, major, minor)
sophia_version = '%d.%d' % (major[0], minor[0])
del major, minor


class SophiaError(Exception):
    pass


class Sophia(object):
    FL_RDWR = lib.SPO_RDWR
    FL_RDONLY = lib.SPO_RDONLY
    FL_CREAT = lib.SPO_CREAT

    _env = None
    _db = None
    _closed = False

    def __init__(self, path, flags):
        if self._env is not None or self._db is not None:
            raise RuntimeError('object was already initialized')
        # initialize environment
コード例 #4
0
ファイル: __init__.py プロジェクト: pombredanne/pysophia
__all__ = ['Sophia', 'SophiaError', 'sophia_version']

from cffi import FFI
from pysophia._c_ffi import lib as libc
from pysophia._sophia_ffi import ffi, lib


# get version
major = ffi.new('uint32_t *')
minor = ffi.new('uint32_t *')
lib.sp_ctl(ffi.NULL, lib.SPVERSION, major, minor)
sophia_version = '%d.%d' % (major[0], minor[0])
del major, minor


class SophiaError(Exception):
    pass


class Sophia(object):
    FL_RDWR   = lib.SPO_RDWR
    FL_RDONLY = lib.SPO_RDONLY
    FL_CREAT  = lib.SPO_CREAT

    _env = None
    _db = None
    _closed = False

    def __init__(self, path, flags):
        if self._env is not None or self._db is not None: