Skip to content

Commit

Permalink
Remove textwrap.indent() because it's not available on Python 2.7
Browse files Browse the repository at this point in the history
NB: At some point I will definitely start dropping Python 2 support
in my open source projects but right now is not yet that time....
  • Loading branch information
xolox committed May 1, 2020
1 parent 4a6217c commit 56eb715
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions deb_pkg_tools/deb822.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Debian packaging tools: Control file manipulation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: April 19, 2020
# Last Change: May 2, 2020
# URL: https://github.com/xolox/python-deb-pkg-tools

"""Parsing and formatting of Debian control fields in the :man:`deb822` format."""
Expand Down Expand Up @@ -34,10 +34,16 @@ def dump_deb822(fields):
for key, value in fields.items():
# Check for multi-line values.
if "\n" in value:
# Replace empty lines with a dot.
value = u"\n".join(line or "." for line in value.splitlines())
# Make sure continuation lines are indented.
value = textwrap.indent(value, " ").strip()
input_lines = value.splitlines()
output_lines = [input_lines.pop(0)]
for line in input_lines:
if line and not line.isspace():
# Make sure continuation lines are indented.
output_lines.append(u" " + line)
else:
# Encode empty continuation lines as a dot (indented).
output_lines.append(u" .")
value = u"\n".join(output_lines)
lines.append(u"%s: %s\n" % (key, value))
return u"".join(lines)

Expand Down

0 comments on commit 56eb715

Please sign in to comment.