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
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
>>> 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']
"""
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()