• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.fs_encode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中module.utils.fs_encode函数的典型用法代码示例。如果您正苦于以下问题:Python fs_encode函数的具体用法?Python fs_encode怎么用?Python fs_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fs_encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: packageFinished

    def packageFinished(self, pypack):
        download_folder = save_join(self.config['general']['download_folder'], pypack.folder, "")

        for link in pypack.getChildren().itervalues():
            file_type = splitext(link["name"])[1][1:].lower()
            #self.logDebug(link, file_type)

            if file_type not in self.formats:
                continue

            hash_file = fs_encode(save_join(download_folder, link["name"]))
            if not isfile(hash_file):
                self.logWarning("File not found: %s" % link["name"])
                continue

            with open(hash_file) as f:
                text = f.read()

            for m in re.finditer(self.regexps.get(file_type, self.regexps['default']), text):
                data = m.groupdict()
                self.logDebug(link["name"], data)

                local_file = fs_encode(save_join(download_folder, data["name"]))
                algorithm = self.methods.get(file_type, file_type)
                checksum = computeChecksum(local_file, algorithm)
                if checksum == data["hash"]:
                    self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (data["name"],
                                                                                           algorithm,
                                                                                           checksum))
                else:
                    self.logWarning("%s checksum for file %s does not match (%s != %s)" % (algorithm,
                                                                                           data["name"],
                                                                                           checksum,
                                                                                           data["hash"]))
开发者ID:Robbi373,项目名称:pyload,代码行数:34,代码来源:Checksum.py


示例2: package_finished

    def package_finished(self, pypack):
        download_folder = fs_join(self.pyload.config.get("general", "download_folder"), pypack.folder, "")

        for link in pypack.getChildren().values():
            file_type = os.path.splitext(link['name'])[1][1:].lower()

            if file_type not in self.formats:
                continue

            hash_file = fs_encode(fs_join(download_folder, link['name']))
            if not os.path.isfile(hash_file):
                self.log_warning(_("File not found"), link['name'])
                continue

            with open(hash_file) as f:
                text = f.read()

            for m in re.finditer(self.regexps.get(file_type, self.regexps['default']), text):
                data = m.groupdict()
                self.log_debug(link['name'], data)

                local_file = fs_encode(fs_join(download_folder, data['NAME']))
                algorithm = self.methods.get(file_type, file_type)
                checksum = computeChecksum(local_file, algorithm)
                if checksum is data['HASH']:
                    self.log_info(_('File integrity of "%s" verified by %s checksum (%s)') %
                                (data['NAME'], algorithm, checksum))
                else:
                    self.log_warning(_("%s checksum for file %s does not match (%s != %s)") %
                                   (algorithm, data['NAME'], checksum, data['HASH']))
开发者ID:earthGavinLee,项目名称:pyload,代码行数:30,代码来源:Checksum.py


示例3: findDuplicates

 def findDuplicates(self, pyfile):
     """ Search all packages for duplicate links to "pyfile".
         Duplicates are links that would overwrite "pyfile".
         To test on duplicity the package-folder and link-name
         of twolinks are compared (basename(link.name)).
         So this method returns a list of all links with equal
         package-folders and filenames as "pyfile", but except
         the data for "pyfile" iotselöf.
         It does MOT check the link's status.
     """
     dups = []
     pyfile_name = fs_encode(basename(pyfile.name))
     # get packages (w/o files, as most file data is useless here)
     queue = self.core.api.getQueue()
     for package in queue:
         # check if package-folder equals pyfile's package folder
         if fs_encode(package.folder) == fs_encode(pyfile.package().folder):
             # now get packaged data w/ files/links
             pdata = self.core.api.getPackageData(package.pid)
             if pdata.links:
                 for link in pdata.links:
                     link_name = fs_encode(basename(link.name))
                     # check if link name collides with pdata's name
                     if link_name == pyfile_name:
                         # at last check if it is not pyfile itself
                         if link.fid != pyfile.id:
                             dups.append(link)
     return dups
开发者ID:3DMeny,项目名称:pyload,代码行数:28,代码来源:UnSkipOnFail.py


示例4: _copyChunks

    def _copyChunks(self):
        init = fs_encode(self.info.getChunkName(0)) #initial chunk name

        if self.info.getCount() > 1:
            fo = open(init, "rb+") #first chunkfile
            for i in range(1, self.info.getCount()):
                #input file
                fo.seek(
                    self.info.getChunkRange(i - 1)[1] + 1) #seek to beginning of chunk, to get rid of overlapping chunks
                fname = fs_encode("%s.chunk%d" % (self.filename, i))
                fi = open(fname, "rb")
                buf = 32 * 1024
                while True: #copy in chunks, consumes less memory
                    data = fi.read(buf)
                    if not data:
                        break
                    fo.write(data)
                fi.close()
                if fo.tell() < self.info.getChunkRange(i)[1]:
                    fo.close()
                    remove(init)
                    self.info.remove() #there are probably invalid chunks
                    raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.")
                remove(fname) #remove chunk
            fo.close()

        if self.nameDisposition and self.disposition:
            self.filename = save_join(dirname(self.filename), self.nameDisposition)

        move(init, fs_encode(self.filename))
        self.info.remove() #remove info file
开发者ID:EikeKre,项目名称:pyload,代码行数:31,代码来源:HTTPDownload.py


示例5: get_download

def get_download(path):
    path = unquote(path).decode("utf8")
    # @TODO some files can not be downloaded

    root = PYLOAD.getConfigValue("general", "download_folder")

    path = path.replace("..", "")
    return static_file(fs_encode(path), fs_encode(root))
开发者ID:B1GPY,项目名称:pyload,代码行数:8,代码来源:pyload.py


示例6: scan

    def scan(self, pyfile, thread):
        file     = fs_encode(pyfile.plugin.last_download)
        filename = os.path.basename(pyfile.plugin.last_download)
        cmdfile  = fs_encode(self.get_config('cmdfile'))
        cmdargs  = fs_encode(self.get_config('cmdargs').strip())

        if not os.path.isfile(file) or not os.path.isfile(cmdfile):
            return

        thread.addActive(pyfile)
        pyfile.setCustomStatus(_("virus scanning"))
        pyfile.setProgress(0)

        try:
            p = subprocess.Popen([cmdfile, cmdargs, file], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

            out, err = map(str.strip, p.communicate())

            if out:
                self.log_info(filename, out)

            if err:
                self.log_warning(filename, err)
                if not self.get_config('ignore-err'):
                    self.log_debug("Delete/Quarantine task is aborted")
                    return

            if p.returncode:
                pyfile.error = _("Infected file")
                action = self.get_config('action')
                try:
                    if action == "Delete":
                        if not self.get_config('deltotrash'):
                            os.remove(file)

                        else:
                            try:
                                send2trash.send2trash(file)

                            except NameError:
                                self.log_warning(_("Send2Trash lib not found, moving to quarantine instead"))
                                pyfile.setCustomStatus(_("file moving"))
                                shutil.move(file, self.get_config('quardir'))

                            except Exception, e:
                                self.log_warning(_("Unable to move file to trash: %s, moving to quarantine instead") % e.message)
                                pyfile.setCustomStatus(_("file moving"))
                                shutil.move(file, self.get_config('quardir'))

                            else:
                                self.log_debug("Successfully moved file to trash")

                    elif action == "Quarantine":
                        pyfile.setCustomStatus(_("file moving"))
                        shutil.move(file, self.get_config('quardir'))

                except (IOError, shutil.Error), e:
                    self.log_error(filename, action + " action failed!", e)
开发者ID:earthGavinLee,项目名称:pyload,代码行数:58,代码来源:AntiVirus.py


示例7: get_download

def get_download(path):
    path = unquote(path).decode("utf8")
    #@TODO some files can not be downloaded

    root = PYLOAD.getConfigValue("general", "download_folder")

    path = path.replace("..", "")
    try:
        return static_file(fs_encode(path), fs_encode(root))

    except Exception, e:
        print e
        return HTTPError(404, "File not Found.")
开发者ID:EikeKre,项目名称:pyload,代码行数:13,代码来源:pyload_app.py


示例8: list

    def list(self, password=None):
        command = "vb" if self.fullpath else "lb"

        p = self.call_cmd(command, "-v", fs_encode(self.filename), password=password)
        out, err = p.communicate()

        if "Cannot open" in err:
            raise ArchiveError(_("Cannot open file"))

        if err.strip():  #: only log error at this point
            self.manager.logError(err.strip())

        result = set()
        if not self.fullpath and self.VERSION.startswith('5'):
            # NOTE: Unrar 5 always list full path
            for f in fs_decode(out).splitlines():
                f = save_join(self.out, os.path.basename(f.strip()))
                if os.path.isfile(f):
                    result.add(save_join(self.out, os.path.basename(f)))
        else:
            for f in fs_decode(out).splitlines():
                f = f.strip()
                result.add(save_join(self.out, f))

        return list(result)
开发者ID:kurtiss,项目名称:htpc,代码行数:25,代码来源:UnRar.py


示例9: downloads

def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not isdir(root):
        return base([_("Download directory not found.")])
    data = {"folder": [], "files": []}

    items = listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if isdir(safe_join(root, item)):
            folder = {"name": item, "path": item, "files": []}
            files = listdir(safe_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if isfile(safe_join(root, item, file)):
                        folder["files"].append(file)
                except:
                    pass

            data["folder"].append(folder)
        elif isfile(join(root, item)):
            data["files"].append(item)

    return render_to_response("downloads.html", {"files": data}, [pre_processor])
开发者ID:B1GPY,项目名称:pyload,代码行数:25,代码来源:pyload.py


示例10: load

    def load(name):
        fs_name = fs_encode("%s.chunks" % name)
        if not exists(fs_name):
            raise IOError()
        fh = codecs.open(fs_name, "r", "utf_8")
        name = fh.readline()[:-1]
        size = fh.readline()[:-1]
        if name.startswith("name:") and size.startswith("size:"):
            name = name[5:]
            size = size[5:]
        else:
            fh.close()
            raise WrongFormat()
        ci = ChunkInfo(name)
        ci.loaded = True
        ci.setSize(size)
        while True:
            if not fh.readline(): #skip line
                break
            name = fh.readline()[1:-1]
            range = fh.readline()[1:-1]
            if name.startswith("name:") and range.startswith("range:"):
                name = name[5:]
                range = range[6:].split("-")
            else:
                raise WrongFormat()

            ci.addChunk(name, (long(range[0]), long(range[1])))
        fh.close()
        return ci
开发者ID:3DMeny,项目名称:pyload,代码行数:30,代码来源:HTTPChunk.py


示例11: process

    def process(self, pyfile):
        if not self.account:
            self.logError(_("Please enter your premium4.me account or deactivate this plugin"))
            self.fail("No premium4.me account provided")

        self.logDebug("premium4.me: Old URL: %s" % pyfile.url)

        tra = self.getTraffic()
        
        #raise timeout to 2min
        self.req.setOption("timeout", 120)
        
        self.download("http://premium4.me/api/getfile.php?authcode=%s&link=%s" % (self.account.authcode, quote(pyfile.url, "")), disposition=True)
        
        err = ''       
        if self.req.http.code == '420':
            # Custom error code send - fail
            lastDownload = fs_encode(self.lastDownload)
            
            if exists(lastDownload): 
                f = open(lastDownload, "rb")
                err = f.read(256).strip()
                f.close()
                remove(lastDownload)
            else:
                err = 'File does not exist'
        
        trb = self.getTraffic()
        self.logInfo("Filesize: %d, Traffic used %d, traffic left %d" % (pyfile.size, tra-trb, trb))
                    
        if err: self.fail(err)
开发者ID:4Christopher,项目名称:pyload,代码行数:31,代码来源:Premium4Me.py


示例12: downloads

def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not isdir(root):
        return base([_('Download directory not found.')])
    data = {
        'folder': [],
        'files': []
    }

    items = listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if isdir(save_join(root, item)):
            folder = {
                'name': item,
                'path': item,
                'files': []
            }
            files = listdir(save_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if isfile(save_join(root, item, file)):
                        folder['files'].append(file)
                except:
                    pass

            data['folder'].append(folder)
        elif isfile(join(root, item)):
            data['files'].append(item)

    return render_to_response('downloads.html', {'files': data}, [pre_processor])
开发者ID:EikeKre,项目名称:pyload,代码行数:32,代码来源:pyload_app.py


示例13: extract

    def extract(self, password=None):
        command = "x" if self.fullpath else "e"

        p = self.call_cmd(command, fs_encode(self.filename), self.out, password=password)

        renice(p.pid, self.renice)

        #: Communicate and retrieve stderr
        self._progress(p)
        err = p.stderr.read().strip()

        if err:
            if self.re_wrongpwd.search(err):
                raise PasswordError

            elif self.re_wrongcrc.search(err):
                raise CRCError(err)

            else:  #: Raise error if anything is on stderr
                raise ArchiveError(err)

        if p.returncode:
            raise ArchiveError(_("Process return code: %d") % p.returncode)

        self.files = self.list(password)
开发者ID:earthGavinLee,项目名称:pyload,代码行数:25,代码来源:UnRar.py


示例14: downloadFinished

    def downloadFinished(self, pyfile):
        """ 
        Compute checksum for the downloaded file and compare it with the hash provided by the hoster.
        pyfile.plugin.check_data should be a dictionary which can contain:
        a) if known, the exact filesize in bytes (e.g. "size": 123456789)
        b) hexadecimal hash string with algorithm name as key (e.g. "md5": "d76505d0869f9f928a17d42d66326307")    
        """
        if hasattr(pyfile.plugin, "check_data") and (isinstance(pyfile.plugin.check_data, dict)):
            data = pyfile.plugin.check_data.copy()
        elif hasattr(pyfile.plugin, "api_data") and (isinstance(pyfile.plugin.api_data, dict)):
            data = pyfile.plugin.api_data.copy()
        else:
            return

        self.logDebug(data)

        if not pyfile.plugin.lastDownload:
            self.checkFailed(pyfile, None, "No file downloaded")

        local_file = fs_encode(pyfile.plugin.lastDownload)
        #download_folder = self.config['general']['download_folder']
        #local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name))

        if not isfile(local_file):
            self.checkFailed(pyfile, None, "File does not exist")

            # validate file size
        if "size" in data:
            api_size = int(data['size'])
            file_size = getsize(local_file)
            if api_size != file_size:
                self.logWarning("File %s has incorrect size: %d B (%d expected)" % (pyfile.name, file_size, api_size))
                self.checkFailed(pyfile, local_file, "Incorrect file size")
            del data['size']

        # validate checksum
        if data and self.config['general']['checksum']:
            if "checksum" in data:
                data['md5'] = data['checksum']

            for key in self.algorithms:
                if key in data:
                    checksum = computeChecksum(local_file, key.replace("-", "").lower())
                    if checksum:
                        if checksum == data[key].lower():
                            self.logInfo('File integrity of "%s" verified by %s checksum (%s).' % (pyfile.name,
                                                                                                   key.upper(),
                                                                                                   checksum))
                            return
                        else:
                            self.logWarning("%s checksum for file %s does not match (%s != %s)" % (key.upper(),
                                                                                                   pyfile.name,
                                                                                                   checksum,
                                                                                                   data[key]))
                            self.checkFailed(pyfile, local_file, "Checksums do not match")
                    else:
                        self.logWarning("Unsupported hashing algorithm: %s" % key.upper())
            else:
                self.logWarning("Unable to validate checksum for file %s" % pyfile.name)
开发者ID:Robbi373,项目名称:pyload,代码行数:59,代码来源:Checksum.py


示例15: verify

    def verify(self):
        with zipfile.ZipFile(fs_encode(self.filename), 'r', allowZip64=True) as z:
            badfile = z.testzip()

            if badfile:
                raise CRCError(badfile)
            else:
                raise PasswordError
开发者ID:earthGavinLee,项目名称:pyload,代码行数:8,代码来源:UnZip.py


示例16: repair

    def repair(self):
        p = self.call_cmd("rc", fs_encode(self.filename))

        #: Communicate and retrieve stderr
        self._progress(p)
        err = p.stderr.read().strip()
        if err or p.returncode:
            return False
        return True
开发者ID:earthGavinLee,项目名称:pyload,代码行数:9,代码来源:UnRar.py


示例17: verify

    def verify(self, password):
        p = self.call_cmd("t", "-v", fs_encode(self.filename), password=password)
        self._progress(p)
        err = p.stderr.read().strip()

        if self.re_wrongpwd.search(err):
            raise PasswordError

        if self.re_wrongcrc.search(err):
            raise CRCError(err)
开发者ID:earthGavinLee,项目名称:pyload,代码行数:10,代码来源:UnRar.py


示例18: save

 def save(self):
     fs_name = fs_encode("%s.chunks" % self.name)
     fh = codecs.open(fs_name, "w", "utf_8")
     fh.write("name:%s\n" % self.name)
     fh.write("size:%s\n" % self.size)
     for i, c in enumerate(self.chunks):
         fh.write("#%d:\n" % i)
         fh.write("\tname:%s\n" % c[0])
         fh.write("\trange:%i-%i\n" % c[1])
     fh.close()
开发者ID:3DMeny,项目名称:pyload,代码行数:10,代码来源:HTTPChunk.py


示例19: check

    def check(self, password):
        p = self.call_cmd("l", "-slt", fs_encode(self.filename))
        out, err = p.communicate()

        # check if output or error macthes the 'wrong password'-Regexp
        if self.re_wrongpwd.search(out):
            raise PasswordError

        if self.re_wrongcrc.search(out):
            raise CRCError(_("Header protected"))
开发者ID:kurtiss,项目名称:htpc,代码行数:10,代码来源:SevenZip.py


示例20: reload_passwords

    def reload_passwords(self):
        try:
            passwords = []

            file = fs_encode(self.get_config('passwordfile'))
            with open(file) as f:
                for pw in f.read().splitlines():
                    passwords.append(pw)

        except IOError, e:
            self.log_error(e)
开发者ID:earthGavinLee,项目名称:pyload,代码行数:11,代码来源:ExtractArchive.py



注:本文中的module.utils.fs_encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.html_unescape函数代码示例发布时间:2022-05-27
下一篇:
Python json.loads函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap