Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed escape workaround for png exports of HTML models #1206

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions panel/io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

import io

from contextlib import contextmanager
from six import string_types

import param

from bokeh.document.document import Document
from bokeh.embed import file_html
from bokeh.io.export import export_png
from bokeh.models import Div
from bokeh.resources import CDN
from pyviz_comms import Comm

from ..config import config
from ..models import HTML
from .embed import embed_state
from .model import add_to_doc
from .state import state
Expand Down Expand Up @@ -48,36 +43,6 @@ def save_png(model, filename):
export_png(model, filename=filename, webdriver=webdriver)


@contextmanager
def swap_html_model():
"""
Temporary fix to swap HTML model for Div model during png export
to avoid issues with DOMParser compatibility in PhantomJS.

Can be removed when switching to chromedriver.
"""

from ..viewable import Viewable

state._html_escape = False
swapped = []
for viewable in param.concrete_descendents(Viewable).values():
model = getattr(viewable, '_bokeh_model', None)
try:
swap_model = issubclass(model, HTML)
assert swap_model
except Exception:
continue
else:
viewable._bokeh_model = Div
swapped.append(viewable)
try:
yield
finally:
state._html_escape = True
for viewable in swapped:
viewable._bokeh_model = HTML

#---------------------------------------------------------------------
# Public API
#---------------------------------------------------------------------
Expand Down Expand Up @@ -130,8 +95,7 @@ def save(panel, filename, title=None, resources=None, template=None,
doc = Document()
comm = Comm()
with config.set(embed=embed):
with swap_html_model():
model = panel.get_root(doc, comm)
model = panel.get_root(doc, comm)
if embed:
embed_state(
panel, model, doc, max_states, max_opts, embed_json,
Expand Down
3 changes: 0 additions & 3 deletions panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class _state(param.Parameterized):
# Used to ensure that events are not scheduled from the wrong thread
_thread_id = None

# Temporary flag to allow using Div model on static export
_html_escape = True

_comm_manager = _CommManager

# An index of all currently active views
Expand Down
27 changes: 1 addition & 26 deletions panel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
except ImportError:
from collections import MutableSequence, MutableMapping

try:
from html import escape as _escape
except Exception:
from xml.sax.saxutils import quoteattr
from html import escape # noqa

import param
import numpy as np
Expand All @@ -33,28 +30,6 @@
unicode = str


html_escape_table = {
'"': """,
"'": "'"
}


def escape(string):
"""
Temporary wrapper around HTML escaping to allow using Div model
during static png exports.
"""
from .io import state

if state._html_escape:
if sys.version_info.major == 2:
return quoteattr(string, html_escape_table)[1:-1]
else:
return _escape(string)
else:
return string


def isfile(path):
"""Safe version of os.path.isfile robust to path length issues on Windows"""
try:
Expand Down