[BioPython] more cleanup

Andreas Kuntzagk andreas.kuntzagk at mdc-berlin.de
Thu Jun 19 14:06:57 EDT 2003


While I was at it, i tried to make Martel/Parser.py a little bit nicer.
Especially _do_callback (only for beaty, not for speed)
I you like it, you can incorporate it, if not, throw it away.

Andreas


-------------- next part --------------
Index: Martel/Parser.py
===================================================================
RCS file: /home/repository/biopython/biopython/Martel/Parser.py,v
retrieving revision 1.8
diff -r1.8 Parser.py
132,133c132,137
<     for item in taglist:
<         tag, l, r, subtags = item
---
>     # bind functions to local names for a slight speedup
>     characters   = cont_handler.characters
>     startElement = cont_handler.startElement
>     endElement   = cont_handler.endElement
>     
>     for tag, l, r, subtags in taglist:
135a140
>         assert begin <= l, "begin = %d and l = %d" % (begin, l)
137,148c142
<             cont_handler.characters(s[begin:l])
<         else:
<             # Some integrity checking
<             assert begin == l, "begin = %d and l = %d" % (begin, l)
< 
<         if tag[0] == ">":
<             if tag == ">ignore":
<                 # Named groups doesn't create ">ignore" tags, so pass them on
<                 # to the ContentHandler.  Unnamed groups still need a name so
<                 # mxTextTools can create subtags for them.  I named them
<                 # ">ignore" - don't create events for them.
<                 pass
---
>             characters(s[begin:l])
150c144,146
<             elif tag[:2] == ">G":
---
>         if tag.startswith(">"):
>             if not tag == ">ignore":
>                 assert tag.startswith(">G"),"Unknown special tag %s" % repr(tag)
153,157c149,150
<                 cont_handler.startElement(realtag, attrs)
< 
<             else:
<                 raise AssertionError("Unknown special tag %s" % repr(tag))
<         else:
---
>                 startElement(realtag, attrs)
>         
159c152
<             cont_handler.startElement(tag, _attribute_list)
---
>             startElement(tag, _attribute_list)
165,166c158
<             cont_handler.characters(s[l:r])
<         begin = r
---
>             characters(s[l:r])
168,175c160,162
<         if tag[0] == ">":
<             if tag == ">ignore":
<                 pass
<             elif tag[:2] == ">G":
<                 realtag, attrs = attrlookup[tag]
<                 cont_handler.endElement(realtag)
<             else:
<                 raise AssertionError("Unknown special tag %s" % repr(tag))
---
>         if not tag == ">ignore":
>             realtag, attrs = attrlookup[tag]
>             endElement(realtag)
177c164
<             cont_handler.endElement(tag)
---
>             endElement(tag)
181,182c168,169
<     if begin < end:
<         cont_handler.characters(s[begin:end])
---
>     if r < end:
>         characters(s[r:end])
202,203c189
<     for item in taglist:
<         tag, l, r, subtags = item
---
>     for tag, l, r, subtags in taglist:
206,211c192,194
<         if begin < l:
<             if save_stack:
<                 cont_handler._save_text += s[begin:l]
<         else:
<             # Some integrity checking
<             assert begin == l, "begin = %d and l = %d" % (begin, l)
---
>         assert begin <= l, "begin = %d and l = %d" % (begin, l)
>         if begin < l and save_stack:
>             cont_handler._save_text += s[begin:l]
245d227
<         begin = r
263,264c245,246
<     if begin < end and save_stack:
<         cont_handler._save_text += s[begin:end]
---
>     if r < end and save_stack:
>         cont_handler._save_text += s[r:end]
543,546c525,530
<     self.make_header_reader, self.header_reader_args, self.header_tagtable,
<     self.make_reader, self.reader_args, self.record_tagtable,
<     self.make_footer_reader, self.footer_reader_args, self.footer_tagtable,
<     (self.want_groupref_names, self.debug_level, self.attrlookup))
---
>                                     self.make_header_reader, self.header_reader_args,
>                                     self.header_tagtable,self.make_reader,
>                                     self.reader_args, self.record_tagtable,
>                                     self.make_footer_reader, self.footer_reader_args,
>                                     self.footer_tagtable,
>                                     (self.want_groupref_names, self.debug_level, self.attrlookup))


More information about the BioPython mailing list