當前位置: 首頁>>代碼示例>>Python>>正文


Python models.FakeAccount類代碼示例

本文整理匯總了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
開發者ID:AndrewHay,項目名稱:lesswrong,代碼行數:27,代碼來源:import_missing_comments.py

示例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()
開發者ID:ChrisCinelli,項目名稱:reddit,代碼行數:17,代碼來源:reddit_base.py


注:本文中的r2.models.FakeAccount類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。