Skip to content

Commit

Permalink
Fix indexerror in parse_code, allow ?%help to work
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Sep 7, 2014
1 parent a1f6373 commit 8e3ddf8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions jupyter_kernel/magickernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ def _parse_code(code, prefixes, suffixes, start=0, end=-1):
pre_magics = {}
for (name, prefix) in prefixes.items():
pre = ''
while snip[len(pre)] == prefix:
while len(pre) < len(snip) and snip[len(pre)] == prefix:
pre += prefix
if pre:
pre_magics[name] = pre

post_magics = {}
for (name, suffix) in suffixes.items():
post = ''
while snip[-len(post) - 1] == suffix:
while len(post) < len(snip) and snip[-len(post) - 1] == suffix:
post += suffix
if post:
post_magics[name] = post
Expand Down
5 changes: 4 additions & 1 deletion jupyter_kernel/magics/help_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def cell_help(self, text):
def get_help_on(self, info, level):

if info['magic'] and info['magic']['name'] == 'help':
code = info['rest']
code = info['rest'].rstrip()

magic_prefix = self.kernel.magic_prefixes['magic']
if code.endswith(magic_prefix + 'help'):
return self.get_help('line', 'help', level)

if magic_prefix + 'help' in code:
while code.startswith(self.kernel.magic_prefixes['magic']):
code = code[1:]
Expand Down

0 comments on commit 8e3ddf8

Please sign in to comment.