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


Python ContactClient.post_files方法代码示例

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


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

示例1: send_files_to_contact

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
    def send_files_to_contact(self, contact, path, fields, files):
        '''
        Sends in a form given file and fields to given contact (at given
        path).
        '''

        if not hasattr(self, "activity"):
            self.activity = None
        client = ContactClient(self.activity)
        try:
            client.post_files(contact, path, fields=fields, files=files)
        except HTTPError:
            self.activity.add_error(contact)
            self.activity.save()
开发者ID:WentaoXu,项目名称:newebe,代码行数:16,代码来源:handlers.py

示例2: send_files_to_contacts

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
    def send_files_to_contacts(self, path, fields, files):
        '''
        Sends in a form given file and fields to all trusted contacts (at given
        path).

        If any error occurs, it is stored in linked activity.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        for contact in contacts:
            try:
                client.post_files(contact, path, fields = fields, files = files)
            except HTTPError:
                self.activity.add_error(contact)
                self.activity.save()
开发者ID:rakoo,项目名称:newebe,代码行数:18,代码来源:handlers.py

示例3: forward_to_contact

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
    def forward_to_contact(self, picture, contact, activity, method="POST"):
        '''
        *picture is sent to *contact* via a request of which method is set
        as *method*. If request succeeds, error linked to this contact
        is removed. Else nothing is done and error code is returned.
        '''

        client = ContactClient()

        try:
            if method == "POST":
                client.post_files(
                    contact,
                    CONTACT_PATH,
                    {"json": str(picture.toJson(localized=False))},
                    [("picture",
                      str(picture.path),
                      picture.fetch_attachment("th_" + picture.path))
                    ],
                    callback=(yield gen.Callback("retry"))
                )
                response = yield gen.Wait("retry")

            else:
                body = picture.toJson(localized=False)
                response = client.put(contact, CONTACT_PATH, body,
                                      callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")

            if response.error:
                message = "Retry picture request to a contact failed ({})."
                self.return_failure(message.format(method))

            else:
                for error in activity.errors:
                    if error["contactKey"] == contact.key:
                        activity.errors.remove(error)
                        activity.save()
                        self.return_success("Picture request correctly resent.")

        except:
            self.return_failure("Picture resend to a contact failed again.")
开发者ID:mpmedia,项目名称:newebe,代码行数:44,代码来源:handlers.py


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