Python pydoc 模块,pipepager() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用pydoc.pipepager()

项目:projects    作者:tiborsimon    | 项目源码 | 文件源码
def show_project_details(data, width):
    doc = doc_generator.generate_doc(data, width)
    doc = doc.format(
        head='\033[0;33m',
        project='\033[1;36m',
        command='\033[1;33m',
        reset='\033[0m'
    )
    pydoc.pipepager(doc, cmd='less -R')
    # pydoc.pager(doc)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_pipepager(self):
        # pipepager does not choke on unicode
        doc = pydoc.render_doc(self.Q)

        saved, os.popen = os.popen, open
        try:
            with test.test_support.temp_cwd():
                pydoc.pipepager(doc, 'pipe')
                self.assertEqual(open('pipe').read(), pydoc._encode(doc))
        finally:
            os.popen = saved
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_pipepager(self):
        # pipepager does not choke on unicode
        doc = pydoc.render_doc(self.Q)

        saved, os.popen = os.popen, open
        try:
            with test.test_support.temp_cwd():
                pydoc.pipepager(doc, 'pipe')
                self.assertEqual(open('pipe').read(), pydoc._encode(doc))
        finally:
            os.popen = saved
项目:deb-python-dcos    作者:openstack    | 项目源码 | 文件源码
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = six.text_type(output)

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        sys.stdout.flush()
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    if pager_command is None:
        pager_command = 'less -R'

    try:
        paginate = config.get_config_val("core.pagination")
    except:
        paginate = True
    if exceeds_tty_height and paginate and \
            spawn.find_executable(pager_command.split(' ')[0]) is not None:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)
项目:grepg-python    作者:evidanary    | 项目源码 | 文件源码
def print_results(self, text, result_items):
        cprint(text)
        if(self.pager):
            less_options = "RKIQ"
            pydoc.pipepager(text, cmd="less -{0}".format(less_options))
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_pipepager(self):
        # pipepager does not choke on unicode
        doc = pydoc.render_doc(self.Q)

        saved, os.popen = os.popen, open
        try:
            with test.test_support.temp_cwd():
                pydoc.pipepager(doc, 'pipe')
                self.assertEqual(open('pipe').read(), pydoc._encode(doc))
        finally:
            os.popen = saved
项目:deploy-marathon-bluegreen    作者:softonic    | 项目源码 | 文件源码
def _page(output, pager_command=None):
    """Conditionally pipes the supplied output through a pager.

    :param output:
    :type output: object
    :param pager_command:
    :type pager_command: str
    """

    output = six.text_type(output)

    if pager_command is None:
        pager_command = 'less -R'

    if not sys.stdout.isatty() or util.is_windows_platform():
        print(output)
        return

    num_lines = output.count('\n')
    exceeds_tty_height = pager.getheight() - 1 < num_lines

    paginate = util.get_config().get("core.pagination", True)
    if exceeds_tty_height and paginate:
        pydoc.pipepager(output, cmd=pager_command)
    else:
        print(output)