diff options
| -rw-r--r-- | libmat2/office.py | 5 | ||||
| -rw-r--r-- | libmat2/torrent.py | 6 | ||||
| -rw-r--r-- | tests/test_corrupted_files.py | 2 |
3 files changed, 7 insertions, 6 deletions
diff --git a/libmat2/office.py b/libmat2/office.py index 6087c47..e0ee6d2 100644 --- a/libmat2/office.py +++ b/libmat2/office.py | |||
| @@ -22,8 +22,7 @@ def _parse_xml(full_path: str): | |||
| 22 | def parse_map(f): # etree support for ns is a bit rough | 22 | def parse_map(f): # etree support for ns is a bit rough |
| 23 | ns_map = dict() | 23 | ns_map = dict() |
| 24 | for event, (k, v) in ET.iterparse(f, ("start-ns", )): | 24 | for event, (k, v) in ET.iterparse(f, ("start-ns", )): |
| 25 | if event == "start-ns": | 25 | ns_map[k] = v |
| 26 | ns_map[k] = v | ||
| 27 | return ns_map | 26 | return ns_map |
| 28 | 27 | ||
| 29 | ns = parse_map(full_path) | 28 | ns = parse_map(full_path) |
| @@ -166,7 +165,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser): | |||
| 166 | 165 | ||
| 167 | elements = list() | 166 | elements = list() |
| 168 | for element in tree.iterfind('.//w:ins', ns): | 167 | for element in tree.iterfind('.//w:ins', ns): |
| 169 | for position, item in enumerate(tree.iter()): | 168 | for position, item in enumerate(tree.iter()): #pragma: no cover |
| 170 | if item == element: | 169 | if item == element: |
| 171 | for children in element.iterfind('./*'): | 170 | for children in element.iterfind('./*'): |
| 172 | elements.append((element, position, children)) | 171 | elements.append((element, position, children)) |
diff --git a/libmat2/torrent.py b/libmat2/torrent.py index c1ea2ca..0f122b0 100644 --- a/libmat2/torrent.py +++ b/libmat2/torrent.py | |||
| @@ -69,9 +69,11 @@ class _BencodeHandler(object): | |||
| 69 | @staticmethod | 69 | @staticmethod |
| 70 | def __decode_string(s: bytes) -> Tuple[bytes, bytes]: | 70 | def __decode_string(s: bytes) -> Tuple[bytes, bytes]: |
| 71 | colon = s.index(b':') | 71 | colon = s.index(b':') |
| 72 | str_len = int(s[:colon]) | 72 | # FIXME Python3 is broken here, the call to `ord` shouldn't be needed, |
| 73 | if s[0] == '0' and colon != 1: | 73 | # but apparently it is. This is utterly idiotic. |
| 74 | if (s[0] == ord('0') or s[0] == '0') and colon != 1: | ||
| 74 | raise ValueError | 75 | raise ValueError |
| 76 | str_len = int(s[:colon]) | ||
| 75 | s = s[1:] | 77 | s = s[1:] |
| 76 | return s[colon:colon+str_len], s[colon+str_len:] | 78 | return s[colon:colon+str_len], s[colon+str_len:] |
| 77 | 79 | ||
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py index 2bb1c76..20b1efa 100644 --- a/tests/test_corrupted_files.py +++ b/tests/test_corrupted_files.py | |||
| @@ -80,7 +80,7 @@ class TestCorruptedFiles(unittest.TestCase): | |||
| 80 | torrent.TorrentParser('./tests/data/clean.torrent') | 80 | torrent.TorrentParser('./tests/data/clean.torrent') |
| 81 | 81 | ||
| 82 | with open("./tests/data/clean.torrent", "w") as f: | 82 | with open("./tests/data/clean.torrent", "w") as f: |
| 83 | f.write("d01:AAAAAAAAA") | 83 | f.write("01:AAAAAAAAA") |
| 84 | with self.assertRaises(ValueError): | 84 | with self.assertRaises(ValueError): |
| 85 | torrent.TorrentParser('./tests/data/clean.torrent') | 85 | torrent.TorrentParser('./tests/data/clean.torrent') |
| 86 | 86 | ||
