def replace(self, pattern, repl, *args, **kwargs): """ Replaces a regular expression pattern with repl in both keys and values. Returns the number of replacements made. """ new, count = [], 0 for k, v in self.lst: k, c = utils.safe_subn(pattern, repl, k, *args, **kwargs) count += c v, c = utils.safe_subn(pattern, repl, v, *args, **kwargs) count += c new.append([k, v]) self.lst = new return count
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 = HTTPMessage.replace(self, pattern, repl, *args, **kwargs) self.path, pc = utils.safe_subn(pattern, repl, self.path, *args, **kwargs) c += pc return c
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 content will be decoded before replacement, and re-encoded afterwards. Returns the number of replacements made. """ with decoded(self): self.content, c = utils.safe_subn(pattern, repl, self.content, *args, **kwargs) c += self.headers.replace(pattern, repl, *args, **kwargs) return c
def replace(self, pattern, repl, flags=0): """ 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. """ # TODO: Proper distinction between text and bytes. c = super(Request, self).replace(pattern, repl, flags) self.path, pc = utils.safe_subn(pattern, repl, self.path, flags=flags) c += pc return c
def replace(self, pattern, repl, flags=0): """ 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. """ # TODO: Proper distinction between text and bytes. c = super(Request, self).replace(pattern, repl, flags) self.path, pc = utils.safe_subn( pattern, repl, self.path, flags=flags ) c += pc return c
def test_safe_subn(): assert utils.safe_subn("foo", u"bar", "\xc2foo")