From 61fac023045ecacdcadc2f68f095b3667c73183c Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Tue, 19 Mar 2013 17:49:56 -0700 Subject: [PATCH] If requests.raw won't work, sut fudge it with a StringIO for now. --- apps/social/models.py | 4 +++- utils/story_functions.py | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/social/models.py b/apps/social/models.py index 8bb412e79..2d9471d55 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -33,6 +33,7 @@ from utils.feed_functions import relative_timesince from utils.story_functions import truncate_chars, strip_tags, linkify, image_size from utils.scrubber import SelectiveScriptScrubber from utils import s3_utils +from StringIO import StringIO RECOMMENDATIONS_LIMIT = 5 IGNORE_IMAGE_SOURCES = [ @@ -1884,7 +1885,8 @@ class MSharedStory(mongo.Document): if any(ignore in image_source for ignore in IGNORE_IMAGE_SOURCES): continue req = requests.get(image_source, headers=headers, stream=True) - _, width, height = image_size(req.content) + datastream = StringIO(req.content[:30]) + _, width, height = image_size(datastream) if width <= 16 or height <= 16: continue image_sizes.append({'src': image_source, 'size': (width, height)}) diff --git a/utils/story_functions.py b/utils/story_functions.py index 6b766bef9..daceac605 100644 --- a/utils/story_functions.py +++ b/utils/story_functions.py @@ -13,7 +13,7 @@ from django.utils.html import strip_tags as strip_tags_django from django.conf import settings from utils.tornado_escape import linkify as linkify_tornado from utils.tornado_escape import xhtml_unescape as xhtml_unescape_tornado -# from vendor import reseekfile +from vendor import reseekfile COMMENTS_RE = re.compile('\') @@ -239,9 +239,8 @@ def truncate_chars(value, max_length): return truncd_val + "..." def image_size(datastream): - # datastream = reseekfile.ReseekFile(datastream) - # data = str(datastream.read(30)) - data = datastream[:30] + datastream = reseekfile.ReseekFile(datastream) + data = str(datastream.read(30)) size = len(data) height = -1 width = -1