• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python http_util.ContactClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: post

    def post(self, slug):
        '''
        When post request is received, contact of which slug is equal to
        slug is retrieved. If its state is Pending or Error, the contact
        request is send again.
        '''

        logger = logging.getLogger("newebe.contact")

        self.contact = ContactManager.getContact(slug)
        owner = UserManager.getUser()

        if self.contact and self.contact.url != owner.url:
            try:
                data = owner.asContact().toJson()

                client = ContactClient()
                client.post(self.contact, "contacts/request/", data,
                            self.on_contact_response)

            except Exception:
                import traceback
                logger.error("Error on adding contact:\n %s" %
                        traceback.format_exc())

                self.contact.state = STATE_ERROR
                self.contact.save()

            self.return_one_document(self.contact)
        else:
            self.return_failure("Contact does not exist", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:31,代码来源:handlers.py


示例2: forward_to_contact

    def forward_to_contact(self, micropost, contact, activity, method="POST"):
        '''
        *micropost* 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.
        '''

        httpClient = ContactClient()
        body = micropost.toJson(localized=False)

        try:
            httpClient.post(contact, CONTACT_PATH, body,
                            callback=(yield gen.Callback("retry")))
            response = yield gen.Wait("retry")

            if response.error:
                self.return_failure("Posting micropost to contact failed.")

            else:
                for error in activity.errors:
                    if error["contactKey"] == contact.key:
                        activity.errors.remove(error)
                        activity.save()
                        self.return_success("Micropost correctly resent.")
                # TODO: handle case where error is not found.

        except:
            self.return_failure("Posting micropost to contact failed.")
开发者ID:mpmedia,项目名称:newebe,代码行数:28,代码来源:handlers.py


示例3: on_picture_found

    def on_picture_found(self, picture, id):
        '''
        '''
        self.picture = picture

        data = dict()
        data["picture"] = picture.toDict(localized=False)
        data["contact"] = UserManager.getUser().asContact().toDict()

        print CURRENT_DOWNLOADS
        print "data picture id %s" % data["picture"]["_id"]
        for download in CURRENT_DOWNLOADS:
            print "download %s " % download

            if download == data["picture"]["_id"]:
                return self.return_success('already downloading')

        CURRENT_DOWNLOADS.append(data["picture"]["_id"])

        contact = ContactManager.getTrustedContact(picture.authorKey)

        client = ContactClient()
        body = json_encode(data)

        try:
            client.post(contact,  u"pictures/contact/download/",
                        body, self.on_download_finished)
        except HTTPError:
            self.return_failure("Cannot download picture from contact.")
开发者ID:DopeChicCity,项目名称:newebe,代码行数:29,代码来源:handlers.py


示例4: forward_to_contact

    def forward_to_contact(self, common, contact, activity, method="POST"):
        '''
        *common 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()
        body = common.toJson()

        try:
            if method == "POST":
                client.post(contact, CONTACT_PATH, body,
                            callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")
            else:
                body = common.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 common 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("Common request correctly resent.")

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


示例5: put

    def put(self, key):
        '''
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        data = self.get_body_as_dict(
                expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:

                user = UserManager.getUser()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date)
                )

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact, CONTACT_PATH, body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                                "Deleting micropost to contact failed.")

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

                except:
                    self.return_failure("Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:60,代码来源:handlers.py


示例6: post

    def post(self, postId):
        """
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        """

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {"date": date_util.get_db_date_from_date(micropost.date), "contactKey": user.key, "path": path}

            client.post(
                contact, "microposts/contacts/attach/", json_encode(body), callback=(yield gen.Callback("getattach"))
            )
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure("An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
开发者ID:prologic,项目名称:newebe,代码行数:34,代码来源:handlers.py


示例7: send_files_to_contact

    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,代码行数:14,代码来源:handlers.py


示例8: send_creation_to_contacts

    def send_creation_to_contacts(self, path, doc):
        '''
        Sends a POST request to all trusted contacts.

        Request body contains object to post at JSON format.
        '''

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


示例9: send_files_to_contacts

    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,代码行数:16,代码来源:handlers.py


示例10: on_picture_found

    def on_picture_found(self, picture, id):
        '''
        '''
        self.picture = picture

        data = dict()
        data["picture"] = picture.toDict(localized=False)
        data["contact"] = UserManager.getUser().asContact().toDict()

        contact = ContactManager.getTrustedContact(picture.authorKey)

        client = ContactClient()
        body = json_encode(data)

        try:
            client.post(contact,  u"pictures/contact/download/",
                        body, self.on_download_finished)
        except HTTPError:
            self.return_failure("Cannot download picture from contact.")
开发者ID:mpmedia,项目名称:newebe,代码行数:19,代码来源:handlers.py


示例11: on_common_found

    def on_common_found(self, common, id):
        '''
        '''
        self.common = common

        data = dict()
        data["common"] = common.toDict(localized=False)
        data["contact"] = UserManager.getUser().asContact().toDict()

        contact = ContactManager.getTrustedContact(common.authorKey)

        client = ContactClient()
        body = json_encode(data)

        try:
            client.post(contact,  u"commons/contact/download/",
                        body, self.on_download_finished)
        except HTTPError:
            self.return_failure("Cannot download common from contact.")
开发者ID:DopeChicCity,项目名称:newebe,代码行数:19,代码来源:handlers.py


示例12: send_deletion_to_contacts

    def send_deletion_to_contacts(self, path, doc):
        '''
        Send a delete request (PUT because Tornado don't handle DELETE request
        with a body) to all trusted contacts.

        Request body contains object to delete at JSON format.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        date = date_util.get_db_date_from_date(doc.date)

        for contact in contacts:
            try:
                client.delete(contact, path, doc.toJson(localized=False), date)
            except HTTPError:
                import pdb
                pdb.set_trace()
                self.activity.add_error(contact, extra=date)
                self.activity.save()
开发者ID:rakoo,项目名称:newebe,代码行数:20,代码来源:handlers.py


示例13: forward_to_contact

    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:
                self.return_failure(
                  "Retry picture request to a contact failed ({}).".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:mike-perdide,项目名称:newebe,代码行数:39,代码来源:handlers.py


示例14: put

    def put(self, slug):
        '''
        Confirm contact request or update tag data.
        '''

        data = self.get_body_as_dict(["tags", "state"])
        state = data["state"]
        tags = data.get("tags", None)
        self.contact = ContactManager.getContact(slug)

        if self.contact:
            if self.contact.state != STATE_TRUSTED and state == STATE_TRUSTED:
                self.contact.state = STATE_TRUSTED
                self.contact.save()

                user = UserManager.getUser()
                data = user.asContact().toJson(localized=False)

                try:
                    client = ContactClient()
                    client.post(self.contact, "contacts/confirm/", data,
                                self.on_contact_response)
                except:
                    self.contact.state = STATE_ERROR
                    self.contact.save()
                    self.return_failure(
                        "Error occurs while confirming contact.")

            elif tags != None:
                self.contact.tags = tags
                self.contact.save()
                self.return_success("Contact tags updated.")

            else:
                self.return_success("Nothing to change.")

        else:
            self.return_failure("Contact to confirm does not exist.")
开发者ID:WentaoXu,项目名称:newebe,代码行数:38,代码来源:handlers.py


示例15: on_picture_found

    def on_picture_found(self, picture, id):
        """
        """
        self.picture = picture

        data = dict()
        data["picture"] = picture.toDict(localized=False)
        data["contact"] = UserManager.getUser().asContact().toDict()

        if picture._id in CURRENT_DOWNLOADS:
            self.return_success("already downloading")
        else:
            CURRENT_DOWNLOADS.append(picture._id)

        contact = ContactManager.getTrustedContact(picture.authorKey)

        client = ContactClient()
        body = json_encode(data)

        try:
            client.post(contact, u"pictures/contact/download/", body, self.on_download_finished)
        except HTTPError:
            self.return_failure("Cannot download picture from contact.")
开发者ID:WentaoXu,项目名称:newebe,代码行数:23,代码来源:handlers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.UserManager类代码示例发布时间:2022-05-27
下一篇:
Python date_util.get_date_from_db_date函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap