def encode_key(self, key): """ Escape a given key bytes with the instance chosen escape method. Key is not escaped if it contains only 'ASCII printable' bytes. """ return apply_escape_bytes(key, self._escape, skip_printable=True)
def encode_value(self, val): """Escape a given value bytes with the instance chosen escape method.""" return apply_escape_bytes(val, self._escape)
def emit(self, *args): self._out.write(codecs.encode("*%s\r\n" % len(args), 'ascii')) for arg in args: val = encodehelpers.apply_escape_bytes(arg, self._escape) self._out.write(codecs.encode("$%s\r\n" % len(val), 'ascii')) self._out.write(val + b"\r\n")