summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/naming.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/sql/naming.py')
-rw-r--r--lib/sqlalchemy/sql/naming.py47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index 0107ce724..144cc4dfc 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -10,8 +10,16 @@
"""
-from .schema import Constraint, ForeignKeyConstraint, PrimaryKeyConstraint, \
- UniqueConstraint, CheckConstraint, Index, Table, Column
+from .schema import (
+ Constraint,
+ ForeignKeyConstraint,
+ PrimaryKeyConstraint,
+ UniqueConstraint,
+ CheckConstraint,
+ Index,
+ Table,
+ Column,
+)
from .. import event, events
from .. import exc
from .elements import _truncated_label, _defer_name, _defer_none_name, conv
@@ -19,7 +27,6 @@ import re
class ConventionDict(object):
-
def __init__(self, const, table, convention):
self.const = const
self._is_fk = isinstance(const, ForeignKeyConstraint)
@@ -79,8 +86,8 @@ class ConventionDict(object):
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)()
+ 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:
@@ -108,12 +115,13 @@ class ConventionDict(object):
return getattr(self, attr)(idx)
raise KeyError(key)
+
_prefix_dict = {
Index: "ix",
PrimaryKeyConstraint: "pk",
CheckConstraint: "ck",
UniqueConstraint: "uq",
- ForeignKeyConstraint: "fk"
+ ForeignKeyConstraint: "fk",
}
@@ -134,15 +142,18 @@ def _constraint_name_for_table(const, table):
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
- isinstance(const.name, _defer_name)):
+ elif (
+ convention is not None
+ and not isinstance(const.name, conv)
+ and (
+ const.name is None
+ or "constraint_name" in convention
+ or isinstance(const.name, _defer_name)
+ )
+ ):
return conv(
- convention % ConventionDict(const, table,
- metadata.naming_convention)
+ convention
+ % ConventionDict(const, table, metadata.naming_convention)
)
elif isinstance(convention, _defer_none_name):
return None
@@ -155,9 +166,11 @@ def _constraint_name(const, table):
# 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)
- )
+ event.listen(
+ table,
+ "after_parent_attach",
+ lambda col, table: _constraint_name(const, table),
+ )
elif isinstance(table, Table):
if isinstance(const.name, (conv, _defer_name)):
return