本文整理匯總了Python中settings.DATABASE屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.DATABASE屬性的具體用法?Python settings.DATABASE怎麽用?Python settings.DATABASE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類settings
的用法示例。
在下文中一共展示了settings.DATABASE屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: clear_database
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def clear_database():
assert settings.TEST_SETTINGS
if os.path.exists(settings.DATABASE):
os.remove(settings.DATABASE)
示例2: create
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def create(cls, creator_id, message, locale='en', vote_options=[],
secret=False, public=False, max_votes=1, bars=False):
"""Creates a new poll without any votes.
Empty vote_options will be replaced by ['Yes', 'No'].
"""
con = sqlite3.connect(settings.DATABASE)
init_database(con)
cur = con.cursor()
if not vote_options:
with force_locale(locale):
vote_options = [tr('Yes'), tr('No')]
# clamp to 1 to len(vote_options)
max_votes = max(1, min(max_votes, len(vote_options)))
cur.execute("""INSERT INTO Polls
(creator, message, locale, finished,
secret, public, max_votes, bars) VALUES
(?, ?, ?, ?, ?, ?, ?, ?)""",
(creator_id, message, locale, False,
secret, public, max_votes, bars))
id = cur.lastrowid
for number, name in enumerate(vote_options):
cur.execute("""INSERT INTO VoteOptions
(poll_id, name, number) VALUES
(?, ?, ?)""",
(id, name, number))
con.commit()
return cls(con, id)
示例3: load
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def load(cls, id):
"""Loads a poll from the database.
Raise a InvalidPollError if no poll with that id
exists.
"""
con = sqlite3.connect(settings.DATABASE)
return cls(con, id)
示例4: create_app
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def create_app(loop):
app = web.Application(loop=loop, debug=settings.DEBUG)
setup_jinja(app, settings.DEBUG)
aiohttp_session.setup(app, EncryptedCookieStorage(
settings.SESSION_SECRET.encode('utf-8'),
max_age=settings.SESSION_MAX_AGE))
app.middlewares.append(aiohttp_login.flash.middleware)
app.router.add_get('/', handlers.index)
app.router.add_get('/users/', handlers.users, name='users')
app['db'] = await asyncpg.create_pool(dsn=settings.DATABASE, loop=loop)
aiohttp_login.setup(app, AsyncpgStorage(app['db']), settings.AUTH)
return app
示例5: __init__
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def __init__(self, channels_amount, channels, log_filename=None):
self.bots = []
self.channels_amount = channels_amount
self.log_filename = log_filename
self.channels = channels
self.db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
示例6: _create_bot
# 需要導入模塊: import settings [as 別名]
# 或者: from settings import DATABASE [as 別名]
def _create_bot(self, name, channels):
conn = IRCConnection(settings.IRC['SERVER'],
settings.IRC['PORT'],
settings.IRC['NICK'],
settings.IRC['PASSWORD'],
self.log_filename)
bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'],
settings.DATABASE['NAME'],
settings.DATABASE['USER'],
settings.DATABASE['PASSWORD'])
bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename)
bot.daemon = True
bot.connect_and_join_channels(channels)
bot.start()
return bot