Source code for bokeh.protocol.messages.pull_doc_reply
#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromtypingimportTYPE_CHECKING,Any,TypedDict# Bokeh importsfrom...core.typesimportIDfrom..exceptionsimportProtocolErrorfrom..messageimportMessageifTYPE_CHECKING:from...document.documentimportDocJson,Document#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('pull_doc_reply',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------classPullDoc(TypedDict):doc:DocJson
[docs]classpull_doc_reply(Message[PullDoc]):''' Define the ``PULL-DOC-REPLY`` message for replying to Document pull requests from clients The ``content`` fragment of for this message is has the form: .. code-block:: python { 'doc' : <Document JSON> } '''msgtype='PULL-DOC-REPLY'
[docs]@classmethoddefcreate(cls,request_id:ID,document:Document,**metadata:Any)->pull_doc_reply:''' Create an ``PULL-DOC-REPLY`` message Args: request_id (str) : The message ID for the message that issues the pull request document (Document) : The Document to reply with Any additional keyword arguments will be put into the message ``metadata`` fragment as-is. '''header=cls.create_header(request_id=request_id)content=PullDoc(doc=document.to_json())msg=cls(header,metadata,content)returnmsg
defpush_to_document(self,doc:Document)->None:if'doc'notinself.content:raiseProtocolError("No doc in PULL-DOC-REPLY")doc.replace_with_json(self.content['doc'])