Ejemplo n.º 1
0
 def to_utf8(name):
     if isinstance(name, unicode):
         u = name
     else:
         try:
             u = decode_from_filesystem(name)
         except Exception, e:
             raise BTFailure(_('Could not convert file/directory name "%s" to '
                               'Unicode (%s). Either the assumed filesystem '
                               'encoding "%s" is wrong or the filename contains '
                               'illegal bytes.') % (name, unicode(e.args[0]), get_filesystem_encoding()))
Ejemplo n.º 2
0
    def _read_torrent_config(self, infohash):
        path = os.path.join(self.data_dir, 'torrents', infohash.encode('hex'))
        if not os.path.exists(path):
            raise BTFailure,_("Coult not open the torrent config: " + infohash.encode('hex'))
        f = file(path, 'rb')
        data = f.read()
        f.close()
        try:
            torrent_config = cPickle.loads(data)
        except:
            # backward compatibility with <= 4.9.3
            torrent_config = bdecode(data)
            for k, v in torrent_config.iteritems():
                try:
                    torrent_config[k] = v.decode('utf8')
                    if k in ('destination_path', 'working_path'):
                        torrent_config[k] = encode_for_filesystem(torrent_config[k])[0]
                except:
                    pass
        if not torrent_config.get('destination_path'):
            raise BTFailure( _("Invalid torrent config file"))
        if not torrent_config.get('working_path'):
            raise BTFailure( _("Invalid torrent config file"))

        if get_filesystem_encoding() == None:
            # These paths should both be unicode.  If they aren't, they are the
            # broken product of some old version, and probably are in the
            # encoding we used to use in config files.  Attempt to recover.
            dp = torrent_config['destination_path']
            if isinstance(dp, str):
                try:
                    dp = dp.decode(old_broken_config_subencoding)
                    torrent_config['destination_path'] = dp
                except:
                    raise BTFailure( _("Invalid torrent config file"))

            wp = torrent_config['working_path']
            if isinstance(wp, str):
                try:
                    wp = wp.decode(old_broken_config_subencoding)
                    torrent_config['working_path'] = wp
                except:
                    raise BTFailure( _("Invalid torrent config file"))

        return torrent_config
 def show_encoding_errors(self, errorfunc):
     self.reported_errors = True
     if self.bad_torrent_unsolvable:
         errorfunc(logging.ERROR,
                   _("This .torrent file has been created with a broken "
                     "tool and has incorrectly encoded filenames. Some or "
                     "all of the filenames may appear different from what "
                     "the creator of the .torrent file intended."))
     elif self.bad_torrent_noncharacter:
         errorfunc(logging.ERROR,
                   _("This .torrent file has been created with a broken "
                     "tool and has bad character values that do not "
                     "correspond to any real character. Some or all of the "
                     "filenames may appear different from what the creator "
                     "of the .torrent file intended."))
     elif self.bad_torrent_wrongfield:
         errorfunc(logging.ERROR,
                   _("This .torrent file has been created with a broken "
                     "tool and has incorrectly encoded filenames. The "
                     "names used may still be correct."))
     elif self.bad_conversion:
         errorfunc(logging.WARNING,
                   _('The character set used on the local filesystem ("%s") '
                     'cannot represent all characters used in the '
                     'filename(s) of this torrent. Filenames have been '
                     'changed from the original.') % get_filesystem_encoding())
     elif self.bad_windows:
         errorfunc(logging.WARNING,
                   _("The Windows filesystem cannot handle some "
                     "characters used in the filename(s) of this torrent. "
                     "Filenames have been changed from the original."))
     elif self.bad_path:
         errorfunc(logging.WARNING,
                   _("This .torrent file has been created with a broken "
                     "tool and has at least 1 file with an invalid file "
                     "or directory name. However since all such files "
                     "were marked as having length 0 those files are "
                     "just ignored."))