diff options
| author | jvoisin | 2018-07-08 15:13:03 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-08 15:13:03 +0200 |
| commit | 3cd4f9111f4a050ff365bbe103993b3a89fdc29d (patch) | |
| tree | 89d2cb1d9e5ba5838d517e728bcfe82f682e871a /libmat2 | |
| parent | b5fcddd6a68b7e18d1e5521e7363046ca0e68667 (diff) | |
Bump coverage for torrent handling
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/torrent.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/libmat2/torrent.py b/libmat2/torrent.py index d614136..925ac55 100644 --- a/libmat2/torrent.py +++ b/libmat2/torrent.py | |||
| @@ -60,8 +60,6 @@ class _BencodeHandler(object): | |||
| 60 | def __decode_int(s: bytes) -> Tuple[int, bytes]: | 60 | def __decode_int(s: bytes) -> Tuple[int, bytes]: |
| 61 | s = s[1:] | 61 | s = s[1:] |
| 62 | next_idx = s.index(b'e') | 62 | next_idx = s.index(b'e') |
| 63 | if next_idx is None: | ||
| 64 | raise ValueError # missing suffix | ||
| 65 | if s.startswith(b'-0'): | 63 | if s.startswith(b'-0'): |
| 66 | raise ValueError # negative zero doesn't exist | 64 | raise ValueError # negative zero doesn't exist |
| 67 | elif s.startswith(b'0') and next_idx != 1: | 65 | elif s.startswith(b'0') and next_idx != 1: |
| @@ -70,16 +68,13 @@ class _BencodeHandler(object): | |||
| 70 | 68 | ||
| 71 | @staticmethod | 69 | @staticmethod |
| 72 | def __decode_string(s: bytes) -> Tuple[bytes, bytes]: | 70 | def __decode_string(s: bytes) -> Tuple[bytes, bytes]: |
| 73 | sep = s.index(b':') | 71 | colon = s.index(b':') |
| 74 | if set is None: | 72 | str_len = int(s[:colon]) |
| 75 | raise ValueError # missing suffix | 73 | print('S: %s' % s) |
| 76 | str_len = int(s[:sep]) | 74 | if s[0] == '0' and colon != 1: |
| 77 | if str_len < 0: | ||
| 78 | raise ValueError | ||
| 79 | elif s[0] == b'0' and sep != 1: | ||
| 80 | raise ValueError | 75 | raise ValueError |
| 81 | s = s[1:] | 76 | s = s[1:] |
| 82 | return s[sep:sep+str_len], s[sep+str_len:] | 77 | return s[colon:colon+str_len], s[colon+str_len:] |
| 83 | 78 | ||
| 84 | def __decode_list(self, s: bytes) -> Tuple[list, bytes]: | 79 | def __decode_list(self, s: bytes) -> Tuple[list, bytes]: |
| 85 | r = list() | 80 | r = list() |
