• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

winazurestorageのフォーク


Commit MetaInfo

修订版0c22ac7e0c1b3b8cb7bd6628492f388782e688ef (tree)
时间2009-04-15 05:11:37
作者Steve Marx <Steve.Marx@micr...>
CommiterSteve Marx

Log Message

adding enqueue and dequeue support

更改概述

差异

--- a/winazurestorage.py
+++ b/winazurestorage.py
@@ -83,7 +83,7 @@ class SharedKeyCredentials(object):
8383 if not for_tables:
8484 string_to_sign += canonicalized_headers + NEW_LINE # Canonicalized headers
8585 string_to_sign += canonicalized_resource # Canonicalized resource
86-
86+
8787 request.add_header('Authorization', 'SharedKey ' + self._account + ':' + base64.encodestring(hmac.new(self._key, unicode(string_to_sign).encode("utf-8"), hashlib.sha256).digest()).strip())
8888 return request
8989
@@ -126,6 +126,8 @@ class Storage(object):
126126
127127 class TableEntity(object): pass
128128
129+class QueueMessage(): pass
130+
129131 class QueueStorage(Storage):
130132 def __init__(self, host, account_name, secret_key, use_path_style_uris = None):
131133 super(QueueStorage, self).__init__(host, account_name, secret_key, use_path_style_uris)
@@ -148,6 +150,44 @@ class QueueStorage(Storage):
148150 return response.code
149151 except URLError, e:
150152 return e.code
153+
154+ def put_message(self, queue_name, payload):
155+ data = "<QueueMessage><MessageText>%s</MessageText></QueueMessage>" % base64.encodestring(payload)
156+ req = RequestWithMethod("POST", "%s/%s/messages" % (self.get_base_url(), queue_name), data=data)
157+ req.add_header("Content-Type", "application/xml")
158+ req.add_header("Content-Length", len(data))
159+ self._credentials.sign_request(req)
160+ try:
161+ response = urlopen(req)
162+ return response.code
163+ except URLError, e:
164+ return e.code
165+
166+ def get_message(self, queue_name):
167+ req = Request("%s/%s/messages" % (self.get_base_url(), queue_name))
168+ self._credentials.sign_request(req)
169+ response = urlopen(req)
170+ dom = minidom.parseString(response.read())
171+ messages = dom.getElementsByTagName("QueueMessage")
172+ result = None
173+ if len(messages) == 1:
174+ message = messages[0]
175+ result = QueueMessage()
176+ result.id = message.getElementsByTagName("MessageId")[0].firstChild.data
177+ result.pop_receipt = message.getElementsByTagName("PopReceipt")[0].firstChild.data
178+ result.text = base64.decodestring(message.getElementsByTagName("MessageText")[0].firstChild.data)
179+ return result
180+
181+ def delete_message(self, queue_name, message):
182+ id = message.id
183+ pop_receipt = message.pop_receipt
184+ req = RequestWithMethod("DELETE", "%s/%s/messages/%s?popreceipt=%s" % (self.get_base_url(), queue_name, id, pop_receipt))
185+ self._credentials.sign_request(req)
186+ try:
187+ response = urlopen(req)
188+ return response.code
189+ except URLError, e:
190+ return e.code
151191
152192 class TableStorage(Storage):
153193 '''Due to local development storage not supporting SharedKey authentication, this class