Beispiel #1
0
    def replace(self, pattern, repl, *args, **kwargs):
        """
            Replaces a regular expression pattern with repl in both the headers
            and the body of the message. Encoded body will be decoded
            before replacement, and re-encoded afterwards.

            Returns the number of replacements made.
        """
        with decoded(self):
            self.body, count = utils.safe_subn(pattern, repl, self.body, *args,
                                               **kwargs)
        fields = []
        for name, value in self.headers.fields:
            name, c = utils.safe_subn(pattern, repl, name, *args, **kwargs)
            count += c
            value, c = utils.safe_subn(pattern, repl, value, *args, **kwargs)
            count += c
            fields.append([name, value])
        self.headers.fields = fields
        return count
Beispiel #2
0
    def replace(self, pattern, repl, *args, **kwargs):
        """
            Replaces a regular expression pattern with repl in both the headers
            and the body of the message. Encoded body will be decoded
            before replacement, and re-encoded afterwards.

            Returns the number of replacements made.
        """
        with decoded(self):
            self.content, count = utils.safe_subn(
                pattern, repl, self.content, *args, **kwargs
            )
        fields = []
        for name, value in self.headers.fields:
            name, c = utils.safe_subn(pattern, repl, name, *args, **kwargs)
            count += c
            value, c = utils.safe_subn(pattern, repl, value, *args, **kwargs)
            count += c
            fields.append([name, value])
        self.headers.fields = fields
        return count
Beispiel #3
0
    def replace(self, pattern, repl, *args, **kwargs):
        """
            Replaces a regular expression pattern with repl in the headers, the
            request path and the body of the request. Encoded content will be
            decoded before replacement, and re-encoded afterwards.

            Returns the number of replacements made.
        """
        c = MessageMixin.replace(self, pattern, repl, *args, **kwargs)
        self.path, pc = utils.safe_subn(pattern, repl, self.path, *args,
                                        **kwargs)
        c += pc
        return c
Beispiel #4
0
    def replace(self, pattern, repl, *args, **kwargs):
        """
            Replaces a regular expression pattern with repl in both the headers
            and the body of the message. Encoded body will be decoded
            before replacement, and re-encoded afterwards.

            Returns the number of replacements made.
        """
        with decoded(self):
            self.body, c = utils.safe_subn(pattern, repl, self.body, *args,
                                           **kwargs)
        c += self.headers.replace(pattern, repl, *args, **kwargs)
        return c
Beispiel #5
0
    def replace(self, pattern, repl, *args, **kwargs):
        """
            Replaces a regular expression pattern with repl in the headers, the
            request path and the body of the request. Encoded content will be
            decoded before replacement, and re-encoded afterwards.

            Returns the number of replacements made.
        """
        c = MessageMixin.replace(self, pattern, repl, *args, **kwargs)
        self.path, pc = utils.safe_subn(
            pattern, repl, self.path, *args, **kwargs
        )
        c += pc
        return c
Beispiel #6
0
 def test_simple(self):
     assert utils.safe_subn("foo", u"bar", "\xc2foo")
Beispiel #7
0
def test_safe_subn():
    assert utils.safe_subn("foo", u"bar", "\xc2foo")
Beispiel #8
0
def test_safe_subn():
    assert utils.safe_subn("foo", u"bar", "\xc2foo")