Ejemplo n.º 1
0
    def test_generates_no_intervals_if_total_is_zero(self):
        total = 0
        intervalSize = 16
        intervals = [
            interval for interval in httpRangeHeaderIntervalGenerator(
                total, intervalSize)
        ]

        self.assertEqual(intervals, [])
Ejemplo n.º 2
0
    def test_starts_at_16_bytes_for_the_init_vector(self):
        total = 32
        intervalSize = 16
        intervals = [
            interval for interval in httpRangeHeaderIntervalGenerator(
                total, intervalSize)
        ]

        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0], [16, total - 1])
Ejemplo n.º 3
0
    def test_generates_a_single_interval_if_interval_size_is_greater_than_total(
            self):
        total = 32
        intervalSize = 64
        intervals = [
            interval for interval in httpRangeHeaderIntervalGenerator(
                total, intervalSize)
        ]

        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0], [16, total - 1])
Ejemplo n.º 4
0
    def test_single_interval_is_generated_if_total_is_equal_to_intervalSize(
            self):
        total = 32
        intervalSize = 32

        intervals = [
            interval for interval in httpRangeHeaderIntervalGenerator(
                total, intervalSize)
        ]

        self.assertEqual(len(intervals), 1)
        self.assertEqual(intervals[0], [16, 31])
Ejemplo n.º 5
0
 def test_throws_exception_if_total_is_negative(self):
     total = -32
     intervalSize = 5
     try:
         intervals = [
             interval for interval in httpRangeHeaderIntervalGenerator(
                 total, intervalSize)
         ]
         self.fail(
             f"Interval generator should throw ValueError with total: -32. Result: {intervals}"
         )
     except ValueError:
         pass
Ejemplo n.º 6
0
 def test_throws_exception_if_interval_size_is_zero(self):
     total = 32
     intervalSize = 0
     try:
         intervals = [
             interval for interval in httpRangeHeaderIntervalGenerator(
                 total, intervalSize)
         ]
         self.fail(
             f"Interval generator should throw ValueError with intervalSize: 0. Result: {intervals}"
         )
     except ValueError:
         pass
Ejemplo n.º 7
0
    def test_generates_every_interval_with_the_interval_size(self):
        total = 48
        intervalSize = 16
        intervals = [
            interval for interval in httpRangeHeaderIntervalGenerator(
                total, intervalSize)
        ]
        expectedIntervals = [[16, 31], [32, total - 1]]

        self.assertEqual(len(intervals), 2)
        self.assertEqual(intervals, expectedIntervals)
        for interval in intervals:
            self.assertEqual(interval[1] - interval[0], intervalSize - 1)
Ejemplo n.º 8
0
    def download(self, fileHandle, partInfo, task):
        token = self.accountData.data["apiToken"]

        headers = {
            "Authorization": f"Bearer {token}",
            "Dropbox-API-Arg": json.dumps({"path": f"/{partInfo.fullPath}"}),
            "Range": "bytes=0-15"
        }
        res = requests.get(self.__DOWNLOAD_URL, headers=headers)
        cipher = AES.new(self.accountData.cryptoKey.encode(),
                         AES.MODE_CFB,
                         iv=res.content)

        for interval in httpRangeHeaderIntervalGenerator(
                partInfo.size, self.__DOWNLOAD_CHUNK_SIZE):
            if task.stale:
                self._logger.info("Dropbox download interrupted.")
                break
            else:
                headers["Range"] = f"bytes={interval[0]}-{interval[1]}"

                res = requests.get(self.__DOWNLOAD_URL, headers=headers)
                decrypted = cipher.decrypt(res.content)
                fileHandle.write(decrypted)