1 """ path.py - An object representing a path to a file or a directory.
2
3 Based on the path module by Jason Orendorff
4 (http://www.jorendorff.com/articles/python/path)
5
6 Written by Noam Raphael to show the idea of using a tuple instead of
7 a string, and to reduce the number of methods.
8
9 Currently only implements posix and nt paths - more can be added.
10
11 """
12
13 import os
14 import stat
15 import itertools
16 import fnmatch
17 import re
18 import string
19
20 class StatWrapper(object):
21 """ A wrapper around stat_result objects which gives additional properties.
22
23 This object is a wrapper around a stat_result object. It allows access
24 to all the original object's attributes, and adds a few convinient
25 properties, by using the stat module.
26
27 This object should have been a subclass posix.stat_result - it simply
28 isn't possible currently. This functionality may also be integrated into
29 the original type.
30 """
31
32 __slots__ = ['_stat']
33
34 def __init__(self, stat):
35 self._stat = stat
36
37 def __getattribute__(self, attr, *default):
38 try:
39 return object.__getattribute__(self, attr, *default)
40 except AttributeError:
41 return getattr(self._stat, attr, *default)
42
43
44
45 @property
46 def isdir(self):
47 return stat.S_ISDIR(self.st_mode)
48 @property
49 def isfile(self):
50 return stat.S_ISREG(self.st_mode)
51 @property
52 def islink(self):
53 return stat.S_ISLNK(self.st_mode)
54
55
56
57