Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 177b197

Browse files
committed
Don't use tornado template class directly, as suggested by @andreabedini
1 parent d8f6ec9 commit 177b197

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

lib/matplotlib/backends/backend_webagg.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,17 @@ def __init__(self, application, request, **kwargs):
427427
request, **kwargs)
428428

429429
def get(self, fignum):
430-
with open(os.path.join(WebAggApplication._mpl_dirs['web_backend'],
431-
'single_figure.html')) as fd:
432-
tpl = fd.read()
433-
434430
fignum = int(fignum)
435431
manager = Gcf.get_fig_manager(fignum)
436432

437433
ws_uri = 'ws://{req.host}{prefix}/'.format(req=self.request,
438434
prefix=self.url_prefix)
439-
t = tornado.template.Template(tpl)
440-
self.write(t.generate(
435+
self.render('single_figure.html',
441436
prefix=self.url_prefix,
442437
ws_uri=ws_uri,
443438
fig_id=fignum,
444439
toolitems=NavigationToolbar2WebAgg.toolitems,
445-
canvas=manager.canvas))
440+
canvas=manager.canvas)
446441

447442
class AllFiguresPage(tornado.web.RequestHandler):
448443
def __init__(self, application, request, **kwargs):
@@ -451,36 +446,26 @@ def __init__(self, application, request, **kwargs):
451446
request, **kwargs)
452447

453448
def get(self):
454-
with open(os.path.join(WebAggApplication._mpl_dirs['web_backend'],
455-
'all_figures.html')) as fd:
456-
tpl = fd.read()
457-
458449
ws_uri = 'ws://{req.host}{prefix}/'.format(req=self.request,
459450
prefix=self.url_prefix)
460-
t = tornado.template.Template(tpl)
461-
462-
self.write(t.generate(
451+
self.render(
452+
"all_figures.html",
463453
prefix=self.url_prefix,
464454
ws_uri=ws_uri,
465-
figures = sorted(list(Gcf.figs.items()), key=lambda item: item[0]),
466-
toolitems=NavigationToolbar2WebAgg.toolitems))
455+
figures=sorted(list(Gcf.figs.items()), key=lambda item: item[0]),
456+
toolitems=NavigationToolbar2WebAgg.toolitems)
467457

468458

469459
class MPLInterfaceJS(tornado.web.RequestHandler):
470460
def get(self):
471-
with open(os.path.join(WebAggApplication._mpl_dirs['web_backend'],
472-
'mpl_interface.js')) as fd:
473-
tpl = fd.read()
474-
475461
manager = Gcf.get_fig_manager(1)
476462
canvas = manager.canvas
477463

478464
self.set_header('Content-Type', 'application/javascript')
479465

480-
t = tornado.template.Template(tpl)
481-
self.write(t.generate(
466+
self.render("mpl_interface.js",
482467
toolitems=NavigationToolbar2WebAgg.toolitems,
483-
canvas=canvas))
468+
canvas=canvas)
484469

485470

486471
class Download(tornado.web.RequestHandler):
@@ -602,12 +587,13 @@ def __init__(self, url_prefix=''):
602587
(url_prefix + r'/([0-9]+)/ws', self.WebSocket),
603588

604589
# Handles the downloading (i.e., saving) of static images
605-
(url_prefix + r'/([0-9]+)/download.([a-z]+)', self.Download),
590+
(url_prefix + r'/([0-9]+)/download.([a-z0-9.]+)', self.Download),
606591

607592
# The page that contains all of the figures
608593
(url_prefix + r'/?', self.AllFiguresPage,
609594
{'url_prefix': url_prefix}),
610-
])
595+
],
596+
template_path=self._mpl_dirs['web_backend'])
611597

612598
@classmethod
613599
def initialize(cls, url_prefix=''):

0 commit comments

Comments
 (0)