• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lbryio / lbry-sdk / 4599645360

pending completion
4599645360

push

github

GitHub
Bump cryptography from 2.5 to 39.0.1

2807 of 6557 branches covered (42.81%)

Branch coverage included in aggregate %.

12289 of 19915 relevant lines covered (61.71%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lbry/torrent/torrent.py
1
import asyncio
×
2
import logging
×
3
import typing
×
4

5

6
log = logging.getLogger(__name__)
×
7

8

9
class TorrentInfo:
×
10
    __slots__ = ('dht_seeds', 'http_seeds', 'trackers', 'total_size')
×
11

12
    def __init__(self, dht_seeds: typing.Tuple[typing.Tuple[str, int]],
×
13
                 http_seeds: typing.Tuple[typing.Dict[str, typing.Any]],
14
                 trackers: typing.Tuple[typing.Tuple[str, int]], total_size: int):
15
        self.dht_seeds = dht_seeds
×
16
        self.http_seeds = http_seeds
×
17
        self.trackers = trackers
×
18
        self.total_size = total_size
×
19

20
    @classmethod
×
21
    def from_libtorrent_info(cls, torrent_info):
×
22
        return cls(
×
23
            torrent_info.nodes(), tuple(
24
                {
25
                    'url': web_seed['url'],
26
                    'type': web_seed['type'],
27
                    'auth': web_seed['auth']
28
                } for web_seed in torrent_info.web_seeds()
29
            ), tuple(
30
                (tracker.url, tracker.tier) for tracker in torrent_info.trackers()
31
            ), torrent_info.total_size()
32
        )
33

34

35
class Torrent:
×
36
    def __init__(self, loop, handle):
×
37
        self._loop = loop
×
38
        self._handle = handle
×
39
        self.finished = asyncio.Event()
×
40

41
    def _threaded_update_status(self):
×
42
        status = self._handle.status()
×
43
        if not status.is_seeding:
×
44
            log.info(
×
45
                '%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d) %s',
46
                status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
47
                status.num_peers, status.state
48
            )
49
        elif not self.finished.is_set():
×
50
            self.finished.set()
×
51

52
    async def wait_for_finished(self):
×
53
        while True:
54
            await self._loop.run_in_executor(
×
55
                None, self._threaded_update_status
56
            )
57
            if self.finished.is_set():
×
58
                log.info("finished downloading torrent!")
×
59
                await self.pause()
×
60
                break
×
61
            await asyncio.sleep(1)
×
62

63
    async def pause(self):
×
64
        log.info("pause torrent")
×
65
        await self._loop.run_in_executor(
×
66
            None, self._handle.pause
67
        )
68

69
    async def resume(self):
×
70
        await self._loop.run_in_executor(
×
71
            None, self._handle.resume
72
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc