File: dummy_data.py

package info (click to toggle)
libtorrent-rasterbar 2.0.11-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,304 kB
  • sloc: cpp: 190,670; python: 7,142; makefile: 1,374; ansic: 574; sh: 317; xml: 104
file content (34 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import libtorrent as lt

import hashlib
import random

PIECE_LENGTH = 16384
NAME = b"test.txt"
LEN = PIECE_LENGTH * 9 + 1000
# Use 7-bit data so we can test piece data as either bytes or str
DATA = bytes(random.getrandbits(7) for _ in range(LEN))
PIECES = [DATA[i:i + PIECE_LENGTH] for i in range(0, LEN, PIECE_LENGTH)]

INFO_DICT = {
        b"name": NAME,
        b"piece length": PIECE_LENGTH,
        b"length": len(DATA),
        b"pieces": b"".join(hashlib.sha1(p).digest() for p in PIECES),
    }

DICT = {
    b"info": INFO_DICT,
}


def get_infohash_bytes():
    return hashlib.sha1(lt.bencode(INFO_DICT)).digest()


def get_infohash():
    return get_infohash_bytes().hex()


def get_sha1_hash():
    return lt.sha1_hash(get_infohash_bytes())