Ejemplo n.º 1
0
    def file_stream(
        self,
        remotepath: str,
        max_chunk_size: int = DEFAULT_MAX_CHUNK_SIZE,
        callback: Callable[..., None] = None,
        encrypt_password: bytes = b"",
        pcs: bool = False,
    ) -> Optional[RangeRequestIO]:
        url = self.download_link(remotepath, pcs=pcs)
        if not url:
            return None

        headers = {
            "Cookie":
            "; ".join([
                f"{k}={v if v is not None else ''}"
                for k, v in self._cookies.items()
            ]),
            "User-Agent":
            PCS_UA,
            "Connection":
            "Keep-Alive",
        }
        return RangeRequestIO(
            Method.Get.value,
            url,
            headers=headers,
            max_chunk_size=max_chunk_size,
            callback=callback,
            encrypt_password=encrypt_password,
        )
Ejemplo n.º 2
0
 def file_stream(
     self,
     remotepath: str,
     max_chunk_size: int = DEFAULT_MAX_CHUNK_SIZE,
     callback: Callable[..., None] = None,
     encrypt_key=Optional[str],
 ) -> RangeRequestIO:
     info = self.download_link(remotepath)
     url = info["urls"][0]["url"]
     headers = {
         "Cookie":
         "; ".join([
             f"{k}={v if v is not None else ''}"
             for k, v in self._cookies.items()
         ]),
         "User-Agent":
         PCS_UA,
         "Connection":
         "Keep-Alive",
     }
     return RangeRequestIO(
         Method.Get.value,
         url,
         headers=headers,
         max_chunk_size=max_chunk_size,
         callback=callback,
         encrypt_key=encrypt_key,
     )
Ejemplo n.º 3
0
def fake_io(io: RangeRequestIO, start: int = 0, end: int = -1):
    while True:
        length = len(io)
        io.seek(start, 0)
        size = length if end < 0 else end - start + 1

        ranges = io._split_chunk(size)
        for _range in ranges:
            with io._request(_range) as resp:
                stream = resp.raw
                while True:
                    b = stream.read(READ_SIZE)
                    if not b:
                        break
                    yield b
        return
Ejemplo n.º 4
0
def test_rangerequestio():
    url = "http://mirror.arizona.edu/ubuntu/dists/xenial/Release.gpg"
    io = RangeRequestIO("GET", url, max_chunk_size=300)

    b = b""
    while True:
        cn = io.read(300)
        if not cn:
            break
        b += cn

    o = requests.get(url).content
    assert b == o