Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#326 closed defect (fixed)

python interactive help does not do CR/NL line endings.

Reported by: Steven Levine Owned by:
Priority: Feedback Pending Milestone:
Component: python Version:
Severity: low Keywords:
Cc:

Description

The python interactive mode help facility do not generate CR/NL line endings.

To reproduce, start with

python -i

From the python command line, enter

help('base64')

to request base64 module help.

The output will be paged, but with NL line endings rather than CR/NL line endings.

Change History (5)

comment:1 Changed 5 years ago by Silvan Scherrer

Priority: minorFeedback Pending

please try the following:
in file /@unixroot/usr/lib/python2.7/pydoc.py change to the following:

def getpager():
    """Decide what method to use for paging through text."""
    if type(sys.stdout) is not types.FileType:
        return plainpager
    if not sys.stdin.isatty() or not sys.stdout.isatty():
        return plainpager
    if 'PAGER' in os.environ:
        if sys.platform == 'win32': # pipes completely broken in Windows
            return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
        elif os.environ.get('TERM') in ('dumb', 'emacs'):
            return lambda text: pipepager(plain(text), os.environ['PAGER'])
        else:
            return lambda text: pipepager(text, os.environ['PAGER'])
    if os.environ.get('TERM') in ('dumb', 'emacs'):
        return plainpager
    if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
        return lambda text: pipepager(text, 'less')
    if sys.platform == 'win32' or sys.platform.startswith('os2'):
        return lambda text: tempfilepager(plain(text), 'more <')

testing for less first and when not found it uses old ugly more. When you have less installed (which is a must anyway I'd say) then it should show a nice help page. If this works for you as well, I will make that the default.

Last edited 5 years ago by Silvan Scherrer (previous) (diff)

comment:2 Changed 5 years ago by Steven Levine

This is better.

I recommend changing

if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:

to

if hasattr(os, 'system') and os.system('less 2>nul') == 0:

It appears that os.system runs the command though the platform shell (aka cmd.exe or 4os2) rather than sh.exe.

If less.exe is not available, this results in

help('base64')

SYS0003: The system cannot find the path specified. "D:\dev\null"
Unknown command "less"

With my mod the SYS0003 goes away.

The more fallback can be improved. Changing to open call in tempfilepager from:

file = open(filename, 'w')

to

file = open(filename, 'wt')

seems to provide the results we want.

comment:3 Changed 5 years ago by Silvan Scherrer

I will consider this in the next python drop. When this happens is unknown atm.

comment:4 Changed 5 years ago by Silvan Scherrer

Resolution: fixed
Status: newclosed

this sys0003 is only there, if EXMSHELL is not set to sh. as our standard rpm set this value right, I did not change the sys003 workaround. the rest is done in r1551

comment:5 Changed 5 years ago by Steven Levine

I can confirm that help() now works as expected with the latest python rpm.

Note: See TracTickets for help on using tickets.