示例#1
0
def pathlist2savefilename(pathlist, encoding):
    fullpath = u''
    for elem in pathlist:
        u = bin2unicode(elem, encoding)
        b = fix_filebasename(u)
        fullpath = os.path.join(fullpath, b)
    return fullpath
示例#2
0
    def set_corrected_infoname(self):
        # H4xor this so the 'name' field is safe
        self.correctedinfoname = fix_filebasename(self.tdef.get_name_as_unicode())

        # Allow correctedinfoname to be overwritten for multifile torrents only
        if self.get_corrected_filename() and self.get_corrected_filename() != '' and 'files' in self.tdef.get_metainfo()['info']:
            self.correctedinfoname = self.get_corrected_filename()
    def set_corrected_infoname(self):
        # H4xor this so the 'name' field is safe
        self.correctedinfoname = fix_filebasename(self.tdef.get_name_as_unicode())

        # Allow correctedinfoname to be overwritten for multifile torrents only
        if self.get_corrected_filename() and self.get_corrected_filename() != '' and 'files' in self.tdef.get_metainfo()['info']:
            self.correctedinfoname = self.get_corrected_filename()
示例#4
0
def pathlist2savefilename(pathlist, encoding):
    fullpath = u''
    for elem in pathlist:
        u = bin2unicode(elem, encoding)
        b = fix_filebasename(u)
        fullpath = os.path.join(fullpath, b)
    return fullpath
示例#5
0
    def setup(self, dcfg = None, pstate = None, initialdlstatus = None, lm_network_engine_wrapper_created_callback = None, lm_network_vod_event_callback = None, wrapperDelay = 0):
        """
        Create a Download object. Used internally by Session.
        @param dcfg DownloadStartupConfig or None (in which case 
        a new DownloadConfig() is created and the result 
        becomes the runtime config of this Download.
        """
        # Called by any thread, assume sessionlock is held
        try:
            with self.dllock:
                # Copy dlconfig, from default if not specified
                if dcfg is None:
                    cdcfg = DownloadStartupConfig()
                else:
                    cdcfg = dcfg
                self.dlconfig = copy.copy(cdcfg.dlconfig)
                
                metainfo = self.tdef.get_metainfo()
                self.set_filepieceranges(metainfo)
    
                # Things that only exist at runtime
                self.dlruntimeconfig= {}
                self.dlruntimeconfig['max_desired_upload_rate'] = 0
                self.dlruntimeconfig['max_desired_download_rate'] = 0
                
                # H4xor this so the 'name' field is safe
                self.correctedinfoname = fix_filebasename(self.tdef.get_name_as_unicode())

                # Allow correctinfoname to be overwritten for multifile torrents only
                if 'files' in metainfo['info'] and dcfg.get_corrected_filename() and dcfg.get_corrected_filename() != '':
                    self.correctedinfoname = dcfg.get_corrected_filename()
        
                self.files = []
                if 'files' in metainfo['info']:
                    for x in metainfo['info']['files']:
                        savepath = torrentfilerec2savefilename(x)
                        full = savefilenames2finaldest(self.get_content_dest(), savepath)
                        # Arno: TODO: this sometimes gives too long filenames for 
                        # Windows. When fixing this take into account that 
                        # Download.get_dest_files() should still produce the same
                        # filenames as your modifications here.
                        self.files.append((full, x['length']))
                else:
                    self.files.append((self.get_content_dest(), metainfo['info']['length']))
        
                if DEBUG:
                    print >> sys.stderr, "LibtorrentDownloadImpl: setup: initialdlstatus", self.tdef.get_infohash(), initialdlstatus
                    
                if initialdlstatus == DLSTATUS_STOPPED:
                    self.pause_after_next_hashcheck = True
                    
                self.create_engine_wrapper(lm_network_engine_wrapper_created_callback, pstate, lm_network_vod_event_callback, initialdlstatus = initialdlstatus, wrapperDelay = wrapperDelay)
                
            self.pstate_for_restart = pstate

        except Exception, e:
            with self.dllock:
                self.error = e
                print_exc()
示例#6
0
    def test_fix_filebasename(self):
        default_name = '_'
        win_name_table = {
            'abcdef': 'abcdef',
          '.': default_name,
          '..': default_name,
          '': default_name,
          ' ': default_name,
          '   ': default_name,
          os.path.join('a', 'b'): 'a_b',
          '\x5c\x61': '_a',    # \x5c = '\\'
          '\x92\x97': '\x92\x97',
          '\x5c\x5c': '__',
          '\x5c\x61\x5c': '_a_',
          '\x2f\x61': '_a',    # \x2f = '/'
          '\x92\x97': '\x92\x97',
          '\x2f\x2f': '__',
          '\x2f\x61\x2f': '_a_',
          'a' * 300: 'a' * 255
        }
        for c in '"*/:<>?\\|':
            win_name_table[c] = default_name

        linux_name_table = {
            'abcdef': 'abcdef',
          '.': default_name,
          '..': default_name,
          '': default_name,
          ' ': default_name,
          '   ': default_name,
          os.path.join('a', 'b'): 'a_b',
          '\x2f\x61': '_a',    # \x2f = '/'
          '\x92\x97': '\x92\x97',
          '\x2f\x2f': '__',
          '\x2f\x61\x2f': '_a_',
          'a' * 300: 'a' * 255
        }

        if sys.platform.startswith('win'):
            name_table = win_name_table
        else:
            name_table = linux_name_table

        for name in name_table:
            fixedname = fix_filebasename(name)
            assert fixedname == name_table[name], (fixedname, name_table[name])
示例#7
0
    def test_fix_filebasename(self):
        default_name = '_'
        win_name_table = {
            'abcdef': 'abcdef',
            '.': default_name,
            '..': default_name,
            '': default_name,
            ' ': default_name,
            '   ': default_name,
            os.path.join('a', 'b'): 'a_b',
            '\x5c\x61': '_a',  # \x5c = '\\'
            '\x92\x97': '\x92\x97',
            '\x5c\x5c': '__',
            '\x5c\x61\x5c': '_a_',
            '\x2f\x61': '_a',  # \x2f = '/'
            '\x92\x97': '\x92\x97',
            '\x2f\x2f': '__',
            '\x2f\x61\x2f': '_a_',
            'a' * 300: 'a' * 255
        }
        for c in '"*/:<>?\\|':
            win_name_table[c] = default_name

        linux_name_table = {
            'abcdef': 'abcdef',
            '.': default_name,
            '..': default_name,
            '': default_name,
            ' ': default_name,
            '   ': default_name,
            os.path.join('a', 'b'): 'a_b',
            '\x2f\x61': '_a',  # \x2f = '/'
            '\x92\x97': '\x92\x97',
            '\x2f\x2f': '__',
            '\x2f\x61\x2f': '_a_',
            'a' * 300: 'a' * 255
        }

        if sys.platform.startswith('win'):
            name_table = win_name_table
        else:
            name_table = linux_name_table

        for name in name_table:
            fixedname = fix_filebasename(name)
            assert fixedname == name_table[name], (fixedname, name_table[name])
    def setup(self, dcfg = None, pstate = None, initialdlstatus = None, lm_network_engine_wrapper_created_callback = None, lm_network_vod_event_callback = None, wrapperDelay = 0):
        """
        Create a Download object. Used internally by Session.
        @param dcfg DownloadStartupConfig or None (in which case 
        a new DownloadConfig() is created and the result 
        becomes the runtime config of this Download.
        """
        # Called by any thread, assume sessionlock is held
        try:
            with self.dllock:
                # Copy dlconfig, from default if not specified
                if dcfg is None:
                    cdcfg = DownloadStartupConfig()
                else:
                    cdcfg = dcfg
                self.dlconfig = copy.copy(cdcfg.dlconfig)
                
                # Things that only exist at runtime
                self.dlruntimeconfig= {}
                self.dlruntimeconfig['max_desired_upload_rate'] = 0
                self.dlruntimeconfig['max_desired_download_rate'] = 0    
                    
                # H4xor this so the 'name' field is safe
                self.correctedinfoname = fix_filebasename(self.tdef.get_name_as_unicode())                

                if not isinstance(self.tdef, TorrentDefNoMetainfo):
                    self.set_files()
        
                if DEBUG:
                    print >> sys.stderr, "LibtorrentDownloadImpl: setup: initialdlstatus", self.tdef.get_infohash(), initialdlstatus
                    
                self.create_engine_wrapper(lm_network_engine_wrapper_created_callback, pstate, lm_network_vod_event_callback, initialdlstatus = initialdlstatus, wrapperDelay = wrapperDelay)
                
            self.pstate_for_restart = pstate

        except Exception, e:
            with self.dllock:
                self.error = e
                print_exc()
    def setup(self, dcfg = None, pstate = None, initialdlstatus = None, lm_network_engine_wrapper_created_callback = None, lm_network_vod_event_callback = None, wrapperDelay = 0):
        """
        Create a Download object. Used internally by Session.
        @param dcfg DownloadStartupConfig or None (in which case 
        a new DownloadConfig() is created and the result 
        becomes the runtime config of this Download.
        """
        # Called by any thread, assume sessionlock is held
        try:
            with self.dllock:
                # Copy dlconfig, from default if not specified
                if dcfg is None:
                    cdcfg = DownloadStartupConfig()
                else:
                    cdcfg = dcfg
                self.dlconfig = copy.copy(cdcfg.dlconfig)
                
                # Things that only exist at runtime
                self.dlruntimeconfig= {}
                self.dlruntimeconfig['max_desired_upload_rate'] = 0
                self.dlruntimeconfig['max_desired_download_rate'] = 0    
                    
                # H4xor this so the 'name' field is safe
                self.correctedinfoname = fix_filebasename(self.tdef.get_name_as_unicode())                

                if not isinstance(self.tdef, TorrentDefNoMetainfo):
                    self.set_files()
        
                if DEBUG:
                    print >> sys.stderr, "LibtorrentDownloadImpl: setup: initialdlstatus", self.tdef.get_infohash(), initialdlstatus
                    
                self.create_engine_wrapper(lm_network_engine_wrapper_created_callback, pstate, lm_network_vod_event_callback, initialdlstatus = initialdlstatus, wrapperDelay = wrapperDelay)
                
            self.pstate_for_restart = pstate

        except Exception, e:
            with self.dllock:
                self.error = e
                print_exc()