many pep8 improvements
This commit is contained in:
1 parent
b716df1a05
commit
4b2ba185ae
117 files changed
+7160
-5670
No files matched your search
+25
-16
@@ -12,6 +12,7 @@ from gluon.sanitizer import sanitize
|
||||
from gluon.contrib.markmin.markmin2latex import markmin2latex
|
||||
from gluon.contrib.markmin.markmin2pdf import markmin2pdf
|
||||
|
||||
|
||||
def wrapper(f):
|
||||
def g(data):
|
||||
try:
|
||||
@@ -25,39 +26,47 @@ def wrapper(f):
|
||||
raise HTTP(405, '%s error' % e)
|
||||
return g
|
||||
|
||||
|
||||
def latex_from_html(html):
|
||||
markmin=TAG(html).element('body').flatten(markmin_serializer)
|
||||
markmin = TAG(html).element('body').flatten(markmin_serializer)
|
||||
return XML(markmin2latex(markmin))
|
||||
|
||||
|
||||
def pdflatex_from_html(html):
|
||||
if os.system('which pdflatex > /dev/null')==0:
|
||||
markmin=TAG(html).element('body').flatten(markmin_serializer)
|
||||
out,warnings,errors=markmin2pdf(markmin)
|
||||
if os.system('which pdflatex > /dev/null') == 0:
|
||||
markmin = TAG(html).element('body').flatten(markmin_serializer)
|
||||
out, warnings, errors = markmin2pdf(markmin)
|
||||
if errors:
|
||||
current.response.headers['Content-Type']='text/html'
|
||||
raise HTTP(405,HTML(BODY(H1('errors'),
|
||||
UL(*errors),
|
||||
H1('warnings'),
|
||||
UL(*warnings))).xml())
|
||||
current.response.headers['Content-Type'] = 'text/html'
|
||||
raise HTTP(405, HTML(BODY(H1('errors'),
|
||||
UL(*errors),
|
||||
H1('warnings'),
|
||||
UL(*warnings))).xml())
|
||||
else:
|
||||
return XML(out)
|
||||
|
||||
|
||||
def pyfpdf_from_html(html):
|
||||
request = current.request
|
||||
|
||||
def image_map(path):
|
||||
if path.startswith('/%s/static/' % request.application):
|
||||
return os.path.join(request.folder,path.split('/',2)[2])
|
||||
return 'http%s://%s%s' % (request.is_https and 's' or '',request.env.http_host, path)
|
||||
class MyFPDF(FPDF, HTMLMixin): pass
|
||||
pdf=MyFPDF()
|
||||
return os.path.join(request.folder, path.split('/', 2)[2])
|
||||
return 'http%s://%s%s' % (request.is_https and 's' or '', request.env.http_host, path)
|
||||
|
||||
class MyFPDF(FPDF, HTMLMixin):
|
||||
pass
|
||||
pdf = MyFPDF()
|
||||
pdf.add_page()
|
||||
html = sanitize(html, escape=False) #### should have better list of allowed tags
|
||||
pdf.write_html(html,image_map=image_map)
|
||||
html = sanitize(
|
||||
html, escape=False) # should have better list of allowed tags
|
||||
pdf.write_html(html, image_map=image_map)
|
||||
return XML(pdf.output(dest='S'))
|
||||
|
||||
|
||||
def pdf_from_html(html):
|
||||
# try use latex and pdflatex
|
||||
if os.system('which pdflatex > /dev/null')==0:
|
||||
if os.system('which pdflatex > /dev/null') == 0:
|
||||
return pdflatex_from_html(html)
|
||||
else:
|
||||
return pyfpdf_from_html(html)
|
||||
Reference in new issue
Block a user