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.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index 053db3e34..9e57418b0 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -11,7 +11,7 @@
"""
from .schema import Constraint, ForeignKeyConstraint, PrimaryKeyConstraint, \
- UniqueConstraint, CheckConstraint, Index, Table, Column
+ UniqueConstraint, CheckConstraint, Index, Table, Column
from .. import event, events
from .. import exc
from .elements import _truncated_label, _defer_name, _defer_none_name, conv
@@ -19,6 +19,7 @@ import re
class ConventionDict(object):
+
def __init__(self, const, table, convention):
self.const = const
self._is_fk = isinstance(const, ForeignKeyConstraint)
@@ -94,6 +95,7 @@ _prefix_dict = {
ForeignKeyConstraint: "fk"
}
+
def _get_convention(dict_, key):
for super_ in key.__mro__:
@@ -104,6 +106,7 @@ def _get_convention(dict_, key):
else:
return None
+
def _constraint_name_for_table(const, table):
metadata = table.metadata
convention = _get_convention(metadata.naming_convention, type(const))
@@ -111,16 +114,17 @@ def _constraint_name_for_table(const, table):
if isinstance(const.name, conv):
return const.name
elif convention is not None and (
- const.name is None or not isinstance(const.name, conv) and
- "constraint_name" in convention
- ):
+ const.name is None or not isinstance(const.name, conv) and
+ "constraint_name" in convention
+ ):
return conv(
- convention % ConventionDict(const, table,
- metadata.naming_convention)
- )
+ convention % ConventionDict(const, table,
+ metadata.naming_convention)
+ )
elif isinstance(convention, _defer_none_name):
return None
+
@event.listens_for(Constraint, "after_parent_attach")
@event.listens_for(Index, "after_parent_attach")
def _constraint_name(const, table):
@@ -129,8 +133,8 @@ def _constraint_name(const, table):
# 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)
- )
+ lambda col, table: _constraint_name(const, table)
+ )
elif isinstance(table, Table):
if isinstance(const.name, (conv, _defer_name)):
return