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

This commit is contained in:
Samuel Clay 2013-03-19 17:49:56 -07:00
parent 0db41bc853
commit 61fac02304
2 changed files with 6 additions and 5 deletions

View file

@ -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.story_functions import truncate_chars, strip_tags, linkify, image_size
from utils.scrubber import SelectiveScriptScrubber from utils.scrubber import SelectiveScriptScrubber
from utils import s3_utils from utils import s3_utils
from StringIO import StringIO
RECOMMENDATIONS_LIMIT = 5 RECOMMENDATIONS_LIMIT = 5
IGNORE_IMAGE_SOURCES = [ IGNORE_IMAGE_SOURCES = [
@ -1884,7 +1885,8 @@ class MSharedStory(mongo.Document):
if any(ignore in image_source for ignore in IGNORE_IMAGE_SOURCES): if any(ignore in image_source for ignore in IGNORE_IMAGE_SOURCES):
continue continue
req = requests.get(image_source, headers=headers, stream=True) 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: if width <= 16 or height <= 16:
continue continue
image_sizes.append({'src': image_source, 'size': (width, height)}) image_sizes.append({'src': image_source, 'size': (width, height)})

View file

@ -13,7 +13,7 @@ from django.utils.html import strip_tags as strip_tags_django
from django.conf import settings from django.conf import settings
from utils.tornado_escape import linkify as linkify_tornado from utils.tornado_escape import linkify as linkify_tornado
from utils.tornado_escape import xhtml_unescape as xhtml_unescape_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]*)\>') 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 + "..." return truncd_val + "..."
def image_size(datastream): def image_size(datastream):
# datastream = reseekfile.ReseekFile(datastream) datastream = reseekfile.ReseekFile(datastream)
# data = str(datastream.read(30)) data = str(datastream.read(30))
data = datastream[:30]
size = len(data) size = len(data)
height = -1 height = -1
width = -1 width = -1