Debian Codegraph @

Lib/test/test_zipfile/_path/test_path.py

raw
1 import contextlib
2 import io
3 import itertools
4 import pathlib
5 import pickle
6 import stat
7 import sys
8 import time
9 import unittest
10 import zipfile
11 import zipfile._path
12
13 from test.support.os_helper import FakePath, temp_dir
14
15 from ._functools import compose
16 from ._itertools import Counter
17 from ._test_params import Invoked, parameterize
18
19
20 class jaraco:
21 class itertools:
22 Counter = Counter
23
24
25 def _make_link(info: zipfile.ZipInfo): # type: ignore[name-defined]
26 info.external_attr |= stat.S_IFLNK << 16
27
28
29 def build_alpharep_fixture():
30 """
31 Create a zip file with this structure:
32
33 .
34 ├── a.txt
35 ├── n.txt (-> a.txt)
36 ├── b
37 │ ├── c.txt
38 │ ├── d
39 │ │ └── e.txt
40 │ └── f.txt
41 ├── g
42 │ └── h
43 │ └── i.txt
44 └── j
45 ├── k.bin
46 ├── l.baz
47 └── m.bar
48
49 This fixture has the following key characteristics:
50
51 - a file at the root (a)
52 - a file two levels deep (b/d/e)
53 - multiple files in a directory (b/c, b/f)
54 - a directory containing only a directory (g/h)
55 - a directory with files of different extensions (j/klm)
56 - a symlink (n) pointing to (a)
57
58 "alpha" because it uses alphabet
59 "rep" because it's a representative example
60 """
61 data = io.BytesIO()
62 zf = zipfile.ZipFile(data, "w")
63 zf.writestr("a.txt", b"content of a")
64 zf.writestr("b/c.txt", b"content of c")
65 zf.writestr("b/d/e.txt", b"content of e")
66 zf.writestr("b/f.txt", b"content of f")
67 zf.writestr("g/h/i.txt", b"content of i")
68 zf.writestr("j/k.bin", b"content of k")
69 zf.writestr("j/l.baz", b"content of l")
70 zf.writestr("j/m.bar", b"content of m")
71 zf.writestr("n.txt", b"a.txt")
72 _make_link(zf.infolist()[-1])
73
74 zf.filename = "alpharep.zip"
75 return zf
76
77
78 alpharep_generators = [
79 Invoked.wrap(build_alpharep_fixture),
80 Invoked.wrap(compose(zipfile._path.CompleteDirs.inject, build_alpharep_fixture)),
81 ]
82
83 pass_alpharep = parameterize(['alpharep'], alpharep_generators)
84
85
86 class TestPath(unittest.TestCase):
87 def setUp(self):
88 self.fixtures = contextlib.ExitStack()
89 self.addCleanup(self.fixtures.close)
90
91 def zipfile_ondisk(self, alpharep):
92 tmpdir = pathlib.Path(self.fixtures.enter_context(temp_dir()))
93 buffer = alpharep.fp
94 alpharep.close()
95 path = tmpdir / alpharep.filename
96 with path.open("wb") as strm:
97 strm.write(buffer.getvalue())
98 return path
99
100 @pass_alpharep
101 def test_iterdir_and_types(self, alpharep):
102 root = zipfile.Path(alpharep)
103 assert root.is_dir()
104 a, n, b, g, j = root.iterdir()
105 assert a.is_file()
106 assert b.is_dir()
107 assert g.is_dir()
108 c, f, d = b.iterdir()
109 assert c.is_file() and f.is_file()
110 (e,) = d.iterdir()
111 assert e.is_file()
112 (h,) = g.iterdir()
113 (i,) = h.iterdir()
114 assert i.is_file()
115
116 @pass_alpharep
117 def test_is_file_missing(self, alpharep):
118 root = zipfile.Path(alpharep)
119 assert not root.joinpath('missing.txt').is_file()
120
121 @pass_alpharep
122 def test_iterdir_on_file(self, alpharep):
123 root = zipfile.Path(alpharep)
124 a, n, b, g, j = root.iterdir()
125 with self.assertRaises(ValueError):
126 a.iterdir()
127
128 @pass_alpharep
129 def test_subdir_is_dir(self, alpharep):
130 root = zipfile.Path(alpharep)
131 assert (root / 'b').is_dir()
132 assert (root / 'b/').is_dir()
133 assert (root / 'g').is_dir()
134 assert (root / 'g/').is_dir()
135
136 @pass_alpharep
137 def test_open(self, alpharep):
138 root = zipfile.Path(alpharep)
139 a, n, b, g, j = root.iterdir()
140 with a.open(encoding="utf-8") as strm:
141 data = strm.read()
142 self.assertEqual(data, "content of a")
143 with a.open('r', "utf-8") as strm: # not a kw, no gh-101144 TypeError
144 data = strm.read()
145 self.assertEqual(data, "content of a")
146
147 def test_open_encoding_utf16(self):
148 in_memory_file = io.BytesIO()
149 zf = zipfile.ZipFile(in_memory_file, "w")
150 zf.writestr("path/16.txt", "This was utf-16".encode("utf-16"))
151 zf.filename = "test_open_utf16.zip"
152 root = zipfile.Path(zf)
153 (path,) = root.iterdir()
154 u16 = path.joinpath("16.txt")
155 with u16.open('r', "utf-16") as strm:
156 data = strm.read()
157 assert data == "This was utf-16"
158 with u16.open(encoding="utf-16") as strm:
159 data = strm.read()
160 assert data == "This was utf-16"
161
162 def test_open_encoding_errors(self):
163 in_memory_file = io.BytesIO()
164 zf = zipfile.ZipFile(in_memory_file, "w")
165 zf.writestr("path/bad-utf8.bin", b"invalid utf-8: \xff\xff.")
166 zf.filename = "test_read_text_encoding_errors.zip"
167 root = zipfile.Path(zf)
168 (path,) = root.iterdir()
169 u16 = path.joinpath("bad-utf8.bin")
170
171 # encoding= as a positional argument for gh-101144.
172 data = u16.read_text("utf-8", errors="ignore")
173 assert data == "invalid utf-8: ."
174 with u16.open("r", "utf-8", errors="surrogateescape") as f:
175 assert f.read() == "invalid utf-8: \udcff\udcff."
176
177 # encoding= both positional and keyword is an error; gh-101144.
178 with self.assertRaisesRegex(TypeError, "encoding"):
179 data = u16.read_text("utf-8", encoding="utf-8")
180
181 # both keyword arguments work.
182 with u16.open("r", encoding="utf-8", errors="strict") as f:
183 # error during decoding with wrong codec.
184 with self.assertRaises(UnicodeDecodeError):
185 f.read()
186
187 @unittest.skipIf(
188 not getattr(sys.flags, 'warn_default_encoding', 0),
189 "Requires warn_default_encoding",
190 )
191 @pass_alpharep
192 def test_encoding_warnings(self, alpharep):
193 """EncodingWarning must blame the read_text and open calls."""
194 assert sys.flags.warn_default_encoding
195 root = zipfile.Path(alpharep)
196 with self.assertWarns(EncodingWarning) as wc: # noqa: F821 (astral-sh/ruff#13296)
197 root.joinpath("a.txt").read_text()
198 assert __file__ == wc.filename
199 with self.assertWarns(EncodingWarning) as wc: # noqa: F821 (astral-sh/ruff#13296)
200 root.joinpath("a.txt").open("r").close()
201 assert __file__ == wc.filename
202
203 def test_open_write(self):
204 """
205 If the zipfile is open for write, it should be possible to
206 write bytes or text to it.
207 """
208 zf = zipfile.Path(zipfile.ZipFile(io.BytesIO(), mode='w'))
209 with zf.joinpath('file.bin').open('wb') as strm:
210 strm.write(b'binary contents')
211 with zf.joinpath('file.txt').open('w', encoding="utf-8") as strm:
212 strm.write('text file')
213
214 @pass_alpharep
215 def test_open_extant_directory(self, alpharep):
216 """
217 Attempting to open a directory raises IsADirectoryError.
218 """
219 zf = zipfile.Path(alpharep)
220 with self.assertRaises(IsADirectoryError):
221 zf.joinpath('b').open()
222
223 @pass_alpharep
224 def test_open_binary_invalid_args(self, alpharep):
225 root = zipfile.Path(alpharep)
226 with self.assertRaises(ValueError):
227 root.joinpath('a.txt').open('rb', encoding='utf-8')
228 with self.assertRaises(ValueError):
229 root.joinpath('a.txt').open('rb', 'utf-8')
230
231 @pass_alpharep
232 def test_open_missing_directory(self, alpharep):
233 """
234 Attempting to open a missing directory raises FileNotFoundError.
235 """
236 zf = zipfile.Path(alpharep)
237 with self.assertRaises(FileNotFoundError):
238 zf.joinpath('z').open()
239
240 @pass_alpharep
241 def test_read(self, alpharep):
242 root = zipfile.Path(alpharep)
243 a, n, b, g, j = root.iterdir()
244 assert a.read_text(encoding="utf-8") == "content of a"
245 # Also check positional encoding arg (gh-101144).
246 assert a.read_text("utf-8") == "content of a"
247 assert a.read_bytes() == b"content of a"
248
249 @pass_alpharep
250 def test_joinpath(self, alpharep):
251 root = zipfile.Path(alpharep)
252 a = root.joinpath("a.txt")
253 assert a.is_file()
254 e = root.joinpath("b").joinpath("d").joinpath("e.txt")
255 assert e.read_text(encoding="utf-8") == "content of e"
256
257 @pass_alpharep
258 def test_joinpath_multiple(self, alpharep):
259 root = zipfile.Path(alpharep)
260 e = root.joinpath("b", "d", "e.txt")
261 assert e.read_text(encoding="utf-8") == "content of e"
262
263 @pass_alpharep
264 def test_traverse_truediv(self, alpharep):
265 root = zipfile.Path(alpharep)
266 a = root / "a.txt"
267 assert a.is_file()
268 e = root / "b" / "d" / "e.txt"
269 assert e.read_text(encoding="utf-8") == "content of e"
270
271 @pass_alpharep
272 def test_pathlike_construction(self, alpharep):
273 """
274 zipfile.Path should be constructable from a path-like object
275 """
276 zipfile_ondisk = self.zipfile_ondisk(alpharep)
277 pathlike = FakePath(str(zipfile_ondisk))
278 root = zipfile.Path(pathlike)
279 root.root.close()
280
281 @pass_alpharep
282 def test_traverse_pathlike(self, alpharep):
283 root = zipfile.Path(alpharep)
284 root / FakePath("a")
285
286 @pass_alpharep
287 def test_parent(self, alpharep):
288 root = zipfile.Path(alpharep)
289 assert (root / 'a').parent.at == ''
290 assert (root / 'a' / 'b').parent.at == 'a/'
291
292 @pass_alpharep
293 def test_dir_parent(self, alpharep):
294 root = zipfile.Path(alpharep)
295 assert (root / 'b').parent.at == ''
296 assert (root / 'b/').parent.at == ''
297
298 @pass_alpharep
299 def test_missing_dir_parent(self, alpharep):
300 root = zipfile.Path(alpharep)
301 assert (root / 'missing dir/').parent.at == ''
302
303 @pass_alpharep
304 def test_mutability(self, alpharep):
305 """
306 If the underlying zipfile is changed, the Path object should
307 reflect that change.
308 """
309 root = zipfile.Path(alpharep)
310 a, n, b, g, j = root.iterdir()
311 alpharep.writestr('foo.txt', 'foo')
312 alpharep.writestr('bar/baz.txt', 'baz')
313 assert any(child.name == 'foo.txt' for child in root.iterdir())
314 assert (root / 'foo.txt').read_text(encoding="utf-8") == 'foo'
315 (baz,) = (root / 'bar').iterdir()
316 assert baz.read_text(encoding="utf-8") == 'baz'
317
318 HUGE_ZIPFILE_NUM_ENTRIES = 2**13
319
320 def huge_zipfile(self):
321 """Create a read-only zipfile with a huge number of entries entries."""
322 strm = io.BytesIO()
323 zf = zipfile.ZipFile(strm, "w")
324 for entry in map(str, range(self.HUGE_ZIPFILE_NUM_ENTRIES)):
325 zf.writestr(entry, entry)
326 zf.mode = 'r'
327 return zf
328
329 def test_joinpath_constant_time(self):
330 """
331 Ensure joinpath on items in zipfile is linear time.
332 """
333 root = zipfile.Path(self.huge_zipfile())
334 entries = jaraco.itertools.Counter(root.iterdir())
335 for entry in entries:
336 entry.joinpath('suffix')
337 # Check the file iterated all items
338 assert entries.count == self.HUGE_ZIPFILE_NUM_ENTRIES
339
340 @pass_alpharep
341 def test_read_does_not_close(self, alpharep):
342 alpharep = self.zipfile_ondisk(alpharep)
343 with zipfile.ZipFile(alpharep) as file:
344 for rep in range(2):
345 zipfile.Path(file, 'a.txt').read_text(encoding="utf-8")
346
347 @pass_alpharep
348 def test_subclass(self, alpharep):
349 class Subclass(zipfile.Path):
350 pass
351
352 root = Subclass(alpharep)
353 assert isinstance(root / 'b', Subclass)
354
355 @pass_alpharep
356 def test_filename(self, alpharep):
357 root = zipfile.Path(alpharep)
358 assert root.filename == pathlib.Path('alpharep.zip')
359
360 @pass_alpharep
361 def test_root_name(self, alpharep):
362 """
363 The name of the root should be the name of the zipfile
364 """
365 root = zipfile.Path(alpharep)
366 assert root.name == 'alpharep.zip' == root.filename.name
367
368 @pass_alpharep
369 def test_root_on_disk(self, alpharep):
370 """
371 The name/stem of the root should match the zipfile on disk.
372
373 This condition must hold across platforms.
374 """
375 root = zipfile.Path(self.zipfile_ondisk(alpharep))
376 assert root.name == 'alpharep.zip' == root.filename.name
377 assert root.stem == 'alpharep' == root.filename.stem
378 root.root.close()
379
380 @pass_alpharep
381 def test_suffix(self, alpharep):
382 """
383 The suffix of the root should be the suffix of the zipfile.
384 The suffix of each nested file is the final component's last suffix, if any.
385 Includes the leading period, just like pathlib.Path.
386 """
387 root = zipfile.Path(alpharep)
388 assert root.suffix == '.zip' == root.filename.suffix
389
390 b = root / "b.txt"
391 assert b.suffix == ".txt"
392
393 c = root / "c" / "filename.tar.gz"
394 assert c.suffix == ".gz"
395
396 d = root / "d"
397 assert d.suffix == ""
398
399 @pass_alpharep
400 def test_suffixes(self, alpharep):
401 """
402 The suffix of the root should be the suffix of the zipfile.
403 The suffix of each nested file is the final component's last suffix, if any.
404 Includes the leading period, just like pathlib.Path.
405 """
406 root = zipfile.Path(alpharep)
407 assert root.suffixes == ['.zip'] == root.filename.suffixes
408
409 b = root / 'b.txt'
410 assert b.suffixes == ['.txt']
411
412 c = root / 'c' / 'filename.tar.gz'
413 assert c.suffixes == ['.tar', '.gz']
414
415 d = root / 'd'
416 assert d.suffixes == []
417
418 e = root / '.hgrc'
419 assert e.suffixes == []
420
421 @pass_alpharep
422 def test_suffix_no_filename(self, alpharep):
423 alpharep.filename = None
424 root = zipfile.Path(alpharep)
425 assert root.joinpath('example').suffix == ""
426 assert root.joinpath('example').suffixes == []
427
428 @pass_alpharep
429 def test_stem(self, alpharep):
430 """
431 The final path component, without its suffix
432 """
433 root = zipfile.Path(alpharep)
434 assert root.stem == 'alpharep' == root.filename.stem
435
436 b = root / "b.txt"
437 assert b.stem == "b"
438
439 c = root / "c" / "filename.tar.gz"
440 assert c.stem == "filename.tar"
441
442 d = root / "d"
443 assert d.stem == "d"
444
445 assert (root / ".gitignore").stem == ".gitignore"
446
447 @pass_alpharep
448 def test_root_parent(self, alpharep):
449 root = zipfile.Path(alpharep)
450 assert root.parent == pathlib.Path('.')
451 root.root.filename = 'foo/bar.zip'
452 assert root.parent == pathlib.Path('foo')
453
454 @pass_alpharep
455 def test_root_unnamed(self, alpharep):
456 """
457 It is an error to attempt to get the name
458 or parent of an unnamed zipfile.
459 """
460 alpharep.filename = None
461 root = zipfile.Path(alpharep)
462 with self.assertRaises(TypeError):
463 root.name
464 with self.assertRaises(TypeError):
465 root.parent
466
467 # .name and .parent should still work on subs
468 sub = root / "b"
469 assert sub.name == "b"
470 assert sub.parent
471
472 @pass_alpharep
473 def test_match_and_glob(self, alpharep):
474 root = zipfile.Path(alpharep)
475 assert not root.match("*.txt")
476
477 assert list(root.glob("b/c.*")) == [zipfile.Path(alpharep, "b/c.txt")]
478 assert list(root.glob("b/*.txt")) == [
479 zipfile.Path(alpharep, "b/c.txt"),
480 zipfile.Path(alpharep, "b/f.txt"),
481 ]
482
483 @pass_alpharep
484 def test_glob_recursive(self, alpharep):
485 root = zipfile.Path(alpharep)
486 files = root.glob("**/*.txt")
487 assert all(each.match("*.txt") for each in files)
488
489 assert list(root.glob("**/*.txt")) == list(root.rglob("*.txt"))
490
491 @pass_alpharep
492 def test_glob_dirs(self, alpharep):
493 root = zipfile.Path(alpharep)
494 assert list(root.glob('b')) == [zipfile.Path(alpharep, "b/")]
495 assert list(root.glob('b*')) == [zipfile.Path(alpharep, "b/")]
496
497 @pass_alpharep
498 def test_glob_subdir(self, alpharep):
499 root = zipfile.Path(alpharep)
500 assert list(root.glob('g/h')) == [zipfile.Path(alpharep, "g/h/")]
501 assert list(root.glob('g*/h*')) == [zipfile.Path(alpharep, "g/h/")]
502
503 @pass_alpharep
504 def test_glob_subdirs(self, alpharep):
505 root = zipfile.Path(alpharep)
506
507 assert list(root.glob("*/i.txt")) == []
508 assert list(root.rglob("*/i.txt")) == [zipfile.Path(alpharep, "g/h/i.txt")]
509
510 @pass_alpharep
511 def test_glob_does_not_overmatch_dot(self, alpharep):
512 root = zipfile.Path(alpharep)
513
514 assert list(root.glob("*.xt")) == []
515
516 @pass_alpharep
517 def test_glob_single_char(self, alpharep):
518 root = zipfile.Path(alpharep)
519
520 assert list(root.glob("a?txt")) == [zipfile.Path(alpharep, "a.txt")]
521 assert list(root.glob("a[.]txt")) == [zipfile.Path(alpharep, "a.txt")]
522 assert list(root.glob("a[?]txt")) == []
523
524 @pass_alpharep
525 def test_glob_chars(self, alpharep):
526 root = zipfile.Path(alpharep)
527
528 assert list(root.glob("j/?.b[ai][nz]")) == [
529 zipfile.Path(alpharep, "j/k.bin"),
530 zipfile.Path(alpharep, "j/l.baz"),
531 ]
532
533 def test_glob_empty(self):
534 root = zipfile.Path(zipfile.ZipFile(io.BytesIO(), 'w'))
535 with self.assertRaises(ValueError):
536 root.glob('')
537
538 @pass_alpharep
539 def test_eq_hash(self, alpharep):
540 root = zipfile.Path(alpharep)
541 assert root == zipfile.Path(alpharep)
542
543 assert root != (root / "a.txt")
544 assert (root / "a.txt") == (root / "a.txt")
545
546 root = zipfile.Path(alpharep)
547 assert root in {root}
548
549 @pass_alpharep
550 def test_is_symlink(self, alpharep):
551 root = zipfile.Path(alpharep)
552 assert not root.joinpath('a.txt').is_symlink()
553 assert root.joinpath('n.txt').is_symlink()
554
555 @pass_alpharep
556 def test_relative_to(self, alpharep):
557 root = zipfile.Path(alpharep)
558 relative = root.joinpath("b", "c.txt").relative_to(root / "b")
559 assert str(relative) == "c.txt"
560
561 relative = root.joinpath("b", "d", "e.txt").relative_to(root / "b")
562 assert str(relative) == "d/e.txt"
563
564 @pass_alpharep
565 def test_inheritance(self, alpharep):
566 cls = type('PathChild', (zipfile.Path,), {})
567 file = cls(alpharep).joinpath('some dir').parent
568 assert isinstance(file, cls)
569
570 @parameterize(
571 ['alpharep', 'path_type', 'subpath'],
572 itertools.product(
573 alpharep_generators,
574 [str, FakePath],
575 ['', 'b/'],
576 ),
577 )
578 def test_pickle(self, alpharep, path_type, subpath):
579 zipfile_ondisk = path_type(str(self.zipfile_ondisk(alpharep)))
580 root = zipfile.Path(zipfile_ondisk, at=subpath)
581 saved_1 = pickle.dumps(root)
582 root.root.close()
583 restored_1 = pickle.loads(saved_1)
584 first, *rest = restored_1.iterdir()
585 assert first.read_text(encoding='utf-8').startswith('content of ')
586 restored_1.root.close()
587
588 @pass_alpharep
589 def test_extract_orig_with_implied_dirs(self, alpharep):
590 """
591 A zip file wrapped in a Path should extract even with implied dirs.
592 """
593 source_path = self.zipfile_ondisk(alpharep)
594 zf = zipfile.ZipFile(source_path)
595 # wrap the zipfile for its side effect
596 zipfile.Path(zf)
597 zf.extractall(source_path.parent)
598 zf.close()
599
600 @pass_alpharep
601 def test_getinfo_missing(self, alpharep):
602 """
603 Validate behavior of getinfo on original zipfile after wrapping.
604 """
605 zipfile.Path(alpharep)
606 with self.assertRaises(KeyError):
607 alpharep.getinfo('does-not-exist')
608
609 def test_malformed_paths(self):
610 """
611 Path should handle malformed paths gracefully.
612
613 Paths with leading slashes are not visible.
614
615 Paths with dots are treated like regular files.
616 """
617 data = io.BytesIO()
618 zf = zipfile.ZipFile(data, "w")
619 zf.writestr("/one-slash.txt", b"content")
620 zf.writestr("//two-slash.txt", b"content")
621 zf.writestr("../parent.txt", b"content")
622 zf.filename = ''
623 root = zipfile.Path(zf)
624 assert list(map(str, root.iterdir())) == ['../']
625 assert root.joinpath('..').joinpath('parent.txt').read_bytes() == b'content'
626
627 def test_unsupported_names(self):
628 """
629 Path segments with special characters are readable.
630
631 On some platforms or file systems, characters like
632 ``:`` and ``?`` are not allowed, but they are valid
633 in the zip file.
634 """
635 data = io.BytesIO()
636 zf = zipfile.ZipFile(data, "w")
637 zf.writestr("path?", b"content")
638 zf.writestr("V: NMS.flac", b"fLaC...")
639 zf.filename = ''
640 root = zipfile.Path(zf)
641 contents = root.iterdir()
642 assert next(contents).name == 'path?'
643 assert next(contents).name == 'V: NMS.flac'
644 assert root.joinpath('V: NMS.flac').read_bytes() == b"fLaC..."
645
646 def test_backslash_not_separator(self):
647 """
648 In a zip file, backslashes are not separators.
649 """
650 data = io.BytesIO()
651 zf = zipfile.ZipFile(data, "w")
652 zf.writestr(DirtyZipInfo.for_name("foo\\bar", zf), b"content")
653 zf.filename = ''
654 root = zipfile.Path(zf)
655 (first,) = root.iterdir()
656 assert not first.is_dir()
657 assert first.name == 'foo\\bar'
658
659 @pass_alpharep
660 def test_interface(self, alpharep):
661 from importlib.resources.abc import Traversable
662
663 zf = zipfile.Path(alpharep)
664 assert isinstance(zf, Traversable)
665
666
667 class DirtyZipInfo(zipfile.ZipInfo):
668 """
669 Bypass name sanitization.
670 """
671
672 def __init__(self, filename, *args, **kwargs):
673 super().__init__(filename, *args, **kwargs)
674 self.filename = filename
675
676 @classmethod
677 def for_name(cls, name, archive):
678 """
679 Construct the same way that ZipFile.writestr does.
680
681 TODO: extract this functionality and re-use
682 """
683 self = cls(filename=name, date_time=time.localtime(time.time())[:6])
684 self.compress_type = archive.compression
685 self.compress_level = archive.compresslevel
686 if self.filename.endswith('/'): # pragma: no cover
687 self.external_attr = 0o40775 << 16 # drwxrwxr-x
688 self.external_attr |= 0x10 # MS-DOS directory flag
689 else:
690 self.external_attr = 0o600 << 16 # ?rw-------
691 return self