當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。