| 28 | |
| 29 | |
| 30 | class ConventionDict: |
| 31 | def __init__(self, const, table, convention): |
| 32 | self.const = const |
| 33 | self._is_fk = isinstance(const, ForeignKeyConstraint) |
| 34 | self.table = table |
| 35 | self.convention = convention |
| 36 | self._const_name = const.name |
| 37 | |
| 38 | def _key_table_name(self): |
| 39 | return self.table.name |
| 40 | |
| 41 | def _column_X(self, idx, attrname): |
| 42 | if self._is_fk: |
| 43 | try: |
| 44 | fk = self.const.elements[idx] |
| 45 | except IndexError: |
| 46 | return "" |
| 47 | else: |
| 48 | return getattr(fk.parent, attrname) |
| 49 | else: |
| 50 | cols = list(self.const.columns) |
| 51 | try: |
| 52 | col = cols[idx] |
| 53 | except IndexError: |
| 54 | return "" |
| 55 | else: |
| 56 | return getattr(col, attrname) |
| 57 | |
| 58 | def _key_constraint_name(self): |
| 59 | if self._const_name in (None, _NONE_NAME): |
| 60 | raise exc.InvalidRequestError( |
| 61 | "Naming convention including " |
| 62 | "%(constraint_name)s token requires that " |
| 63 | "constraint is explicitly named." |
| 64 | ) |
| 65 | if not isinstance(self._const_name, conv): |
| 66 | self.const.name = None |
| 67 | return self._const_name |
| 68 | |
| 69 | def _key_column_X_key(self, idx): |
| 70 | # note this method was missing before |
| 71 | # [ticket:3989], meaning tokens like ``%(column_0_key)s`` weren't |
| 72 | # working even though documented. |
| 73 | return self._column_X(idx, "key") |
| 74 | |
| 75 | def _key_column_X_name(self, idx): |
| 76 | return self._column_X(idx, "name") |
| 77 | |
| 78 | def _key_column_X_label(self, idx): |
| 79 | return self._column_X(idx, "_ddl_label") |
| 80 | |
| 81 | def _key_referred_table_name(self): |
| 82 | fk = self.const.elements[0] |
| 83 | refs = fk.target_fullname.split(".") |
| 84 | if len(refs) == 3: |
| 85 | refschema, reftable, refcol = refs |
| 86 | else: |
| 87 | reftable, refcol = refs |
no outgoing calls
no test coverage detected