本文整理匯總了Python中newebe.lib.http_util.ContactClient.post方法的典型用法代碼示例。如果您正苦於以下問題:Python ContactClient.post方法的具體用法?Python ContactClient.post怎麽用?Python ContactClient.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類newebe.lib.http_util.ContactClient
的用法示例。
在下文中一共展示了ContactClient.post方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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)
示例2: forward_to_contact
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例3: on_picture_found
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例4: forward_to_contact
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例5: post
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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)
示例6: send_creation_to_contacts
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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()
示例7: on_picture_found
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例8: on_common_found
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例9: put
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例10: on_picture_found
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
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.")
示例11: put
# 需要導入模塊: from newebe.lib.http_util import ContactClient [as 別名]
# 或者: from newebe.lib.http_util.ContactClient import post [as 別名]
def put(self, slug):
'''
Confirm contact request.
'''
self.contact = ContactManager.getContact(slug)
if self.contact:
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.")
else:
self.return_failure("Contact to confirm does not exist.")