annotate cutils/util/walk.py @ 352:b256ae4f4bc8

treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 01 Apr 2025 20:38:06 +0200
parents 0a58948df713
children 7761a15b9736
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 # :-
323
48430941c18c Adopt copyright and license wordings from https://reuse.software/faq/.
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
3 # SPDX-FileCopyrightText: © 2025 Franz Glasner
48430941c18c Adopt copyright and license wordings from https://reuse.software/faq/.
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
4 # SPDX-License-Identifier: BSD-3-Clause
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 # :-
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 r"""Utility sub-module to implement a heavily customized :func:`os.walk`.
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 """
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9
196
0f4febf646f5 Prepare for more Python2/3 compatibility: everywhere import print_function and absolute_import
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
10 from __future__ import print_function, absolute_import
0f4febf646f5 Prepare for more Python2/3 compatibility: everywhere import print_function and absolute_import
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
11
0f4febf646f5 Prepare for more Python2/3 compatibility: everywhere import print_function and absolute_import
Franz Glasner <fzglas.hg@dom66.de>
parents: 195
diff changeset
12
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
13 __all__ = ["WalkDirEntry", "ScanDir", "getfsencoding"]
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
344
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
16 import logging
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 import os
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19 from os import scandir
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 except ImportError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 from scandir import scandir
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 except ImportError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24 scandir = None
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
25 import stat
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
26 import sys
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27
164
a813094ae4f5 Move PY2 from cutils.util.constants into cutils.util
Franz Glasner <fzglas.hg@dom66.de>
parents: 162
diff changeset
28 from . import PY2
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30
352
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
31 HELP_FILETYPE_INDICATORS = r"""
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
32 FILETYPE INDICATORS
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
33 ===================
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
34
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
35 File and directory paths are printed using names analogous to calling
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
36 "ls -F/--classify". The indicator strings (aka "marker" or "tags") are
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
37 appended to their names as follows.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
38
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
39 Some standard indicators are:
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
40
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
41 /
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
42 denotes a directory
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
43
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
44 /./@/
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
45 denotes a symbolic link to a directory
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
46
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
47 /./@
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
48 Classifies a symlink to a regular filesystem object (i.e. a regular file).
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
49 The target objects are not classified as directories or other special
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
50 filesystem objects.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
51 Also used if a symbolic link is broken and the target type cannot
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
52 determined.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
53
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
54 /./| --- /./@|
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
55 FIFO --- symlink to FIFO
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
56
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
57 /./= --- /./@=
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
58 Socket --- symlink to socket
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
59
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
60 /./> --- /./@>
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
61 Door -- symlink to door.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
62
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
63 Solaris.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
64
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
65 /./% --- /./@%
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
66 Whiteout --- symlink to whiteout.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
67
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
68 Typically Used by union filesystems) (BSD).
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
69
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
70 More non-standard indicators are:
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
71
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
72 /./: --- /./@:
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
73 Character special device --- symlink to character special device
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
74
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
75 /./; --- /./@;
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
76 Block special device --- symlink to block special device
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
77
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
78 /./+ --- /./@+
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
79 Event port --- symlink to event port.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
80
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
81 Solaris, Illumos.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
82
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
83 In an aggregated (directory) checksum at the end of a block the following
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
84 indicators are used:
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
85
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
86 ./@/
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
87 Symbolic link to a directory
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
88
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
89 ./@
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
90 Symbolic link to other filesystem object.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
91
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
92 Also used if the link is broken and the target type cannot determined.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
93
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
94 NOTE: Executable files have no special indicator here. The "ls -F" command
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
95 would use the `*' character in this case.
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
96
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
97 """
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
98
b256ae4f4bc8 treesum: implement the "filetypes" command to show all the filetype indicators that are used in digest output
Franz Glasner <fzglas.hg@dom66.de>
parents: 344
diff changeset
99
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
100 _notset = object()
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
101
344
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
102 _logger = logging.getLogger(__name__)
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
103
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
104 _FSENCODING = sys.getfilesystemencoding()
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
105
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
106
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
107 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
108
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
109 def _unix_path(s):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
110 if isinstance(s, bytes):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
111 return s.replace(b"\\", b"/")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
112 return s.replace(u"\\", u"/")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
113
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
114 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
115
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
116 def _unix_path(s):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
117 return s.replace("\\", "/")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
118
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
119
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120 class WalkDirEntry(object):
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
122 """A :class:`os.DirEntry` alike to be used in :func:`walk` and for
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
123 its results.
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
124
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
125 """
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
126
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
127 __slots__ = ("_name", "_path", # encoded as given in the ctor
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
128 "_is_symlink", "_is_reg", "_is_dir", "_stat_result",
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
129 "_stat_errno", "_stat_errstr",
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
130 "_alt_fsname", "_alt_u8name")
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
131
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
132 def __init__(self, name, path):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
133 self._name = name # the name as given in the constructor
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
134 """The name exactly as given in the ctor"""
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
135 self._path = _unix_path(path)
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
136 """The path as given in the ctor -- but normalized to have slashes"""
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
137 self._is_symlink = self._is_reg = self._is_dir = self._stat_result = \
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
138 self._stat_errno = self._stat_errstr = None
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
139 self._alt_fsname = self._alt_u8name = _notset
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
140
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141 @property
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 def name(self):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
143 """The original name exactly as given in the ctor"""
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 return self._name
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
146 @property
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147 def path(self):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
148 """The original path exactly as given in the ctor."""
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149 return self._path
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
151 @property
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
152 def fsname(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
153 """The name as bytes for the filesystem.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
154
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
155 Also do not allow CR of LF in the name.
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
156
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
157 :rtype: bytes or None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
158
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
159 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
160 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
161 if isinstance(self._name, bytes):
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
162 s = self._name
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
163 try:
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
164 s = self._name.encode(_FSENCODING, "strict")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
165 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
166 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
167 else:
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
168 s = os.fsencode(self._name)
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
169 if (b'\n' in s) or (b'\r' in s) or (b'\\' in s):
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
170 return None
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
171 return s
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
172
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
173 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
174 def fspath(self):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
175 """Always bytes.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
176
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
177 Also do not allow CR of LF in the path.
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
178
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
179 :rtype: bytes or None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
180
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
181 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
182 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
183 if isinstance(self._path, bytes):
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
184 p = self._path
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
185 try:
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
186 p = self._path.encode(_FSENCODING, "strict")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
187 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
188 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
189 else:
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
190 p = os.fsencode(self._path)
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
191 if (b'\n' in p) or (b'\r' in p) or (b'\\' in p):
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
192 return None
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
193 return p
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
194
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
195 @property
282
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
196 def alt_fsname(self):
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
197 """Alternative and "escaped" filesystem name -- always bytes.
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
198
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
199 :rtype: bytes
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
200
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
201 """
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
202 if self._alt_fsname is _notset:
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
203 self._alt_fsname = WalkDirEntry.alt_fs(self._name)
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
204 return self._alt_fsname
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
205
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
206 @property
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
207 def alt_fspath(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
208 """Alternative and "escaped" filesystem path -- always bytes.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
209
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
210 :rtype: bytes
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
211
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
212 """
203
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
213 return WalkDirEntry.alt_fs(self._path)
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
214
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
215 @staticmethod
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
216 def alt_fs(what):
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
217 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
218 # Prevent double encoding ...
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
219 # ... and hope that the current FS encoding is compatible
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
220 # with it
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
221 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
222 if isinstance(what, bytes):
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
223 s = (what.replace(b'\\', b"\\x5c")
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
224 .replace(b'\n', b"\\x0a")
343
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
225 .replace(b'\r', b"\\x0d")
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
226 .replace(b'\t', b"\\x09"))
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
227 else:
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
228 s = (what.replace(u'\\', u"\\x5c")
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
229 .replace(u'\n', u"\\x0a")
343
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
230 .replace(u'\r', u"\\x0d")
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
231 .replace(u'\t', u"\\x09"))
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
232 if PY2:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
233 if isinstance(s, bytes):
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
234 return s
281
16507317e834 treesum: FIX: Also do not allow CR and/or LF and/or backslashes in strictly FS encoded names
Franz Glasner <fzglas.hg@dom66.de>
parents: 280
diff changeset
235 else:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
236 return s.encode(_FSENCODING, "backslashreplace")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
237 else:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
238 return os.fsencode(s)
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
239
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
240 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
241 def uname(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
242 """Always "real", strictly encoded Unicode or `None` if this is not
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
243 possible.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
244
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
245 :rtype: text or None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
246
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
247 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
248 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
249 if isinstance(self._name, bytes):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
250 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
251 return self._name.decode(_FSENCODING, "strict")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
252 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
253 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
254 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
255 return self._name
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
256 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
257 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
258 self._name.encode("utf-8", "strict")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
259 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
260 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
261 return self._name
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
262
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
263 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
264 def upath(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
265 """Always "real", strictly encoded Unicode or `None` if this is not
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
266 possible.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
267
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
268 :rtype: text or None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
269
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
270 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
271 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
272 if isinstance(self._path, bytes):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
273 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
274 return self._path.decode(_FSENCODING, "strict")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
275 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
276 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
277 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
278 return self._path
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
279 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
280 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
281 self._path.encode("utf-8", "strict")
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
282 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
283 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
284 return self._path
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
285
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
286 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
287 def u8name(self):
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
288 """`.uname` as UTF-8 or `None` (as strict as `uname`).
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
289
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
290 Also do not allow CR of LF in the name.
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
291
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
292 """
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
293 n = self.uname
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
294 if n is None:
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
295 return None
280
f3e0b479928c treesum: FIX: Also check for that backslashes are nor in u8name or u8path and encode them
Franz Glasner <fzglas.hg@dom66.de>
parents: 276
diff changeset
296 if (u'\n' in n) or (u'\r' in n) or (u'\\' in n):
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
297 return None
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
298 return n.encode("utf-8", "strict")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
299
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
300 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
301 def u8path(self):
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
302 """`.upath` as UTF-8 or `None` (as strict as `upath`.
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
303
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
304 Also do not allow CR or LF in the path.
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
305
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
306 """
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
307 p = self.upath
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
308 if p is None:
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
309 return None
280
f3e0b479928c treesum: FIX: Also check for that backslashes are nor in u8name or u8path and encode them
Franz Glasner <fzglas.hg@dom66.de>
parents: 276
diff changeset
310 if (u'\n' in p) or (u'\r' in p) or (u'\\' in p):
276
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
311 return None
f7850ff5cbe0 treesum: when walking: if filenames contain CR and/or LF pretend that this names are not properly encoded.
Franz Glasner <fzglas.hg@dom66.de>
parents: 274
diff changeset
312 return p.encode("utf-8", "strict")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
313
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
314 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
315 def alt_u8name(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
316 if self._alt_u8name is _notset:
203
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
317 self._alt_u8name = WalkDirEntry.alt_u8(self._name)
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
318 return self._alt_u8name
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
319
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
320 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
321 def alt_u8path(self):
203
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
322 return WalkDirEntry.alt_u8(self._path)
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
323
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
324 @staticmethod
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
325 def alt_u8(what):
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
326 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
327 # Prevent double encoding ...
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
328 # ... and hope that the current UTF-8 is compatible
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
329 # with it
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
330 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
331 if isinstance(what, bytes):
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
332 s = (what.replace(b'\\', b"\\x5c")
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
333 .replace(b'\n', b"\\x0a")
343
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
334 .replace(b'\r', b"\\x0d")
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
335 .replace(b'\t', b"\\x09"))
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
336 else:
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
337 s = (what.replace(u'\\', u"\\x5c")
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
338 .replace(u'\n', u"\\x0a")
343
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
339 .replace(u'\r', u"\\x0d")
b3931b511ed0 Also encode TAB characters specially for output in digest files.
Franz Glasner <fzglas.hg@dom66.de>
parents: 323
diff changeset
340 .replace(u'\t', u"\\x09"))
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
341 if PY2:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
342 if isinstance(s, bytes):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
343 try:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
344 return (s.decode(_FSENCODING, "strict")
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
345 .encode("utf-8", "strict"))
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
346 except UnicodeError:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
347 return (WalkDirEntry.surrogate_decode(s)
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
348 .encode("ascii", "backslashreplace"))
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
349 else:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
350 return s.encode("ascii", "backslashreplace")
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
351 else:
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
352 return s.encode("utf-8", "backslashreplace")
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
353
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
354 @property
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
355 def is_symlink(self):
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
356 return self._is_symlink
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
357
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
358 @property
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
359 def is_reg(self):
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
360 return self._is_reg
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
361
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
362 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
363 def is_dir(self):
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
364 return self._is_dir
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
365
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
366 @property
274
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
367 def is_chr(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
368 return (stat.S_ISCHR(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
369 if self._stat_result is not None
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
370 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
371
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
372 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
373 def is_blk(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
374 return (stat.S_ISBLK(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
375 if self._stat_result is not None
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
376 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
377
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
378 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
379 def is_fifo(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
380 return (stat.S_ISFIFO(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
381 if self._stat_result is not None
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
382 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
383
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
384 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
385 def is_socket(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
386 return (stat.S_ISSOCK(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
387 if self._stat_result is not None
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
388 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
389
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
390 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
391 def is_door(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
392 test = getattr(stat, "S_ISDOOR", None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
393 return (test(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
394 if test and (self._stat_result is not None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
395 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
396
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
397 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
398 def is_eventport(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
399 test = getattr(stat, "S_ISPORT", None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
400 return (test(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
401 if test and (self._stat_result is not None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
402 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
403
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
404 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
405 def is_whiteout(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
406 test = getattr(stat, "S_ISWHT", None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
407 return (test(self._stat_result.st_mode)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
408 if test and (self._stat_result is not None)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
409 else False)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
410
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
411 @property
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
412 def is_special(self):
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
413 """Anything besides a regular file and a directory"""
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
414 if self._stat_result is None:
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
415 return False
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
416 return not (self.is_reg or self.is_dir)
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
417
224725fd9f2f WalkDirEntry: add support for special files (character and block special, FIFO, socket, door, whiteout, event port, ...)
Franz Glasner <fzglas.hg@dom66.de>
parents: 273
diff changeset
418 @property
344
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
419 def special_tag(self):
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
420 """Return a special tag (string) for a special file"""
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
421 assert self.is_special
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
422 if self.is_chr:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
423 return ':'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
424 elif self.is_blk:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
425 return ';'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
426 elif self.is_fifo:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
427 return '|'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
428 elif self.is_socket:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
429 return '='
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
430 elif self.is_door:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
431 return '>'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
432 elif self.is_whiteout:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
433 return '%'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
434 elif self.is_eventport:
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
435 return '+'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
436 _logger.warning(
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
437 "unknown special file type: 0x%X",
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
438 stat.S_IFMT(self._stat_result.st_mode))
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
439 return '?'
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
440
0a58948df713 Move the computation of the special tag string marker for special files into a property
Franz Glasner <fzglas.hg@dom66.de>
parents: 343
diff changeset
441 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
442 def stat(self):
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
443 return self._stat_result
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
444
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
445 @property
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
446 def stat_errno(self):
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
447 return self._stat_errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
448
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
449 @property
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
450 def stat_errstr(self):
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
451 return self._stat_errstr
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
452
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
453 def __repr__(self):
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
454 tag = ""
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
455 if self._is_symlink:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
456 tag += "l"
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
457 if self._is_dir:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
458 tag += "d"
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
459 if tag:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
460 return "<WalkDirEntry %r (%s)>" % (self._name, tag)
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
461 return "<WalkDirEntry %r>" % (self._name,)
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
462
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
463 @classmethod
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
464 def from_direntry(cls_, entry):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
465 w = cls_(entry.name, entry.path)
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
466 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
467 w._is_dir = entry.is_dir(follow_symlinks=True)
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
468 except OSError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
469 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
470 # If is_dir() raises an OSError, consider that the entry
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
471 # is not a directory, same behaviour than os.path.isdir().
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
472 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
473 w._is_dir = False
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
474 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
475 w._is_symlink = entry.is_symlink()
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
476 except OSError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
477 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
478 # If is_symlink() raises an OSError, consider that the entry
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
479 # is not a symbolic link, same behaviour than os.path.islink().
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
480 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
481 w._is_symlink = False
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
482 # Consistently follow symlinks
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
483 try:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
484 w._stat_result = entry.stat(follow_symlinks=True)
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
485 except OSError as e:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
486 w._stat_result = None
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
487 w._stat_errno = e.errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
488 w._stat_errstr = e.strerror
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
489 w._is_reg = False
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
490 else:
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
491 w._is_reg = stat.S_ISREG(w._stat_result.st_mode)
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
492 return w
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
493
162
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
494 @classmethod
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
495 def from_path_name(cls_, path, name, _do_stat=True):
265
188f448ab5e9 FIX: typo in docs
Franz Glasner <fzglas.hg@dom66.de>
parents: 221
diff changeset
496 """`_do_stat` is to be used only for testing purposes"""
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
497 w = cls_(name, os.path.join(path, name))
162
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
498 try:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
499 w._is_dir = os.path.isdir(w._path)
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
500 except OSError:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
501 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
502 # If is_dir() raises an OSError, consider that the entry
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
503 # is not a directory, same behaviour than os.path.isdir().
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
504 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
505 w._is_dir = False
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
506 try:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
507 w._is_symlink = os.path.islink(w._path)
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
508 except OSError:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
509 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
510 # If is_symlink() raises an OSError, consider that the entry
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
511 # is not a symbolic link, same behaviour than os.path.islink().
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
512 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
513 w._is_symlink = False
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
514 if _do_stat:
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
515 try:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
516 w._stat_result = os.stat(w._path)
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
517 except OSError as e:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
518 w._stat_result = None
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
519 w._stat_errno = e.errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
520 w._stat_errstr = e.strerror
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
521 w._is_reg = False
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
522 else:
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
523 w._is_reg = stat.S_ISREG(w._stat_result.st_mode)
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
524 return w
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
525
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
526 @classmethod
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
527 def from_readlink(cls_, path):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
528 w = cls_(os.path.basename(path), path)
162
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
529 return w
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
530
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
531 @staticmethod
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 203
diff changeset
532 def sort_key_fs(entry):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
533 return entry.alt_fsname # because it should never throw
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
534
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
535 @staticmethod
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 203
diff changeset
536 def sort_key_u8(entry):
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
537 return entry.alt_u8name # because it should never throw
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
538
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
539 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
540
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
541 @staticmethod
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
542 def surrogate_decode(what):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
543 """Decode the bytes object `what` using surrogates from :pep:`383`
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
544 for all non-ASCII octets.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
545
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
546 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
547 uwhat = []
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
548 assert isinstance(what, bytes)
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
549 for ch in what:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
550 chcode = ord(ch)
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
551 if chcode <= 0x7f:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
552 uwhat.append(unichr(chcode)) # noqa: F821 unichr
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
553 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
554 uwhat.append(unichr(0xDC00 + chcode)) # noqa: F821 unichr
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
555 return u"".join(uwhat)
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
556
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
557
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
558 if scandir:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
559
178
dac26a2d9de5 Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents: 177
diff changeset
560 class ScanDir(object):
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
561
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
562 """An :func:`os.scandir` wrapper that is always an iterator and
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
563 a context manager.
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
564
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
565 """
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
566
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
567 __slots__ = ("_scandir_it", )
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
568
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
569 def __init__(self, path):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
570 super(ScanDir, self).__init__()
195
e5f6f4db9157 Use the imported "scandir()" implementation instead always the "os.scandir"
Franz Glasner <fzglas.hg@dom66.de>
parents: 192
diff changeset
571 self._scandir_it = scandir(path)
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
572
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
573 def __iter__(self):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
574 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
575
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
576 def __next__(self):
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
577 if self._scandir_it is None:
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
578 raise StopIteration("closed")
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
579 return WalkDirEntry.from_direntry(next(self._scandir_it))
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
580
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
581 if PY2:
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
582 next = __next__
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
583
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
584 def __enter__(self):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
585 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
586
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
587 def __exit__(self, *args, **kwds):
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
588 self.close()
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
589
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
590 def close(self):
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
591 if self._scandir_it is not None:
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
592 if hasattr(self._scandir_it, "close"):
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
593 self._scandir_it.close()
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
594 self._scandir_it = None
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
595
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
596 else:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
597
178
dac26a2d9de5 Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents: 177
diff changeset
598 class ScanDir(object):
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
599
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
600 """An :func:`os.scandir` wrapper that is always an iterator and
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
601 a context manager.
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
602
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
603 """
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
604
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
605 __slots__ = ("_listdir_it", "_path")
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
606
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
607 def __init__(self, path):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
608 super(ScanDir, self).__init__()
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
609 self._listdir_it = iter(os.listdir(path))
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
610 self._path = path
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
611
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
612 def __iter__(self):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
613 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
614
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
615 def __next__(self):
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
616 if self._listdir_it is None:
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
617 raise StopIteration("closed")
175
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
618 return WalkDirEntry.from_path_name(self._path,
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
619 next(self._listdir_it))
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
620
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
621 if PY2:
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
622 next = __next__
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
623
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
624 def __enter__(self):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
625 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
626
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
627 def __exit__(self, *args, **kwds):
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
628 pass
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
629
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
630 def close(self):
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
631 pass
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
632
198
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
633
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
634 def getfsencoding():
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
635 """Return the stored _FSENCODING of this module"""
c1e875ba4bdc Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents: 196
diff changeset
636 return _FSENCODING