<commit_before>from django.http import HttpResponse
from django.conf import settings
import urllib
import oauth2
import types


def ImageView(request, spot_id, image_id, thumb_width=None, thumb_height=None, constrain=False):

    # Required settings for the client

    if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
        raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
    if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
    if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))

    consumer = oauth2.Consumer(key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET)
    client = oauth2.Client(consumer)

    #TODO: really, rather than increase the size of the missing value, we should be able to pass None to get_image
    if constrain is True:
        if thumb_width is None:
            thumb_width = thumb_height * 999

        if thumb_height is None:
            thumb_height = thumb_width * 999

    contenttype, img = get_image(client, spot_id, image_id, thumb_width, thumb_height, constrain)

    response = HttpResponse(img)

    response["Content-type"] = contenttype

    return response


def get_image(client, spot_id, image_id, thumb_width, thumb_height, constrain):
    if constrain is True:
        url = "{0}/api/v1/spot/{1}/image/{2}/thumb/constrain/width:{3},height:{4}".format(settings.SS_WEB_SERVER_HOST, spot_id, image_id, thumb_width, thumb_height)
    else:
        url = "{0}/api/v1/spot/{1}/image/{2}/thumb/{3}x{4}".format(settings.SS_WEB_SERVER_HOST, spot_id, image_id, thumb_width, thumb_height)

    resp, content = client.request(url, 'GET')

    if resp.status == 200:
        return resp['content-type'], content

    return '[]'<commit_msg>Fixed the way the web client asks the server for constrained thumbnails.<commit_after>from django.http import HttpResponse
from django.conf import settings
import urllib
import oauth2
import types


def ImageView(request, spot_id, image_id, thumb_width=None, thumb_height=None, constrain=False):

    # Required settings for the client

    if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
        raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
    if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
    if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))

    consumer = oauth2.Consumer(key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET)
    client = oauth2.Client(consumer)

    contenttype, img = get_image(client, spot_id, image_id, constrain, thumb_width, thumb_height)

    response = HttpResponse(img)

    response["Content-type"] = contenttype

    return response


def get_image(client, spot_id, image_id, constrain, thumb_width=None, thumb_height=None):
    if constrain is True:
        constraint = []
        if thumb_width:
            constraint.append("width:%s" % thumb_width)
        if thumb_height:
            constraint.append("height:%s" % thumb_height)
        url = "{0}/api/v1/spot/{1}/image/{2}/thumb/constrain/{3}".format(settings.SS_WEB_SERVER_HOST, spot_id, image_id, ','.join(constraint))
    else:
        url = "{0}/api/v1/spot/{1}/image/{2}/thumb/{3}x{4}".format(settings.SS_WEB_SERVER_HOST, spot_id, image_id, thumb_width, thumb_height)

    resp, content = client.request(url, 'GET')

    if resp.status == 200:
        return resp['content-type'], content

    return '[]'
{'fraction_non_alphanumeric': 0.10942668136714444, 'fraction_numerical': 0.011300992282249173, 'mean_word_length': 4.169515669515669, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1015201', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1141, 'n_words': 265}