--- a/mercurial/changelog.py Mon Oct 02 21:10:31 2006 +0200
+++ b/mercurial/changelog.py Mon Oct 02 22:35:37 2006 +0200
@@ -10,6 +10,23 @@
from demandload import demandload
demandload(globals(), "os time util")
+def _string_escape(text):
+ """
+ >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)}
+ >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d
+ >>> s
+ 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n'
+ >>> res = _string_escape(s)
+ >>> s == _string_unescape(res)
+ True
+ """
+ # subset of the string_escape codec
+ text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r')
+ return text.replace('\0', '\\0')
+
+def _string_unescape(text):
+ return text.decode('string_escape')
+
class changelog(revlog):
def __init__(self, opener, defversion=REVLOGV0):
revlog.__init__(self, opener, "00changelog.i", "00changelog.d",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-doctest.py Mon Oct 02 22:35:37 2006 +0200
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+#
+
+import doctest
+
+import mercurial.changelog
+# test doctest from changelog
+
+doctest.testmod(mercurial.changelog)
+