Package Pyblio :: Package Parsers :: Package Syntax :: Module Tagged :: Class Parser
[hide private]
[frames] | no frames]

Class Parser

source code

object --+
         |
        Parser
Known Subclasses:
ISI.ISIParser, RIS.RISParser

Generic Parser for 'tagged' records, to be derived by actual parsers. An actual subclass will need to at least override the self.line_handler () method to generate events by calling self.push (). The parser is in charge of general state bookkeeping, and that sort of things...

Instance Methods [hide private]
 
__init__(self, fd, charset='UTF-8')
Create a new parser for a file containing 'tagged' records
source code
 
file_start(self)
Override me to have a function called before the first record is to be parsed
source code
 
file_stop(self)
Override me to be called after the last record has been parsed
source code
 
file_stopping(self)
Override me to be called just at the end of file
source code
 
line_handler(self, line, number)
Override me to handle each line of input and generate self.push () events.
source code
 
field_handler(self, tag, value)
Transforms a single field of a record
source code
 
push(self, *ev)
Emit a new event.
source code
 
metadata_add(self, tag, value)
Call me to notify the availability of a new meta data
source code
 
record_start(self) source code
 
record_end(self) source code
 
field_start(self, tag, line) source code
 
field_end(self) source code
 
field_data(self, data) source code
 
unread(self, line, count)
Put back a line so that it will be returned by self._pop when it is next invoked.
source code
 
next(self)
Call this function to get the next record as a list of tuples
source code
 
_ev_pop(self)
Parse enough lines to get the next event
source code
 
_pop(self)
Return a line from the file with its line number.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  EV_DONE = 6
  EV_FIELD_DATA = 3
  EV_FIELD_END = 4
  EV_FIELD_START = 2
  EV_FILE_END = 5
  EV_METADATA = 7
  EV_RECORD_END = 1
  EV_RECORD_START = 0
  ST_IN_FIELD = 1
  ST_IN_RECORD = 0
  ST_OUTSIDE = 2
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fd, charset='UTF-8')
(Constructor)

source code 
Create a new parser for a file containing 'tagged' records
Overrides: object.__init__

line_handler(self, line, number)

source code 
Override me to handle each line of input and generate self.push () events. Will be called with line == '' when the end of file is reached.

push(self, *ev)

source code 
Emit a new event. Available events are listed below, with their additional parameters listed, when needed:
  • self.EV_RECORD_START
  • self.EV_RECORD_END
  • self.EV_FIELD_START, tag, line
  • self.EV_FIELD_DATA, data
  • self.EV_FIELD_END
  • self.EV_FILE_END

next(self)

source code 

Call this function to get the next record as a list of tuples

('D', [ (tag, value), ...]) ('M', tag, value)

or None when there are no more records