From 21d17db7e2ff72b299a7e728aef39538c0d23e66 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 16 Apr 2013 22:37:35 +0200 Subject: [PATCH] formatting: Make indent() more useful --- mopidy/utils/formatting.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mopidy/utils/formatting.py b/mopidy/utils/formatting.py index ba311fb5..3c313eae 100644 --- a/mopidy/utils/formatting.py +++ b/mopidy/utils/formatting.py @@ -4,13 +4,15 @@ import re import unicodedata -def indent(string, places=4, linebreak='\n'): +def indent(string, places=4, linebreak='\n', singles=False): lines = string.split(linebreak) - if len(lines) == 1: + if not singles and len(lines) == 1: return string - result = '' - for line in lines: - result += linebreak + ' ' * places + line + for i, line in enumerate(lines): + lines[i] = ' ' * places + line + result = linebreak.join(lines) + if not singles: + result = linebreak + result return result