from sqlalchemy.util import *
from sqlalchemy.types import *
-import copy, re
+import copy, re, string
__all__ = ['SchemaItem', 'Table', 'Column', 'ForeignKey', 'Sequence', 'SchemaEngine', 'SchemaVisitor']
"""returns a string that identifies this SchemaItem uniquely"""
return repr(self)
+ def __repr__(self):
+ return "%s()" % self.__class__.__name__
+
def __getattr__(self, key):
"""proxies method calls to an underlying implementation object for methods not found
locally"""
self.fullname = self.name
if len(kwargs):
raise "Unknown arguments passed to Table: " + repr(kwargs.keys())
+
+ def __repr__(self):
+ return "Table(%s)" % string.join(
+ [repr(self.name)] + [repr(self.engine)] +
+ [repr(x) for x in self.columns] +
+ ["%s=%s" % (k, repr(getattr(self, k))) for k in ['schema']]
+ , ',\n')
def reload_values(self, *args):
"""clears out the columns and other properties of this Table, and reloads them from the
original = property(lambda s: s._orig or s)
engine = property(lambda s: s.table.engine)
-
+
+ def __repr__(self):
+ return "Column(%s)" % string.join(
+ [repr(self.name)] + [repr(self.type)] +
+ [repr(x) for x in [self.foreign_key] if x is not None] +
+ ["%s=%s" % (k, repr(getattr(self, k))) for k in ['key', 'primary_key', 'nullable', 'hidden', 'default']]
+ , ',')
+
def append_item(self, item):
self._init_items(item)
self._colspec = column
self._column = None
+ def __repr__(self):
+ return "ForeignKey(%s)" % repr(self._get_colspec())
+
def copy(self):
"""produces a copy of this ForeignKey object."""
+ return ForeignKey(self._get_colspec())
+
+ def _get_colspec(self):
if isinstance(self._colspec, str):
- return ForeignKey(self._colspec)
+ return self._colspec
+ elif self._colspec.table.schema is not None:
+ return "%s.%s.%s" % (self._colspec.table.schema, self._colspec.table.name, self._colspec.column.key)
else:
- if self._colspec.table.schema is not None:
- return ForeignKey("%s.%s.%s" % (self._colspec.table.schema, self._colspec.table.name, self._colspec.column.key))
- else:
- return ForeignKey("%s.%s" % (self._colspec.table.name, self._colspec.column.key))
-
+ return "%s.%s" % (self._colspec.table.name, self._colspec.column.key)
+
def references(self, table):
"""returns True if the given table is referenced by this ForeignKey."""
try:
def _set_parent(self, column):
self.column = column
self.column.default = self
-
+ def __repr__(self):
+ return "DefaultGenerator()"
+
class ColumnDefault(DefaultGenerator):
"""A plain default value on a column. this could correspond to a constant,
a callable function, or a SQL clause."""
def accept_visitor(self, visitor):
"""calls the visit_column_default method on the given visitor."""
return visitor.visit_column_default(self)
+ def __repr__(self):
+ return "ColumnDefault(%s)" % repr(self.arg)
class Sequence(DefaultGenerator):
"""represents a sequence, which applies to Oracle and Postgres databases."""
self.start = start
self.increment = increment
self.optional=optional
+ def __repr__(self):
+ return "Sequence(%s)" % string.join(
+ [repr(self.name)] +
+ ["%s=%s" % (k, repr(getattr(self, k))) for k in ['start', 'increment', 'optional']]
+ , ',')
+
def accept_visitor(self, visitor):
"""calls the visit_seauence method on the given visitor."""
return visitor.visit_sequence(self)
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-__all__ = ['OrderedProperties', 'OrderedDict']
+__all__ = ['OrderedProperties', 'OrderedDict', 'generic_repr', 'HashSet']
import thread, weakref, UserList,string, inspect
def to_list(x):
return [x]
else:
return x
+
+def generic_repr(obj, exclude=None):
+ L = ['%s=%s' % (a, repr(getattr(obj, a))) for a in dir(obj) if not callable(getattr(obj, a)) and not a.startswith('_') and (exclude is None or not exclude.has_key(a))]
+ return '%s(%s)' % (obj.__class__.__name__, ','.join(L))
class OrderedProperties(object):
"""an object that maintains the order in which attributes are set upon it.