How to use the jupyter.seq_kernel.redirector.stdout_stderr_redirector function in jupyter

To help you get started, we’ve selected a few jupyter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seq-lang / seq / jupyter / seq_kernel / kernel.py View on Github external
def do_complete(self, code, cursor_pos):
        """
            Code completion.
            Parameters:
                code (str) -- The code already present.
                cursor_pos (int) -- The position in the code where completion is requested.
        """

        matches = []
        ferr = BytesIO()
        with stdout_stderr_redirector(BytesIO(), ferr):
            matches = self.seqwrapper.complete(code)

        ferr_string = ferr.getvalue().decode('utf-8').strip()

        if ferr_string:
            return {
                'status': 'error',
                'ename': 'CompletionError',
                'evalue': ferr_string,
                'traceback': []
            }

        return {
            'status': 'ok',
            'matches': [ match for match in matches],
            'cursor_start': 0,
github seq-lang / seq / jupyter / seq_kernel / kernel.py View on Github external
inspect_text = ''
        doc_text = ''
        ferr = BytesIO()
        cell = 0
        line = 0
        col = 0

        if code in self.cells:
            cell = self.cells.index(code) + 1
            line = code[:cursor_pos].count('\n') + 1
            col = cursor_pos - code[:cursor_pos].rfind('\n') - 1
            if col < 0:
                col = 0


        with stdout_stderr_redirector(BytesIO(), ferr):
            if cell > 0:
                inspect_text = self.seqwrapper.inspect(cell, line, col)
            if cell <= 0 or inspect_text.startswith('Not found:'):
                doc_text = self.seqwrapper.document(code)
                inspect_text = ''

        ferr_string = ferr.getvalue().decode('utf-8').strip()

        if ferr_string:
            return {
                'status': 'error',
                'ename': 'InspectionError',
                'evalue': ferr_string,
                'traceback': []
            }
github seq-lang / seq / jupyter / seq_kernel / kernel.py View on Github external
user_expressions (dict) -- Mapping of names to expressions to evaluate after the code has run.
                    You can ignore this if you need to.
                allow_stdin (bool) -- Whether the frontend can provide input on request (e.g. for Python's raw_input()).
        """
        if not code.strip():
            return {
                'status': 'ok',
                'execution_count': self.execution_count,
                'payload': [],
                'user_expressions': {}
            }

        fout = BytesIO()
        ferr = BytesIO()

        with stdout_stderr_redirector(fout, ferr):
            code = code.rstrip()
            self.seqwrapper.exec(code)
            self.cells.append(code)

        fout_string = fout.getvalue().decode('utf-8').strip()
        ferr_string = ferr.getvalue().decode('utf-8').strip()

        if ferr_string:
            if not silent:
                self.send_response(
                    self.iopub_socket,
                    'stream',
                    {'name': 'stderr', 'text': ferr_string}
                )
            return {
                'status': 'error',