From 02d5dca1d7993e5708748940945f4e3137128155 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Tue, 22 Apr 2014 15:40:21 -0700 Subject: [PATCH] CSS Filter: remove unnecessary save_sr_image wrapper. --- r2/r2/controllers/api.py | 6 ++++-- r2/r2/controllers/promotecontroller.py | 12 +++++------- r2/r2/lib/cssfilter.py | 13 ------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 5986e331a..d0b31f1a9 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1930,10 +1930,12 @@ class ApiController(RedditController): return UploadedImage("", "", "", errors=errors, form_id=form_id).render() else: try: - new_url = cssfilter.save_sr_image(c.site, file, suffix ='.' + img_type) - except cssfilter.BadImage: + new_url = media.upload_media(file, file_type="." + img_type) + except Exception as e: + g.log.warning("error uploading subreddit image: %s", e) errors['IMAGE_ERROR'] = _("Invalid image or general image error") return UploadedImage("", "", "", errors=errors, form_id=form_id).render() + size = str_to_image(file).size if header: c.site.header = new_url diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index b6daaff7d..2a3804b19 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -32,7 +32,7 @@ from r2.controllers.api import ApiController from r2.controllers.listingcontroller import ListingController from r2.controllers.reddit_base import RedditController -from r2.lib import cssfilter, inventory, promote +from r2.lib import inventory, promote from r2.lib.authorize import get_account_info, edit_profile, PROFILE_LIMIT from r2.lib.db import queries from r2.lib.errors import errors @@ -867,12 +867,10 @@ class PromoteApiController(ApiController): if link and (not promote.is_promoted(link) or c.user_is_sponsor or c.user.trusted_sponsor): errors = dict(BAD_CSS_NAME="", IMAGE_ERROR="") - try: - # thumnails for promoted links can change and therefore expire - force_thumbnail(link, file, file_type=".%s" % img_type) - except cssfilter.BadImage: - # if the image doesn't clean up nicely, abort - errors["IMAGE_ERROR"] = _("bad image") + + # thumnails for promoted links can change and therefore expire + force_thumbnail(link, file, file_type=".%s" % img_type) + if any(errors.values()): return UploadedImage("", "", "upload", errors=errors, form_id="image-upload").render() diff --git a/r2/r2/lib/cssfilter.py b/r2/r2/lib/cssfilter.py index 60a6e2b0d..4525b10fe 100644 --- a/r2/r2/lib/cssfilter.py +++ b/r2/r2/lib/cssfilter.py @@ -35,8 +35,6 @@ from mako import filters import os import tempfile -from r2.lib.media import upload_media - import re from urlparse import urlparse @@ -389,14 +387,3 @@ def rendered_comment(comments, gilded=False): for w in wrapped: w.gilded_message = "this comment was fake-gilded" return wrapped.render(style="html") - -class BadImage(Exception): - def __init__(self, error = None): - self.error = error - -def save_sr_image(sr, data, suffix = '.png'): - try: - return upload_media(data, file_type = suffix) - except Exception as e: - raise BadImage(e) -