summaryrefslogtreecommitdiff
path: root/libmat2/torrent.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmat2/torrent.py')
-rw-r--r--libmat2/torrent.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/libmat2/torrent.py b/libmat2/torrent.py
index c547a20..e6407ff 100644
--- a/libmat2/torrent.py
+++ b/libmat2/torrent.py
@@ -1,5 +1,5 @@
1import logging 1import logging
2from typing import Union 2from typing import Union, Dict, List, Tuple
3 3
4from . import abstract 4from . import abstract
5 5
@@ -15,7 +15,7 @@ class TorrentParser(abstract.AbstractParser):
15 if self.dict_repr is None: 15 if self.dict_repr is None:
16 raise ValueError 16 raise ValueError
17 17
18 def get_meta(self) -> dict[str, Union[str, dict]]: 18 def get_meta(self) -> Dict[str, Union[str, Dict]]:
19 metadata = {} 19 metadata = {}
20 for key, value in self.dict_repr.items(): 20 for key, value in self.dict_repr.items():
21 if key not in self.allowlist: 21 if key not in self.allowlist:
@@ -56,7 +56,7 @@ class _BencodeHandler:
56 } 56 }
57 57
58 @staticmethod 58 @staticmethod
59 def __decode_int(s: bytes) -> tuple[int, bytes]: 59 def __decode_int(s: bytes) -> Tuple[int, bytes]:
60 s = s[1:] 60 s = s[1:]
61 next_idx = s.index(b'e') 61 next_idx = s.index(b'e')
62 if s.startswith(b'-0'): 62 if s.startswith(b'-0'):
@@ -66,7 +66,7 @@ class _BencodeHandler:
66 return int(s[:next_idx]), s[next_idx+1:] 66 return int(s[:next_idx]), s[next_idx+1:]
67 67
68 @staticmethod 68 @staticmethod
69 def __decode_string(s: bytes) -> tuple[bytes, bytes]: 69 def __decode_string(s: bytes) -> Tuple[bytes, bytes]:
70 colon = s.index(b':') 70 colon = s.index(b':')
71 # FIXME Python3 is broken here, the call to `ord` shouldn't be needed, 71 # FIXME Python3 is broken here, the call to `ord` shouldn't be needed,
72 # but apparently it is. This is utterly idiotic. 72 # but apparently it is. This is utterly idiotic.
@@ -76,7 +76,7 @@ class _BencodeHandler:
76 s = s[1:] 76 s = s[1:]
77 return s[colon:colon+str_len], s[colon+str_len:] 77 return s[colon:colon+str_len], s[colon+str_len:]
78 78
79 def __decode_list(self, s: bytes) -> tuple[list, bytes]: 79 def __decode_list(self, s: bytes) -> Tuple[List, bytes]:
80 ret = list() 80 ret = list()
81 s = s[1:] # skip leading `l` 81 s = s[1:] # skip leading `l`
82 while s[0] != ord('e'): 82 while s[0] != ord('e'):
@@ -84,7 +84,7 @@ class _BencodeHandler:
84 ret.append(value) 84 ret.append(value)
85 return ret, s[1:] 85 return ret, s[1:]
86 86
87 def __decode_dict(self, s: bytes) -> tuple[dict, bytes]: 87 def __decode_dict(self, s: bytes) -> Tuple[Dict, bytes]:
88 ret = dict() 88 ret = dict()
89 s = s[1:] # skip leading `d` 89 s = s[1:] # skip leading `d`
90 while s[0] != ord(b'e'): 90 while s[0] != ord(b'e'):
@@ -113,10 +113,10 @@ class _BencodeHandler:
113 ret += self.__encode_func[type(value)](value) 113 ret += self.__encode_func[type(value)](value)
114 return b'd' + ret + b'e' 114 return b'd' + ret + b'e'
115 115
116 def bencode(self, s: Union[dict, list, bytes, int]) -> bytes: 116 def bencode(self, s: Union[Dict, List, bytes, int]) -> bytes:
117 return self.__encode_func[type(s)](s) 117 return self.__encode_func[type(s)](s)
118 118
119 def bdecode(self, s: bytes) -> Union[dict, None]: 119 def bdecode(self, s: bytes) -> Union[Dict, None]:
120 try: 120 try:
121 ret, trail = self.__decode_func[s[0]](s) 121 ret, trail = self.__decode_func[s[0]](s)
122 except (IndexError, KeyError, ValueError) as e: 122 except (IndexError, KeyError, ValueError) as e: