diff options
author | Brian Jarrett <celttechie@gmail.com> | 2014-07-20 12:44:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-20 12:44:40 -0400 |
commit | cca03097f47f22783d42d1853faac6cf84607c5a (patch) | |
tree | 4fe1a63d03a2d88d1cf37e1167759dfaf84f4ce7 /lib/sqlalchemy/sql/naming.py | |
parent | 827329a0cca5351094a1a86b6b2be2b9182f0ae2 (diff) | |
download | sqlalchemy-cca03097f47f22783d42d1853faac6cf84607c5a.tar.gz |
- apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,
sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
Diffstat (limited to 'lib/sqlalchemy/sql/naming.py')
-rw-r--r-- | lib/sqlalchemy/sql/naming.py | 22 |
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 |