示例#1
0
    def test(self):
        self.assertEqual(
            ("c05-v2-final-orioles-12-x-large", []),
            utils.parse_action_tuples("c05-v2-final-orioles-12-x-large"))

        self.assertEqual(
            ("c05-v2-final-orioles-12-x-large", [("r", "100x100")]),
            utils.parse_action_tuples(
                "c05-v2-final-orioles-12-x-large_r100x100"))

        self.assertEqual(
            ("final-orioles-12-x-large", [("r", "100x100")]),
            utils.parse_action_tuples("final-orioles-12-x-large_r100x100"))

        self.assertEqual(("foo_bar", []), utils.parse_action_tuples("foo_bar"))

        self.assertEqual(("foo_", []), utils.parse_action_tuples("foo_"))

        self.assertEqual(("foo_bar", [("r", "100")]),
                         utils.parse_action_tuples("foo_bar_r100"))

        self.assertEqual(("", [("c", "1088")]),
                         utils.parse_action_tuples("c1088"))

        self.assertEqual(("c1088-1_1", []),
                         utils.parse_action_tuples("c1088-1_1"))

        self.assertEqual(("", [("c", "1088"), ("c", "0-0-100-100")]),
                         utils.parse_action_tuples("c1088_c0-0-100-100"))
    def render(self, context):
        action_list = []
        imageurl = resolve(self.imageurl, context)

        if not imageurl:
            imageurl = settings.NO_IMAGE_URL

        if not imageurl:
            return ""

        for action in self.actions:
            action_code = ACTIONS[action[0]]
            arg_list = [str(resolve(template.Variable(arg), context)) for arg in action[1:]]
            args = "-".join(arg_list)
            if settings.PROCESSORS[action_code].param_pattern().match(args):
                action_list.append("_%s%s" % (action_code, args))
            else:
                raise template.TemplateSyntaxError("The action '%s' doesn't accept the arguments: %s" % (action[0], ",".join(action[1:])))

        # Make sure we've actually got some actions.
        if not action_list:
            return imageurl

        # Create the new URL
        action_string = "".join(action_list)
        prefix, ext = os.path.splitext(imageurl)
        imageurl = "%s%s%s" % (prefix, action_string, ext)

        # Create a security hash from the new URL
        base_file_name, action_tuples = utils.parse_action_tuples(imageurl)
        security_hash = utils.create_securityhash(action_tuples)

        return "%s?%s" % (imageurl, security_hash)
示例#3
0
    def test(self):
        self.assertEqual(
            ("c05-v2-final-orioles-12-x-large", []),
            utils.parse_action_tuples("c05-v2-final-orioles-12-x-large")
        )

        self.assertEqual(
            ("c05-v2-final-orioles-12-x-large", [("r", "100x100")]),
            utils.parse_action_tuples(
                "c05-v2-final-orioles-12-x-large_r100x100"
            )
        )

        self.assertEqual(
            ("final-orioles-12-x-large", [("r", "100x100")]),
            utils.parse_action_tuples("final-orioles-12-x-large_r100x100")
        )

        self.assertEqual(
            ("foo_bar", []),
            utils.parse_action_tuples("foo_bar")
        )

        self.assertEqual(
            ("foo_", []),
            utils.parse_action_tuples("foo_")
        )

        self.assertEqual(
            ("foo_bar", [("r", "100")]),
            utils.parse_action_tuples("foo_bar_r100")
        )

        self.assertEqual(
            ("", [("c", "1088")]),
            utils.parse_action_tuples("c1088")
        )

        self.assertEqual(
            ("c1088-1_1", []),
            utils.parse_action_tuples("c1088-1_1")
        )

        self.assertEqual(
            ("", [("c", "1088"), ("c", "0-0-100-100")]),
            utils.parse_action_tuples("c1088_c0-0-100-100")
        )
    def inner(imageurl, arg_string=""):
        action_list = []

        bits = arg_string.split()

        # parse one arg vs two args
        if len(bits) == 2:
            arg_list = [bits[0], bits[1].lstrip("#")]
        else:
            arg_list = bits

        # dispose of an existing security hash if it exists
        if "?" in imageurl:
            imageurl, _ = imageurl.split("?", 1)

        if not imageurl:
            imageurl = settings.NO_IMAGE_URL

        if not imageurl:
            return ""

        # build the action list
        action_code = ACTIONS[action]
        args = "-".join(arg_list)
        if settings.PROCESSORS[action_code].param_pattern().match(args):
            action_list.append("_%s%s" % (action_code, args))
        else:
            raise template.TemplateSyntaxError(
                "The action '%s' doesn't accept the arguments: %s" %
                (action[0], ",".join(action[1:])))

        if not action_list:
            return imageurl

        # Create the new URL
        action_string = "".join(action_list)
        prefix, ext = os.path.splitext(imageurl)
        imageurl = "%s%s%s" % (prefix, action_string, ext)

        # Create a security hash from the new URL
        base_file_name, action_tuples = utils.parse_action_tuples(imageurl)
        security_hash = utils.create_securityhash(action_tuples)

        return "%s?%s" % (imageurl, security_hash)
    def inner(imageurl, arg_string=""):
        action_list = []

        bits = arg_string.split()

        # parse one arg vs two args
        if len(bits) == 2:
            arg_list = [bits[0], bits[1].lstrip("#")]
        else:
            arg_list = bits

        # dispose of an existing security hash if it exists
        if "?" in imageurl:
            imageurl, _ = imageurl.split("?", 1)

        if not imageurl:
            imageurl = settings.NO_IMAGE_URL

        if not imageurl:
            return ""

        # build the action list
        action_code = ACTIONS[action]
        args = "-".join(arg_list)
        if settings.PROCESSORS[action_code].param_pattern().match(args):
            action_list.append("_%s%s" % (action_code, args))
        else:
            raise template.TemplateSyntaxError("The action '%s' doesn't accept the arguments: %s" % (action[0], ",".join(action[1:])))

        if not action_list:
            return imageurl

        # Create the new URL
        action_string = "".join(action_list)
        prefix, ext = os.path.splitext(imageurl)
        imageurl = "%s%s%s" % (prefix, action_string, ext)

        # Create a security hash from the new URL
        base_file_name, action_tuples = utils.parse_action_tuples(imageurl)
        security_hash = utils.create_securityhash(action_tuples)

        return "%s?%s" % (imageurl, security_hash)
    def render(self, context):
        action_list = []
        imageurl = resolve(self.imageurl, context)

        if not imageurl:
            imageurl = settings.NO_IMAGE_URL

        if not imageurl:
            return ""

        for action in self.actions:
            action_code = ACTIONS[action[0]]
            arg_list = [
                str(resolve(template.Variable(arg), context))
                for arg in action[1:]
            ]
            args = "-".join(arg_list)
            if settings.PROCESSORS[action_code].param_pattern().match(args):
                action_list.append("_%s%s" % (action_code, args))
            else:
                raise template.TemplateSyntaxError(
                    "The action '%s' doesn't accept the arguments: %s" %
                    (action[0], ",".join(action[1:])))

        # Make sure we've actually got some actions.
        if not action_list:
            return imageurl

        # Create the new URL
        action_string = "".join(action_list)
        prefix, ext = os.path.splitext(imageurl)
        imageurl = "%s%s%s" % (prefix, action_string, ext)

        # Create a security hash from the new URL
        base_file_name, action_tuples = utils.parse_action_tuples(imageurl)
        security_hash = utils.create_securityhash(action_tuples)

        return "%s?%s" % (imageurl, security_hash)