The textwrap library is contained in the python standard library.
The code contains a workaround for textwrap.wrap discarding newlines which should be preserved.
Therefore the text is first split into lines and non empty lines get processed by textwrap.wrap.
Empty lines get appended to the line buffer.