def send(self, data): # pylint: disable=invalid-name files.WriteStreamBytes(sys.stdout, data) if not six.PY2: # WriteStreamBytes flushes python2 but not python3. Perhaps it should # be modified to also flush python3. sys.stdout.buffer.flush() return len(data)
def WriteToFileOrStdout(path, content, overwrite=True, binary=False, private=False): """Writes content to the specified file or stdout if path is '-'. Args: path: str, The path of the file to write. content: str, The content to write to the file. overwrite: bool, Whether or not to overwrite the file if it exists. binary: bool, True to open the file in binary mode. private: bool, Whether to write the file in private mode. Raises: Error: If the file cannot be written. """ if path == '-': if binary: files.WriteStreamBytes(sys.stdout, content) else: out.write(content) elif binary: files.WriteBinaryFileContents(path, content, overwrite=overwrite, private=private) else: files.WriteFileContents(path, content, overwrite=overwrite, private=private)