Beispiel #1
0
    def get_index_of_file_in_files(self, file):
        info = self.metainfo['info']

        if file is not None and 'files' in info:
            for i in range(len(info['files'])):
                file_dict = info['files'][i]

                if 'path.utf-8' in file_dict:
                    intorrentpath = maketorrent.pathlist2filename(file_dict['path.utf-8'])
                else:
                    intorrentpath = maketorrent.pathlist2filename(file_dict['path'])

                if intorrentpath == file:
                    return i
            raise ValueError("File not found in torrent")
        else:
            raise ValueError("File not found in single-file torrent")
Beispiel #2
0
    def get_index_of_file_in_files(self, file):
        info = self.metainfo['info']

        if file is not None and 'files' in info:
            for i in range(len(info['files'])):
                file_dict = info['files'][i]

                if 'path.utf-8' in file_dict:
                    intorrentpath = maketorrent.pathlist2filename(
                        file_dict['path.utf-8'])
                else:
                    intorrentpath = maketorrent.pathlist2filename(
                        file_dict['path'])

                if intorrentpath == file:
                    return i
            raise ValueError("File not found in torrent")
        else:
            raise ValueError("File not found in single-file torrent")
Beispiel #3
0
    def get_index_of_file_in_files(self, file):
        if not self.metainfo_valid:
            raise NotYetImplementedException()  # must save first

        info = self.metainfo['info']

        if file is not None and 'files' in info:
            for i in range(len(info['files'])):
                x = info['files'][i]

                intorrentpath = maketorrent.pathlist2filename(x['path'])
                if intorrentpath == file:
                    return i
            return ValueError("File not found in torrent")
        else:
            raise ValueError("File not found in single-file torrent")
Beispiel #4
0
 def test_pathlist2filename_utf8(self):
     path_list = [u"test", u"path"]
     path = pathlist2filename(path_list)
     self.assertEqual(path, os.path.join(u"test", u"path"))
Beispiel #5
0
 def test_pathlist2filename_not_utf8(self):
     part = u'\xb0\xe7'.encode("latin-1")
     path_list = ["test", part]
     path = pathlist2filename(path_list)
     self.assertEqual(path, os.path.join(u"test", u"\xb0\xe7"))