# Path: spyder_notebook/utils/localization.py

# 
# Path: spyder_notebook/widgets/dom.py
# class DOMWidget(WebView):
#     """Widget to do DOM manipulations using Javascript."""
# 
#     def __init__(self, parent):
#         """Constructor."""
#         super().__init__(parent)
#         if WEBENGINE:
#             self.dom = self.page()
#         else:
#             self.dom = self.page().mainFrame()
# 
#     def evaluate(self, script):
#         """
#         Evaluate script in page frame.
# 
#         :param script: The script to evaluate.
#         """
#         if WEBENGINE:
#             return self.dom.runJavaScript("{}".format(script))
#         else:
#             return self.dom.evaluateJavaScript("{}".format(script))
# 
#     def mousedown(self, selector, btn=0):
#         """
#         Simulate a mousedown event on the targeted element.
# 
#         :param selector: A CSS3 selector to targeted element.
#         :param btn: The number of mouse button.
#             0 - left button,
#             1 - middle button,
#             2 - right button
#         """
#         return self.evaluate("""
#             (function () {{
#                 var element = document.querySelector({0});
#                 var evt = document.createEvent("MouseEvents");
#                 evt.initMouseEvent("mousedown", true, true, window,
#                                    1, 1, 1, 1, 1, false, false, false, false,
#                                    {1}, element);
#                 return element.dispatchEvent(evt);
#             }})();
#         """.format(repr(selector), repr(btn)))
# 
#     def set_input_value(self, selector, value):
#         """Set the value of the input matched by given selector."""
#         script = 'document.querySelector("%s").setAttribute("value", "%s")'
#         script = script % (selector, value)
#         self.evaluate(script)


import json
import os
import os.path as osp
import sys
import requests
        import webbrowser
from string import Template
from qtpy.QtCore import QUrl, Qt
from qtpy.QtGui import QFontMetrics, QFont
from qtpy.QtWebEngineWidgets import (QWebEnginePage, QWebEngineSettings,
                                     QWebEngineView, WEBENGINE)
from qtpy.QtWidgets import (QApplication, QMenu, QVBoxLayout, QWidget,
                            QMessageBox)
from notebook.utils import url_path_join, url_escape
from spyder.config.base import get_image_path, get_module_source_path
from spyder.utils.qthelpers import add_actions
from spyder.utils import sourcecode
from spyder.widgets.findreplace import FindReplace
from spyder_notebook.utils.localization import _
from spyder_notebook.widgets.dom import DOMWidget
    from spyder.utils.qthelpers import qapplication
    def get_session_url(self):
        """
        Get the kernel sessions URL of the client.

        Return a str with the URL or None, if no server is associated to
        the client.
        """
        if self.server_url:
            session_url = url_path_join(self.server_url, 'api/sessions')
            return self.add_token(session_url)
        else:
            return None

    def get_kernel_id(self):
        """
        Get the kernel id of the client.

        Return a str with the kernel id or None. On error, display a dialog
        box and return None.
        """
        sessions_url = self.get_session_url()
        if not sessions_url:
            return None

        try:
            sessions_response = requests.get(sessions_url)
        except requests.exceptions.RequestException as exception:
            msg = _('Spyder could not get a list of sessions '
                    'from the Jupyter Notebook server. '
                    'Message: {}').format(exception)

# Path: spyder_notebook/utils/localization.py

# 
# Path: spyder_notebook/widgets/dom.py
# class DOMWidget(WebView):
#     """Widget to do DOM manipulations using Javascript."""
# 
#     def __init__(self, parent):
#         """Constructor."""
#         super().__init__(parent)
#         if WEBENGINE:
#             self.dom = self.page()
#         else:
#             self.dom = self.page().mainFrame()
# 
#     def evaluate(self, script):
#         """
#         Evaluate script in page frame.
# 
#         :param script: The script to evaluate.
#         """
#         if WEBENGINE:
#             return self.dom.runJavaScript("{}".format(script))
#         else:
#             return self.dom.evaluateJavaScript("{}".format(script))
# 
#     def mousedown(self, selector, btn=0):
#         """
#         Simulate a mousedown event on the targeted element.
# 
#         :param selector: A CSS3 selector to targeted element.
#         :param btn: The number of mouse button.
#             0 - left button,
#             1 - middle button,
#             2 - right button
#         """
#         return self.evaluate("""
#             (function () {{
#                 var element = document.querySelector({0});
#                 var evt = document.createEvent("MouseEvents");
#                 evt.initMouseEvent("mousedown", true, true, window,
#                                    1, 1, 1, 1, 1, false, false, false, false,
#                                    {1}, element);
#                 return element.dispatchEvent(evt);
#             }})();
#         """.format(repr(selector), repr(btn)))
# 
#     def set_input_value(self, selector, value):
#         """Set the value of the input matched by given selector."""
#         script = 'document.querySelector("%s").setAttribute("value", "%s")'
#         script = script % (selector, value)
#         self.evaluate(script)


# Path: spyder_notebook/widgets/client.py
import json
import os
import os.path as osp
import sys
import requests
        import webbrowser
from string import Template
from qtpy.QtCore import QUrl, Qt
from qtpy.QtGui import QFontMetrics, QFont
from qtpy.QtWebEngineWidgets import (QWebEnginePage, QWebEngineSettings,
                                     QWebEngineView, WEBENGINE)
from qtpy.QtWidgets import (QApplication, QMenu, QVBoxLayout, QWidget,
                            QMessageBox)
from notebook.utils import url_path_join, url_escape
from spyder.config.base import get_image_path, get_module_source_path
from spyder.utils.qthelpers import add_actions
from spyder.utils import sourcecode
from spyder.widgets.findreplace import FindReplace
from spyder_notebook.utils.localization import _
from spyder_notebook.widgets.dom import DOMWidget
    from spyder.utils.qthelpers import qapplication

    def get_session_url(self):
        """
        Get the kernel sessions URL of the client.

        Return a str with the URL or None, if no server is associated to
        the client.
        """
        if self.server_url:
            session_url = url_path_join(self.server_url, 'api/sessions')
            return self.add_token(session_url)
        else:
            return None

    def get_kernel_id(self):
        """
        Get the kernel id of the client.

        Return a str with the kernel id or None. On error, display a dialog
        box and return None.
        """
        sessions_url = self.get_session_url()
        if not sessions_url:
            return None

        try:
            sessions_response = requests.get(sessions_url)
        except requests.exceptions.RequestException as exception:
            msg = _('Spyder could not get a list of sessions '
                    'from the Jupyter Notebook server. '
                    'Message: {}').format(exception)

            QMessageBox.warning(self, _('Server error'), msg)