Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
inspect.BlockFinder Class Reference

List of all members.

Public Member Functions

def __init__
def tokeneater

Public Attributes

 indent
 islambda
 started
 passline
 last

Detailed Description

Provide a tokeneater() method to detect the end of a code block.

Definition at line 628 of file inspect.py.


Constructor & Destructor Documentation

Definition at line 630 of file inspect.py.

00630 
00631     def __init__(self):
00632         self.indent = 0
00633         self.islambda = False
00634         self.started = False
00635         self.passline = False
00636         self.last = 1

Here is the caller graph for this function:


Member Function Documentation

def inspect.BlockFinder.tokeneater (   self,
  type,
  token,
  srowcol,
  erowcol,
  line 
)

Definition at line 637 of file inspect.py.

00637 
00638     def tokeneater(self, type, token, srowcol, erowcol, line):
00639         if not self.started:
00640             # look for the first "def", "class" or "lambda"
00641             if token in ("def", "class", "lambda"):
00642                 if token == "lambda":
00643                     self.islambda = True
00644                 self.started = True
00645             self.passline = True    # skip to the end of the line
00646         elif type == tokenize.NEWLINE:
00647             self.passline = False   # stop skipping when a NEWLINE is seen
00648             self.last = srowcol[0]
00649             if self.islambda:       # lambdas always end at the first NEWLINE
00650                 raise EndOfBlock
00651         elif self.passline:
00652             pass
00653         elif type == tokenize.INDENT:
00654             self.indent = self.indent + 1
00655             self.passline = True
00656         elif type == tokenize.DEDENT:
00657             self.indent = self.indent - 1
00658             # the end of matching indent/dedent pairs end a block
00659             # (note that this only works for "def"/"class" blocks,
00660             #  not e.g. for "if: else:" or "try: finally:" blocks)
00661             if self.indent <= 0:
00662                 raise EndOfBlock
00663         elif self.indent == 0 and type not in (tokenize.COMMENT, tokenize.NL):
00664             # any other token on the same indentation level end the previous
00665             # block as well, except the pseudo-tokens COMMENT and NL.
00666             raise EndOfBlock

Here is the caller graph for this function:


Member Data Documentation

Definition at line 631 of file inspect.py.

Definition at line 632 of file inspect.py.

Definition at line 635 of file inspect.py.

Definition at line 634 of file inspect.py.

Definition at line 633 of file inspect.py.


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