##// END OF EJS Templates
Comments and minor fixes
Joel Nothman -
Show More
@@ -446,15 +446,17 b' def match_dict_keys(keys, prefix):'
446 try:
446 try:
447 if not key.startswith(prefix_str):
447 if not key.startswith(prefix_str):
448 continue
448 continue
449 except (AttributeError, TypeError):
449 except (AttributeError, TypeError, UnicodeError):
450 # Python 3+ TypeError on b'a'.startswith('a') or vice-versa
450 # Python 3+ TypeError on b'a'.startswith('a') or vice-versa
451 continue
451 continue
452
452
453 # reformat remainder of key to begin with prefix
453 # reformat remainder of key to begin with prefix
454 rem = key[len(prefix_str):]
454 rem = key[len(prefix_str):]
455 # force repr with '
455 # force repr wrapped in '
456 rem_repr = repr(rem + '"')
456 rem_repr = repr(rem + '"')
457 if rem_repr.startswith('u') and prefix[0] not in 'uU':
457 if rem_repr.startswith('u') and prefix[0] not in 'uU':
458 # Found key is unicode, but prefix is Py2 string.
459 # Therefore attempt to interpret key as string.
458 try:
460 try:
459 rem_repr = repr(rem.encode('ascii') + '"')
461 rem_repr = repr(rem.encode('ascii') + '"')
460 except UnicodeEncodeError:
462 except UnicodeEncodeError:
@@ -462,6 +464,9 b' def match_dict_keys(keys, prefix):'
462
464
463 rem_repr = rem_repr[1 + rem_repr.index("'"):-2]
465 rem_repr = rem_repr[1 + rem_repr.index("'"):-2]
464 if quote == '"':
466 if quote == '"':
467 # The entered prefix is quoted with ",
468 # but the match is quoted with '.
469 # A contained " hence needs escaping for comparison:
465 rem_repr = rem_repr.replace('"', '\\"')
470 rem_repr = rem_repr.replace('"', '\\"')
466
471
467 # then reinsert prefix from start of token
472 # then reinsert prefix from start of token
@@ -539,7 +539,7 b' def test_dict_key_completion_unicode_py2():'
539 ip = get_ipython()
539 ip = get_ipython()
540 complete = ip.Completer.complete
540 complete = ip.Completer.complete
541
541
542 ip.user_ns['d'] = {unicode_type('abc'): None,
542 ip.user_ns['d'] = {u'abc': None,
543 unicode_type('a\xd7\x90', 'utf8'): None}
543 unicode_type('a\xd7\x90', 'utf8'): None}
544
544
545 _, matches = complete(line_buffer="d[")
545 _, matches = complete(line_buffer="d[")
General Comments 0
You need to be logged in to leave comments. Login now