Mercurial > hgrepos > Python > apps > py-cutils
annotate cutils/util/walk.py @ 389:faa36af3c629 default tip
===== signature for changeset 85da58b83475
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 18 May 2025 06:00:46 +0200 |
| parents | bfe1160fbfd3 |
| children |
| 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 |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
28 from . import PY2, escape_for_output |
|
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 |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
127 __slots__ = ("_name", "_npath", # encoded as given in the ctor |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
128 "_path", # encoded as given but with shashes |
|
273
c02a57df2a29
treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
129 "_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
|
130 "_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
|
131 "_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
|
132 |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
133 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
|
134 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
|
135 """The name exactly as given in the ctor""" |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
136 self._npath = path |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
137 """The path exactly as given in the ctor""" |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
138 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
|
139 """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
|
140 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
|
141 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
|
142 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
|
143 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
144 @property |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
145 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
|
146 """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
|
147 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
|
148 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
149 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
150 def npath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
151 """The original path exactly as given in the ctor""" |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
152 return self._npath |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
153 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
154 @property |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
155 def path(self): |
| 369 | 156 """The original path exactly as given in the ctor -- but normalized to |
| 157 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
|
158 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
|
159 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
160 @property |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
161 def fsname(self): |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
162 """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
|
163 |
|
371
29a301ff2501
treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents:
369
diff
changeset
|
164 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
|
165 |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
166 :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
|
167 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
168 """ |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
169 if PY2: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 except UnicodeError: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
175 return None |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 return s |
|
201
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 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
183 def fsnpath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
184 """Always bytes. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
185 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
186 Also do not allow TAB, CR or LF in the path. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
187 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
188 :rtype: bytes or None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
189 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
190 """ |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
191 if PY2: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
192 if isinstance(self._npath, bytes): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
193 p = self._npath |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
194 try: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
195 p = self._npath.encode(_FSENCODING, "strict") |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
196 except UnicodeError: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
197 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
198 else: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
199 p = os.fsencode(self._npath) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
200 if (b'\n' in p) or (b'\r' in p) or (b'\t' in p) or (b'\\' in p): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
201 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
202 return p |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
203 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
204 @property |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
205 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
|
206 """Always bytes. |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
207 |
|
371
29a301ff2501
treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents:
369
diff
changeset
|
208 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
|
209 |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
210 :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
|
211 |
|
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 if PY2: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 except UnicodeError: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
219 return None |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 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
|
224 return p |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
225 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
226 @property |
|
282
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
227 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
|
228 """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
|
229 |
|
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
230 :rtype: bytes |
|
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
231 |
|
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
232 """ |
|
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 |
|
d507ae4943d5
Reordering of methods: make it a little bit more consistent
Franz Glasner <fzglas.hg@dom66.de>
parents:
281
diff
changeset
|
237 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
238 def alt_fsnpath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
239 """Alternative and "escaped" filesystem path -- always bytes. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
240 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
241 :rtype: bytes |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
242 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
243 """ |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
244 return WalkDirEntry.alt_fs(self._npath) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
245 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
246 @property |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
247 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
|
248 """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
|
249 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
250 :rtype: bytes |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
251 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
252 """ |
|
203
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
253 return WalkDirEntry.alt_fs(self._path) |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
254 |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
255 @staticmethod |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
256 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
|
257 # |
|
99b78fa04bc1
FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents:
282
diff
changeset
|
258 # 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
|
259 # ... 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
|
260 # 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
|
261 # |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
262 s = escape_for_output(what) |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
271 @property |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
272 def uname(self): |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
273 """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
|
274 possible. |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
275 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
276 :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
|
277 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
278 """ |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
279 if PY2: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
280 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
|
281 try: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
282 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
|
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 else: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
286 return self._name |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
287 else: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
288 try: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
289 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
|
290 except UnicodeError: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
291 return None |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
292 return self._name |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
293 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
294 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
295 def unpath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
296 """Always "real", strictly encoded Unicode or `None` if this is not |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
297 possible. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
298 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
299 :rtype: text or None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
300 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
301 """ |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
302 if PY2: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
303 if isinstance(self._npath, bytes): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
304 try: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
305 return self._npath.decode(_FSENCODING, "strict") |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
306 except UnicodeError: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
307 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
308 else: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
309 return self._npath |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
310 else: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
311 try: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
312 self._npath.encode("utf-8", "strict") |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
313 except UnicodeError: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
314 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
315 return self._npath |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
316 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
317 @property |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
318 def upath(self): |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
319 """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
|
320 possible. |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
321 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
322 :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
|
323 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
324 """ |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
325 if PY2: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
326 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
|
327 try: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
328 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
|
329 except UnicodeError: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
330 return None |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
331 else: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
332 return self._path |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
333 else: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
334 try: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
335 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
|
336 except UnicodeError: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
337 return None |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
338 return self._path |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
339 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
340 @property |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
341 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
|
342 """`.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
|
343 |
|
371
29a301ff2501
treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents:
369
diff
changeset
|
344 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
|
345 |
|
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
|
346 """ |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
354 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
355 def u8npath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
356 """`.unpath` as UTF-8 or `None` (as strict as `upath`. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
357 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
358 Also do not allow TAB, CR or LF in the path. |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
359 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
360 """ |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
361 p = self.unpath |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
362 if p is None: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
363 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
364 if (u'\n' in p) or (u'\r' in p) or (u'\t' in p) or (u'\\' in p): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
365 return None |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
366 return p.encode("utf-8", "strict") |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
367 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
368 @property |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
369 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
|
370 """`.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
|
371 |
|
371
29a301ff2501
treesum: FIX: also check for TABs when trying to encode strictly
Franz Glasner <fzglas.hg@dom66.de>
parents:
369
diff
changeset
|
372 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
|
373 |
|
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
|
374 """ |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
382 @property |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
383 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
|
384 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
|
385 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
|
386 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
|
387 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
388 @property |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
389 def alt_u8npath(self): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
390 return WalkDirEntry.alt_u8(self._npath) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
391 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
392 @property |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
393 def alt_u8path(self): |
|
203
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
394 return WalkDirEntry.alt_u8(self._path) |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
395 |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
396 @staticmethod |
|
3a85f7bbe0b1
Common static method for some alternative encodings
Franz Glasner <fzglas.hg@dom66.de>
parents:
201
diff
changeset
|
397 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
|
398 # |
|
99b78fa04bc1
FIX: Unittests in test_walk.py: adjust to the new escaping behaviour
Franz Glasner <fzglas.hg@dom66.de>
parents:
282
diff
changeset
|
399 # 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
|
400 # ... 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
|
401 # 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
|
402 # |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
403 s = escape_for_output(what) |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 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
|
408 .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
|
409 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
|
410 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
|
411 .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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 |
|
372
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
417 @staticmethod |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
418 def alt_bytes(what, use_utf8): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
419 if not what: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
420 return what |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
421 if use_utf8: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
422 return WalkDirEntry.alt_u8(what) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
423 else: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
424 return WalkDirEntry.alt_fs(what) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
425 |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
426 @staticmethod |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
427 def alt_text(what, use_utf8): |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
428 b = WalkDirEntry.alt_bytes(what, use_utf8) |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
429 if PY2: |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
430 return b |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
431 return b.decode("iso-8859-1") |
|
bfe1160fbfd3
treesum: Make ERROR outputs more consistent: use native paths where possible
Franz Glasner <fzglas.hg@dom66.de>
parents:
371
diff
changeset
|
432 |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
433 @property |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
434 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
|
435 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
|
436 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
437 @property |
|
273
c02a57df2a29
treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
438 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
|
439 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
|
440 |
|
c02a57df2a29
treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
441 @property |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
442 def 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
|
443 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
|
444 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
445 @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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 |
|
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
|
451 @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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 |
|
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
|
457 @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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 |
|
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
|
463 @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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 |
|
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
|
469 @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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 |
|
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
|
476 @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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 |
|
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
|
483 @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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 |
|
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
|
490 @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
|
491 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
|
492 """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
|
493 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
|
494 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
|
495 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
|
496 |
|
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
|
497 @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
|
498 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
|
499 """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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 _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
|
516 "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
|
517 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
|
518 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
|
519 |
|
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
|
520 @property |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
521 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
|
522 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
|
523 |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
524 @property |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
525 def stat_errno(self): |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
526 return self._stat_errno |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
527 |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
528 @property |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
529 def stat_errstr(self): |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
530 return self._stat_errstr |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
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 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
|
533 tag = "" |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
534 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
|
535 tag += "l" |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
536 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
|
537 tag += "d" |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
538 if tag: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
539 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
|
540 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
|
541 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
542 @classmethod |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
543 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
|
544 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
|
545 try: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
546 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
|
547 except OSError: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
548 # |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
549 # 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
|
550 # 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
|
551 # |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
552 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
|
553 try: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
554 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
|
555 except OSError: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
556 # |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
557 # 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
|
558 # 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
|
559 # |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
560 w._is_symlink = False |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
561 # Consistently follow symlinks |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
562 try: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
563 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
|
564 except OSError as e: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
565 w._stat_result = None |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
566 w._stat_errno = e.errno |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
567 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
|
568 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
|
569 else: |
|
c02a57df2a29
treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
570 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
|
571 return w |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
572 |
|
162
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
573 @classmethod |
|
201
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
574 def from_path_name(cls_, path, name, _do_stat=True): |
| 265 | 575 """`_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
|
576 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
|
577 try: |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
578 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
|
579 except OSError: |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
580 # |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
581 # 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
|
582 # 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
|
583 # |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
584 w._is_dir = False |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
585 try: |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
586 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
|
587 except OSError: |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
588 # |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
589 # 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
|
590 # 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
|
591 # |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
592 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
|
593 if _do_stat: |
|
266
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
594 try: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
595 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
|
596 except OSError as e: |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
597 w._stat_result = None |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
598 w._stat_errno = e.errno |
|
0add8276e6b8
treesum: Handle errors like broken symlinks properly
Franz Glasner <fzglas.hg@dom66.de>
parents:
265
diff
changeset
|
599 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
|
600 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
|
601 else: |
|
c02a57df2a29
treesum: - WalkDirEntry tests with a FIFO special file - WalkDirEntry.is_reg
Franz Glasner <fzglas.hg@dom66.de>
parents:
266
diff
changeset
|
602 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
|
603 return w |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
604 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
605 @classmethod |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
606 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
|
607 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
|
608 return w |
|
29dd5528174c
Implement walk._walk() using os.listdir() also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
156
diff
changeset
|
609 |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
610 @staticmethod |
|
221
ca9d5a0dc9bb
Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
611 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
|
612 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
|
613 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
614 @staticmethod |
|
221
ca9d5a0dc9bb
Rename WalkDirEntry.sort_key and WalkDirEntry.alt_sort_key
Franz Glasner <fzglas.hg@dom66.de>
parents:
203
diff
changeset
|
615 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
|
616 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
|
617 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
618 if PY2: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
619 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
620 @staticmethod |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
621 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
|
622 """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
|
623 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
|
624 |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
625 """ |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
626 uwhat = [] |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
627 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
|
628 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
|
629 chcode = ord(ch) |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
630 if chcode <= 0x7f: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
631 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
|
632 else: |
|
58d93453c307
Much more encoding-related methods for DirWalkEntry and some unittests
Franz Glasner <fzglas.hg@dom66.de>
parents:
199
diff
changeset
|
633 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
|
634 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
|
635 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
636 |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
637 if scandir: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
638 |
|
178
dac26a2d9de5
Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents:
177
diff
changeset
|
639 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
|
640 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
641 """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
|
642 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
|
643 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
644 """ |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
645 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
646 __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
|
647 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
648 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
|
649 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
|
650 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
|
651 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
652 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
|
653 return self |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
654 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
655 def __next__(self): |
|
199
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
660 if PY2: |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
661 next = __next__ |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
662 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
663 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
|
664 return self |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
665 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
666 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
|
667 self.close() |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
668 |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
669 def close(self): |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
670 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
|
671 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
|
672 self._scandir_it.close() |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
673 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
|
674 |
|
121
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
675 else: |
|
2dc26a2f3d1c
A heavily customized "os.walk()" alike to support the coming treeview implementation
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
676 |
|
178
dac26a2d9de5
Cleanup: remove non used walk-code
Franz Glasner <fzglas.hg@dom66.de>
parents:
177
diff
changeset
|
677 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
|
678 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
679 """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
|
680 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
|
681 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
682 """ |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
683 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
684 __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
|
685 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
686 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
|
687 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
|
688 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
|
689 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
|
690 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
691 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
|
692 return self |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
693 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
694 def __next__(self): |
|
199
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 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
|
699 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
700 if PY2: |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
701 next = __next__ |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
702 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
703 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
|
704 return self |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
705 |
|
506d895a8500
Implement cutils.util.walk.Scandir as a wrapper for os.scandir()
Franz Glasner <fzglas.hg@dom66.de>
parents:
164
diff
changeset
|
706 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
|
707 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
|
708 |
|
199
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
709 def close(self): |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
710 pass |
|
b2aba84ca426
Implement a "close()" method for cutils.util.walk.ScanDir.
Franz Glasner <fzglas.hg@dom66.de>
parents:
198
diff
changeset
|
711 |
|
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
|
712 |
|
c1e875ba4bdc
Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
Franz Glasner <fzglas.hg@dom66.de>
parents:
196
diff
changeset
|
713 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
|
714 """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
|
715 return _FSENCODING |
