当前位置: 首页>>代码示例>>Python>>正文


Python Comm.open方法代码示例

本文整理汇总了Python中ipykernel.comm.Comm.open方法的典型用法代码示例。如果您正苦于以下问题:Python Comm.open方法的具体用法?Python Comm.open怎么用?Python Comm.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ipykernel.comm.Comm的用法示例。


在下文中一共展示了Comm.open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from ipykernel.comm import Comm [as 别名]
# 或者: from ipykernel.comm.Comm import open [as 别名]
class BeakerX:

    def __init__(self):
        BeakerX.pandas_display_table()
        self._comm = None
        self._queue = Queue()
        self._server = BeakerxZMQServer(self._queue)
        self._url = self._server.url

    @staticmethod
    def pandas_display_default():
        pandas.DataFrame._ipython_display_ = None

    @staticmethod
    def pandas_display_table():
        pandas.DataFrame._ipython_display_ = TableDisplayWrapper()

    def set4(self, var, val, unset, sync):
        args = {'name': var, 'sync': sync}
        if not unset:
            val = transform(val)
            args['value'] = json.dumps(val, cls=DataFrameEncoder)
            state = {'state': args}
        if self._comm is None:
            self.init_autotranslation_comm()
        self._comm.send(data=state)

    def init_autotranslation_comm(self):
        self._comm = Comm(target_name='beakerx.autotranslation')
        self._comm.open()

    def get(self, var):
        result = autotranslation_get(var)
        if result == 'undefined':
            raise NameError('name \'' + var + '\' is not defined on the beakerx object')
        return transformBack(json.loads(result))

    def set_session(self, id):
        self.session_id = id

    def register_output(self):
        ip = IPython.InteractiveShell.instance()
        ip.display_formatter.formatters['application/json'] = MyJSONFormatter(parent=ip.display_formatter)

    def set(self, var, val):
        autotranslation_update(var, val)
        return self.set4(var, val, False, True)

    def unset(self, var):
        return self.set4(var, None, True, True)

    def isDefined(self, var):
        return autotranslation_get(var) != 'undefined'

    def createOutputContainer(self):
        return OutputContainer()

    def showProgressUpdate(self):
        return "WARNING: python3 language plugin does not support progress updates"

    def evaluate(self, filter):
        args = {'filter': filter, 'session': self.session_id}
        req = urllib.request.Request(self.core_url + '/rest/notebookctrl/evaluate',
                                     urllib.parse.urlencode(args).encode('utf8'))
        conn = self._beaker_url_opener.open(req)
        result = json.loads(conn.read().decode())
        return transformBack(result)

    def evaluateCode(self, evaluator, code):
        args = {'evaluator': evaluator, 'code': code, 'session': self.session_id}
        req = urllib.request.Request(self.core_url + '/rest/notebookctrl/evaluateCode',
                                     urllib.parse.urlencode(args).encode('utf8'))
        conn = self._beaker_url_opener.open(req)
        result = json.loads(conn.read().decode())
        return transformBack(result)

    def showStatus(self, msg):
        args = {'msg': msg, 'session': self.session_id}
        req = urllib.request.Request(self.core_url + '/rest/notebookctrl/showStatus',
                                     urllib.parse.urlencode(args).encode('utf8'))
        conn = self._beaker_url_opener.open(req)
        result = conn.read()
        return result == "true"

    def clearStatus(self, msg):
        args = {'msg': msg, 'session': self.session_id}
        req = urllib.request.Request(self.core_url + '/rest/notebookctrl/clearStatus',
                                     urllib.parse.urlencode(args).encode('utf8'))
        conn = self._beaker_url_opener.open(req)
        result = conn.read()
        return result == "true"

    def showTransientStatus(self, msg):
        args = {'msg': msg, 'session': self.session_id}
        req = urllib.request.Request(self.core_url + '/rest/notebookctrl/showTransientStatus',
                                     urllib.parse.urlencode(args).encode('utf8'))
        conn = self._beaker_url_opener.open(req)
        result = conn.read()
        return result == "true"

#.........这里部分代码省略.........
开发者ID:twosigma,项目名称:beaker-notebook,代码行数:103,代码来源:runtime.py


注:本文中的ipykernel.comm.Comm.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。