equal
deleted
inserted
replaced
75 """ |
75 """ |
76 |
76 |
77 # this should fail for non-ASCII str |
77 # this should fail for non-ASCII str |
78 return name.encode('utf-8') |
78 return name.encode('utf-8') |
79 |
79 |
80 def __init__ (self, parent, fsname=None, name=None, config=None) : |
80 def __init__ (self, parent, fsname=None, name=None) : |
81 """ |
81 """ |
82 Initialize the node with a parent and both name/fsname. |
82 Initialize the node with a parent and both name/fsname. |
83 |
83 |
84 If not given, fsname is encoded from name, or name decoded from fsname, using encode/decode_name. |
84 If not given, fsname is encoded from name, or name decoded from fsname, using encode/decode_name. |
85 |
85 |
98 # fsname must not be an unicode string |
98 # fsname must not be an unicode string |
99 assert not fsname or isinstance(fsname, str) |
99 assert not fsname or isinstance(fsname, str) |
100 |
100 |
101 if parent and not fsname and not name : |
101 if parent and not fsname and not name : |
102 # no name given -> we're the same as parent |
102 # no name given -> we're the same as parent |
103 self.parent, self.config, self.fsname, self.name = parent.parent, parent.config, parent.fsname, parent.name |
103 self.parent, self.fsname, self.name = parent.parent, parent.fsname, parent.name |
104 |
104 |
105 else : |
105 else : |
106 # store |
106 # store |
107 self.parent = parent |
107 self.parent = parent |
108 |
108 |
109 # config, either as given, or copy from parent |
|
110 if config : |
|
111 self.config = config |
|
112 |
|
113 elif parent : |
|
114 self.config = parent.config |
|
115 |
|
116 else : |
|
117 # XXX: no config |
|
118 self.config = None |
|
119 |
|
120 # fsname |
109 # fsname |
121 if fsname : |
110 if fsname : |
122 self.fsname = fsname |
111 self.fsname = fsname |
123 |
112 |
124 else : |
113 else : |
395 Each node must either be the parent or the child of the following node. |
384 Each node must either be the parent or the child of the following node. |
396 |
385 |
397 The first and last nodes may be Files, but all other objects must be Directories. |
386 The first and last nodes may be Files, but all other objects must be Directories. |
398 |
387 |
399 XXX: better to keep Paths symbolic/relative? |
388 XXX: better to keep Paths symbolic/relative? |
400 XXX: welcome to Circular Reference Hell, a place has been reserved for you |
389 XXX: welcome to Circular Reference Hell |
401 """ |
390 """ |
402 |
391 |
403 def __init__ (self, *nodes) : |
392 def __init__ (self, *nodes) : |
404 """ |
393 """ |
405 Initialize with the given node path. |
394 Initialize with the given node path. |
694 class Root (Directory) : |
683 class Root (Directory) : |
695 """ |
684 """ |
696 A special Directory that overrides the Node methods to anchor the recursion/etc at some 'real' filesystem path. |
685 A special Directory that overrides the Node methods to anchor the recursion/etc at some 'real' filesystem path. |
697 """ |
686 """ |
698 |
687 |
699 # XXX: config needs a default |
688 def __init__ (self, fspath) : |
700 def __init__ (self, fspath, config=None) : |
|
701 """ |
689 """ |
702 Construct the directory tree root at the given 'real' path, which must be a raw str |
690 Construct the directory tree root at the given 'real' path, which must be a raw str |
703 """ |
691 """ |
704 |
692 |
705 # abuse Node's concept of a "name" a bit |
693 # abuse Node's concept of a "name" a bit |
706 super(Root, self).__init__(None, fspath, config=config) |
694 # XXX: this will break path manipulations, methinks |
|
695 super(Root, self).__init__(None, fspath) |
707 |
696 |
708 def nodepath (self) : |
697 def nodepath (self) : |
709 """ |
698 """ |
710 Just return ourself |
699 Just return ourself |
711 """ |
700 """ |