本文整理汇总了Python中pyload.utils.fs_encode函数的典型用法代码示例。如果您正苦于以下问题:Python fs_encode函数的具体用法?Python fs_encode怎么用?Python fs_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fs_encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: packageFinished
def packageFinished(self, pypack):
download_folder = fs_join(self.config.get("general", "download_folder"), pypack.folder, "")
for link in pypack.getChildren().itervalues():
file_type = 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 isfile(hash_file):
self.logWarning(_("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.logDebug(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 == 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:PaddyPat,项目名称:pyload,代码行数:30,代码来源:Checksum.py
示例2: _copyChunks
def _copyChunks(self):
init = fs_encode(self.info.getChunkName(0)) #: initial chunk name
if self.info.getCount() > 1:
with open(init, "rb+") as fo: #: first chunkfile
for i in xrange(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))
with open(fname, "rb") as fi:
buf = 32 * 1024
while True: #: copy in chunks, consumes less memory
data = fi.read(buf)
if not data:
break
fo.write(data)
if fo.tell() < self.info.getChunkRange(i)[1]:
reshutil.move(init)
self.info.remove() #: there are probably invalid chunks
raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.")
reshutil.move(fname) #: remove chunk
if self.nameDisposition and self.disposition:
self.filename = fs_join(os.path.dirname(self.filename), self.nameDisposition)
shutil.move(init, fs_encode(self.filename))
self.info.remove() #: remove info file
开发者ID:Bobbaone,项目名称:pyload,代码行数:28,代码来源:HTTPDownload.py
示例3: 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:torrero007,项目名称:pyload,代码行数:8,代码来源:pyloadweb.py
示例4: scan
def scan(self, pyfile, thread):
file = fs_encode(pyfile.plugin.lastDownload)
filename = os.path.basename(pyfile.plugin.lastDownload)
cmdfile = fs_encode(self.getConfig('cmdfile'))
cmdargs = fs_encode(self.getConfig('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.logInfo(filename, out)
if err:
self.logWarning(filename, err)
if not self.getConfig('ignore-err'):
self.logDebug("Delete/Quarantine task is aborted")
return
if p.returncode:
pyfile.error = _("infected file")
action = self.getConfig('action')
try:
if action == "Delete":
if not self.getConfig('deltotrash'):
os.remove(file)
elif self.trashable:
send2trash.send2trash(file)
else:
self.logWarning(_("Unable to move file to trash, move to quarantine instead"))
pyfile.setCustomStatus(_("file moving"))
shutil.move(file, self.getConfig('quardir'))
elif action == "Quarantine":
pyfile.setCustomStatus(_("file moving"))
shutil.move(file, self.getConfig('quardir'))
except (IOError, shutil.Error), e:
self.logError(filename, action + " action failed!", e)
elif not out and not err:
self.logDebug(filename, "No infected file found")
开发者ID:PaddyPat,项目名称:pyload,代码行数:52,代码来源:AntiVirus.py
示例5: 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:achimschneider,项目名称:pyload,代码行数:30,代码来源:HTTPChunk.py
示例6: 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(fs_join(root, item)):
folder = {
'name': item,
'path': item,
'files': []
}
files = listdir(fs_join(root, item))
for file in sorted([fs_decode(x) for x in files]):
try:
if isfile(fs_join(root, item, file)):
folder['files'].append(file)
except Exception:
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:torrero007,项目名称:pyload,代码行数:32,代码来源:pyloadweb.py
示例7: 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:achimschneider,项目名称:pyload,代码行数:25,代码来源:UnRar.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 = fs_join(self.out, os.path.basename(f.strip()))
if os.path.isfile(f):
result.add(fs_join(self.out, os.path.basename(f)))
else:
for f in fs_decode(out).splitlines():
f = f.strip()
result.add(fs_join(self.out, f))
return list(result)
开发者ID:achimschneider,项目名称:pyload,代码行数:25,代码来源:UnRar.py
示例9: 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:achimschneider,项目名称:pyload,代码行数:8,代码来源:UnZip.py
示例10: 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:achimschneider,项目名称:pyload,代码行数:9,代码来源:UnRar.py
示例11: 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:achimschneider,项目名称:pyload,代码行数:10,代码来源:HTTPChunk.py
示例12: 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:Bobbaone,项目名称:pyload,代码行数:10,代码来源:SevenZip.py
示例13: 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:achimschneider,项目名称:pyload,代码行数:10,代码来源:UnRar.py
示例14: reloadPasswords
def reloadPasswords(self):
try:
passwords = []
file = fs_encode(self.getConfig('passwordfile'))
with open(file) as f:
for pw in f.read().splitlines():
passwords.append(pw)
except IOError, e:
self.logError(e)
开发者ID:PaddyPat,项目名称:pyload,代码行数:11,代码来源:ExtractArchive.py
示例15: addPassword
def addPassword(self, password):
""" Adds a password to saved list"""
try:
self.passwords = uniqify([password] + self.passwords)
file = fs_encode(self.getConfig('passwordfile'))
with open(file, "wb") as f:
for pw in self.passwords:
f.write(pw + '\n')
except IOError, e:
self.logError(e)
开发者ID:PaddyPat,项目名称:pyload,代码行数:12,代码来源:ExtractArchive.py
示例16: downloadPreparing
def downloadPreparing(self, pyfile):
uar = self.getConfig('uar')
uaf = fs_encode(self.getConfig('uaf'))
if uar and os.path.isfile(uaf):
with open(uaf) as f:
uas = random.choice([ua for ua in f.read().splitlines()])
else:
uas = self.getConfig('uas')
if uas:
self.logDebug("Use custom user-agent string: " + uas)
pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, uas.encode('utf-8'))
开发者ID:Bobbaone,项目名称:pyload,代码行数:13,代码来源:UserAgentSwitcher.py
示例17: verify
def verify(self, password):
# 7z can't distinguish crc and pw error in test
p = self.call_cmd("l", "-slt", fs_encode(self.filename))
out, err = p.communicate()
if self.re_wrongpwd.search(out):
raise PasswordError
if self.re_wrongpwd.search(err):
raise PasswordError
if self.re_wrongcrc.search(err):
raise CRCError(err)
开发者ID:Bobbaone,项目名称:pyload,代码行数:13,代码来源:SevenZip.py
示例18: periodical
def periodical(self):
folder = fs_encode(self.getConfig('folder'))
file = fs_encode(self.getConfig('file'))
try:
if not os.path.isdir(os.path.join(folder, "finished")):
os.makedirs(os.path.join(folder, "finished"))
if self.getConfig('watch_file'):
with open(file, "a+") as f:
f.seek(0)
content = f.read().strip()
if content:
f = open(file, "wb")
f.close()
name = "%s_%s.txt" % (file, time.strftime("%H-%M-%S_%d%b%Y"))
with open(fs_join(folder, "finished", name), "wb") as f:
f.write(content)
self.core.api.addPackage(f.name, [f.name], 1)
for f in os.listdir(folder):
path = os.path.join(folder, f)
if not os.path.isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."):
continue
newpath = os.path.join(folder, "finished", f if self.getConfig('keep') else "tmp_" + f)
shutil.move(path, newpath)
self.logInfo(_("Added %s from HotFolder") % f)
self.core.api.addPackage(f, [newpath], 1)
except (IOError, OSError), e:
self.logError(e)
开发者ID:Bobbaone,项目名称:pyload,代码行数:38,代码来源:HotFolder.py
示例19: decrypt
def decrypt(self, pyfile):
KEY = binascii.unhexlify(self.KEY)
IV = binascii.unhexlify(self.IV)
iv = AES.new(KEY, AES.MODE_ECB).encrypt(IV)
cipher = AES.new(KEY, AES.MODE_CFB, iv)
try:
fs_filename = fs_encode(pyfile.url.strip())
with open(fs_filename, 'r') as rsdf:
data = rsdf.read()
except IOError, e:
self.fail(e)
开发者ID:PaddyPat,项目名称:pyload,代码行数:14,代码来源:RSDF.py
示例20: check
def check(self, password):
p = self.call_cmd("l", "-v", fs_encode(self.filename), password=password)
out, err = p.communicate()
if self.re_wrongpwd.search(err):
raise PasswordError
if self.re_wrongcrc.search(err):
raise CRCError(err)
# output only used to check if passworded files are present
for attr in self.re_filelist.findall(out):
if attr[0].startswith("*"):
raise PasswordError
开发者ID:achimschneider,项目名称:pyload,代码行数:14,代码来源:UnRar.py
注:本文中的pyload.utils.fs_encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论