Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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': []
}
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',