本文整理汇总了Python中types.ModuleType.mapper方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.mapper方法的具体用法?Python ModuleType.mapper怎么用?Python ModuleType.mapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.mapper方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import mapper [as 别名]
def _make_module():
db = ModuleType('db')
_get_items = lambda mod: ((key, getattr(mod, key)) for key in mod.__all__)
modules = (_get_items(sqlalchemy), _get_items(orm))
for module in modules:
for key, value in module:
setattr(db, key, value)
# support for postgresql array type
from sqlalchemy.dialects.postgresql.base import PGArray
db.PGArray = PGArray
db.get_engine = get_engine
db.session = session
db.metadata = metadata
db.mapper = mapper
db.atomic_add = atomic_add
db.no_autoflush = no_autoflush
db.find_next_increment = find_next_increment
db.select_blocks = select_blocks
db.driver = driver
db.Model = Model
db.Query = Query
db.File = File
db.SlugGenerator = SlugGenerator
db.GuidGenerator = GuidGenerator
db.AttributeExtension = AttributeExtension
db.ColumnProperty = orm.ColumnProperty
db.NoResultFound = orm.exc.NoResultFound
db.SQLAlchemyError = exc.SQLAlchemyError
return db
示例2: setattr
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import mapper [as 别名]
db.__doc__ = __doc__
for name in 'delete', 'save', 'flush', 'execute', 'begin', 'query', \
'commit', 'rollback', 'clear', 'refresh', 'expire':
setattr(db, name, getattr(session, name))
db.session = session
recipients_table = db.Table('recipients', metadata,
db.Column('id', db.Integer, primary_key=True),
db.Column('name', db.String(100), nullable=False),
db.Column('mail', db.String(100), nullable=False),
db.Column('active', db.Boolean, nullable=False),
db.Column('comment', db.String(100), nullable=True),
)
class Recipient(object):
def __init__(self, name=None, mail=None, active=False, comment=None):
self.name = name or u'unknown'
self.mail = mail or u'unknown'
self.active = active
self.comment = comment
def __eq__(self, other):
for item in ('name', 'mail', 'active', 'comment'):
if not getattr(self, item) == getattr(other, item):
return False
return True
db.mapper(Recipient, recipients_table)
示例3: ModuleType
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import mapper [as 别名]
session = orm.scoped_session(lambda: orm.create_session(
local.application.sqla_db_engine,
autoflush=True, transactional=True),
local_manager.get_ident)
#: create a new module for all the database related functions and objects
db = ModuleType('db')
key = value = mod = None
for mod in sqlalchemy, orm:
for key, value in mod.__dict__.iteritems():
if key in mod.__all__:
setattr(db, key, value)
del key, mod, value
db.__doc__ = __doc__
db.mapper = mapper
db.get_engine = lambda: local.application.database_engine
for name in 'delete', 'save', 'flush', 'execute', 'begin', \
'commit', 'rollback', 'clear', 'refresh', 'expire':
setattr(db, name, getattr(session, name))
db.session = session
db.DatabaseManager = DatabaseManager
#: support for SQLAlchemy's 0.4.2 Text type, in older versions it's
#: just Text. This patch will go away once SQLAlchemy 0.5 is out
#: or something like that.
if not hasattr(db, 'Text'):
db.Text = db.String
#: called at the end of a request
cleanup_session = session.remove