|
|
883749f |
From 7047c6a90535564c9d05121fc8a095aef1de3c21 Mon Sep 17 00:00:00 2001
|
|
|
883749f |
From: kernc <kerncece@gmail.com>
|
|
|
883749f |
Date: Wed, 21 Apr 2021 17:29:22 +0200
|
|
|
883749f |
Subject: [PATCH] Replace deprecated jinja2.Markup with jinja2.tojson (#11174)
|
|
|
883749f |
|
|
|
883749f |
* Replace deprecated jinja2.Markup -> markupsafe.Markup
|
|
|
883749f |
|
|
|
883749f |
* Expose |tojson as |json. Bump Jinja2 >=2.9
|
|
|
883749f |
|
|
|
883749f |
* Replace |json filter with jinja's |tojson throughout
|
|
|
883749f |
|
|
|
883749f |
* Fix test_autoload_template_has_changed
|
|
|
883749f |
---
|
|
|
883749f |
_setup_support.py | 2 +-
|
|
|
883749f |
bokeh/core/_templates/autoload_js.js | 14 +++++++-------
|
|
|
883749f |
bokeh/core/_templates/autoload_nb_js.js | 6 +++---
|
|
|
883749f |
bokeh/core/templates.py | 4 +---
|
|
|
883749f |
tests/unit/bokeh/core/test_templates.py | 2 +-
|
|
|
883749f |
5 files changed, 13 insertions(+), 15 deletions(-)
|
|
|
883749f |
|
|
|
883749f |
diff --git a/bokeh/core/_templates/autoload_js.js b/bokeh/core/_templates/autoload_js.js
|
|
|
883749f |
index 792a74c7cc2..d15ea9778e6 100644
|
|
|
883749f |
--- a/bokeh/core/_templates/autoload_js.js
|
|
|
883749f |
+++ b/bokeh/core/_templates/autoload_js.js
|
|
|
883749f |
@@ -20,7 +20,7 @@ calls it with the rendered model.
|
|
|
883749f |
return new Date();
|
|
|
883749f |
}
|
|
|
883749f |
|
|
|
883749f |
- var force = {{ force|default(False)|json }};
|
|
|
883749f |
+ var force = {{ force|default(False)|tojson }};
|
|
|
883749f |
|
|
|
883749f |
if (typeof root._bokeh_onload_callbacks === "undefined" || force === true) {
|
|
|
883749f |
root._bokeh_onload_callbacks = [];
|
|
|
883749f |
@@ -32,7 +32,7 @@ calls it with the rendered model.
|
|
|
883749f |
|
|
|
883749f |
{% block autoload_init %}
|
|
|
883749f |
{%- if elementid -%}
|
|
|
883749f |
- var element = document.getElementById({{ elementid|json }});
|
|
|
883749f |
+ var element = document.getElementById({{ elementid|tojson }});
|
|
|
883749f |
if (element == null) {
|
|
|
883749f |
console.warn("Bokeh: autoload.js configured with elementid '{{ elementid }}' but no matching script tag was found.")
|
|
|
883749f |
}
|
|
|
883749f |
@@ -91,7 +91,7 @@ calls it with the rendered model.
|
|
|
883749f |
document.body.appendChild(element);
|
|
|
883749f |
}
|
|
|
883749f |
|
|
|
883749f |
- const hashes = {{ bundle.hashes|json }};
|
|
|
883749f |
+ const hashes = {{ bundle.hashes|tojson }};
|
|
|
883749f |
|
|
|
883749f |
for (let i = 0; i < js_urls.length; i++) {
|
|
|
883749f |
const url = js_urls[i];
|
|
|
883749f |
@@ -110,17 +110,17 @@ calls it with the rendered model.
|
|
|
883749f |
}
|
|
|
883749f |
|
|
|
883749f |
{% if bundle %}
|
|
|
883749f |
- var js_urls = {{ bundle.js_urls|json }};
|
|
|
883749f |
- var css_urls = {{ bundle.css_urls|json }};
|
|
|
883749f |
+ var js_urls = {{ bundle.js_urls|tojson }};
|
|
|
883749f |
+ var css_urls = {{ bundle.css_urls|tojson }};
|
|
|
883749f |
{% else %}
|
|
|
883749f |
- var js_urls = {{ js_urls|json }};
|
|
|
883749f |
- var css_urls = {{ css_urls|json }};
|
|
|
883749f |
+ var js_urls = {{ js_urls|tojson }};
|
|
|
883749f |
+ var css_urls = {{ css_urls|tojson }};
|
|
|
883749f |
{% endif %}
|
|
|
883749f |
|
|
|
883749f |
var inline_js = [
|
|
|
883749f |
{%- for css in (bundle.css_raw if bundle else css_raw) %}
|
|
|
883749f |
function(Bokeh) {
|
|
|
883749f |
- inject_raw_css({{ css|json }});
|
|
|
883749f |
+ inject_raw_css({{ css|tojson }});
|
|
|
883749f |
},
|
|
|
883749f |
{%- endfor %}
|
|
|
883749f |
{%- for js in (bundle.js_raw if bundle else js_raw) %}
|
|
|
883749f |
diff --git a/bokeh/core/_templates/autoload_nb_js.js b/bokeh/core/_templates/autoload_nb_js.js
|
|
|
883749f |
index 2c75850b2b4..ca96a59cd2d 100644
|
|
|
883749f |
--- a/bokeh/core/_templates/autoload_nb_js.js
|
|
|
883749f |
+++ b/bokeh/core/_templates/autoload_nb_js.js
|
|
|
883749f |
@@ -132,7 +132,7 @@
|
|
|
883749f |
|
|
|
883749f |
{% block autoload_init %}
|
|
|
883749f |
if (typeof (root._bokeh_timeout) === "undefined" || force === true) {
|
|
|
883749f |
- root._bokeh_timeout = Date.now() + {{ timeout|default(0)|json }};
|
|
|
883749f |
+ root._bokeh_timeout = Date.now() + {{ timeout|default(0)|tojson }};
|
|
|
883749f |
root._bokeh_failed_load = false;
|
|
|
883749f |
}
|
|
|
883749f |
|
|
|
883749f |
@@ -153,7 +153,7 @@
|
|
|
883749f |
""}};
|
|
|
883749f |
|
|
|
883749f |
function display_loaded() {
|
|
|
883749f |
- var el = document.getElementById({{ elementid|json }});
|
|
|
883749f |
+ var el = document.getElementById({{ elementid|tojson }});
|
|
|
883749f |
if (el != null) {
|
|
|
883749f |
el.textContent = "BokehJS is loading...";
|
|
|
883749f |
}
|
|
|
883749f |
@@ -181,7 +181,7 @@
|
|
|
883749f |
console.log("Bokeh: BokehJS failed to load within specified timeout.");
|
|
|
883749f |
root._bokeh_failed_load = true;
|
|
|
883749f |
} else if (force !== true) {
|
|
|
883749f |
- var cell = $(document.getElementById({{ elementid|json }})).parents('.cell').data().cell;
|
|
|
883749f |
+ var cell = $(document.getElementById({{ elementid|tojson }})).parents('.cell').data().cell;
|
|
|
883749f |
cell.output_area.append_execute_result(NB_LOAD_WARNING)
|
|
|
883749f |
}
|
|
|
883749f |
{% endblock %}
|
|
|
883749f |
diff --git a/bokeh/core/templates.py b/bokeh/core/templates.py
|
|
|
883749f |
index 10344ecaf7d..c7cd25ea7f2 100644
|
|
|
883749f |
--- a/bokeh/core/templates.py
|
|
|
883749f |
+++ b/bokeh/core/templates.py
|
|
|
883749f |
@@ -36,12 +36,11 @@
|
|
|
883749f |
#-----------------------------------------------------------------------------
|
|
|
883749f |
|
|
|
883749f |
# Standard library imports
|
|
|
883749f |
-import json
|
|
|
883749f |
import sys
|
|
|
883749f |
from os.path import dirname, join
|
|
|
883749f |
|
|
|
883749f |
# External imports
|
|
|
883749f |
-from jinja2 import Environment, FileSystemLoader, Markup
|
|
|
883749f |
+from jinja2 import Environment, FileSystemLoader
|
|
|
883749f |
|
|
|
883749f |
#-----------------------------------------------------------------------------
|
|
|
883749f |
# Globals and constants
|
|
|
883749f |
@@ -86,7 +85,6 @@ def get_env():
|
|
|
883749f |
#-----------------------------------------------------------------------------
|
|
|
883749f |
|
|
|
883749f |
_env = get_env()
|
|
|
883749f |
-_env.filters['json'] = lambda obj: Markup(json.dumps(obj))
|
|
|
883749f |
|
|
|
883749f |
#-----------------------------------------------------------------------------
|
|
|
883749f |
# General API
|