@@ -70,11 +70,11 @@ except AttributeError:
7070ip = ' 127.0.0.1'
7171try :
7272 km
73- except NameError:
74- km = None
75- try :
73+ kc
7674 pid
7775except NameError:
76+ km = None
77+ kc = None
7878 pid = None
7979
8080def km_from_string (s = ' ' ):
@@ -87,23 +87,23 @@ def km_from_string(s=''):
8787 from Queue import Empty
8888 try :
8989 from IPython.kernel import (
90- BlockingKernelManager ,
90+ KernelManager ,
9191 find_connection_file,
9292 )
9393 except ImportError:
94- # < 0.14
95- from IPython.zmq.blockingkernelmanager import BlockingKernelManager
94+ # IPython < 1.0
95+ from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
9696 from IPython.zmq.kernelapp import kernel_aliases
9797 try :
9898 from IPython.lib.kernel import find_connection_file
9999 except ImportError:
100100 # < 0.12 , no find_connection_file
101101 pass
102102
103- global km ,send,Empty
103+ global km , kc, send, Empty
104104
105105 s = s .replace (' --existing' , ' ' )
106- if ' connection_file' in BlockingKernelManager .class_trait_names ():
106+ if ' connection_file' in KernelManager .class_trait_names ():
107107 # 0.12 uses files instead of a collection of ports
108108 # include default IPython search path
109109 # filefind also allows for absolute paths, in which case the search
@@ -124,7 +124,7 @@ def km_from_string(s=''):
124124 echo (" :IPython " + s + " failed" , " Info" )
125125 echo (" ^-- failed '" + s + " ' not found" , " Error" )
126126 return
127- km = BlockingKernelManager (connection_file = fullpath)
127+ km = KernelManager (connection_file = fullpath)
128128 km .load_connection_file ()
129129 else :
130130 if s == ' ' :
@@ -133,7 +133,7 @@ def km_from_string(s=''):
133133 loader = KeyValueConfigLoader (s .split (), aliases= kernel_aliases)
134134 cfg = loader.load_config ()[' KernelApp' ]
135135 try :
136- km = BlockingKernelManager (
136+ km = KernelManager (
137137 shell_address= (ip, cfg[' shell_port' ]),
138138 sub_address= (ip, cfg[' iopub_port' ]),
139139 stdin_address= (ip, cfg[' stdin_port' ]),
@@ -142,12 +142,18 @@ def km_from_string(s=''):
142142 echo (" :IPython " + s + " failed" , " Info" )
143143 echo (" ^-- failed --" + e .message.replace (' _port' ,' ' )+ " not specified" , " Error" )
144144 return
145- km .start_channels ()
146- send = km .shell_channel.execute
145+
146+ try :
147+ kc = km .client ()
148+ except AttributeError:
149+ # 0.13
150+ kc = km
151+ kc.start_channels ()
152+ send = kc.shell_channel.execute
147153
148154 #XXX : backwards compatability for IPython < 1.0
149- if not hasattr (km , ' iopub_channel' ):
150- km .iopub_channel = km .sub_channel
155+ if not hasattr (kc , ' iopub_channel' ):
156+ kc .iopub_channel = kc .sub_channel
151157
152158 # now that we're connect to an ipython kernel, activate completion
153159 # machinery, but do so only for the local buffer if the user added the
@@ -184,9 +190,9 @@ def disconnect():
184190 pass
185191
186192def get_doc (word, level = 0 ):
187- if km is None:
193+ if kc is None:
188194 return [" Not connected to IPython, cannot query: %s" % word]
189- msg_id = km .shell_channel.object_info (word, level )
195+ msg_id = kc .shell_channel.object_info (word, level )
190196 doc = get_doc_msg (msg_id)
191197 # get around unicode problems when interfacing with vim
192198 return [d .encode (vim_encoding) for d in doc]
@@ -277,9 +283,9 @@ def update_subchannel_msgs(debug=False, force=False):
277283 This function will do nothing if the vim - ipython shell is not visible,
278284 unless force= True argument is passed.
279285 " ""
280- if km is None or (not vim_ipython_is_open () and not force):
286+ if kc is None or (not vim_ipython_is_open () and not force):
281287 return False
282- msgs = km .iopub_channel.get_msgs ()
288+ msgs = kc .iopub_channel.get_msgs ()
283289 if debug :
284290 #try :
285291 # vim .command (" b debug_msgs" )
@@ -389,7 +395,7 @@ def get_child_msg(msg_id):
389395 # XXX : message handling should be split into its own process in the future
390396 while True:
391397 # get_msg will raise with Empty exception if no messages arrive in 1 second
392- m = km .shell_channel.get_msg (timeout = 1 )
398+ m = kc .shell_channel.get_msg (timeout = 1 )
393399 if m [' parent_header' ][' msg_id' ] == msg_id:
394400 break
395401 else :
@@ -418,7 +424,7 @@ def with_subchannel(f,*args):
418424 f (* args )
419425 if monitor_subchannel:
420426 update_subchannel_msgs ()
421- except AttributeError: #if km is None
427+ except AttributeError: #if kc is None
422428 echo (" not connected to IPython" , ' Error' )
423429 return f_with_update
424430
@@ -477,7 +483,7 @@ def set_pid():
477483 " ""
478484 Explicitly ask the ipython kernel for its pid
479485 " ""
480- global km , pid
486+ global pid
481487 lines = ' \n' .join ([' import os' , ' _pid = os.getpid()' ])
482488 msg_id = send (lines , silent = True, user_variables= [' _pid' ])
483489
@@ -684,7 +690,7 @@ endpython
684690 python << endpython
685691base = vim .eval (" a:base" )
686692findstart = vim .eval (" a:findstart" )
687- msg_id = km .shell_channel.complete (base, current_line, vim .eval (" col('.')" ))
693+ msg_id = kc .shell_channel.complete (base, current_line, vim .eval (" col('.')" ))
688694try :
689695 m = get_child_msg (msg_id)
690696 matches = m [' content' ][' matches' ]
0 commit comments