import os
import os.path
+import sys
+
+if sys.version_info < (2, 5, 0, 'alpha', 0):
+ raise Exception('Requires at least Python 2.5, not %s'
+ % ('.'.join([str(x) for x in sys.version_info])))
+elif sys.version_info < (2, 6, 0, 'alpha', 0): # Workarounds for 2.5
+ def walk(top, topdown=True, onerror=None, followlinks=False):
+ """From 2.6's os.py."""
+ from os import listdir, error
+ from os.path import join, isdir, islink
+ try:
+ names = listdir(top)
+ except error, err:
+ if onerror is not None:
+ onerror(err)
+ return
+
+ dirs, nondirs = [], []
+ for name in names:
+ if isdir(join(top, name)):
+ dirs.append(name)
+ else:
+ nondirs.append(name)
+
+ if topdown:
+ yield top, dirs, nondirs
+ for name in dirs:
+ path = join(top, name)
+ if followlinks or not islink(path):
+ for x in walk(path, topdown, onerror, followlinks):
+ yield x
+ if not topdown:
+ yield top, dirs, nondirs
+
+ os.walk = walk
+
+ from os.path import curdir, abspath, commonprefix, sep, pardir, join
+
+ def relpath(path, start=curdir):
+ """From 2.6's posixpath.py."""
+ if not path:
+ raise ValueError("no path specified")
+
+ start_list = abspath(start).split(sep)
+ path_list = abspath(path).split(sep)
+
+ i = len(commonprefix([start_list, path_list]))
+
+ rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+ if not rel_list:
+ return curdir
+ return join(*rel_list)
+
+ os.path.relpath = relpath
class Node (list):
>>> os.listdir('test/tag/x/y')
['b1.html']
>>> d.add_tag(['a', 'a3.html'], ['x', 'y'])
- >>> os.listdir('test/tag/x/y')
+ >>> sorted(os.listdir('test/tag/x/y'))
['a3.html', 'b1.html']
>>> print 'Z'+os.path.realpath('test/tag/x/y/a3.html') # doctest: +ELLIPSIS
Z.../test/raw/a/a3.html