1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """File name manipulation."""
20
21 __all__ = ['PathName', 'DirName', 'FileName']
22
23 import os
24
25
27
28 """String with extra methods for filename operations."""
29
31 return str.__new__(cls, os.path.normpath(path))
32
34 if isinstance(path, (DirName, FileName)):
35 ctor = path.__class__
36 else:
37 ctor = PathName
38 return ctor(os.path.join(self, path))
39
41 return '%s(%s)' % (type(self).__name__, str.__repr__(self))
42
44 return self.__class__(os.path.abspath(self))
48 return self.__class__(os.path.basename(self))
49
51 if 'realpath' in dir(os.path):
52 return self.__class__(os.path.realpath(self))
53 else:
54 return self.abspath()
55
57 dir_, base = os.path.split(self)
58 return DirName(dir_), self.__class__(base)
59
60
62
63 """PathName, further characterized as a directory name."""
64
65
67
68 """PathName further characterized as a file name."""
69