From 8b181c6ca5c6fc699efbd6ff3f68e87401ae8ab5 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 2 Dec 2015 17:40:05 +0100 Subject: Improves the way torrents are handled This commit makes metadata removal of torrents recursive. It's close to useless, because I haven't seen any torrent with a recursive structure, but the documentation says that it can happen, and the method was already implemented, so better safe than sorry. --- libmat/misc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libmat/misc.py b/libmat/misc.py index cc480e5..e5db06d 100644 --- a/libmat/misc.py +++ b/libmat/misc.py @@ -54,8 +54,10 @@ class TorrentStripper(parser.GenericParser): """ Remove recursively all compromizing fields """ d = dict() - for i, j in [i for i in list(dictionary.items()) if i in self.fields]: - if isinstance(j, dict): + for i, j in list(dictionary.items()): + if not i in self.fields: + continue + elif isinstance(j, dict): d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) else: d[i] = j @@ -67,7 +69,7 @@ class TorrentStripper(parser.GenericParser): with open(self.filename, 'r') as f: decoded = bencode.bdecode(f.read()) - cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields} + cleaned = self.__remove_all_recursively(decoded) with open(self.output, 'w') as f: # encode the decoded torrent f.write(bencode.bencode(cleaned)) # and write it in self.output -- cgit v1.3