Revision: 399
Author: bslatkin
Date: Mon Nov 15 15:47:16 2010
Log: hub: properly handle non-utf-8 encoded payloads
http://code.google.com/p/pubsubhubbub/source/detail?r=399
Modified:
/trunk/hub/main.py
/trunk/hub/main_test.py
=======================================
--- /trunk/hub/main.py Mon Nov 15 14:49:03 2010
+++ /trunk/hub/main.py Mon Nov 15 15:47:16 2010
@@ -1402,7 +1402,7 @@
return cls(key=key, entry_content_hash=content_hash)
-class EventToDeliver(db.Model):
+class EventToDeliver(db.Expando):
"""Represents a publishing event to deliver to subscribers.
This model is meant to be used together with Subscription entities. When
a
@@ -1426,7 +1426,6 @@
topic = db.TextProperty(required=True)
topic_hash = db.StringProperty(required=True)
- payload = db.TextProperty(required=True)
last_callback = db.TextProperty(default='') # For paging Subscriptions
failed_callbacks = db.ListProperty(db.Key) # Refs to Subscription
entities
delivery_mode = db.StringProperty(default=NORMAL, choices=DELIVERY_MODES)
@@ -1503,11 +1502,14 @@
else:
parent = None
+ if isinstance(payload, unicode):
+ payload = payload.encode('utf-8')
+
return cls(
parent=parent,
topic=topic,
topic_hash=sha1_hash(topic),
- payload=payload,
+ payload=db.Blob(payload),
last_modified=now(),
content_type=content_type,
max_failures=max_failures)
=======================================
--- /trunk/hub/main_test.py Mon Nov 15 14:49:03 2010
+++ /trunk/hub/main_test.py Mon Nov 15 15:47:16 2010
@@ -2252,6 +2252,24 @@
self.assertEquals('my crazy content type', event.content_type)
self.assertEquals('arbitrary', FeedRecord.all().get().format)
+ def testPullBinaryContent(self):
+ """Tests pulling binary content."""
+ data = '\xff\x12 some binary data'
+ topic = 'http://example.com/my-topic'
+ callback = 'http://example.com/my-subscriber'
+ self.assertTrue(Subscription.insert(callback,
topic, 'token', 'secret'))
+ FeedToFetch.insert([topic])
+ urlfetch_test_stub.instance.expect(
+ 'get', topic, 200, data,
+ response_headers={'Content-Type': 'my crazy content type'})
+ self.run_fetch_task()
+ feed = FeedToFetch.get_by_key_name(get_hash_key_name(topic))
+ self.assertTrue(feed is None)
+ event = EventToDeliver.all().get()
+ self.assertEquals(data, event.payload)
+ self.assertEquals('my crazy content type', event.content_type)
+ self.assertEquals('arbitrary', FeedRecord.all().get().format)
+
def testMultipleFetch(self):
"""Tests doing multiple fetches asynchronously in parallel.