• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

winazurestorageのフォーク


コミットメタ情報

リビジョン132c7dcdcc51549576cc6f2a1dfbc35a75339b9e (tree)
日時2009-03-19 16:18:42
作者Steve Marx <Steve.Marx@micr...>
コミッターSteve Marx

ログメッセージ

better table support, minimal queue support

変更サマリ

差分

--- a/winazurestorage.py
+++ b/winazurestorage.py
@@ -3,6 +3,7 @@
33 """
44 Python wrapper around Windows Azure storage
55 Sriram Krishnan <sriramk@microsoft.com>
6+Steve Marx <steve.marx@microsoft.com>
67 """
78
89 import base64
@@ -38,13 +39,16 @@ TIME_FORMAT ="%a, %d %b %Y %H:%M:%S %Z"
3839
3940 def parse_edm_datetime(input):
4041 d = datetime.strptime(input[:input.find('.')], "%Y-%m-%dT%H:%M:%S")
41- if input[:input.find('.')] != -1:
42+ if input.find('.') != -1:
4243 d += timedelta(0, 0, int(round(float(input[input.index('.'):-1])*1000000)))
4344 return d
4445
4546 def parse_edm_int32(input):
4647 return int(input)
4748
49+def parse_edm_double(input):
50+ return float(input)
51+
4852 def parse_edm_boolean(input):
4953 return input.lower() == "true"
5054
@@ -122,12 +126,69 @@ class Storage(object):
122126
123127 class TableEntity(object): pass
124128
129+class QueueStorage(Storage):
130+ def __init__(self, host, account_name, secret_key, use_path_style_uris = None):
131+ super(QueueStorage, self).__init__(host, account_name, secret_key, use_path_style_uris)
132+
133+ def create_queue(self, name):
134+ req = RequestWithMethod("PUT", "%s/%s" % (self.get_base_url(), name))
135+ req.add_header("Content-Length", "0")
136+ self._credentials.sign_request(req)
137+ try:
138+ response = urlopen(req)
139+ return response.code
140+ except URLError, e:
141+ return e.code
142+
143+ def delete_queue(self, name):
144+ req = RequestWithMethod("DELETE", "%s/%s" % (self.get_base_url(), name))
145+ self._credentials.sign_request(req)
146+ try:
147+ response = urlopen(req)
148+ return response.code
149+ except URLError, e:
150+ return e.code
151+
125152 class TableStorage(Storage):
126- '''Due to local development storage not supporting SharedKeyLite authentication, this class
153+ '''Due to local development storage not supporting SharedKey authentication, this class
127154 will only work against cloud storage.'''
128155 def __init__(self, host, account_name, secret_key, use_path_style_uris = None):
129156 super(TableStorage, self).__init__(host, account_name, secret_key, use_path_style_uris)
130157
158+ def create_table(self, name):
159+ data = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
160+<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
161+ <title />
162+ <updated>%s</updated>
163+ <author>
164+ <name />
165+ </author>
166+ <id />
167+ <content type="application/xml">
168+ <m:properties>
169+ <d:TableName>%s</d:TableName>
170+ </m:properties>
171+ </content>
172+</entry>""" % (time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime()), name)
173+ req = RequestWithMethod("POST", "%s/Tables" % self.get_base_url(), data=data)
174+ req.add_header("Content-Length", "%d" % len(data))
175+ req.add_header("Content-Type", "application/atom+xml")
176+ self._credentials.sign_table_request(req)
177+ try:
178+ response = urlopen(req)
179+ return response.code
180+ except URLError, e:
181+ return e.code
182+
183+ def delete_table(self, name):
184+ req = RequestWithMethod("DELETE", "%s/Tables('%s')" % (self.get_base_url(), name))
185+ self._credentials.sign_table_request(req)
186+ try:
187+ response = urlopen(req)
188+ return response.code
189+ except URLError, e:
190+ return e.code
191+
131192 def list_tables(self):
132193 req = Request("%s/Tables" % self.get_base_url())
133194 self._credentials.sign_table_request(req)
@@ -157,8 +218,9 @@ class TableStorage(Storage):
157218 if t.lower() == 'edm.datetime': value = parse_edm_datetime(property.firstChild.data)
158219 elif t.lower() == 'edm.int32': value = parse_edm_int32(property.firstChild.data)
159220 elif t.lower() == 'edm.boolean': value = parse_edm_boolean(property.firstChild.data)
221+ elif t.lower() == 'edm.double': value = parse_edm_double(property.firstChild.data)
160222 else: raise Exception(t.lower())
161- else: value = property.firstChild.data
223+ else: value = property.firstChild is not None and property.firstChild.data or None
162224 setattr(entity, key, value)
163225 return entity
164226