当前位置: 首页>>代码示例>>Python>>正文


Python Transmitter.set_account方法代码示例

本文整理汇总了Python中transmitter.Transmitter.set_account方法的典型用法代码示例。如果您正苦于以下问题:Python Transmitter.set_account方法的具体用法?Python Transmitter.set_account怎么用?Python Transmitter.set_account使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transmitter.Transmitter的用法示例。


在下文中一共展示了Transmitter.set_account方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_upload_entry

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [as 别名]
 def test_upload_entry(self):
     tt = Transmitter()
     tt.set_account(self.account_with_good_password)
     filename = 'test_files/entry_test'
     entry = ElyxerEntry()
     entry.set_transmitter(tt)
     entry.load(filename)
     entry.set_title('WoooYAH!')
     tt.publish_entry(entry)
开发者ID:jackdesert,项目名称:lyxblogger_oo,代码行数:11,代码来源:test_transmitter.py

示例2: test_set_transmitter_exactly_once

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [as 别名]
 def test_set_transmitter_exactly_once(self):
     tt = Transmitter()
     url = 'whee.com'
     username = 'boyhowdy'
     account = Account(url, username, None)
     tt.set_account(account)
     aa = ElyxerEntry()
     aa.set_transmitter(tt)
     self.assertRaises(TransmitterAlreadyExistsError, lambda: aa.set_transmitter(tt))
开发者ID:jackdesert,项目名称:lyxblogger_oo,代码行数:11,代码来源:test_entry.py

示例3: test_publish_image

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [as 别名]
 def test_publish_image(self):
     Image.set_abs_reference_dir_from_html_file(self.filename)
     account = AccountManager.get_default_account()
     tt = Transmitter()
     tt.set_account(account)
     image = Image("some <img src='Suzanne.jpg' /> string")
     before = image.get_remote_src()
     self.assertEqual(before, None)
     tt.publish_image(image)
     after = image.get_remote_src()
     self.assertNotEqual(after, None)
开发者ID:jackdesert,项目名称:lyxblogger_oo,代码行数:13,代码来源:test_transmitter.py

示例4: __init__

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [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

示例5: test_check_credentials_no_password

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [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

示例6: test_check_credentials_bad_password

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [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

示例7: test_check_credentials_bogus

# 需要导入模块: from transmitter import Transmitter [as 别名]
# 或者: from transmitter.Transmitter import set_account [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.set_account方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。