本文整理汇总了Python中flask.Markup.upper方法的典型用法代码示例。如果您正苦于以下问题:Python Markup.upper方法的具体用法?Python Markup.upper怎么用?Python Markup.upper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Markup
的用法示例。
在下文中一共展示了Markup.upper方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: choose_filename
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import upper [as 别名]
def choose_filename(f,text=False):
'''
Elige el archivo correcto
'''
text=slugify(text) if text else text
srcs = f['file']['src']
fns = f['file']['fn']
chosen = None
max_count = -1
has_text = 0
try:
for hexuri,src in srcs.items():
if 'bl' in src and src['bl']!=0:
continue
this_has_text=0
for crc,srcfn in src['fn'].items():
#si no tiene nombre no se tiene en cuenta
m = srcfn['m'] if len(fns[crc]['n'])>0 else 0
if 'c' in fns[crc]:
fns[crc]['c']+=m
else:
fns[crc]['c']=m
if text:
slugified_fn = slugify(fns[crc]['n']).strip()
if len(slugified_fn)>0:
#TODO hace lo mismo que para poner el nombre en negrita y sacar el mejor texto aunque no tenga tildes o no venga unido por espacios
if slugified_fn.upper().find(text.upper())!=-1:
this_has_text = 2000
else:
matches = 0
for word in [re.escape(w) for w in text.split(" ")]:
matches += len(re.findall(r"/((?:\b|_)%s(?:\b|_))/i"%word, slugified_fn))
if matches>0:
this_has_text = 1000 + matches
f['file']['fn'][crc]['tht'] = this_has_text
better = fns[crc]['c']>max_count
if this_has_text > has_text or (better and this_has_text==has_text):
has_text = this_has_text
chosen = crc
max_count = fns[crc]['c']
except KeyError as e: #para los sources que tienen nombre pero no estan en el archivo
logging.exception(e)
f['view']['url'] = mid2url(hex2mid(f['file']['_id']))
if chosen:
filename = fns[chosen]['n']
ext = fns[chosen]['x']
else: #uses filename from src
srcurl = ""
for hexuri,src in srcs.items():
if src['url'].find("/")!=-1:
srcurl = src['url']
if srcurl=="":
return
srcurl = srcurl[srcurl.rfind("/")+1:]
ext = srcurl[srcurl.rfind(".")+1:]
filename = srcurl[0:srcurl.rfind(".")]
filename = Markup(filename).striptags()[:512]
if not ext in EXTENSIONS:
filename += ext
ext=""
nfilename = filename
else:
#clean filename
end = filename.upper().rfind("."+ext.upper())
if end == -1:
nfilename = filename
else:
nfilename = filename.strip()[0:end]
f['view']['fn'] = filename #TODO para los tipo archive buscar el tipo real en el nombre (mp3,avi...)
f['view']['fnx'] = ext
f['view']['efn'] = filename.replace(" ", "%20")
#poner bonito nombre del archivo
if nfilename.find(" ")==-1:
nfilename = nfilename.replace(".", " ")
f['view']['nfn'] = nfilename.replace("_", " ")
#nombre del archivo escapado para generar las url de descarga
f['view']['qfn'] = u(filename).encode("UTF-8")
#nombre del archivo con las palabras que coinciden con la busqueda resaltadas
if not text:# or not has_text:
f['view']['fnh'] = f['view']['fnhs'] = filename
else:
f['view']['fnh'], f['view']['fnhs'] = highlight(text,filename,True)
return has_text>0