本文整理匯總了Python中r2.models.FakeAccount._commit方法的典型用法代碼示例。如果您正苦於以下問題:Python FakeAccount._commit方法的具體用法?Python FakeAccount._commit怎麽用?Python FakeAccount._commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類r2.models.FakeAccount
的用法示例。
在下文中一共展示了FakeAccount._commit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_account
# 需要導入模塊: from r2.models import FakeAccount [as 別名]
# 或者: from r2.models.FakeAccount import _commit [as 別名]
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