From 3b341e375f6da21b9dafe75125c5eb6668f27cf5 Mon Sep 17 00:00:00 2001 From: David Goetz Date: Wed, 13 Feb 2013 12:04:21 -0800 Subject: [PATCH] fix large objects with unicode Change-Id: I2a088e6cfe354d18cb2107a42bc626c2e7822e42 --- swift/proxy/controllers/obj.py | 13 +++++++++++-- test/unit/proxy/test_server.py | 7 ++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index ee2b7da6fb..30225c93f9 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -57,6 +57,15 @@ from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPNotFound, \ HTTPClientDisconnect +def segment_listing_iter(listing): + listing = iter(listing) + while True: + seg_dict = listing.next() + if isinstance(seg_dict['name'], unicode): + seg_dict['name'] = seg_dict['name'].encode('utf-8') + yield seg_dict + + class SegmentedIterable(object): """ Iterable that returns the object contents for a segmented object in Swift. @@ -77,7 +86,7 @@ class SegmentedIterable(object): def __init__(self, controller, container, listing, response=None): self.controller = controller self.container = container - self.listing = iter(listing) + self.listing = segment_listing_iter(listing) self.segment = 0 self.segment_dict = None self.segment_peek = None @@ -280,7 +289,7 @@ class ObjectController(Controller): sublisting = json.loads(lresp.body) if not sublisting: break - marker = sublisting[-1]['name'] + marker = sublisting[-1]['name'].encode('utf-8') yield sublisting def _remaining_items(self, listing_iter): diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 62e4f1d16a..05f1713f35 100755 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -963,7 +963,7 @@ class TestObjectController(unittest.TestCase): listing3 = [{"hash": "6605f80e3cefaa24e9823544df4edbd6", "last_modified": "2012-11-08T04:05:37.853710", "bytes": 2, - "name": "seg05", + "name": u'\N{SNOWMAN}seg05', "content_type": "application/octet-stream"}] response_bodies = ( @@ -1029,9 +1029,10 @@ class TestObjectController(unittest.TestCase): ['GET', '/a/segments/seg04', {}], ['GET', '/a/segments', {'format': 'json', 'prefix': 'seg', 'marker': 'seg04'}], - ['GET', '/a/segments/seg05', {}], + ['GET', '/a/segments/\xe2\x98\x83seg05', {}], ['GET', '/a/segments', - {'format': 'json', 'prefix': 'seg', 'marker': 'seg05'}]]) + {'format': 'json', 'prefix': 'seg', + 'marker': '\xe2\x98\x83seg05'}]]) finally: # other tests in this file get very unhappy if this