megfile 3.1.6__py3-none-any.whl → 3.1.6.post1__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.
- megfile/config.py +2 -0
- megfile/lib/s3_prefetch_reader.py +5 -1
- megfile/s3_path.py +24 -15
- megfile/utils/__init__.py +8 -0
- megfile/version.py +1 -1
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/METADATA +1 -1
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/RECORD +12 -12
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/LICENSE +0 -0
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/LICENSE.pyre +0 -0
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/WHEEL +0 -0
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/entry_points.txt +0 -0
- {megfile-3.1.6.dist-info → megfile-3.1.6.post1.dist-info}/top_level.txt +0 -0
megfile/config.py
CHANGED
|
@@ -76,7 +76,11 @@ class S3PrefetchReader(BasePrefetchReader):
|
|
|
76
76
|
try:
|
|
77
77
|
start, end = 0, self._block_size - 1
|
|
78
78
|
first_index_response = self._fetch_response(start=start, end=end)
|
|
79
|
-
|
|
79
|
+
if "ContentRange" in first_index_response:
|
|
80
|
+
content_size = int(first_index_response["ContentRange"].split("/")[-1])
|
|
81
|
+
else:
|
|
82
|
+
# usually when read a file only have one block
|
|
83
|
+
content_size = int(first_index_response["ContentLength"])
|
|
80
84
|
except S3InvalidRangeError:
|
|
81
85
|
# usually when read a empty file
|
|
82
86
|
# can use minio test empty file: https://hub.docker.com/r/minio/minio
|
megfile/s3_path.py
CHANGED
|
@@ -7,16 +7,18 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
7
7
|
from functools import cached_property, lru_cache, wraps
|
|
8
8
|
from logging import getLogger as get_logger
|
|
9
9
|
from typing import IO, Any, BinaryIO, Callable, Dict, Iterator, List, Optional, Tuple
|
|
10
|
+
from urllib.parse import urlparse
|
|
10
11
|
|
|
11
12
|
import boto3
|
|
12
13
|
import botocore
|
|
13
|
-
from botocore.awsrequest import AWSResponse
|
|
14
|
+
from botocore.awsrequest import AWSPreparedRequest, AWSResponse
|
|
14
15
|
|
|
15
16
|
from megfile.config import (
|
|
16
17
|
DEFAULT_BLOCK_SIZE,
|
|
17
18
|
DEFAULT_MAX_BLOCK_SIZE,
|
|
18
19
|
DEFAULT_MIN_BLOCK_SIZE,
|
|
19
20
|
GLOBAL_MAX_WORKERS,
|
|
21
|
+
HTTP_AUTH_HEADERS,
|
|
20
22
|
S3_CLIENT_CACHE_MODE,
|
|
21
23
|
S3_MAX_RETRY_TIMES,
|
|
22
24
|
)
|
|
@@ -76,6 +78,7 @@ from megfile.utils import (
|
|
|
76
78
|
generate_cache_path,
|
|
77
79
|
get_binary_mode,
|
|
78
80
|
get_content_offset,
|
|
81
|
+
is_domain_or_subdomain,
|
|
79
82
|
is_readable,
|
|
80
83
|
necessary_params,
|
|
81
84
|
process_local,
|
|
@@ -162,24 +165,30 @@ def _patch_make_request(client: botocore.client.BaseClient, redirect: bool = Fal
|
|
|
162
165
|
retry_callback=retry_callback,
|
|
163
166
|
)
|
|
164
167
|
|
|
165
|
-
def
|
|
166
|
-
def
|
|
167
|
-
|
|
168
|
+
def patch_send(send):
|
|
169
|
+
def patched_send(request: AWSPreparedRequest) -> AWSResponse:
|
|
170
|
+
response: AWSResponse = send(request)
|
|
168
171
|
if (
|
|
169
|
-
|
|
170
|
-
and
|
|
171
|
-
and "Location" in
|
|
172
|
+
request.method == "GET" # only support GET method for now
|
|
173
|
+
and response.status_code in (301, 302, 307, 308)
|
|
174
|
+
and "Location" in response.headers
|
|
172
175
|
):
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
# Permit sending auth/cookie headers from "foo.com" to "sub.foo.com".
|
|
177
|
+
# See also: https://go.dev/src/net/http/client.go#L980
|
|
178
|
+
location = response.headers["Location"]
|
|
179
|
+
ihost = urlparse(request.url).hostname
|
|
180
|
+
dhost = urlparse(location).hostname
|
|
181
|
+
if not is_domain_or_subdomain(dhost, ihost):
|
|
182
|
+
for name in HTTP_AUTH_HEADERS:
|
|
183
|
+
request.headers.pop(name, None)
|
|
184
|
+
request.url = location
|
|
185
|
+
response = send(request)
|
|
186
|
+
return response
|
|
187
|
+
|
|
188
|
+
return patched_send
|
|
178
189
|
|
|
179
190
|
if redirect:
|
|
180
|
-
client._endpoint.
|
|
181
|
-
client._endpoint._send_request
|
|
182
|
-
)
|
|
191
|
+
client._endpoint._send = patch_send(client._endpoint._send)
|
|
183
192
|
|
|
184
193
|
return client
|
|
185
194
|
|
megfile/utils/__init__.py
CHANGED
|
@@ -346,3 +346,11 @@ class cached_classproperty(cached_property):
|
|
|
346
346
|
val = self.func(cls)
|
|
347
347
|
setattr(cls, self.attrname, val)
|
|
348
348
|
return val
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def is_domain_or_subdomain(sub, parent):
|
|
352
|
+
if sub == parent:
|
|
353
|
+
return True
|
|
354
|
+
if sub.endswith(f".{parent}"):
|
|
355
|
+
return True
|
|
356
|
+
return False
|
megfile/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = "3.1.6"
|
|
1
|
+
VERSION = "3.1.6.post1"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
docs/conf.py,sha256=sfDSly5jO8W_RmuAptOIp4hd8dNcO-9a5XrHTbxFnNo,2448
|
|
2
2
|
megfile/__init__.py,sha256=i2Lbq_VxIgppaqwkxG0_H35dRfcjJ4mCYWjprOf4hHo,7318
|
|
3
3
|
megfile/cli.py,sha256=0Sgbz3jeUryVll9Aa6R0MpJdQJUGENvz55YF7Jm1Uxc,23482
|
|
4
|
-
megfile/config.py,sha256=
|
|
4
|
+
megfile/config.py,sha256=k52eO9YUyYRJ0-bsscAXcfEt8xIAHGOHdLSnEJf6z7k,2411
|
|
5
5
|
megfile/errors.py,sha256=a55qKQgyfiLmV-qnojUFzq2gu9JXpj3ZiC2qVaWyUTA,14160
|
|
6
6
|
megfile/fs.py,sha256=dgj5fW-EEzQNdjMF2tkB5DjXu3iHQbtLi5PSIMxR8fc,11966
|
|
7
7
|
megfile/fs_path.py,sha256=Ffvukc176beH5aQMZXXtwH6ApwLYXPViCIUP0pijgT0,41590
|
|
@@ -12,14 +12,14 @@ megfile/http_path.py,sha256=BhMNjQVB85IaCGGIKzgEfY73mAVdCzJP08W1RuGeMRA,16119
|
|
|
12
12
|
megfile/interfaces.py,sha256=7C53Q2FAVFmOEnplfplvWqHab29HJE5RQnpfdb4loVY,8679
|
|
13
13
|
megfile/pathlike.py,sha256=5VAKIArm2UqrpMBJMoNAEydFxLd1mjCZ8iQnKFUIYu0,31274
|
|
14
14
|
megfile/s3.py,sha256=7SdfLjAePVh-bpRyuj566VB4Qa7KP86rCJGzYANR7wQ,13008
|
|
15
|
-
megfile/s3_path.py,sha256=
|
|
15
|
+
megfile/s3_path.py,sha256=kOrP45zQbxCxNQcoovd060QARkP8QWYKd8BQGfxGY2g,95447
|
|
16
16
|
megfile/sftp.py,sha256=vyDnYXX3i1j2fhXMC8YCeX-66MDb9wrBQQjQVhZx0uo,13004
|
|
17
17
|
megfile/sftp_path.py,sha256=4tByWvUJK1KBJoa3t5aoWYnZpaRWN9nQIE6ZyiGHrbk,53519
|
|
18
18
|
megfile/smart.py,sha256=Vr4R7HpjXjt587KOc2-1QGbQ5EsZ48YRzCaK0rz3IS0,36108
|
|
19
19
|
megfile/smart_path.py,sha256=Wsn6fR9g7NTwNwwvZ_0H39NLHIlOLnCqK-ZY0n5CvKk,7812
|
|
20
20
|
megfile/stdio.py,sha256=UYe-h440Wc4f5COOzOTG1svnp5nFzrfpixehJ0_0_NY,653
|
|
21
21
|
megfile/stdio_path.py,sha256=7jzVdreamO18yBWZM7Pp71cO7GmrYb0M0qyQde2Ypq4,2706
|
|
22
|
-
megfile/version.py,sha256=
|
|
22
|
+
megfile/version.py,sha256=XtGruYz10E7g9ijesLiQ9efrLMwPQjA29gsjMfo552o,25
|
|
23
23
|
megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
megfile/lib/base_prefetch_reader.py,sha256=CaYWuiKmlk4Utr0IFDPwPC58wV2jBAhqpxhwhRHc734,13652
|
|
25
25
|
megfile/lib/combine_reader.py,sha256=uSzo3PmhD5ck6_Vv6dFU5vVx4boeA97VS-puPyhF_BE,4657
|
|
@@ -37,19 +37,19 @@ megfile/lib/s3_cached_handler.py,sha256=QrQKck06ye16o7GD71T-fVCseKlOhsxp82LtBTtA
|
|
|
37
37
|
megfile/lib/s3_limited_seekable_writer.py,sha256=v-e7rfFBfWCSQVtJIaFHM_i0Hb1FkfVLHlhawo5MOIk,6358
|
|
38
38
|
megfile/lib/s3_memory_handler.py,sha256=NGKWbI4LG2cmV06CP7KOVPqS_BNpm3ApqKi5ibgIBvQ,4208
|
|
39
39
|
megfile/lib/s3_pipe_handler.py,sha256=DY1UTNCq8oD3QWXNb4orOiz3EoEAo6dhwmZZdk6h1bU,3694
|
|
40
|
-
megfile/lib/s3_prefetch_reader.py,sha256=
|
|
40
|
+
megfile/lib/s3_prefetch_reader.py,sha256=gjnnYI95LFwxpneDFfLBzw8gvT1Vc8yJJlBL101oysI,4501
|
|
41
41
|
megfile/lib/s3_share_cache_reader.py,sha256=jhGL1B6NPv68cQnW1Jf7ey-zTQ8XfiJg5ILDNgRWHy0,3671
|
|
42
42
|
megfile/lib/shadow_handler.py,sha256=TntewlvIW9ZxCfmqASDQREHoiZ8v42faOe9sovQYQz0,2779
|
|
43
43
|
megfile/lib/stdio_handler.py,sha256=IDdgENLQlhigEwkLL4zStueVSzdWg7xVcTF_koof_Ek,1987
|
|
44
44
|
megfile/lib/url.py,sha256=ER32pWy9Q2MAk3TraAaNEBWIqUeBmLuM57ol2cs7-Ks,103
|
|
45
|
-
megfile/utils/__init__.py,sha256=
|
|
45
|
+
megfile/utils/__init__.py,sha256=RAj8dAJZX5TkWKJu3Ip78uhA5XZ8wpir61eCm6bAnd4,10874
|
|
46
46
|
megfile/utils/mutex.py,sha256=asb8opGLgK22RiuBJUnfsvB8LnMmodP8KzCVHKmQBWA,2561
|
|
47
47
|
scripts/convert_results_to_sarif.py,sha256=nDiOfsedb22Ps7ZodmYdlXZlxv54fRxCQgOZsB2OkNk,2833
|
|
48
48
|
scripts/generate_file.py,sha256=-mTcBiqiQ1juvqojVfVZ-uZWgpANHJNdhrF7s68zNfc,10903
|
|
49
|
-
megfile-3.1.6.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
50
|
-
megfile-3.1.6.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
|
|
51
|
-
megfile-3.1.6.dist-info/METADATA,sha256=
|
|
52
|
-
megfile-3.1.6.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
53
|
-
megfile-3.1.6.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
|
|
54
|
-
megfile-3.1.6.dist-info/top_level.txt,sha256=oTnYXo1Z3V61qSWAKtnY9RkDgRSHvfRN38FQae6E0W0,50
|
|
55
|
-
megfile-3.1.6.dist-info/RECORD,,
|
|
49
|
+
megfile-3.1.6.post1.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
50
|
+
megfile-3.1.6.post1.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
|
|
51
|
+
megfile-3.1.6.post1.dist-info/METADATA,sha256=AEZWwtG0zg1mZzAIyM9YHZ5JmbS0Bwc6YCMsGFrTYDo,9184
|
|
52
|
+
megfile-3.1.6.post1.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
53
|
+
megfile-3.1.6.post1.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
|
|
54
|
+
megfile-3.1.6.post1.dist-info/top_level.txt,sha256=oTnYXo1Z3V61qSWAKtnY9RkDgRSHvfRN38FQae6E0W0,50
|
|
55
|
+
megfile-3.1.6.post1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|