Permalink
Browse files

If requests.raw won't work, sut fudge it with a StringIO for now.

  • Loading branch information...
1 parent 0db41bc commit 61fac023045ecacdcadc2f68f095b3667c73183c @samuelclay committed Mar 20, 2013
Showing with 6 additions and 5 deletions.
  1. +3 −1 apps/social/models.py
  2. +3 −4 utils/story_functions.py
View
@@ -33,6 +33,7 @@
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 @@ def calculate_image_sizes(self, force=False):
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)})
View
@@ -13,7 +13,7 @@
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('\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>')
@@ -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

0 comments on commit 61fac02

Please sign in to comment.