Code to support writing parsers.
Classes:
AbstractParser Base class for parsers.
AbstractConsumer Base class of all Consumers.
TaggingConsumer Consumer that tags output with its event. For debugging
SGMLStrippingConsumer Consumer that strips SGML tags from output.
EventGenerator Generate Biopython Events from Martel XML output
Functions:
safe_readline Read a line from a handle, with check for EOF.
safe_peekline Peek at next line, with check for EOF.
read_and_call Read a line from a handle and pass it to a method.
read_and_call_while Read many lines, as long as a condition is met.
read_and_call_until Read many lines, until a condition is met.
attempt_read_and_call Like read_and_call, but forgiving of errors.
is_blank_line Test whether a line is blank.
Imported modules
|
|
from Bio import File
import string
import sys
import traceback
from types import *
|
Functions
|
|
_fails_conditions
attempt_read_and_call
is_blank_line
read_and_call
read_and_call_until
read_and_call_while
safe_peekline
safe_readline
|
|
_fails_conditions
|
_fails_conditions (
line,
start=None,
end=None,
contains=None,
blank=None,
has_re=None,
)
|
|
attempt_read_and_call
|
attempt_read_and_call (
uhandle,
method,
**keywds,
)
attempt_read_and_call(uhandle, method, **keywds) -> boolean
Similar to read_and_call, but returns a boolean specifying
whether the line has passed the checks. Does not raise
exceptions.
See docs for read_and_call for a description of the function
arguments.
|
|
is_blank_line
|
is_blank_line ( line, allow_spaces=0 )
is_blank_line(line, allow_spaces=0) -> boolean
Return whether a line is blank. allow_spaces specifies whether to
allow whitespaces in a blank line. A true value signifies that a
line containing whitespaces as well as end-of-line characters
should be considered blank.
|
|
read_and_call
|
read_and_call (
uhandle,
method,
**keywds,
)
read_and_call(uhandle, method[, start][, end][, contains][, blank][, has_re])
Read a line from uhandle, check it, and pass it to the method.
Raises a SyntaxError if the line does not pass the checks.
start, end, contains, blank, and has_re specify optional conditions
that the line must pass. start and end specifies what the line must
begin or end with (not counting EOL characters). contains
specifies a substring that must be found in the line. If blank
is a true value, then the line must be blank. has_re should be
a regular expression object with a pattern that the line must match
somewhere.
|
|
read_and_call_until
|
read_and_call_until (
uhandle,
method,
**keywds,
)
read_and_call_until(uhandle, method,
start=None, end=None, contains=None, blank=None) -> number of lines Read a line from uhandle and pass it to the method until
some condition is true. Returns the number of lines that were read.
See the docstring for read_and_call for a description of the parameters.
|
|
read_and_call_while
|
read_and_call_while (
uhandle,
method,
**keywds,
)
read_and_call_while(uhandle, method[, start][, end][, contains][, blank][, has_re]) -> number of lines
Read a line from uhandle and pass it to the method as long as
some condition is true. Returns the number of lines that were read.
See the docstring for read_and_call for a description of the parameters.
|
|
safe_peekline
|
safe_peekline ( handle )
safe_peekline(handle) -> line
Peek at the next line in an UndoHandle and return it. If there are no
more lines to peek, I will raise a SyntaxError.
Exceptions
|
|
SyntaxError, "Unexpected end of stream."
|
|
|
safe_readline
|
safe_readline ( handle )
safe_readline(handle) -> line
Read a line from an UndoHandle and return it. If there are no more
lines to read, I will raise a SyntaxError.
Exceptions
|
|
SyntaxError, "Unexpected end of stream."
|
|
Classes
|
|
|
|