GRAYBYTE WORDPRESS FILE MANAGER4837

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/hc_python/lib/python3.12/site-packages/sqlalchemy/sql/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/hc_python/lib/python3.12/site-packages/sqlalchemy/sql//naming.py
# sql/naming.py
# Copyright (C) 2005-2025 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
# mypy: allow-untyped-defs, allow-untyped-calls

"""Establish constraint and index naming conventions.


"""

from __future__ import annotations

import re

from . import events  # noqa
from .base import _NONE_NAME
from .elements import conv as conv
from .schema import CheckConstraint
from .schema import Column
from .schema import Constraint
from .schema import ForeignKeyConstraint
from .schema import Index
from .schema import PrimaryKeyConstraint
from .schema import Table
from .schema import UniqueConstraint
from .. import event
from .. import exc


class ConventionDict:
    def __init__(self, const, table, convention):
        self.const = const
        self._is_fk = isinstance(const, ForeignKeyConstraint)
        self.table = table
        self.convention = convention
        self._const_name = const.name

    def _key_table_name(self):
        return self.table.name

    def _column_X(self, idx, attrname):
        if self._is_fk:
            try:
                fk = self.const.elements[idx]
            except IndexError:
                return ""
            else:
                return getattr(fk.parent, attrname)
        else:
            cols = list(self.const.columns)
            try:
                col = cols[idx]
            except IndexError:
                return ""
            else:
                return getattr(col, attrname)

    def _key_constraint_name(self):
        if self._const_name in (None, _NONE_NAME):
            raise exc.InvalidRequestError(
                "Naming convention including "
                "%(constraint_name)s token requires that "
                "constraint is explicitly named."
            )
        if not isinstance(self._const_name, conv):
            self.const.name = None
        return self._const_name

    def _key_column_X_key(self, idx):
        # note this method was missing before
        # [ticket:3989], meaning tokens like ``%(column_0_key)s`` weren't
        # working even though documented.
        return self._column_X(idx, "key")

    def _key_column_X_name(self, idx):
        return self._column_X(idx, "name")

    def _key_column_X_label(self, idx):
        return self._column_X(idx, "_ddl_label")

    def _key_referred_table_name(self):
        fk = self.const.elements[0]
        refs = fk.target_fullname.split(".")
        if len(refs) == 3:
            refschema, reftable, refcol = refs
        else:
            reftable, refcol = refs
        return reftable

    def _key_referred_column_X_name(self, idx):
        fk = self.const.elements[idx]
        # note that before [ticket:3989], this method was returning
        # the specification for the :class:`.ForeignKey` itself, which normally
        # would be using the ``.key`` of the column, not the name.
        return fk.column.name

    def __getitem__(self, key):
        if key in self.convention:
            return self.convention[key](self.const, self.table)
        elif hasattr(self, "_key_%s" % key):
            return getattr(self, "_key_%s" % key)()
        else:
            col_template = re.match(r".*_?column_(\d+)(_?N)?_.+", key)
            if col_template:
                idx = col_template.group(1)
                multiples = col_template.group(2)

                if multiples:
                    if self._is_fk:
                        elems = self.const.elements
                    else:
                        elems = list(self.const.columns)
                    tokens = []
                    for idx, elem in enumerate(elems):
                        attr = "_key_" + key.replace("0" + multiples, "X")
                        try:
                            tokens.append(getattr(self, attr)(idx))
                        except AttributeError:
                            raise KeyError(key)
                    sep = "_" if multiples.startswith("_") else ""
                    return sep.join(tokens)
                else:
                    attr = "_key_" + key.replace(idx, "X")
                    idx = int(idx)
                    if hasattr(self, attr):
                        return getattr(self, attr)(idx)
        raise KeyError(key)


_prefix_dict = {
    Index: "ix",
    PrimaryKeyConstraint: "pk",
    CheckConstraint: "ck",
    UniqueConstraint: "uq",
    ForeignKeyConstraint: "fk",
}


def _get_convention(dict_, key):
    for super_ in key.__mro__:
        if super_ in _prefix_dict and _prefix_dict[super_] in dict_:
            return dict_[_prefix_dict[super_]]
        elif super_ in dict_:
            return dict_[super_]
    else:
        return None


def _constraint_name_for_table(const, table):
    metadata = table.metadata
    convention = _get_convention(metadata.naming_convention, type(const))

    if isinstance(const.name, conv):
        return const.name
    elif (
        convention is not None
        and not isinstance(const.name, conv)
        and (
            const.name is None
            or "constraint_name" in convention
            or const.name is _NONE_NAME
        )
    ):
        return conv(
            convention
            % ConventionDict(const, table, metadata.naming_convention)
        )
    elif convention is _NONE_NAME:
        return None


@event.listens_for(
    PrimaryKeyConstraint, "_sa_event_column_added_to_pk_constraint"
)
def _column_added_to_pk_constraint(pk_constraint, col):
    if pk_constraint._implicit_generated:
        # only operate upon the "implicit" pk constraint for now,
        # as we have to force the name to None to reset it.  the
        # "implicit" constraint will only have a naming convention name
        # if at all.
        table = pk_constraint.table
        pk_constraint.name = None
        newname = _constraint_name_for_table(pk_constraint, table)
        if newname:
            pk_constraint.name = newname


@event.listens_for(Constraint, "after_parent_attach")
@event.listens_for(Index, "after_parent_attach")
def _constraint_name(const, table):
    if isinstance(table, Column):
        # this path occurs for a CheckConstraint linked to a Column

        # for column-attached constraint, set another event
        # to link the column attached to the table as this constraint
        # associated with the table.
        event.listen(
            table,
            "after_parent_attach",
            lambda col, table: _constraint_name(const, table),
        )

    elif isinstance(table, Table):
        if isinstance(const.name, conv) or const.name is _NONE_NAME:
            return

        newname = _constraint_name_for_table(const, table)
        if newname:
            const.name = newname

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
January 01 1970 00:00:00
root / root
0
__pycache__
--
April 04 2025 08:00:25
root / root
0755
__init__.py
5.684 KB
April 04 2025 08:00:23
root / root
0644
_dml_constructors.py
3.706 KB
April 04 2025 08:00:23
root / root
0644
_elements_constructors.py
61.162 KB
April 04 2025 08:00:23
root / root
0644
_orm_types.py
0.61 KB
April 04 2025 08:00:23
root / root
0644
_py_util.py
2.122 KB
April 04 2025 08:00:23
root / root
0644
_selectable_constructors.py
19.896 KB
April 04 2025 08:00:23
root / root
0644
_typing.py
12.546 KB
April 04 2025 08:00:23
root / root
0644
annotation.py
17.817 KB
April 04 2025 08:00:23
root / root
0644
base.py
72.213 KB
April 04 2025 08:00:23
root / root
0644
cache_key.py
32.879 KB
April 04 2025 08:00:23
root / root
0644
coercions.py
39.7 KB
April 04 2025 08:00:23
root / root
0644
compiler.py
269.122 KB
April 04 2025 08:00:23
root / root
0644
crud.py
55.189 KB
April 04 2025 08:00:23
root / root
0644
ddl.py
46.318 KB
April 04 2025 08:00:23
root / root
0644
default_comparator.py
16.315 KB
April 04 2025 08:00:23
root / root
0644
dml.py
64.68 KB
April 04 2025 08:00:23
root / root
0644
elements.py
173.157 KB
April 04 2025 08:00:23
root / root
0644
events.py
17.883 KB
April 04 2025 08:00:23
root / root
0644
expression.py
7.408 KB
April 04 2025 08:00:23
root / root
0644
functions.py
62.361 KB
April 04 2025 08:00:23
root / root
0644
lambdas.py
48.043 KB
April 04 2025 08:00:23
root / root
0644
naming.py
6.697 KB
April 04 2025 08:00:23
root / root
0644
operators.py
74.992 KB
April 04 2025 08:00:23
root / root
0644
roles.py
7.482 KB
April 04 2025 08:00:23
root / root
0644
schema.py
224.635 KB
April 04 2025 08:00:23
root / root
0644
selectable.py
235.405 KB
April 04 2025 08:00:23
root / root
0644
sqltypes.py
125.935 KB
April 04 2025 08:00:23
root / root
0644
traversals.py
32.875 KB
April 04 2025 08:00:23
root / root
0644
type_api.py
82.849 KB
April 04 2025 08:00:23
root / root
0644
util.py
46.959 KB
April 04 2025 08:00:23
root / root
0644
visitors.py
35.468 KB
April 04 2025 08:00:23
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF