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


Python Sync.push方法代码示例

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


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

示例1: SyncManager

# 需要导入模块: from sync import Sync [as 别名]
# 或者: from sync.Sync import push [as 别名]

#.........这里部分代码省略.........

    def ask_for_sync_settings(self):
        """
        Ask the user for sync settings: Asks for server-URL, username and password.
        """
        print("Bitte geben Sie die Einstellungen für Ihren Synchronisations-Server an...")
        self.server_address = input("URL: ")
        self.username = input("Benutzername: ")
        self.password = input("Passwort: ")
        line = input("Zertifikat im .pem-Format (beenden mit einer Leerzeile): ")
        while len(line) > 0:
            self.certificate += line + "\n"
            line = input("")
        self.certificate += line
        if self.certificate_file:
            self.certificate_file.close()
        self.certificate_file = NamedTemporaryFile()
        self.certificate_file.write(self.certificate.encode('utf-8'))
        self.certificate_file.seek(0)
        self.create_sync()

    def set_server_address(self, url):
        """
        Sets the url without ajax folder and php file names but with https://

        :param url: the url
        :type url: str
        """
        self.server_address = url

    def set_username(self, username):
        """
        Sets the username.

        :param username: the username
        :type username: str
        """
        self.username = username

    def set_password(self, password):
        """
        Sets the password.

        :param password: the password
        :type password: str
        """
        self.password = password

    def set_certificate(self, certificate):
        """
        Sets the certificate from a string in PEM format.

        :param certificate: certificate in PEM format
        :type certificate: str
        """
        self.certificate = certificate
        if self.certificate_file:
            self.certificate_file.close()
        self.certificate_file = NamedTemporaryFile()
        self.certificate_file.write(self.certificate.encode('utf-8'))
        self.certificate_file.seek(0)

    def create_sync(self):
        """
        creates a sync object.
        """
        self.sync = Sync(self.server_address, self.username, self.password, self.certificate_file.name)

    def has_settings(self):
        """
        Returns true if pull or push are possible

        :return: Are there settings?
        :rtype: bool
        """
        return bool(self.sync)

    def pull(self):
        """
        pulls data from the sync server. Returns an empty string if no connection is possible.

        :return: pulled base64 data
        :rtype: str
        """
        if self.sync:
            return self.sync.pull()
        else:
            return False, ''

    def push(self, data):
        """
        pushes data to the sync server. If the push fails an error message is displayed.

        :param str data: base64 data
        """
        if self.sync:
            if not self.sync.push(data):
                print("Synchronisation fehlgeschlagen.")
        else:
            print("Sie haben keine gültigen Einstellungen für den sync server.")
开发者ID:JPO1,项目名称:ctSESAM-pyside,代码行数:104,代码来源:sync_manager.py

示例2: test_push

# 需要导入模块: from sync import Sync [as 别名]
# 或者: from sync.Sync import push [as 别名]
 def test_push(self):
     sync = Sync("https://ersatzworld.net/ctpwdgen-server/", 'inter', 'op', 'file.pem')
     self.assertTrue(sync.push(str(b64encode(b'Test'), encoding='utf-8')))
开发者ID:JPO1,项目名称:ctSESAM-pyside,代码行数:5,代码来源:test_Sync.py


注:本文中的sync.Sync.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。