Ejemplo n.º 1
0
Archivo: gap3.py Proyecto: drupel/sage
    def help(self, topic, pager=True):
        r"""
        Print help on the given topic.

        INPUT:

        - ``topic`` -- string

        EXAMPLES::

            sage: gap3.help('help', pager=False)           #optional - gap3
            Help _______________________________________________________...
            <BLANKLINE>
            This  section describes  together with  the following sectio...
            help system.  The help system lets you read the manual inter...

        ::

            sage: gap3.help('SymmetricGroup', pager=False) #optional - gap3
            no section with this name was found

        TESTS::

            sage: m = gap3([[1,2,3],[4,5,6]]); m           #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: gap3.help('help', pager=False)           #optional - gap3
            Help _______________________________________________________...
            sage: m                                        #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: m.Print()                                #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: gap3.help('Group', pager=False)          #optional - gap3
            Group ______________________________________________________...
            sage: m                                        #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: m.Print()                                #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
        """

        import pexpect
        if self._expect is None:
            self._start()
        E = self._expect
        helptext = []

        # we request the help document
        E.sendline("? %s" % topic)
        # it seems necessary to skip TWO echoes (as is done in the GAP4 interface)
        E.expect("\r\n")
        E.expect("\r\n")

        # next we process the help document; translating special characters, etc.
        while True:
            try:
                x = E.expect_list(self._compiled_full_pattern, timeout=2)
            except pexpect.TIMEOUT:
                break
            if x == 1:
                # matched @@; replace with @
                helptext.append('@')
                helptext.append(E.before)
            elif x == 2:
                # matched a special char; convert and insert
                helptext.append(chr(ord(E.after[1:2])-ord('A')+1))
                helptext.append(E.before)
            elif x == 10:
                # matched @n (normal input mode); it seems we're done
                break
            elif x==11:
                # matched @r (echoing input); skip to end of line
                E.expect_list(self._compiled_small_pattern)

        # merge the help text into one string and print it.
        helptext = "".join(helptext).strip()
        if pager is True:
            from sage.misc.pager import pager as pag
            pag()(helptext)
        else:
            print(helptext)
Ejemplo n.º 2
0
    def help(self, topic, pager=True):
        r"""
        Print help on the given topic.

        INPUT:

        - ``topic`` -- string

        EXAMPLES::

            sage: gap3.help('help', pager=False)           #optional - gap3
            Help _______________________________________________________...
            <BLANKLINE>
            This  section describes  together with  the following sectio...
            help system.  The help system lets you read the manual inter...

        ::

            sage: gap3.help('SymmetricGroup', pager=False) #optional - gap3
            no section with this name was found

        TESTS::

            sage: m = gap3([[1,2,3],[4,5,6]]); m           #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: gap3.help('help', pager=False)           #optional - gap3
            Help _______________________________________________________...
            sage: m                                        #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: m.Print()                                #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: gap3.help('Group', pager=False)          #optional - gap3
            Group ______________________________________________________...
            sage: m                                        #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
            sage: m.Print()                                #optional - gap3
            [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
        """

        import pexpect
        if self._expect is None:
            self._start()
        E = self._expect
        helptext = []

        # we request the help document
        E.sendline("? %s" % topic)
        # it seems necessary to skip TWO echoes (as is done in the GAP4 interface)
        E.expect("\r\n")
        E.expect("\r\n")

        # next we process the help document; translating special characters, etc.
        while True:
            try:
                x = E.expect_list(self._compiled_full_pattern, timeout=2)
            except pexpect.TIMEOUT:
                break
            if x == 1:
                # matched @@; replace with @
                helptext.append('@')
                helptext.append(E.before)
            elif x == 2:
                # matched a special char; convert and insert
                helptext.append(chr(ord(E.after[1:2]) - ord('A') + 1))
                helptext.append(E.before)
            elif x == 10:
                # matched @n (normal input mode); it seems we're done
                break
            elif x == 11:
                # matched @r (echoing input); skip to end of line
                E.expect_list(self._compiled_small_pattern)

        # merge the help text into one string and print it.
        helptext = "".join(helptext).strip()
        if pager is True:
            from sage.misc.pager import pager as pag
            pag()(helptext)
        else:
            print(helptext)