Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.support.pygments.lexers.agile.PythonConsoleLexer Class Reference
Inheritance diagram for MoinMoin.support.pygments.lexers.agile.PythonConsoleLexer:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.lexers.agile.PythonConsoleLexer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_tokens_unprocessed

Public Attributes

 python3

Static Public Attributes

string name = 'Python console session'
list aliases = ['pycon']
list mimetypes = ['text/x-python-doctest']

Detailed Description

For Python console output or doctests, such as:

.. sourcecode:: pycon

    >>> a = 'foo'
    >>> print a
    foo
    >>> 1 / 0
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ZeroDivisionError: integer division or modulo by zero

Additional options:

`python3`
    Use Python 3 lexer for code.  Default is ``False``.
    *New in Pygments 1.0.*

Definition at line 274 of file agile.py.


Constructor & Destructor Documentation

Definition at line 298 of file agile.py.

00298 
00299     def __init__(self, **options):
00300         self.python3 = get_bool_opt(options, 'python3', False)
00301         Lexer.__init__(self, **options)


Member Function Documentation

Definition at line 302 of file agile.py.

00302 
00303     def get_tokens_unprocessed(self, text):
00304         if self.python3:
00305             pylexer = Python3Lexer(**self.options)
00306             tblexer = Python3TracebackLexer(**self.options)
00307         else:
00308             pylexer = PythonLexer(**self.options)
00309             tblexer = PythonTracebackLexer(**self.options)
00310 
00311         curcode = ''
00312         insertions = []
00313         curtb = ''
00314         tbindex = 0
00315         tb = 0
00316         for match in line_re.finditer(text):
00317             line = match.group()
00318             if line.startswith('>>> ') or line.startswith('... '):
00319                 tb = 0
00320                 insertions.append((len(curcode),
00321                                    [(0, Generic.Prompt, line[:4])]))
00322                 curcode += line[4:]
00323             elif line.rstrip() == '...':
00324                 tb = 0
00325                 insertions.append((len(curcode),
00326                                    [(0, Generic.Prompt, '...')]))
00327                 curcode += line[3:]
00328             else:
00329                 if curcode:
00330                     for item in do_insertions(insertions,
00331                                     pylexer.get_tokens_unprocessed(curcode)):
00332                         yield item
00333                     curcode = ''
00334                     insertions = []
00335                 if (line.startswith('Traceback (most recent call last):') or
00336                     re.match(r'  File "[^"]+", line \d+\n$', line)):
00337                     tb = 1
00338                     curtb = line
00339                     tbindex = match.start()
00340                 elif line == 'KeyboardInterrupt\n':
00341                     yield match.start(), Name.Class, line
00342                 elif tb:
00343                     curtb += line
00344                     if not (line.startswith(' ') or line.strip() == '...'):
00345                         tb = 0
00346                         for i, t, v in tblexer.get_tokens_unprocessed(curtb):
00347                             yield tbindex+i, t, v
00348                 else:
00349                     yield match.start(), Generic.Output, line
00350         if curcode:
00351             for item in do_insertions(insertions,
00352                                       pylexer.get_tokens_unprocessed(curcode)):
00353                 yield item
00354 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 295 of file agile.py.

Definition at line 296 of file agile.py.

string MoinMoin.support.pygments.lexers.agile.PythonConsoleLexer.name = 'Python console session' [static]

Definition at line 294 of file agile.py.

Definition at line 299 of file agile.py.


The documentation for this class was generated from the following file: