Skip to content

Commit

Permalink
Trac #27275: py3: fix sage.libs.readline.pyx for python3
Browse files Browse the repository at this point in the history
fix doctests failures : sage -t --long src/sage/libs/readline.pyx # 10
doctests failed

URL: https://trac.sagemath.org/27275
Reported by: vklein
Ticket author(s): Vincent Klein
Reviewer(s): Erik Bray, Frédéric Chapoton
  • Loading branch information
Release Manager authored and vbraun committed Feb 22, 2019
2 parents f38f0cd + 7ccd2a5 commit 1b90e31
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/sage/libs/readline.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ EXAMPLES::
sage: from sage.libs.readline import *
sage: replace_line('foobar', 0)
sage: set_point(3)
sage: print('current line: ' + repr(copy_text(0, get_end())))
sage: print('current line:', repr(copy_text(0, get_end())))
current line: 'foobar'
sage: print('cursor position: {}'.format(get_point()))
sage: print('cursor position:', get_point())
cursor position: 3
When printing with :class:`interleaved_output` the prompt and current
line is removed::
sage: with interleaved_output():
....: print('output')
....: print('current line: ' + repr(copy_text(0, get_end())))
....: print('cursor position: {}'.format(get_point()))
....: print('current line: ',
....: repr(copy_text(0, get_end())))
....: print('cursor position:', get_point())
output
current line: ''
cursor position: 0
After the interleaved output, the line and cursor is restored to the
old value::
sage: print('current line: ' + repr(copy_text(0, get_end())))
sage: print('current line:', repr(copy_text(0, get_end())))
current line: 'foobar'
sage: print('cursor position: {}'.format(get_point()))
sage: print('cursor position:', get_point())
cursor position: 3
Finally, clear the current line for the remaining doctests::
Expand All @@ -49,6 +50,7 @@ Finally, clear the current line for the remaining doctests::
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function
from sage.cpython.string cimport str_to_bytes, bytes_to_str


cdef extern from 'readline/readline.h':
Expand Down Expand Up @@ -206,7 +208,7 @@ def copy_text(pos_start, pos_end):
sage: copy_text(1, 5)
'ooba'
"""
return rl_copy_text(pos_start, pos_end)
return bytes_to_str(rl_copy_text(pos_start, pos_end))

def replace_line(text, clear_undo):
"""
Expand All @@ -228,7 +230,7 @@ def replace_line(text, clear_undo):
sage: copy_text(1, 5)
'ooba'
"""
rl_replace_line(text, clear_undo)
rl_replace_line(str_to_bytes(text), clear_undo)

def initialize():
"""
Expand Down

0 comments on commit 1b90e31

Please sign in to comment.