Source

pypy-postgresql / pypy / module / postgresql / __init__.py

Full commit
from pypy.interpreter.mixedmodule import MixedModule


class ExtensionsModule(MixedModule):
    appleveldefs = {}
    interpleveldefs = {
        "adapt": "interp_adapters.adapt",
        "register_adapter": "interp_adapters.register_adapter",
        "register_type": "interp_state.register_type",
        "new_type": "interp_state.new_type",

        "AsIs": "interp_adapters.W_AsIs",
        "QuotedString": "interp_adapters.W_QuotedString",

        "TRANSACTION_STATUS_IDLE": "space.wrap(0)",
        "TRANSACTION_STATUS_ACTIVE": "space.wrap(1)",
        "TRANSACTION_STATUS_INTRANS": "space.wrap(2)",
        "TRANSACTION_STATUS_INERROR": "space.wrap(3)",
        "TRANSACTION_STATUS_UNKNOWN": "space.wrap(4)",
    }

    for level in [
        "ISOLATION_LEVEL_AUTOCOMMIT", "ISOLATION_LEVEL_READ_COMMITTED",
        "ISOLATION_LEVEL_SERIALIZABLE", "ISOLATION_LEVEL_READ_UNCOMMITTED",
        "ISOLATION_LEVEL_REPEATABLE_READ",
    ]:
        interpleveldefs[level] = "space.wrap(interp_connection.W_Connection.%s)" % level

    for type_name in ["UNICODE"]:
        interpleveldefs[type_name] = "interp_state.get(space).w_%s" % type_name

class TZModule(MixedModule):
    appleveldefs = {
        "FixedOffsetTimezone": "app_tz.FixedOffsetTimezone",
    }
    interpleveldefs = {}

class Module(MixedModule):
    applevel_name = "psycopg2"

    appleveldefs = {}

    interpleveldefs = {
        "apilevel": 'space.wrap("2.0")',
        # Kind of a made up value, but it's the upstream psycopg2 version I
        # happened to be working with.
        "__version__": 'space.wrap("2.4")',
        "paramstyle": 'space.wrap("pyformat")',
        "connect": "interp_connection.connect",

        "Date": "interp_types.w_Date",
        "DateFromTicks": "interp_types.w_DateFromTicks",
        "Binary": "interp_types.w_Binary",
    }
    for type_name in ["STRING"]:
        interpleveldefs[type_name] = "interp_state.get(space).w_%s" % type_name

    for error in [
        "Warning", "Error", "InterfaceError", "DatabaseError", "OperationalError",
        "IntegrityError", "InternalError", "ProgrammingError", "NotSupportedError",
    ]:
        interpleveldefs[error] = "interp_state.get(space).w_%s" % error

    submodules = {
        "extensions": ExtensionsModule,
        "tz": TZModule,
    }

    def startup(self, space):
        from pypy.module.postgresql.interp_state import get

        MixedModule.startup(self, space)
        get(space).startup(space)