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


Python Transmitter.check_credentials方法代碼示例

本文整理匯總了Python中transmitter.Transmitter.check_credentials方法的典型用法代碼示例。如果您正苦於以下問題:Python Transmitter.check_credentials方法的具體用法?Python Transmitter.check_credentials怎麽用?Python Transmitter.check_credentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在transmitter.Transmitter的用法示例。


在下文中一共展示了Transmitter.check_credentials方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from transmitter import Transmitter [as 別名]
# 或者: from transmitter.Transmitter import check_credentials [as 別名]
class AccountManager:

    DEFAULT_ACCOUNT_ID = 0

    def __init__(self):
        self.__transmitter = Transmitter()
        self.__configpath  = self.__set_configpath()
        self.__config      = self.__init_config()
        self.__default_account = AccountManager.get_default_account()
        self.__accounts    = []
        self.__load_accounts_from_config()

    def pass_transmitter(self):
        return self.__transmitter

    def reset_config(self):
        self.__accounts = []
        if os.path.exists(self.__configpath):
            os.remove(self.__configpath)
        self.__config = self.__init_config()

    def get_accounts(self):
        return [self.__default_account] + self.__accounts

    def add_new_account(self, account):
        self.__verify_account(account)
        self.__set_section_id_and_load_account(account)
        self.__add_account_to_config(account)

    def get_recent_account(self):
        id = self.get_recent_id()
        id = int(id)
        return self.get_account_by_id(id)

    def get_recent_id(self):
        id = self.__config.get('DEFAULT', 'last_profile')
        return int(id) 

    def get_account_by_id(self, id):
        self.__record_recent_account(id)
        if id == 0:
            account = self.__default_account
        else:
            account = self.__accounts[id - 1]
        self.__transmitter.set_account(account) 
        return  account
    
    def delete_account_by_id(self, id):
        offset_id = id - 1
        del self.__accounts[offset_id]
        self.__renumber_accounts()


    def __set_section_id_and_load_account(self, account):
        account.set_section_id(self.__next_id())
        self.__accounts.append(account)



    def __load_accounts_from_config(self):
        for section in self.__config.sections():
            section_id = self.__next_id()
            url = self.__config.get(section, 'url')
            username = self.__config.get(section, 'username')
            try:
                password = self.__config.get(section, 'password')
                if password == '': password = None
            except NoOptionError:
                password = None
            new_account = Account(url, username, password)
            new_account.set_section_id(section_id)
            self.__set_section_id_and_load_account(new_account)

    def __verify_account(self, account):
        self.__transmitter.set_account(account)
        self.__transmitter.check_credentials()

    def __next_id(self):
        return len(self.__accounts) + 1

    def __add_account_to_config(self, account):
        id = int(account.get_section_id()) # This will throw an exception if it's not a number
        id = str(id)
        try:
            self.__config.add_section(id)
        except DuplicateSectionError:
            # No need to add it if it's already there
            message = 'a ok'

        self.__config.set(id, 'url', account.get_url())
        self.__config.set(id, 'username', account.get_username())
        if account.get_password():
            self.__config.set(id, 'password', account.get_password())
        self.__save_config_to_file()

    def __save_config_to_file(self):
        with open(self.__configpath, 'wb') as handle: 
            self.__config.write(handle)

    def __record_recent_account(self, id):
#.........這裏部分代碼省略.........
開發者ID:jackdesert,項目名稱:lyxblogger_oo,代碼行數:103,代碼來源:account_manager.py

示例2: test_check_credentials_bad_password

# 需要導入模塊: from transmitter import Transmitter [as 別名]
# 或者: from transmitter.Transmitter import check_credentials [as 別名]
 def test_check_credentials_bad_password(self):
     tt = Transmitter()
     tt.set_account(self.account_with_bad_password)
     self.assertEquals(tt.check_credentials(), 'username/password error') 
開發者ID:jackdesert,項目名稱:lyxblogger_oo,代碼行數:6,代碼來源:test_transmitter.py

示例3: test_check_credentials_no_password

# 需要導入模塊: from transmitter import Transmitter [as 別名]
# 或者: from transmitter.Transmitter import check_credentials [as 別名]
 def test_check_credentials_no_password(self):
     tt = Transmitter()
     tt.set_account(self.account_with_no_password)
     self.assertEquals(tt.check_credentials(), True) 
開發者ID:jackdesert,項目名稱:lyxblogger_oo,代碼行數:6,代碼來源:test_transmitter.py

示例4: test_check_credentials_bogus

# 需要導入模塊: from transmitter import Transmitter [as 別名]
# 或者: from transmitter.Transmitter import check_credentials [as 別名]
 def test_check_credentials_bogus(self):
     tt = Transmitter()
     tt.set_account(self.bogus_account)
     self.assertEquals(tt.check_credentials(), 'host not found') 
開發者ID:jackdesert,項目名稱:lyxblogger_oo,代碼行數:6,代碼來源:test_transmitter.py


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