

def serve_mogilefs_file(request, key=None):
    '\n    Called when a user requests an image.\n    Either reproxy the path to perlbal, or serve the image outright\n    '
    mimetype = (mimetypes.guess_type(key)[0] or 'application/x-octet-stream')
    client = mogilefs.Client(settings.MOGILEFS_DOMAIN, settings.MOGILEFS_TRACKERS)
    if (hasattr(settings, 'SERVE_WITH_PERLBAL') and settings.SERVE_WITH_PERLBAL):
        path = cache.get(key)
        if (not path):
            path = client.get_paths(key)
            cache.set(key, path, 60)
        if path:
            response = HttpResponse(content_type=mimetype)
            response['X-REPROXY-URL'] = path[0]
        else:
            response = HttpResponseNotFound()
    else:
        file_data = client[key]
        if file_data:
            response = HttpResponse(file_data, mimetype=mimetype)
        else:
            response = HttpResponseNotFound()
    return response

dataset/ETHPy150Open jschneier/django-storages/storages/backends/mogile.py serve_mogilefs_file/original