微软项目经理Sriram Krishnan已经为Windows Azure数据存储编写了一个Python包装。Python是Windows Azure支持的语言之一。
根据微软的Azure网站,Python是Windows Azure所支持的工具和语言之一:
Windows Azure是一个开放的平台,将同时支持微软和非微软的语言和环境。Windows Azure欢迎第三方的工具和语言,例如Eclipse,Ruby,PHP和Python……
世界各地有数百万的开发人员使用.NET Framework和Visual Studio开发环境。开发者可以用相同的技能使用Visual Studio创建云化的应用程序,直接使用Visual Studio编写,测试和部署。在不久的将来开发人员能够部署用RubyOn Rails和Python编写的应用程序。
Sriram已经用Python编写了一个Windows Azure的数据存储包装并放在GitHub的代码库上。下面的例子演示了存储和查询数据:
conn = WAStorageConnection(DEVSTORE_HOST, DEVSTORE_ACCOUNT, DEVSTORE_SECRET_KEY)
for (container_name,etag, last_modified ) in conn.list_containers():
print container_name
print etag
print last_modified
conn.create_container("testcontainer", False)
conn.put_blob("testcontainer","test","Hello World!" )
print conn.get_blob("testcontainer", "test")
下面的例子演示登录:
def _get_auth_header(self, http_method, path, data, headers):
# As documented at http://msdn.microsoft.com/en-us/library/dd179428.aspx
string_to_sign =""
#First element is the method
string_to_sign += http_method + NEW_LINE
#Second is the optional content MD5
string_to_sign += NEW_LINE
#content type - this should have been initialized atleast to a blank value
if headers.has_key("content-type"):
string_to_sign += headers["content-type"]
string_to_sign += NEW_LINE
# date - we don't need to add header here since the special date storage header
# always exists in our implementation
string_to_sign += NEW_LINE
# Construct canonicalized storage headers.
# TODO: Note that this doesn't implement parts of the spec -
# combining header fields with same name,
# unfolding long lines and trimming white spaces around the colon
ms_headers =[header_key for header_key in headers.keys()
if header_key.startswith(PREFIX_STORAGE_HEADER)]
ms_headers.sort()
for header_key in ms_headers:
string_to_sign += "%s:%s%s" % (header_key, headers[header_key], NEW_LINE)
# Add canonicalized resource
string_to_sign += "/" + self.account_name + path
utf8_string_to_sign = unicode(string_to_sign).encode("utf-8")
hmac_digest = hmac.new(self.secret_key,
utf8_string_to_sign,
hashlib.sha256).digest()
return base64.encodestring(hmac_digest).strip()
微软的Windows Azure计划看起来像是要超越Google所提供的。Google的App Engine目前只支持Python,但是Google在将来有支持多语言的计划 。
查看英文原文:Python Has Wrapped Itself Around Windows Azure