Permalink
Browse files

Remove deprecated Bio.File.StringHandle and SGMLStripper

Also removes Bio.ParserSupport.SGMLStrippingConsumer
  • Loading branch information...
1 parent 63997ea commit 084c89800e0e92746ded560a31c0ecbc9b0492e0 @peterjc peterjc committed Feb 4, 2013
Showing with 12 additions and 116 deletions.
  1. +0 −65 Bio/File.py
  2. +0 −34 Bio/ParserSupport.py
  3. +5 −2 DEPRECATED
  4. +2 −11 Tests/test_File.py
  5. +5 −4 Tests/test_ParserSupport.py
View
65 Bio/File.py
@@ -11,12 +11,6 @@
UndoHandle File object decorator with support for undo-like operations.
-StringHandle Wraps a file object around a string. This is now DEPRECATED,
- and is likely to be removed in a future release of Biopython.
-
-SGMLStripper Object that strips SGML. This is now DEPRECATED, and is likely
- to be removed in a future release of Biopython.
-
Additional private classes used in Bio.SeqIO and Bio.SearchIO for indexing
files are also defined under Bio.File but these are not intended for direct
use.
@@ -184,65 +178,6 @@ def __exit__(self, type, value, traceback):
self._handle.close()
-# I could make this faster by using cStringIO.
-# However, cStringIO (in v1.52) does not implement the
-# readlines method.
-class StringHandle(StringIO.StringIO):
- def __init__(self, buffer=''):
- import warnings
- import Bio
- warnings.warn("This class is deprecated, and is likely to be removed in a future version of Biopython. Please use the class StringIO in the module StringIO in the Python standard library instead", Bio.BiopythonDeprecationWarning)
- StringIO.StringIO.__init__(self, buffer)
-
-try:
- import sgmllib
-except ImportError:
- #This isn't available on Python 3, but we don't care much as SGMLStripper
- #is obsolete
- pass
-else:
- class SGMLStripper(object):
- """Object to strip SGML tags (OBSOLETE)."""
- class MyParser(sgmllib.SGMLParser):
- def __init__(self):
- sgmllib.SGMLParser.__init__(self)
- self.data = ''
-
- def handle_data(self, data):
- self.data = self.data + data
-
- def __init__(self):
- import warnings
- import Bio
- warnings.warn("This class is deprecated, and is likely to be removed in a future version of Biopython", Bio.BiopythonDeprecationWarning)
- self._parser = SGMLStripper.MyParser()
-
- def strip(self, str):
- """S.strip(str) -> string
-
- Strip the SGML tags from str.
-
- """
- if not str: # empty string, don't do anything.
- return ''
- # I need to make sure that I don't return an empty string if
- # the buffer is not empty. This can happen if there's a newline
- # character embedded within a tag. Thus, I'll first check to
- # see if the last character is a newline. If it is, and it's stripped
- # away, I'll add it back.
- is_newline = str[-1] in ['\n', '\r']
-
- self._parser.data = '' # clear the parser's data (don't reset)
- self._parser.feed(str)
- if self._parser.data:
- str = self._parser.data
- elif is_newline:
- str = '\n'
- else:
- str = ''
- return str
-
-
#The rest of this file defines code used in Bio.SeqIO and Bio.SearchIO
#for indexing
View
34 Bio/ParserSupport.py
@@ -11,7 +11,6 @@
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
(note that Martel is now DEPRECATED)
@@ -134,39 +133,6 @@ def __getattr__(self, attr):
return method
-class SGMLStrippingConsumer(object):
- """A consumer that strips off SGML tags.
-
- This is meant to be used as a decorator for other consumers.
-
- """
- def __init__(self, consumer):
- import Bio
- warnings.warn("SGMLStrippingConsumer is deprecated, and is likely to be removed in a future version of Biopython", Bio.BiopythonDeprecationWarning)
- if type(consumer) is not InstanceType:
- raise ValueError("consumer should be an instance")
- self._consumer = consumer
- self._prev_attr = None
- self._stripper = File.SGMLStripper()
-
- def _apply_clean_data(self, data):
- clean = self._stripper.strip(data)
- self._prev_attr(clean)
-
- def __getattr__(self, name):
- if name in ['_prev_attr', '_stripper']:
- return getattr(self, name)
- attr = getattr(self._consumer, name)
- # If this is not a method, then return it as is.
- if type(attr) is not MethodType:
- return attr
- # If it's a section method, then return it.
- if name[:6] == 'start_' or name[:4] == 'end_':
- return attr
- # Otherwise, it's an info event, and return my method.
- self._prev_attr = attr
- return self._apply_clean_data
-
# onle use the Event Generator if XML handling is okay
if xml_support:
class EventGenerator(handler.ContentHandler):
View
7 DEPRECATED
@@ -145,7 +145,8 @@ Bio.File
========
Bio.File.SGMLHandle was declared obsolete in Release 1.50, deprecated in
Release 1.52, and removed in Release 1.56. Bio.File.SGMLStripper was deprecated
-in Release 1.57. Bio.File.StringHandle was deprecated in Release 1.59.
+in Release 1.57, removed in Release 1.61. Bio.File.StringHandle was deprecated
+in Release 1.59, removed in Release 1.61.
Bio.Graphics.GenomeDiagram and colour/color, centre/center
==========================================================
@@ -522,4 +523,6 @@ method get_seq_by_num were deprecated in Release 1.57.
Bio.ParserSupport
=================
Bio.ParserSupport was declared obsolete in Release 1.59.
-Bio.ParserSupport.SGMLStrippingConsumer was deprecated in Release 1.59.
+
+Bio.ParserSupport.SGMLStrippingConsumer was deprecated in Release 1.59, and
+removed in Release 1.61.
View
13 Tests/test_File.py
@@ -20,18 +20,9 @@
file"""
-### StringHandle
-
-h = File.StringHandle(data)
-print repr(h.readline()) # 'This'
-print len(h.readlines()) # 3
-print repr(h.readline()) # ''
-h.close()
-
-
### UndoHandle
-h = File.UndoHandle(File.StringHandle(data))
+h = File.UndoHandle(StringIO(data))
print h.readline() # 'This'
print h.peekline() # 'is'
@@ -57,7 +48,7 @@
print repr(h.readline()) # ''
# test read method
-h = File.UndoHandle(File.StringHandle("some text"))
+h = File.UndoHandle(StringIO("some text"))
h.saveline("more text")
print h.read() # 'more textsome text'
View
9 Tests/test_ParserSupport.py
@@ -4,6 +4,7 @@
# as part of this package.
import string
+from StringIO import StringIO
from Bio import File
from Bio import ParserSupport
@@ -58,7 +59,7 @@ def write(self, s):
data = """This
file"""
-h = File.UndoHandle(File.StringHandle(data))
+h = File.UndoHandle(StringIO(data))
safe_readline = ParserSupport.safe_readline
print safe_readline(h) # "This"
@@ -79,7 +80,7 @@ def write(self, s):
data = """This
file"""
-h = File.UndoHandle(File.StringHandle(data))
+h = File.UndoHandle(StringIO(data))
print safe_peekline(h) # "This"
h.readline()
@@ -109,7 +110,7 @@ def write(self, s):
"""
-h = File.UndoHandle(File.StringHandle(data))
+h = File.UndoHandle(StringIO(data))
rac = ParserSupport.read_and_call
lines = []
@@ -171,7 +172,7 @@ def m(line):
RKEYAVVNLDKLNGFAEGTEVTPELLLETGVISKLNAGVKILGNGKLEKKLTVKANKFSASAKEAVEAAG
GTAEVI"""
-h = File.UndoHandle(File.StringHandle(data))
+h = File.UndoHandle(StringIO(data))
arac = lambda *args, **keywds: \
pb(ParserSupport.attempt_read_and_call(*args, **keywds))

0 comments on commit 084c898

Please sign in to comment.