mirror of
https://github.com/JonathanHerrewijnen/calibre-web.git
synced 2024-11-13 06:34:26 +00:00
missing urllib migration
This commit is contained in:
parent
c3fd205b7d
commit
bf8688fee1
@ -245,7 +245,10 @@ def get_valid_filename(value, replace_whitespace=True):
|
|||||||
value=value.replace(u'ß',u'ss')
|
value=value.replace(u'ß',u'ss')
|
||||||
value = unicodedata.normalize('NFKD', value)
|
value = unicodedata.normalize('NFKD', value)
|
||||||
re_slugify = re.compile('[\W\s-]', re.UNICODE)
|
re_slugify = re.compile('[\W\s-]', re.UNICODE)
|
||||||
value = str(re_slugify.sub('', value).strip())
|
try:
|
||||||
|
value = str(re_slugify.sub('', value).strip())
|
||||||
|
except: #will exception on Python2.7
|
||||||
|
value = unicode(re_slugify.sub('', value).strip())
|
||||||
if replace_whitespace:
|
if replace_whitespace:
|
||||||
#*+:\"/<>? werden durch _ ersetzt
|
#*+:\"/<>? werden durch _ ersetzt
|
||||||
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
|
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
|
||||||
|
17
cps/web.py
17
cps/web.py
@ -50,10 +50,11 @@ from tornado import version as tornadoVersion
|
|||||||
from builtins import str
|
from builtins import str
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from urllib.parse import quote
|
||||||
from imp import reload
|
from imp import reload
|
||||||
from past.builtins import xrange
|
from past.builtins import xrange
|
||||||
except:
|
except:
|
||||||
pass
|
from urllib import quote
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from wand.image import Image
|
from wand.image import Image
|
||||||
@ -1243,22 +1244,22 @@ def read_book(book_id, format):
|
|||||||
zfile.close()
|
zfile.close()
|
||||||
return render_title_template('read.html', bookid=book_id, title=_(u"Read a Book"))
|
return render_title_template('read.html', bookid=book_id, title=_(u"Read a Book"))
|
||||||
elif format.lower() == "pdf":
|
elif format.lower() == "pdf":
|
||||||
all_name = str(book_id) + "/" + urllib.quote(book.data[0].name) + ".pdf"
|
all_name = str(book_id) + "/" + quote(book.data[0].name) + ".pdf"
|
||||||
tmp_file = os.path.join(book_dir, urllib.quote(book.data[0].name)) + ".pdf"
|
tmp_file = os.path.join(book_dir, quote(book.data[0].name)) + ".pdf"
|
||||||
if not os.path.exists(tmp_file):
|
if not os.path.exists(tmp_file):
|
||||||
pdf_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".pdf"
|
pdf_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".pdf"
|
||||||
copyfile(pdf_file, tmp_file)
|
copyfile(pdf_file, tmp_file)
|
||||||
return render_title_template('readpdf.html', pdffile=all_name, title=_(u"Read a Book"))
|
return render_title_template('readpdf.html', pdffile=all_name, title=_(u"Read a Book"))
|
||||||
elif format.lower() == "txt":
|
elif format.lower() == "txt":
|
||||||
all_name = str(book_id) + "/" + urllib.quote(book.data[0].name) + ".txt"
|
all_name = str(book_id) + "/" + quote(book.data[0].name) + ".txt"
|
||||||
tmp_file = os.path.join(book_dir, urllib.quote(book.data[0].name)) + ".txt"
|
tmp_file = os.path.join(book_dir, quote(book.data[0].name)) + ".txt"
|
||||||
if not os.path.exists(all_name):
|
if not os.path.exists(all_name):
|
||||||
txt_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".txt"
|
txt_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".txt"
|
||||||
copyfile(txt_file, tmp_file)
|
copyfile(txt_file, tmp_file)
|
||||||
return render_title_template('readtxt.html', txtfile=all_name, title=_(u"Read a Book"))
|
return render_title_template('readtxt.html', txtfile=all_name, title=_(u"Read a Book"))
|
||||||
elif format.lower() == "cbr":
|
elif format.lower() == "cbr":
|
||||||
all_name = str(book_id) + "/" + urllib.quote(book.data[0].name) + ".cbr"
|
all_name = str(book_id) + "/" + quote(book.data[0].name) + ".cbr"
|
||||||
tmp_file = os.path.join(book_dir, urllib.quote(book.data[0].name)) + ".cbr"
|
tmp_file = os.path.join(book_dir, quote(book.data[0].name)) + ".cbr"
|
||||||
if not os.path.exists(all_name):
|
if not os.path.exists(all_name):
|
||||||
cbr_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".cbr"
|
cbr_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".cbr"
|
||||||
copyfile(cbr_file, tmp_file)
|
copyfile(cbr_file, tmp_file)
|
||||||
@ -1290,7 +1291,7 @@ def get_download_link(book_id, format):
|
|||||||
response.headers["Content-Type"] = mimetypes.types_map['.' + format]
|
response.headers["Content-Type"] = mimetypes.types_map['.' + format]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (file_name.encode('utf-8'), format)
|
response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (quote(file_name.encode('utf-8')), format)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
Loading…
Reference in New Issue
Block a user