本文整理匯總了Python中r2.models.FakeAccount類的典型用法代碼示例。如果您正苦於以下問題:Python FakeAccount類的具體用法?Python FakeAccount怎麽用?Python FakeAccount使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeAccount類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_account
def create_account(full_name):
name = full_name.replace(' ', '_')
retry = 2 # First retry will by name2
username = name
while True:
# Create a new account
try:
if dryrun:
try:
account = Account._by_name(username)
if account:
raise AccountExists
except NotFound:
account = FakeAccount()
account.name = username
else:
account = register(username, generate_password(), None)
account.ob_account_name = full_name
account._commit()
except AccountExists:
# This username is taken, generate another, but first limit the retries
if retry > MAX_RETRIES:
raise StandardError("Unable to create account for '%s' after %d attempts" % (full_name, retry - 1))
else:
return account
username = "%s%d" % (name, retry)
retry += 1
示例2: __init__
def __init__(self, browser_langs, *a, **kw):
FakeAccount.__init__(self, *a, **kw)
if browser_langs:
lang = browser_langs[0]
content_langs = list(browser_langs)
# try to coerce the default language
if g.lang not in content_langs:
content_langs.append(g.lang)
content_langs.sort()
else:
lang = g.lang
content_langs = 'all'
self._defaults = self._defaults.copy()
self._defaults['pref_lang'] = lang
self._defaults['pref_content_langs'] = content_langs
self._defaults['pref_frame_commentspanel'] = False
self._load()