Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions | Private Attributes
Bio.Blast.NCBIXML._XMLparser Class Reference
Inheritance diagram for Bio.Blast.NCBIXML._XMLparser:
Inheritance graph
[legend]
Collaboration diagram for Bio.Blast.NCBIXML._XMLparser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def startElement
def characters
def endElement

Private Member Functions

def _secure_name

Private Attributes

 _tag
 _value
 _debug
 _debug_ignore_list

Detailed Description

Generic SAX Parser

Just a very basic SAX parser.

Redefine the methods startElement, characters and endElement.

Definition at line 28 of file NCBIXML.py.


Constructor & Destructor Documentation

def Bio.Blast.NCBIXML._XMLparser.__init__ (   self,
  debug = 0 
)
Constructor

debug - integer, amount of debug information to print

Reimplemented in Bio.Blast.NCBIXML.BlastParser.

Definition at line 35 of file NCBIXML.py.

00035 
00036     def __init__(self, debug=0):
00037         """Constructor
00038 
00039         debug - integer, amount of debug information to print
00040         """
00041         self._tag = []
00042         self._value = ''
00043         self._debug = debug
00044         self._debug_ignore_list = []

Here is the caller graph for this function:


Member Function Documentation

def Bio.Blast.NCBIXML._XMLparser._secure_name (   self,
  name 
) [private]
Removes 'dangerous' from tag names

name -- name to be 'secured'

Definition at line 45 of file NCBIXML.py.

00045 
00046     def _secure_name(self, name):
00047         """Removes 'dangerous' from tag names
00048 
00049         name -- name to be 'secured'
00050         """
00051         # Replace '-' with '_' in XML tag names
00052         return name.replace('-', '_')
    

Here is the caller graph for this function:

def Bio.Blast.NCBIXML._XMLparser.characters (   self,
  ch 
)
Found some text

ch -- characters read

Definition at line 87 of file NCBIXML.py.

00087 
00088     def characters(self, ch):
00089         """Found some text
00090 
00091         ch -- characters read
00092         """
00093         self._value += ch # You don't ever get the whole string

def Bio.Blast.NCBIXML._XMLparser.endElement (   self,
  name 
)
Found XML end tag

name -- tag name

Definition at line 94 of file NCBIXML.py.

00094 
00095     def endElement(self, name):
00096         """Found XML end tag
00097 
00098         name -- tag name
00099         """
00100         # DON'T strip any white space, we may need it e.g. the hsp-midline
00101         
00102         # Try to call a method (defined in subclasses)
00103         method = self._secure_name('_end_' + name)
00104         #Note could use try / except AttributeError
00105         #BUT I found often triggered by nested errors...
00106         if hasattr(self, method):
00107             eval("self.%s()" % method)
00108             if self._debug > 2:
00109                 print "NCBIXML: Parsed:  " + method, self._value
00110         else:
00111             # Doesn't exist (yet)
00112             if method not in self._debug_ignore_list:
00113                 if self._debug > 1:
00114                     print "NCBIXML: Ignored: " + method, self._value
00115                 self._debug_ignore_list.append(method)
00116         
00117         # Reset character buffer
00118         self._value = ''
        

Here is the call graph for this function:

def Bio.Blast.NCBIXML._XMLparser.startElement (   self,
  name,
  attr 
)
Found XML start tag

No real need of attr, BLAST DTD doesn't use them

name -- name of the tag

attr -- tag attributes

Definition at line 53 of file NCBIXML.py.

00053 
00054     def startElement(self, name, attr):
00055         """Found XML start tag
00056 
00057         No real need of attr, BLAST DTD doesn't use them
00058 
00059         name -- name of the tag
00060 
00061         attr -- tag attributes
00062         """
00063         self._tag.append(name)
00064         
00065         # Try to call a method (defined in subclasses)
00066         method = self._secure_name('_start_' + name)
00067 
00068         #Note could use try / except AttributeError
00069         #BUT I found often triggered by nested errors...
00070         if hasattr(self, method):
00071             eval("self.%s()" % method)
00072             if self._debug > 4:
00073                 print "NCBIXML: Parsed:  " + method
00074         else:
00075             # Doesn't exist (yet)
00076             if method not in self._debug_ignore_list:
00077                 if self._debug > 3:
00078                     print "NCBIXML: Ignored: " + method
00079                 self._debug_ignore_list.append(method)
00080 
00081         #We don't care about white space in parent tags like Hsp,
00082         #but that white space doesn't belong to child tags like Hsp_midline
00083         if self._value.strip():
00084             raise ValueError("What should we do with %s before the %s tag?" \
00085                              % (repr(self._value), name))
00086         self._value = ""

Here is the call graph for this function:


Member Data Documentation

Definition at line 42 of file NCBIXML.py.

Definition at line 43 of file NCBIXML.py.

Definition at line 40 of file NCBIXML.py.

Definition at line 41 of file NCBIXML.py.


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