$17 GRAYBYTE WORDPRESS FILE MANAGER $87

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/lib64/python2.7/site-packages/sqlalchemy/testing/

HOME
Current File : /lib64/python2.7/site-packages/sqlalchemy/testing//schema.py
# testing/schema.py
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php

import sys

from . import config
from . import exclusions
from .. import event
from .. import schema
from .. import types as sqltypes
from ..util import OrderedDict


__all__ = ["Table", "Column"]

table_options = {}


def Table(*args, **kw):
    """A schema.Table wrapper/hook for dialect-specific tweaks."""

    test_opts = {k: kw.pop(k) for k in list(kw) if k.startswith("test_")}

    kw.update(table_options)

    if exclusions.against(config._current, "mysql"):
        if (
            "mysql_engine" not in kw
            and "mysql_type" not in kw
            and "autoload_with" not in kw
        ):
            if "test_needs_fk" in test_opts or "test_needs_acid" in test_opts:
                kw["mysql_engine"] = "InnoDB"
            else:
                kw["mysql_engine"] = "MyISAM"
    elif exclusions.against(config._current, "mariadb"):
        if (
            "mariadb_engine" not in kw
            and "mariadb_type" not in kw
            and "autoload_with" not in kw
        ):
            if "test_needs_fk" in test_opts or "test_needs_acid" in test_opts:
                kw["mariadb_engine"] = "InnoDB"
            else:
                kw["mariadb_engine"] = "MyISAM"

    # Apply some default cascading rules for self-referential foreign keys.
    # MySQL InnoDB has some issues around selecting self-refs too.
    if exclusions.against(config._current, "firebird"):
        table_name = args[0]
        unpack = config.db.dialect.identifier_preparer.unformat_identifiers

        # Only going after ForeignKeys in Columns.  May need to
        # expand to ForeignKeyConstraint too.
        fks = [
            fk
            for col in args
            if isinstance(col, schema.Column)
            for fk in col.foreign_keys
        ]

        for fk in fks:
            # root around in raw spec
            ref = fk._colspec
            if isinstance(ref, schema.Column):
                name = ref.table.name
            else:
                # take just the table name: on FB there cannot be
                # a schema, so the first element is always the
                # table name, possibly followed by the field name
                name = unpack(ref)[0]
            if name == table_name:
                if fk.ondelete is None:
                    fk.ondelete = "CASCADE"
                if fk.onupdate is None:
                    fk.onupdate = "CASCADE"

    return schema.Table(*args, **kw)


def Column(*args, **kw):
    """A schema.Column wrapper/hook for dialect-specific tweaks."""

    test_opts = {k: kw.pop(k) for k in list(kw) if k.startswith("test_")}

    if not config.requirements.foreign_key_ddl.enabled_for_config(config):
        args = [arg for arg in args if not isinstance(arg, schema.ForeignKey)]

    col = schema.Column(*args, **kw)
    if test_opts.get("test_needs_autoincrement", False) and kw.get(
        "primary_key", False
    ):

        if col.default is None and col.server_default is None:
            col.autoincrement = True

        # allow any test suite to pick up on this
        col.info["test_needs_autoincrement"] = True

        # hardcoded rule for firebird, oracle; this should
        # be moved out
        if exclusions.against(config._current, "firebird", "oracle"):

            def add_seq(c, tbl):
                c._init_items(
                    schema.Sequence(
                        _truncate_name(
                            config.db.dialect, tbl.name + "_" + c.name + "_seq"
                        ),
                        optional=True,
                    )
                )

            event.listen(col, "after_parent_attach", add_seq, propagate=True)
    return col


class eq_type_affinity(object):
    """Helper to compare types inside of datastructures based on affinity.

    E.g.::

        eq_(
            inspect(connection).get_columns("foo"),
            [
                {
                    "name": "id",
                    "type": testing.eq_type_affinity(sqltypes.INTEGER),
                    "nullable": False,
                    "default": None,
                    "autoincrement": False,
                },
                {
                    "name": "data",
                    "type": testing.eq_type_affinity(sqltypes.NullType),
                    "nullable": True,
                    "default": None,
                    "autoincrement": False,
                },
            ],
        )

    """

    def __init__(self, target):
        self.target = sqltypes.to_instance(target)

    def __eq__(self, other):
        return self.target._type_affinity is other._type_affinity

    def __ne__(self, other):
        return self.target._type_affinity is not other._type_affinity


class eq_clause_element(object):
    """Helper to compare SQL structures based on compare()"""

    def __init__(self, target):
        self.target = target

    def __eq__(self, other):
        return self.target.compare(other)

    def __ne__(self, other):
        return not self.target.compare(other)


def _truncate_name(dialect, name):
    if len(name) > dialect.max_identifier_length:
        return (
            name[0 : max(dialect.max_identifier_length - 6, 0)]
            + "_"
            + hex(hash(name) % 64)[2:]
        )
    else:
        return name


def pep435_enum(name):
    # Implements PEP 435 in the minimal fashion needed by SQLAlchemy
    __members__ = OrderedDict()

    def __init__(self, name, value, alias=None):
        self.name = name
        self.value = value
        self.__members__[name] = self
        value_to_member[value] = self
        setattr(self.__class__, name, self)
        if alias:
            self.__members__[alias] = self
            setattr(self.__class__, alias, self)

    value_to_member = {}

    @classmethod
    def get(cls, value):
        return value_to_member[value]

    someenum = type(
        name,
        (object,),
        {"__members__": __members__, "__init__": __init__, "get": get},
    )

    # getframe() trick for pickling I don't understand courtesy
    # Python namedtuple()
    try:
        module = sys._getframe(1).f_globals.get("__name__", "__main__")
    except (AttributeError, ValueError):
        pass
    if module is not None:
        someenum.__module__ = module

    return someenum

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
23 Sep 2024 10.41 AM
root / root
0755
plugin
--
23 Sep 2024 10.41 AM
root / root
0755
suite
--
23 Sep 2024 10.41 AM
root / root
0755
__init__.py
2.914 KB
5 Sep 2024 10.50 PM
root / root
0644
__init__.pyc
3.738 KB
23 Sep 2024 10.41 AM
root / root
0644
assertions.py
28.454 KB
5 Sep 2024 10.50 PM
root / root
0644
assertions.pyc
32.271 KB
23 Sep 2024 10.41 AM
root / root
0644
assertsql.py
14.613 KB
5 Sep 2024 10.50 PM
root / root
0644
assertsql.pyc
15.358 KB
23 Sep 2024 10.41 AM
root / root
0644
asyncio.py
3.585 KB
5 Sep 2024 10.50 PM
root / root
0644
asyncio.pyc
3.564 KB
23 Sep 2024 10.41 AM
root / root
0644
config.py
9.439 KB
5 Sep 2024 10.50 PM
root / root
0644
config.pyc
12.109 KB
23 Sep 2024 10.41 AM
root / root
0644
engines.py
13.078 KB
5 Sep 2024 10.50 PM
root / root
0644
engines.pyc
17.368 KB
23 Sep 2024 10.41 AM
root / root
0644
entities.py
3.177 KB
5 Sep 2024 10.50 PM
root / root
0644
entities.pyc
3.331 KB
23 Sep 2024 10.41 AM
root / root
0644
exclusions.py
13.001 KB
5 Sep 2024 10.50 PM
root / root
0644
exclusions.pyc
19.058 KB
23 Sep 2024 10.41 AM
root / root
0644
fixtures.py
30.199 KB
5 Sep 2024 10.50 PM
root / root
0644
fixtures.pyc
30.239 KB
23 Sep 2024 10.41 AM
root / root
0644
mock.py
0.873 KB
5 Sep 2024 10.50 PM
root / root
0644
mock.pyc
0.749 KB
23 Sep 2024 10.41 AM
root / root
0644
pickleable.py
2.818 KB
5 Sep 2024 10.50 PM
root / root
0644
pickleable.pyc
7.781 KB
23 Sep 2024 10.41 AM
root / root
0644
profiling.py
10.401 KB
5 Sep 2024 10.50 PM
root / root
0644
profiling.pyc
9.858 KB
23 Sep 2024 10.41 AM
root / root
0644
provision.py
12.029 KB
5 Sep 2024 10.50 PM
root / root
0644
provision.pyc
13.639 KB
23 Sep 2024 10.41 AM
root / root
0644
requirements.py
43.585 KB
5 Sep 2024 10.50 PM
root / root
0644
requirements.pyc
69.734 KB
23 Sep 2024 10.41 AM
root / root
0644
schema.py
6.391 KB
5 Sep 2024 10.50 PM
root / root
0644
schema.pyc
7.188 KB
23 Sep 2024 10.41 AM
root / root
0644
util.py
13.677 KB
5 Sep 2024 10.50 PM
root / root
0644
util.pyc
17.46 KB
23 Sep 2024 10.41 AM
root / root
0644
warnings.py
2.411 KB
5 Sep 2024 10.50 PM
root / root
0644
warnings.pyc
2.457 KB
23 Sep 2024 10.41 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF