def request_file(request):
    assert request.method == 'POST'
    assert 'instructions' in request.POST
    assert 'checksum' in request.POST
    
    try:
        processor = FileProcessor.objects.get(pk=request.POST['checksum'])
        
    except FileProcessor.DoesNotExist:
        processor = FileProcessor(instructions=request.POST['instructions'])
        
        assert processor.get_checksum() == request.POST['checksum']
        
        processor.save()
    
    return HttpResponse(processor.get_output())
    def get_output(self):
        """ Get the absolute URL for the FileProcessor specified by instructions. """
        
        if ENDPOINT_URL == 'LOCAL':
            # No need to cache if running locally
            logging.debug('Running processing locally.')
            
            from fileprocessor.models import FileProcessor
            processor = FileProcessor(instructions=self.instructions)
            
            return processor.get_output()
        
        else:
            # Cache using key fileprocessor-<checksum> if not local
            logging.debug('Fetching output from %s', ENDPOINT_URL)

            import urllib2
    
            return urllib2.urlopen(ENDPOINT_URL, {'instructions': self.instructions,
                                                  'checksum': self.get_checksum()})