Exemple #1
0
def class_mapper(class_, compile=True):
    """Given a class, return the primary :class:`.Mapper` associated 
    with the key.

    Raises :class:`.UnmappedClassError` if no mapping is configured
    on the given class, or :class:`.ArgumentError` if a non-class
    object is passed.

    """

    try:
        class_manager = attributes.manager_of_class(class_)
        mapper = class_manager.mapper

    except exc.NO_STATE:
        if not isinstance(class_, type):
            raise sa_exc.ArgumentError("Class object expected, got '%r'." %
                                       class_)
        raise exc.UnmappedClassError(class_)

    if compile and mapperlib.module._new_mappers:
        mapperlib.configure_mappers()
    return mapper
Exemple #2
0
 def mapper(self):
     # raises unless self.mapper has been assigned
     raise exc.UnmappedClassError(self.class_)