def write(self, string, flags=None, new_line=False, with_indent=True ): # type: (str, Optional[int], bool, bool) -> None """ Writes a string to the output stream. The string is formatted before it is written to the output stream. """ if self._may_write(flags): if self._indent > 0 and with_indent: string = "\n".join((" " * self._indent + s) if s else s for s in string.split("\n")) if self._format_output: formatted = self.format(string) else: formatted = self.remove_format(string) if new_line: formatted += "\n" self._stream.write(to_str(formatted))
def write_line_raw(self, string, flags=None): # type: (str, Optional[int]) -> None """ Writes a string to the output stream without formatting. """ if self._may_write(flags): self._stream.write(to_str(string.rstrip("\n") + "\n"))
def write(self, string, flags=None): # type: (str, Optional[int]) -> None """ Writes a string to the output stream. The string is formatted before it is written to the output stream. """ if self._may_write(flags): if self._format_output: formatted = self.format(string) else: formatted = self.remove_format(string) self._stream.write(to_str(formatted))
def write_line(self, string, flags=None): # type: (str, Optional[int]) -> None """ Writes a line of text to the output stream. The string is formatted before it is written to the output stream. """ if self._may_write(flags): string = string.rstrip("\n") if self._format_output: formatted = self.format(string) else: formatted = self.remove_format(string) self._stream.write(to_str(formatted + "\n"))