diff options
author | grubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-07-24 09:22:01 +0000 |
---|---|---|
committer | grubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-07-24 09:22:01 +0000 |
commit | 8d8939678b0cfb025290b2b6e6d0f003581410d4 (patch) | |
tree | 525faace11282913987b91aeba3389ec1ae97ebe | |
parent | 5720d8e72b40d8dbc60edc5c04d9d4dca54ecfbb (diff) | |
download | docutils-8d8939678b0cfb025290b2b6e6d0f003581410d4.tar.gz |
Fix 366: as it is done in trunk Commit [r8294], moving the function.
git-svn-id: http://svn.code.sf.net/p/docutils/code/branches/rel-0.15@8295 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | docutils/HISTORY.txt | 2 | ||||
-rw-r--r-- | docutils/docutils/nodes.py | 20 | ||||
-rw-r--r-- | docutils/docutils/utils/__init__.py | 14 |
3 files changed, 19 insertions, 17 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index fa69490bc..c05f3c9eb 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -24,6 +24,8 @@ branches/rel-0.15 - Fix 366: circular import when docutils nodes is iported before docutils.utils by putting ``import docutils.utils`` into astext. + - Fix 366: as it is done in trunk Commit [r8294], moving the function. + Release 0.15 (2019-07-20) ========================= diff --git a/docutils/docutils/nodes.py b/docutils/docutils/nodes.py index 62ea9996c..bd5780428 100644 --- a/docutils/docutils/nodes.py +++ b/docutils/docutils/nodes.py @@ -29,9 +29,6 @@ import warnings import types import unicodedata -# 2019-07-23 Fix bugs#366 move import docutils.utils into function astext -# import docutils.utils - # ============================== # Functional Node Base Classes # ============================== @@ -323,6 +320,20 @@ def ensure_str(s): return s.encode('ascii', 'backslashreplace') return s +# definition moved here from `utils` to avoid circular import dependency +def unescape(text, restore_backslashes=False, respect_whitespace=False): + """ + Return a string with nulls removed or restored to backslashes. + Backslash-escaped spaces are also removed. + """ + # `respect_whitespace` is ignored (since introduction 2016-12-16) + if restore_backslashes: + return text.replace('\x00', '\\') + else: + for sep in ['\x00 ', '\x00\n', '\x00']: + text = ''.join(text.split(sep)) + return text + class Text(Node, reprunicode): @@ -365,8 +376,7 @@ class Text(Node, reprunicode): return domroot.createTextNode(unicode(self)) def astext(self): - import docutils.utils - return reprunicode(docutils.utils.unescape(self)) + return reprunicode(unescape(self)) # Note about __unicode__: The implementation of __unicode__ here, # and the one raising NotImplemented in the superclass Node had diff --git a/docutils/docutils/utils/__init__.py b/docutils/docutils/utils/__init__.py index dee90ff6d..3bea6ccd6 100644 --- a/docutils/docutils/utils/__init__.py +++ b/docutils/docutils/utils/__init__.py @@ -18,6 +18,7 @@ import warnings import unicodedata from docutils import ApplicationError, DataError, __version_info__ from docutils import nodes +from docutils.nodes import unescape import docutils.io from docutils.utils.error_reporting import ErrorOutput, SafeString @@ -576,18 +577,7 @@ def escape2null(text): parts.append('\x00' + text[found+1:found+2]) start = found + 2 # skip character after escape -def unescape(text, restore_backslashes=False, respect_whitespace=False): - """ - Return a string with nulls removed or restored to backslashes. - Backslash-escaped spaces are also removed. - """ - # `respect_whitespace` is ignored (since introduction 2016-12-16) - if restore_backslashes: - return text.replace('\x00', '\\') - else: - for sep in ['\x00 ', '\x00\n', '\x00']: - text = ''.join(text.split(sep)) - return text +# `unescape` definition moved to `nodes` to avoid circular import dependency. def split_escaped_whitespace(text): """ |