annotate cutils/util/walk.py @ 371:29a301ff2501

treesum: FIX: also check for TABs when trying to encode strictly
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 12 Apr 2025 09:05:48 +0200
parents 04d7945ff4ae
children bfe1160fbfd3
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):
369
04d7945ff4ae treesum: Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 368
diff changeset
148 """The original path exactly as given in the ctor -- but normalized to
04d7945ff4ae treesum: Comment
Franz Glasner <fzglas.hg@dom66.de>
parents: 368
diff changeset
149 have forward slashes"""
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 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
151
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
152 @property
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
153 def fsname(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
154 """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
155
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
156 Also do not allow TAB, CR or LF in the name.
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
157
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
158 :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
159
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
160 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
161 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
162 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
163 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
164 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
165 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
166 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
167 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
168 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
169 s = os.fsencode(self._name)
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
170 if (b'\n' in s) or (b'\r' in s) or (b'\t' in s) or (b'\\' in 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
171 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
172 return s
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
173
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
174 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
175 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
176 """Always bytes.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
177
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
178 Also do not allow TAB, CR or LF in the path.
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
179
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
180 :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
181
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
182 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
183 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
184 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
185 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
186 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
187 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
188 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
189 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
190 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
191 p = os.fsencode(self._path)
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
192 if (b'\n' in p) or (b'\r' in p) or (b'\t' in p) or (b'\\' in p):
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
193 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
194 return p
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
195
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
196 @property
282
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
197 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
198 """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
199
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
200 :rtype: bytes
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 """
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
203 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
204 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
205 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
206
d507ae4943d5 Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents: 281
diff changeset
207 @property
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
208 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
209 """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
210
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
211 :rtype: bytes
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
212
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
213 """
203
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
214 return WalkDirEntry.alt_fs(self._path)
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
215
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
216 @staticmethod
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
217 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
218 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
219 # 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
220 # ... 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
221 # 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
222 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
223 if isinstance(what, bytes):
368
7761a15b9736 treesum: Escape `\' using `\\' instead of `\x5c'.
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
224 s = (what.replace(b'\\', b"\\\\")
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
225 .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
226 .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
227 .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
228 else:
368
7761a15b9736 treesum: Escape `\' using `\\' instead of `\x5c'.
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
229 s = (what.replace(u'\\', u"\\\\")
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
230 .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
231 .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
232 .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
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
241 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
242 def uname(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
243 """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
244 possible.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
245
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
246 :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
247
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
248 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
249 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
250 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
251 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
252 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
253 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
254 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
255 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
256 return self._name
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
257 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
258 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
259 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
260 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
261 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
262 return self._name
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
263
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
264 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
265 def upath(self):
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
266 """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
267 possible.
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
268
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
269 :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
270
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
271 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
272 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
273 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
274 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
275 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
276 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
277 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
278 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
279 return self._path
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
280 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
281 try:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
282 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
283 except UnicodeError:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
284 return None
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
285 return self._path
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
286
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
287 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
288 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
289 """`.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
290
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
291 Also do not allow TAB, CR or LF in the name.
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
292
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
293 """
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
294 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
295 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
296 return None
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
297 if (u'\n' in n) or (u'\r' in n) or (u'\t' 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
298 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
299 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
300
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
301 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
302 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
303 """`.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
304
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
305 Also do not allow TAB, CR or LF in the path.
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
306
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
307 """
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
308 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
309 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
310 return None
371
29a301ff2501 treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents: 369
diff changeset
311 if (u'\n' in p) or (u'\r' in p) or (u'\t' 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
312 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
313 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
314
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
315 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
316 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
317 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
318 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
319 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
320
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
321 @property
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
322 def alt_u8path(self):
203
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
323 return WalkDirEntry.alt_u8(self._path)
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
324
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
325 @staticmethod
3a85f7bbe0b1 Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents: 201
diff changeset
326 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
327 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
328 # 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
329 # ... 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
330 # 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
331 #
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
332 if isinstance(what, bytes):
368
7761a15b9736 treesum: Escape `\' using `\\' instead of `\x5c'.
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
333 s = (what.replace(b'\\', b"\\\\")
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
334 .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
335 .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
336 .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
337 else:
368
7761a15b9736 treesum: Escape `\' using `\\' instead of `\x5c'.
Franz Glasner <fzglas.hg@dom66.de>
parents: 352
diff changeset
338 s = (what.replace(u'\\', u"\\\\")
283
99b78fa04bc1 FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents: 282
diff changeset
339 .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
340 .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
341 .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
342 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
343 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
344 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
345 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
346 .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
347 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
348 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
349 .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
350 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
351 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
352 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
353 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
354
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
355 @property
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
356 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
357 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
358
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
359 @property
273
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
360 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
361 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
362
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
363 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
364 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
365 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
366
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
367 @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
368 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
369 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
370 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
371 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
372
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 @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
374 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
375 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
376 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
377 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
378
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 @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
380 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
381 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
382 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
383 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
384
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 @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
386 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
387 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
388 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
389 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
390
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 @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
392 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
393 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
394 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
395 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
396 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
397
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 @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
399 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
400 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
401 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
402 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
403 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
404
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 @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
406 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
407 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
408 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
409 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
410 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
411
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 @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
413 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
414 """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
415 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
416 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
417 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
418
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
419 @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
420 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
421 """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
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 _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
438 "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
439 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
440 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
441
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
442 @property
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
443 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
444 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
445
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
446 @property
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
447 def stat_errno(self):
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
448 return self._stat_errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
449
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
450 @property
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
451 def stat_errstr(self):
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
452 return self._stat_errstr
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
453
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
454 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
455 tag = ""
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
456 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
457 tag += "l"
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
458 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
459 tag += "d"
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
460 if 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 (%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
462 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
463
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
464 @classmethod
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
465 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
466 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
467 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
468 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
469 except OSError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
470 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
471 # 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
472 # 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
473 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
474 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
475 try:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
476 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
477 except OSError:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
478 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
479 # 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
480 # 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
481 #
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
482 w._is_symlink = False
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
483 # Consistently follow symlinks
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
484 try:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
485 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
486 except OSError as e:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
487 w._stat_result = None
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
488 w._stat_errno = e.errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
489 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
490 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
491 else:
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
492 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
493 return w
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
494
162
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
495 @classmethod
201
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
496 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
497 """`_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
498 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
499 try:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
500 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
501 except OSError:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
502 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
503 # 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
504 # 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
505 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
506 w._is_dir = False
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
507 try:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
508 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
509 except OSError:
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
510 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
511 # 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
512 # 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
513 #
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
514 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
515 if _do_stat:
266
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
516 try:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
517 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
518 except OSError as e:
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
519 w._stat_result = None
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
520 w._stat_errno = e.errno
0add8276e6b8 treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 265
diff changeset
521 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
522 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
523 else:
c02a57df2a29 treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents: 266
diff changeset
524 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
525 return w
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
526
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
527 @classmethod
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
528 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
529 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
530 return w
29dd5528174c Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 156
diff changeset
531
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
532 @staticmethod
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 203
diff changeset
533 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
534 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
535
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
536 @staticmethod
221
ca9d5a0dc9bb Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents: 203
diff changeset
537 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
538 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
539
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
540 if PY2:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
541
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
542 @staticmethod
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
543 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
544 """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
545 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
546
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
547 """
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
548 uwhat = []
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
549 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
550 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
551 chcode = ord(ch)
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
552 if chcode <= 0x7f:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
553 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
554 else:
58d93453c307 Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents: 199
diff changeset
555 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
556 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
557
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
558
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
559 if scandir:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
560
178
dac26a2d9de5 Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents: 177
diff changeset
561 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
562
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
563 """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
564 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
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
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
568 __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
569
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
570 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
571 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
572 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
573
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
574 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
575 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
576
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
577 def __next__(self):
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
578 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
579 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
580 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
581
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
582 if PY2:
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
583 next = __next__
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
584
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
585 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
586 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
587
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
588 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
589 self.close()
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
590
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
591 def close(self):
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
592 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
593 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
594 self._scandir_it.close()
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
595 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
596
121
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
597 else:
2dc26a2f3d1c A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
598
178
dac26a2d9de5 Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents: 177
diff changeset
599 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
600
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
601 """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
602 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
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
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
606 __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
607
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
608 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
609 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
610 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
611 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
612
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
613 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
614 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
615
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
616 def __next__(self):
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
617 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
618 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
619 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
620 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
621
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
622 if PY2:
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
623 next = __next__
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
624
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
625 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
626 return self
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
627
506d895a8500 Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents: 164
diff changeset
628 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
629 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
630
199
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
631 def close(self):
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
632 pass
b2aba84ca426 Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents: 198
diff changeset
633
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
634
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 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
636 """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
637 return _FSENCODING