From a4eaafab5a003298c8235f7502fb684da2220ca8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 6 Feb 2011 16:56:13 +1300 Subject: [PATCH] Further fine-tuning for pretty_xmlish. --- libmproxy/utils.py | 16 ++++++++-------- test/test_utils.py | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 2a8786761..e29910c5a 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -52,13 +52,10 @@ TAG = r""" (?P\s*\/)? (?P\w+) ( - [a-zA-Z0-9_#:=().%\/]+ - | - "[^\"]*"['\"]* - | - '[^']*'['\"]* - | - \s+ + [^'"\t >]+ | + "[^\"]*"['\"]* | + '[^']*'['\"]* | + \s+ )* (?P\s*\/\s*)? \s*> @@ -67,7 +64,7 @@ UNI = set(["br", "hr", "img", "input", "area", "link"]) INDENT = " "*4 def pretty_xmlish(s): """ - This is a robust, general pretty-printer for XML-ish data. + A robust pretty-printer for XML-ish data. Returns a list of lines. """ data, offset, indent, prev = [], 0, 0, None @@ -87,6 +84,9 @@ def pretty_xmlish(s): if not any([i.group("close"), i.group("selfcont"), name in UNI]): indent += 1 prev = name + trail = s[offset:] + if trail.strip(): + data.append(s[offset:]) return data diff --git a/test/test_utils.py b/test/test_utils.py index 1ec4f2f50..5cf81e2ef 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -242,6 +242,9 @@ class upretty_xmlish(libpry.AutoTree): assert f(r"") assert f(r'') assert f('') + assert f('