From 128b5cb8067411890f32415c498f5fe790c56a06 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 20 Jul 2010 15:01:13 -0400 Subject: [PATCH] Transition a -> alpha (\u03b1) to test unicode paths --- README | 18 ++++---- dirtag/__init__.py | 69 ++++++++++++++++++------------ test/raw/a/a1.html | 1 - test/raw/a/a2.html | 1 - test/raw/a/a3.html | 1 - "test/raw/\316\261/\316\2611.html" | 1 + "test/raw/\316\261/\316\2612.html" | 1 + "test/raw/\316\261/\316\2613.html" | 1 + test/tag/1/a1.html | 1 - "test/tag/1/\316\2611.html" | 1 + test/tag/x/a2.html | 1 - "test/tag/x/\316\2612.html" | 1 + 12 files changed, 55 insertions(+), 42 deletions(-) delete mode 100644 test/raw/a/a1.html delete mode 100644 test/raw/a/a2.html delete mode 100644 test/raw/a/a3.html create mode 100644 "test/raw/\316\261/\316\2611.html" create mode 100644 "test/raw/\316\261/\316\2612.html" create mode 100644 "test/raw/\316\261/\316\2613.html" delete mode 120000 test/tag/1/a1.html create mode 120000 "test/tag/1/\316\2611.html" delete mode 120000 test/tag/x/a2.html create mode 120000 "test/tag/x/\316\2612.html" diff --git a/README b/README index c2fc95a..dfaf778 100644 --- a/README +++ b/README @@ -9,10 +9,10 @@ access tagged categories using the command line or dumb tools. For example, with a raw directory like this:: raw - |-- a - | |-- a1.html - | |-- a2.html - | `-- a3.html + |-- α + | |-- α1.html + | |-- α2.html + | `-- α3.html `-- b |-- b1.svg |-- b2.html @@ -22,19 +22,19 @@ You could create a tag directory like this:: tag/ |-- 1 - | |-- a1.html -> ../../raw/a/a1.html + | |-- α1.html -> ../../rαw/α/α1.html | `-- b1.svg -> ../../raw/b/b1.svg `-- x - |-- a2.html -> ../../raw/a/a2.html + |-- α2.html -> ../../rαw/α/α2.html |-- b3.html -> ../../raw/b/b3.html `-- y `-- b1.svg -> ../../../raw/b/b1.svg Corresponding to the following tags:: - a1.html 1 - a2.html x - a3.html + α1.html 1 + α2.html x + α3.html b1.svg 1, x/y b2.html b3.html x diff --git a/dirtag/__init__.py b/dirtag/__init__.py index 045c37c..f55b88f 100644 --- a/dirtag/__init__.py +++ b/dirtag/__init__.py @@ -197,23 +197,26 @@ class Tree (list): def dir_tree(root_dir): """Generate a directory tree. - >>> t = dir_tree('test/tag') - >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1)]) + >>> t = dir_tree(u'test/tag') + >>> print '\\n'.join(['|'.join(x).encode('unicode escape') + ... for x in t.traverse(depth=1)]) 1 - 1|a1.html 1|b1.svg + 1|\\u03b11.html x x|y x|y|b1.svg - x|a2.html x|b3.html - >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='files')]) - 1|a1.html + x|\\u03b12.html + >>> print '\\n'.join(['|'.join(x).encode('unicode escape') + ... for x in t.traverse(depth=1, type='files')]) 1|b1.svg + 1|\\u03b11.html x|y|b1.svg - x|a2.html x|b3.html - >>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='dirs')]) + x|\\u03b12.html + >>> print '\\n'.join(['|'.join(x).encode('unicode escape') + ... for x in t.traverse(depth=1, type='dirs')]) 1 x x|y @@ -237,24 +240,27 @@ def dir_tree(root_dir): class Dirtag (object): """ - >>> d = Dirtag('test/raw', 'test/tag') - >>> print '\\n'.join(['\t'.join([x.type, x.root, '|'.join(x), - ... ','.join(['/'.join(t) for t in x.tags])]) + >>> d = Dirtag(u'test/raw', u'test/tag') + >>> print '\\n'.join(['\t'.join([ + ... x.type, x.root, + ... '|'.join(x).encode('unicode escape'), + ... ','.join(['/'.join(t) for t in x.tags])]) ... for x in d.elements()] ... ) # doctest: +NORMALIZE_WHITESPACE - dir test/raw a - file test/raw a|a1.html 1 - file test/raw a|a2.html x - file test/raw a|a3.html dir test/raw b file test/raw b|b1.svg 1,x/y file test/raw b|b2.html file test/raw b|b3.html x - >>> print '\\n'.join(['|'.join(x) for x in d.elements(['x'])]) - x|y - x|y|b1.svg - x|a2.html - x|b3.html + dir test/raw \\u03b1 + file test/raw \\u03b1|\\u03b11.html 1 + file test/raw \\u03b1|\\u03b12.html x + file test/raw \\u03b1|\\u03b13.html + >>> for x in d.elements(['x']): + ... print repr('|'.join(x).encode('unicode escape')) + 'x|y' + 'x|y|b1.svg' + 'x|b3.html' + 'x|\\\\u03b12.html' >>> print '\\n'.join(['|'.join(x) for x in d.tags()]) 1 x @@ -264,16 +270,17 @@ class Dirtag (object): >>> print '\\n'.join(['|'.join(x) for x in d.tags(['b', 'b1.svg'])]) 1 x|y - >>> print d.tag_path(['a', 'a3.html'], ['x', 'y']) - test/tag/x/y/a3.html + >>> d.tag_path(['a', u'\\u03b13.html'], + ... ['x', 'y']).encode('unicode escape') + 'test/tag/x/y/\\\\u03b13.html' >>> os.listdir('test/tag/x/y') ['b1.svg'] - >>> d.add_tag(['a', 'a3.html'], ['x', 'y']) - >>> sorted(os.listdir('test/tag/x/y')) - ['a3.html', 'b1.svg'] - >>> print 'Z'+os.path.realpath('test/tag/x/y/a3.html') # doctest: +ELLIPSIS - Z.../test/raw/a/a3.html - >>> d.remove_tag(['a', 'a3.html'], ['x', 'y']) + >>> d.add_tag([u'\\u03b1', u'\\u03b13.html'], ['x', 'y']) + >>> sorted(os.listdir(u'test/tag/x/y')) + [u'b1.svg', u'\\u03b13.html'] + >>> 'Z'+os.path.realpath(u'test/tag/x/y/\u03b13.html').encode('unicode escape') # doctest: +ELLIPSIS + 'Z.../test/raw/\\\\u03b1/\\\\u03b13.html' + >>> d.remove_tag([u'\\u03b1', u'\\u03b13.html'], ['x', 'y']) >>> os.listdir('test/tag/x/y') ['b1.svg'] """ @@ -348,5 +355,11 @@ class Dirtag (object): if __name__ == '__main__': + # Uncomment the following lines if you're having problems with + # UTF-8 in your docstrings. + #import sys + #reload(sys) + #sys.setdefaultencoding('utf-8') + import doctest doctest.testmod() diff --git a/test/raw/a/a1.html b/test/raw/a/a1.html deleted file mode 100644 index 7bb4bc6..0000000 --- a/test/raw/a/a1.html +++ /dev/null @@ -1 +0,0 @@ -

a1.html

diff --git a/test/raw/a/a2.html b/test/raw/a/a2.html deleted file mode 100644 index 3172739..0000000 --- a/test/raw/a/a2.html +++ /dev/null @@ -1 +0,0 @@ -

a2.html

diff --git a/test/raw/a/a3.html b/test/raw/a/a3.html deleted file mode 100644 index 010e71c..0000000 --- a/test/raw/a/a3.html +++ /dev/null @@ -1 +0,0 @@ -

a3.html

diff --git "a/test/raw/\316\261/\316\2611.html" "b/test/raw/\316\261/\316\2611.html" new file mode 100644 index 0000000..be67402 --- /dev/null +++ "b/test/raw/\316\261/\316\2611.html" @@ -0,0 +1 @@ +

α1.html

diff --git "a/test/raw/\316\261/\316\2612.html" "b/test/raw/\316\261/\316\2612.html" new file mode 100644 index 0000000..d574c08 --- /dev/null +++ "b/test/raw/\316\261/\316\2612.html" @@ -0,0 +1 @@ +

α2.html

diff --git "a/test/raw/\316\261/\316\2613.html" "b/test/raw/\316\261/\316\2613.html" new file mode 100644 index 0000000..4ebec45 --- /dev/null +++ "b/test/raw/\316\261/\316\2613.html" @@ -0,0 +1 @@ +

α3.html

diff --git a/test/tag/1/a1.html b/test/tag/1/a1.html deleted file mode 120000 index 56821b4..0000000 --- a/test/tag/1/a1.html +++ /dev/null @@ -1 +0,0 @@ -../../raw/a/a1.html \ No newline at end of file diff --git "a/test/tag/1/\316\2611.html" "b/test/tag/1/\316\2611.html" new file mode 120000 index 0000000..a012737 --- /dev/null +++ "b/test/tag/1/\316\2611.html" @@ -0,0 +1 @@ +../../raw/α/α1.html \ No newline at end of file diff --git a/test/tag/x/a2.html b/test/tag/x/a2.html deleted file mode 120000 index 19bf565..0000000 --- a/test/tag/x/a2.html +++ /dev/null @@ -1 +0,0 @@ -../../raw/a/a2.html \ No newline at end of file diff --git "a/test/tag/x/\316\2612.html" "b/test/tag/x/\316\2612.html" new file mode 120000 index 0000000..e54070d --- /dev/null +++ "b/test/tag/x/\316\2612.html" @@ -0,0 +1 @@ +../../raw/α/α2.html \ No newline at end of file -- 2.26.2