Exemplo n.º 1
0
def test_parse_modify_spec():
    spec = parse_modify_spec("/foo/bar/voing", True)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    spec = parse_modify_spec("/foo/bar/vo/ing/", False)
    assert spec.matches.pattern == "foo"
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"vo/ing/"

    spec = parse_modify_spec("/bar/voing", False)
    assert spec.matches(tflow.tflow())
    assert spec.subject == b"bar"
    assert spec.read_replacement() == b"voing"

    with pytest.raises(ValueError, match="Invalid regular expression"):
        parse_modify_spec("/[/two", True)
Exemplo n.º 2
0
    def configure(self, updated):
        if "modify_body" in updated:
            self.replacements = []
            for option in ctx.options.modify_body:
                try:
                    spec = parse_modify_spec(option, True)
                except ValueError as e:
                    raise exceptions.OptionsError(f"Cannot parse modify_body option {option}: {e}") from e

                self.replacements.append(spec)
Exemplo n.º 3
0
    def test_parse_modify_spec(self):
        x = modifyheaders.parse_modify_spec("/foo/bar/voing")
        assert [x[0], x[2], x[3]] == ["foo", b"bar", b"voing"]

        x = modifyheaders.parse_modify_spec("/foo/bar/vo/ing/")
        assert [x[0], x[2], x[3]] == ["foo", b"bar", b"vo/ing/"]

        x = modifyheaders.parse_modify_spec("/bar/voing")
        assert [x[0], x[2], x[3]] == [".*", b"bar", b"voing"]

        with pytest.raises(Exception, match="Invalid number of parameters"):
            modifyheaders.parse_modify_spec("/")

        with pytest.raises(Exception, match="Invalid filter pattern"):
            modifyheaders.parse_modify_spec("/~b/one/two")

        with pytest.raises(Exception, match="Invalid file path"):
            modifyheaders.parse_modify_spec("/~q/foo/@nonexistent")
Exemplo n.º 4
0
    def configure(self, updated):
        if "modify_body" in updated:
            self.replacements = []
            for option in ctx.options.modify_body:
                try:
                    spec = parse_modify_spec(option)
                    try:
                        re.compile(spec.subject)
                    except re.error:
                        raise ValueError(f"Invalid regular expression: {spec.subject}")
                except ValueError as e:
                    raise exceptions.OptionsError(
                        f"Cannot parse modify_body option {option}: {e}"
                    ) from e

                self.replacements.append(spec)