# Path: sqlalchemy_continuum/table_builder.py
# class TableBuilder(object):
#     """
#     TableBuilder handles the building of version tables based on parent
#     table's structure and versioning configuration options.
#     """
#     def __init__(
#         self,
#         versioning_manager,
#         parent_table,
#         model=None
#     ):
#         self.manager = versioning_manager
#         self.parent_table = parent_table
#         self.model = model
# 
#     def option(self, name):
#         try:
#             return self.manager.option(self.model, name)
#         except TypeError:
#             return self.manager.options[name]
# 
#     @property
#     def table_name(self):
#         """
#         Returns the version table name for current parent table.
#         """
#         return self.option('table_name') % self.parent_table.name
# 
#     @property
#     def columns(self):
#         return list(
#             column for column in
#             ColumnReflector(self.manager, self.parent_table, self.model)
#         )
# 
#     def __call__(self, extends=None):
#         """
#         Builds version table.
#         """
#         columns = self.columns if extends is None else []
#         self.manager.plugins.after_build_version_table_columns(self, columns)
#         return sa.schema.Table(
#             extends.name if extends is not None else self.table_name,
#             self.parent_table.metadata,
#             *columns,
#             schema=self.parent_table.schema,
#             extend_existing=extends is not None
#         )
# 
# Path: sqlalchemy_continuum/utils.py
# def adapt_columns(expr):
#     return VersioningClauseAdapter().traverse(expr)
# 
# def version_class(model):
#     """
#     Return the version class for given SQLAlchemy declarative model class.
# 
#     ::
# 
#         version_class(Article)  # ArticleVersion class
# 
# 
#     :param model: SQLAlchemy declarative model class
# 
#     .. seealso:: :func:`parent_class`
#     """
#     manager = get_versioning_manager(model)
#     try:
#         return manager.version_class_map[model]
#     except KeyError:
#         return model
# 
# def option(obj_or_class, option_name):
#     """
#     Return the option value of given option for given versioned object or
#     class.
# 
#     :param obj_or_class: SQLAlchemy declarative model object or class
#     :param option_name: The name of an option to return
#     """
#     if isinstance(obj_or_class, AliasedClass):
#         obj_or_class = sa.inspect(obj_or_class).mapper.class_
#     cls = obj_or_class if isclass(obj_or_class) else obj_or_class.__class__
#     if not hasattr(cls, '__versioned__'):
#         cls = parent_class(cls)
#     return get_versioning_manager(cls).option(
#         cls, option_name
#     )


import sqlalchemy as sa
from .exc import ClassNotVersioned
from .expression_reflector import VersionExpressionReflector
from .operation import Operation
from .table_builder import TableBuilder
from .utils import adapt_columns, version_class, option

        self.manager.association_tables.add(column.table)
        builder = TableBuilder(
            self.manager,
            column.table
        )
        metadata = column.table.metadata
        if builder.parent_table.schema:
            table_name = builder.parent_table.schema + '.' + builder.table_name
        elif metadata.schema:
            table_name = metadata.schema + '.' + builder.table_name
        else:
            table_name = builder.table_name

        if table_name not in metadata.tables:
            self.association_version_table = table = builder()
            self.manager.association_version_tables.add(table)
        else:
            # may have already been created if we visiting the 'other' side of
            # a self-referential many-to-many relationship
            self.association_version_table = metadata.tables[table_name]

    def __call__(self):
        """
        Builds reflected relationship between version classes based on given
        parent object's RelationshipProperty.
        """
        self.local_cls = version_class(self.model)
        self.versioned = False
        try:

# Path: sqlalchemy_continuum/table_builder.py
# class TableBuilder(object):
#     """
#     TableBuilder handles the building of version tables based on parent
#     table's structure and versioning configuration options.
#     """
#     def __init__(
#         self,
#         versioning_manager,
#         parent_table,
#         model=None
#     ):
#         self.manager = versioning_manager
#         self.parent_table = parent_table
#         self.model = model
# 
#     def option(self, name):
#         try:
#             return self.manager.option(self.model, name)
#         except TypeError:
#             return self.manager.options[name]
# 
#     @property
#     def table_name(self):
#         """
#         Returns the version table name for current parent table.
#         """
#         return self.option('table_name') % self.parent_table.name
# 
#     @property
#     def columns(self):
#         return list(
#             column for column in
#             ColumnReflector(self.manager, self.parent_table, self.model)
#         )
# 
#     def __call__(self, extends=None):
#         """
#         Builds version table.
#         """
#         columns = self.columns if extends is None else []
#         self.manager.plugins.after_build_version_table_columns(self, columns)
#         return sa.schema.Table(
#             extends.name if extends is not None else self.table_name,
#             self.parent_table.metadata,
#             *columns,
#             schema=self.parent_table.schema,
#             extend_existing=extends is not None
#         )
# 
# Path: sqlalchemy_continuum/utils.py
# def adapt_columns(expr):
#     return VersioningClauseAdapter().traverse(expr)
# 
# def version_class(model):
#     """
#     Return the version class for given SQLAlchemy declarative model class.
# 
#     ::
# 
#         version_class(Article)  # ArticleVersion class
# 
# 
#     :param model: SQLAlchemy declarative model class
# 
#     .. seealso:: :func:`parent_class`
#     """
#     manager = get_versioning_manager(model)
#     try:
#         return manager.version_class_map[model]
#     except KeyError:
#         return model
# 
# def option(obj_or_class, option_name):
#     """
#     Return the option value of given option for given versioned object or
#     class.
# 
#     :param obj_or_class: SQLAlchemy declarative model object or class
#     :param option_name: The name of an option to return
#     """
#     if isinstance(obj_or_class, AliasedClass):
#         obj_or_class = sa.inspect(obj_or_class).mapper.class_
#     cls = obj_or_class if isclass(obj_or_class) else obj_or_class.__class__
#     if not hasattr(cls, '__versioned__'):
#         cls = parent_class(cls)
#     return get_versioning_manager(cls).option(
#         cls, option_name
#     )


# Path: sqlalchemy_continuum/relationship_builder.py
import sqlalchemy as sa
from .exc import ClassNotVersioned
from .expression_reflector import VersionExpressionReflector
from .operation import Operation
from .table_builder import TableBuilder
from .utils import adapt_columns, version_class, option


        self.manager.association_tables.add(column.table)
        builder = TableBuilder(
            self.manager,
            column.table
        )
        metadata = column.table.metadata
        if builder.parent_table.schema:
            table_name = builder.parent_table.schema + '.' + builder.table_name
        elif metadata.schema:
            table_name = metadata.schema + '.' + builder.table_name
        else:
            table_name = builder.table_name

        if table_name not in metadata.tables:
            self.association_version_table = table = builder()
            self.manager.association_version_tables.add(table)
        else:
            # may have already been created if we visiting the 'other' side of
            # a self-referential many-to-many relationship
            self.association_version_table = metadata.tables[table_name]

    def __call__(self):
        """
        Builds reflected relationship between version classes based on given
        parent object's RelationshipProperty.
        """
        self.local_cls = version_class(self.model)
        self.versioned = False
        try:

            self.remote_cls = version_class(self.property.mapper.class_)