megfile 4.0.3__py3-none-any.whl → 4.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,15 +21,15 @@ class S3MemoryHandler(Readable[bytes], Seekable, Writable[bytes]):
21
21
  s3_client,
22
22
  profile_name: Optional[str] = None,
23
23
  ):
24
- if mode not in ("rb", "wb", "ab", "rb+", "wb+", "ab+"):
25
- raise ValueError("unacceptable mode: %r" % mode)
26
-
27
24
  self._bucket = bucket
28
25
  self._key = key
29
26
  self._mode = mode
30
27
  self._client = s3_client
31
28
  self._profile_name = profile_name
32
29
 
30
+ if mode not in ("rb", "wb", "ab", "rb+", "wb+", "ab+"):
31
+ raise ValueError("unacceptable mode: %r" % mode)
32
+
33
33
  self._fileobj = BytesIO()
34
34
  self._download_fileobj()
35
35
 
@@ -34,9 +34,6 @@ class S3PipeHandler(Readable[bytes], Writable[bytes]):
34
34
  join_thread: bool = True,
35
35
  profile_name: Optional[str] = None,
36
36
  ):
37
- if mode not in ("rb", "wb"):
38
- raise ValueError("unacceptable mode: %r" % mode)
39
-
40
37
  self._bucket = bucket
41
38
  self._key = key
42
39
  self._mode = mode
@@ -45,6 +42,9 @@ class S3PipeHandler(Readable[bytes], Writable[bytes]):
45
42
  self._offset = 0
46
43
  self._profile_name = profile_name
47
44
 
45
+ if mode not in ("rb", "wb"):
46
+ raise ValueError("unacceptable mode: %r" % mode)
47
+
48
48
  self._exc = None
49
49
  self._pipe = os.pipe()
50
50
  _s3_opened_pipes.append(self._pipe)
@@ -76,7 +76,7 @@ class S3PipeHandler(Readable[bytes], Writable[bytes]):
76
76
  try:
77
77
  with os.fdopen(self._pipe[1], "wb") as buffer:
78
78
  self._client.download_fileobj(self._bucket, self._key, buffer)
79
- except BrokenPipeError:
79
+ except BrokenPipeError: # pragma: no cover
80
80
  if self._fileobj.closed:
81
81
  return
82
82
  raise
megfile/pathlike.py CHANGED
@@ -412,7 +412,7 @@ class BasePath:
412
412
  raw_suffix = self.suffix
413
413
  return self.from_path(path[: len(path) - len(raw_suffix)] + suffix)
414
414
 
415
- def relpath(self, start=None):
415
+ def relpath(self, start: Optional[str] = None):
416
416
  """Return the relative path."""
417
417
  if start is None:
418
418
  raise TypeError("start is required")
@@ -485,7 +485,7 @@ class BasePath:
485
485
  """Return the canonical path of the path."""
486
486
  return self.path_with_protocol
487
487
 
488
- def resolve(self):
488
+ def resolve(self, strict=False):
489
489
  """Alias of realpath."""
490
490
  return self.path_with_protocol
491
491
 
@@ -615,18 +615,18 @@ class BasePath:
615
615
  """Return the names of the entries in the directory the path points to."""
616
616
  raise NotImplementedError('method "listdir" not implemented: %r' % self)
617
617
 
618
- def scandir(self) -> Iterator[FileEntry]:
618
+ def scandir(self):
619
619
  """
620
620
  Return an iterator of FileEntry objects corresponding to the entries
621
621
  in the directory.
622
622
  """
623
623
  raise NotImplementedError('method "scandir" not implemented: %r' % self)
624
624
 
625
- def getsize(self, follow_symlinks: bool = True) -> int:
625
+ def getsize(self, follow_symlinks: bool = False) -> int:
626
626
  """Return the size, in bytes."""
627
627
  raise NotImplementedError('method "getsize" not implemented: %r' % self)
628
628
 
629
- def getmtime(self, follow_symlinks: bool = True) -> float:
629
+ def getmtime(self, follow_symlinks: bool = False) -> float:
630
630
  """Return the time of last modification."""
631
631
  raise NotImplementedError('method "getmtime" not implemented: %r' % self)
632
632
 
megfile/s3.py CHANGED
@@ -73,9 +73,7 @@ __all__ = [
73
73
  ]
74
74
 
75
75
 
76
- def s3_access(
77
- path: PathLike, mode: Access = Access.READ, followlinks: bool = False
78
- ) -> bool:
76
+ def s3_access(path: PathLike, mode: Access = Access.READ) -> bool:
79
77
  """
80
78
  Test if path has access permission described by mode
81
79
 
@@ -83,7 +81,7 @@ def s3_access(
83
81
  :param mode: access mode
84
82
  :returns: bool, if the bucket of s3_url has read/write access.
85
83
  """
86
- return S3Path(path).access(mode, followlinks)
84
+ return S3Path(path).access(mode)
87
85
 
88
86
 
89
87
  def s3_exists(path: PathLike, followlinks: bool = False) -> bool:
@@ -161,7 +159,7 @@ def s3_isfile(path: PathLike, followlinks: bool = False) -> bool:
161
159
  return S3Path(path).is_file(followlinks)
162
160
 
163
161
 
164
- def s3_listdir(path: PathLike, followlinks: bool = False) -> List[str]:
162
+ def s3_listdir(path: PathLike) -> List[str]:
165
163
  """
166
164
  Get all contents of given s3_url. The result is in ascending alphabetical order.
167
165
 
@@ -169,10 +167,10 @@ def s3_listdir(path: PathLike, followlinks: bool = False) -> List[str]:
169
167
  :returns: All contents have prefix of s3_url in ascending alphabetical order
170
168
  :raises: S3FileNotFoundError, S3NotADirectoryError
171
169
  """
172
- return S3Path(path).listdir(followlinks)
170
+ return S3Path(path).listdir()
173
171
 
174
172
 
175
- def s3_load_from(path: PathLike, followlinks: bool = False) -> BinaryIO:
173
+ def s3_load_from(path: PathLike) -> BinaryIO:
176
174
  """Read all content in binary on specified path and write into memory
177
175
 
178
176
  User should close the BinaryIO manually
@@ -180,7 +178,7 @@ def s3_load_from(path: PathLike, followlinks: bool = False) -> BinaryIO:
180
178
  :param path: Given path
181
179
  :returns: BinaryIO
182
180
  """
183
- return S3Path(path).load(followlinks)
181
+ return S3Path(path).load()
184
182
 
185
183
 
186
184
  def s3_hasbucket(path: PathLike) -> bool:
@@ -260,15 +258,15 @@ def s3_scan_stat(
260
258
  return S3Path(path).scan_stat(missing_ok, followlinks)
261
259
 
262
260
 
263
- def s3_scandir(path: PathLike, followlinks: bool = False) -> Iterator[FileEntry]:
261
+ def s3_scandir(path: PathLike) -> Iterator[FileEntry]:
264
262
  """
265
- Get all contents of given s3_url, the order of result is not guaranteed.
263
+ Get all contents of given s3_url, the order of result is in arbitrary order.
266
264
 
267
265
  :param path: Given path
268
266
  :returns: All contents have prefix of s3_url
269
267
  :raises: S3FileNotFoundError, S3NotADirectoryError
270
268
  """
271
- return S3Path(path).scandir(followlinks)
269
+ return S3Path(path).scandir()
272
270
 
273
271
 
274
272
  def s3_stat(path: PathLike, follow_symlinks=True) -> StatResult:
@@ -453,7 +451,6 @@ def s3_glob(
453
451
  path: PathLike,
454
452
  recursive: bool = True,
455
453
  missing_ok: bool = True,
456
- followlinks: bool = False,
457
454
  ) -> List[str]:
458
455
  """Return s3 path list in ascending alphabetical order,
459
456
  in which path matches glob pattern
@@ -472,7 +469,6 @@ def s3_glob(
472
469
  path=path,
473
470
  recursive=recursive,
474
471
  missing_ok=missing_ok,
475
- followlinks=followlinks,
476
472
  )
477
473
  )
478
474
 
@@ -481,7 +477,6 @@ def s3_glob_stat(
481
477
  path: PathLike,
482
478
  recursive: bool = True,
483
479
  missing_ok: bool = True,
484
- followlinks: bool = False,
485
480
  ) -> Iterator[FileEntry]:
486
481
  """Return a generator contains tuples of path and file stat,
487
482
  in ascending alphabetical order, in which path matches glob pattern
@@ -497,7 +492,7 @@ def s3_glob_stat(
497
492
  in which paths match `s3_pathname`
498
493
  """
499
494
  return S3Path(path).glob_stat(
500
- pattern="", recursive=recursive, missing_ok=missing_ok, followlinks=followlinks
495
+ pattern="", recursive=recursive, missing_ok=missing_ok
501
496
  )
502
497
 
503
498
 
@@ -505,7 +500,6 @@ def s3_iglob(
505
500
  path: PathLike,
506
501
  recursive: bool = True,
507
502
  missing_ok: bool = True,
508
- followlinks: bool = False,
509
503
  ) -> Iterator[str]:
510
504
  """Return s3 path iterator in ascending alphabetical order,
511
505
  in which path matches glob pattern
@@ -520,7 +514,7 @@ def s3_iglob(
520
514
  :returns: An iterator contains paths match `s3_pathname`
521
515
  """
522
516
  for path_obj in S3Path(path).iglob(
523
- pattern="", recursive=recursive, missing_ok=missing_ok, followlinks=followlinks
517
+ pattern="", recursive=recursive, missing_ok=missing_ok
524
518
  ):
525
519
  yield path_obj.path_with_protocol
526
520