|
From: <mi...@us...> - 2017-11-04 10:06:48
|
Revision: 8195
http://sourceforge.net/p/docutils/code/8195
Author: milde
Date: 2017-11-04 10:06:45 +0000 (Sat, 04 Nov 2017)
Log Message:
-----------
New function `utils.unescape_rawsource`.
Removes backslashes and backslash-escaped whitespace from
`rawsource` arguments.
Required for fixes in definition list terms, author docinfo extraction,
and smartquote escaping.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/test/test_utils.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2017-11-04 09:40:27 UTC (rev 8194)
+++ trunk/docutils/HISTORY.txt 2017-11-04 10:06:45 UTC (rev 8195)
@@ -69,6 +69,7 @@
* docutils/utils/__init__.py:
- Deprecate `unique_combinations` (obsoleted by `itertools.combinations`).
+ - New function `unescape_rawsource`.
Release 0.14 (2017-08-03)
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2017-11-04 09:40:27 UTC (rev 8194)
+++ trunk/docutils/docutils/utils/__init__.py 2017-11-04 10:06:45 UTC (rev 8195)
@@ -588,6 +588,13 @@
text = ''.join(text.split(sep))
return text
+def unescape_rawsource(text):
+ """Remove escape-backslashes and escaped whitespace."""
+ # remove escaped whitespace or backslash at end of text
+ text = re.sub(r'(?<!\\)\\([ \n]|$)', r'', text)
+ # remove backslash-escapes
+ return re.sub(r'\\(.)', r'\1', text)
+
def split_escaped_whitespace(text):
"""
Split `text` on escaped whitespace (null+space or null+newline).
Modified: trunk/docutils/test/test_utils.py
===================================================================
--- trunk/docutils/test/test_utils.py 2017-11-04 09:40:27 UTC (rev 8194)
+++ trunk/docutils/test/test_utils.py 2017-11-04 10:06:45 UTC (rev 8195)
@@ -321,6 +321,22 @@
self.assertEqual(utils.find_file_in_dirs('gibts/nicht.txt', dirs),
'gibts/nicht.txt')
+ # samples for the (un)escaping tests:
+ raw = r'spa\m\ and \\ham' + '\\'
+ nulled = 'spa\x00m\x00 and \x00\ham\x00'
+ unescaped = 'spamand \\ham'
+ def test_escape2null(self):
+ self.assertEqual(utils.escape2null(self.raw), self.nulled)
+
+ def test_unescape(self):
+ self.assertEqual(utils.unescape(self.nulled), self.unescaped)
+ self.assertEqual(utils.unescape(self.nulled, restore_backslashes=True),
+ self.raw)
+
+ def test_unescape_rawsource(self):
+ self.assertEqual(utils.unescape_rawsource(self.raw), self.unescaped)
+
+
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|