• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

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

winazurestorageのフォーク


Commit MetaInfo

Revision9008da70a682554b06c475c2ac21cfdca9f2ab3f (tree)
Zeit2012-04-20 17:09:56
Autorhylom <hylom@hylo...>
Commiterhylom

Log Message

fix tablestorage: encoding error when key has unicode value

Ändern Zusammenfassung

Diff

--- a/winazurestorage.py
+++ b/winazurestorage.py
@@ -15,7 +15,7 @@ import os
1515 from xml.dom import minidom #TODO: Use a faster way of processing XML
1616 import re
1717 from urllib2 import Request, urlopen, URLError
18-from urllib import urlencode
18+from urllib import urlencode, quote
1919 from urlparse import urlsplit, parse_qs
2020 from datetime import datetime, timedelta
2121
@@ -158,7 +158,7 @@ class TableEntityException(Exception):
158158
159159 class TableEntity(object):
160160 "Table Entity"
161- def __init__(self, partition_key, row_key, props):
161+ def __init__(self, partition_key="", row_key="", props={}):
162162 self.partition_key = partition_key
163163 self.row_key = row_key
164164 self.properties = props
@@ -186,7 +186,7 @@ class TableEntity(object):
186186 def to_insert_xml(self):
187187 contents = [self._make_property_node(propname, self.properties[propname]) for propname in self.properties]
188188 contents_str = "\n".join(contents)
189- now_str = datetime.utcnow().isoformat()
189+ now_str = datetime.utcnow().isoformat() + "Z"
190190 xml = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
191191 <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">
192192 <title />
@@ -421,7 +421,7 @@ class TableStorage(Storage):
421421 def insert_entity(self, table_name, entity):
422422 data = entity.to_insert_xml()
423423 url = "%s/%s" % (self.get_base_url(), table_name)
424- req = winazurestorage.RequestWithMethod("POST", url, data=data)
424+ req = RequestWithMethod("POST", url, data=data)
425425 req.add_header("Content-Length", "%d" % len(data))
426426 req.add_header("Content-Type", "application/atom+xml")
427427 self._credentials.sign_table_request(req)
@@ -434,8 +434,10 @@ class TableStorage(Storage):
434434 def update_entity(self, table_name, partition_key, row_key, entity):
435435 data = entity.to_update_xml()
436436 url = """%s/%s(PartitionKey='%s',RowKey='%s')""" % (self.get_base_url(), table_name, partition_key, row_key)
437+ if isinstance(url, unicode):
438+ url = url.encode('utf-8')
437439
438- req = winazurestorage.RequestWithMethod("PUT", url, data=data)
440+ req = RequestWithMethod("PUT", url, data=data)
439441 req.add_header("Content-Length", "%d" % len(data))
440442 req.add_header("Content-Type", "application/atom+xml")
441443 self._credentials.sign_table_request(req)
@@ -443,13 +445,14 @@ class TableStorage(Storage):
443445 response = urlopen(req)
444446 return response.code
445447 except URLError, e:
446- print data
447448 return e.code
448449
449450 def merge_entity(self, table_name, partition_key, row_key, entity):
450451 data = entity.to_update_xml()
451452 url = """%s/%s(PartitionKey='%s',RowKey='%s')""" % (self.get_base_url(), table_name, partition_key, row_key)
452- req = winazurestorage.RequestWithMethod("MERGE", url, data=data)
453+ if isinstance(url, unicode):
454+ url = url.encode('utf-8')
455+ req = RequestWithMethod("MERGE", url, data=data)
453456 req.add_header("Content-Length", "%d" % len(data))
454457 req.add_header("Content-Type", "application/atom+xml")
455458 self._credentials.sign_table_request(req)
@@ -462,7 +465,9 @@ class TableStorage(Storage):
462465 def delete_entity(self, table_name, partition_key, row_key, condition="*"):
463466 data = ""
464467 url = """%s/%s(PartitionKey='%s',RowKey='%s')""" % (self.get_base_url(), table_name, partition_key, row_key)
465- req = winazurestorage.RequestWithMethod("DELETE", url, data)
468+ if isinstance(url, unicode):
469+ url = url.encode('utf-8')
470+ req = RequestWithMethod("DELETE", url, data)
466471 req.add_header("Content-Length", "%d" % len(data))
467472 req.add_header("Content-Type", "application/atom+xml")
468473 req.add_header("If-Match", condition)
@@ -474,9 +479,11 @@ class TableStorage(Storage):
474479 return e.code
475480
476481 def query_entity(self, table_name, filter):
477- quoted_filter = urllib.quote(filter)
482+ quoted_filter = quote(filter)
478483 url = """%s/%s()?$filter=%s""" % (self.get_base_url(), table_name, quoted_filter)
479- req = winazurestorage.RequestWithMethod("GET", url)
484+ if isinstance(url, unicode):
485+ url = url.encode('utf-8')
486+ req = RequestWithMethod("GET", url)
480487 self._credentials.sign_table_request(req)
481488 try:
482489 resp = urlopen(req)
@@ -493,7 +500,9 @@ class TableStorage(Storage):
493500
494501 def top_entity(self, table_name, size):
495502 url = """%s/%s()?$top=%s""" % (self.get_base_url(), table_name, size)
496- req = winazurestorage.RequestWithMethod("GET", url)
503+ if isinstance(url, unicode):
504+ url = url.encode('utf-8')
505+ req = RequestWithMethod("GET", url)
497506 self._credentials.sign_table_request(req)
498507
499508 try: