Пример #1
0
 def test_valid_thumb(self):
     """ test that thumbnail with 2d or width/height only works """
     h, w = geometry_parse('thumbnail', '10x20', self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 20)
     h, w = geometry_parse('thumbnail', '10', self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, None)
     h, w = geometry_parse('thumbnail', 'x20', self.TestException)
     self.assertEqual(h, None)
     self.assertEqual(w, 20)
Пример #2
0
 def test_valid_resize(self):
     """ test that resize computes the correct geometry for 2d and width/height only """
     h, w = geometry_parse('resize', '10x20', self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 20)
     h, w = geometry_parse('resize', '10', self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 10)
     h, w = geometry_parse('resize', 'x10', self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 10)
Пример #3
0
 def test_valid_thumb(self):
     """ test that thumbnail with 2d or width/height only works """
     h, w = geometry_parse("thumbnail", "10x20", self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 20)
     h, w = geometry_parse("thumbnail", "10", self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, None)
     h, w = geometry_parse("thumbnail", "x20", self.TestException)
     self.assertEqual(h, None)
     self.assertEqual(w, 20)
Пример #4
0
 def test_valid_resize(self):
     """ test that resize computes the correct geometry for 2d and width/height only """
     h, w = geometry_parse("resize", "10x20", self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 20)
     h, w = geometry_parse("resize", "10", self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 10)
     h, w = geometry_parse("resize", "x10", self.TestException)
     self.assertEqual(h, 10)
     self.assertEqual(w, 10)
Пример #5
0
    def get(self, request, action, geometry, source_path):
        """
        Perform action routing and handle sanitizing url input. Handles caching the path to a rendered image to
        django.cache and saves the new image on the filesystem. 404s are cached to
        save time the next time the missing image is requested.

        :param request: HttpRequest
        :param action: some action, eg thumbnail or resize
        :param geometry: a string of either '\dx\d' or just '\d'
        :param source_path: the fs path to the image to be manipulated
        :returns: an HttpResponse with an image/{format} content_type
        """

        # reject naughty paths and actions
        if source_path.startswith('/'):
            logger.info("%s: blocked bad path" % source_path)
            return self.four_oh_four()
        if re.match('\.\./', source_path):
            logger.info("%s: blocked bad path" % source_path)
            return self.four_oh_four()
        if action not in self.allowed_actions:
            logger.info("%s: bad action requested: %s" % (source_path, action))
            return self.four_oh_four()

        try:
            width, height = geometry_parse(action, geometry, ValueError)
        except ValueError, e:
            logger.info('corrupted geometry "%s" for action "%s"' % (geometry, action))
            return self.four_oh_four()
Пример #6
0
    def get(self, request, action, geometry, source_path):
        """
        Perform action routing and handle sanitizing url input. Handles caching the path to a rendered image to
        django.cache and saves the new image on the filesystem. 404s are cached to
        save time the next time the missing image is requested.

        :param request: HttpRequest
        :param action: some action, eg thumbnail or resize
        :param geometry: a string of either '\dx\d' or just '\d'
        :param source_path: the fs path to the image to be manipulated
        :returns: an HttpResponse with an image/{format} content_type
        """

        # reject naughty paths and actions
        if source_path.startswith('/'):
            logger.info("%s: blocked bad path" % source_path)
            return self.four_oh_four()
        if re.match('\.\./', source_path):
            logger.info("%s: blocked bad path" % source_path)
            return self.four_oh_four()
        if action not in self._allowed_actions:
            logger.info("%s: bad action requested: %s" % (source_path, action))
            return self.four_oh_four()

        try:
            width, height = geometry_parse(action, geometry, ValueError)
        except ValueError, e:
            logger.info('corrupted geometry "%s" for action "%s"' %
                        (geometry, action))
            return self.four_oh_four()