def read_proc(path): path = proc_path(path) try: fp = open_text(path) try: for line in fp: yield line.rstrip() finally: # don't use context manager to support StringIO on Python 2 # for unit tests fp.close() except (OSError, IOError): return
def write_text(filename, content): with open_text(filename, write=True) as fp: fp.write(content) fp.flush()