##// END OF EJS Templates
Merge pull request #1627 from minrk/msgspec...
Merge pull request #1627 from minrk/msgspec Test the Message Spec and add our zmq subpackage to the test suite. It uses Traitlets to perform validation of keys. Checks right now are not very strict, as (almost) any key is allowed to be None, as long as it is defined. This is because I simply do not know which keys are allowed to be None, and this is not discussed in the specification. If no keys are allowed to be None, we violate that all over the place. Parametric tests are used, so every key validation counts as a test (147!). Message spec doc was found to misrepresent code in a few points, and some changes were made: * spec had error keys as `exc_name/value`, but we are actually using `ename/value` (docs updated to match code) * payloads were inaccurate - list of dicts, rather than single dict, and transformed_output is a payload, not top-level in exec-reply (docs update to match code). * in oinfo_request, detail_level was in message spec, but not actually implemented (code updated to match docs). History messages are not yet tested, but I think I get at least elementary coverage of everything else in the doc.

File last commit:

r5611:fd342639
r6567:232fa81a merge
Show More
completer.py
44 lines | 1.4 KiB | text/x-python | PythonLexer
Omar Andres Zapata Mesa
-mworking in tab-completion
r5584 # -*- coding: utf-8 -*-
import readline
Thomas Kluyver
Refactor and simplification of zmqterminal.
r5596 from Queue import Empty
Thomas Kluyver
Minor tidy up of zmqterminal.completer
r5595
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 class ZMQCompleter(object):
Omar Andres Zapata Mesa
-mworking in tab-completion
r5584 """Client-side completion machinery.
How it works: self.complete will be called multiple times, with
state=0,1,2,... When state=0 it should compute ALL the completion matches,
and then return them for each value of state."""
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 def __init__(self, shell, km):
self.shell = shell
Omar Andres Zapata Mesa
-mworking in tab-completion
r5584 self.km = km
self.matches = []
def complete_request(self,text):
Omar Andres Zapata Mesa
tab completion is not working yet, unknow error
r5585 line = readline.get_line_buffer()
Thomas Kluyver
Simplify handling of messaging in zmqterminal.
r5597 cursor_pos = readline.get_endidx()
Omar Andres Zapata Mesa
tab completion is not working yet, unknow error
r5585 # send completion request to kernel
# Give the kernel up to 0.5s to respond
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 msg_id = self.km.shell_channel.complete(text=text, line=line,
Thomas Kluyver
Simplify handling of messaging in zmqterminal.
r5597 cursor_pos=cursor_pos)
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 msg = self.km.shell_channel.get_msg(timeout=0.5)
if msg['parent_header']['msg_id'] == msg_id:
return msg["content"]["matches"]
Thomas Kluyver
Refactor and simplification of zmqterminal.
r5596 return []
Omar Andres Zapata Mesa
-mworking in tab-completion
r5584
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 def rlcomplete(self, text, state):
Thomas Kluyver
Minor tidy up of zmqterminal.completer
r5595 if state == 0:
try:
self.matches = self.complete_request(text)
Thomas Kluyver
Refactor and simplification of zmqterminal.
r5596 except Empty:
Thomas Kluyver
Minor tidy up of zmqterminal.completer
r5595 print('WARNING: Kernel timeout on tab completion.')
Thomas Kluyver
Replace tabs with spaces
r5591 try:
return self.matches[state]
except IndexError:
return None
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600
def complete(self, text, line, cursor_pos=None):
return self.rlcomplete(text, 0)