Commits

Lars Yencken committed a470680

Uses external gzip or bzip2 processes for decompression.

Comments (0)

Files changed (1)

 """
 
 from xml.etree import cElementTree as ElementTree
-import bz2
-import gzip
+import subprocess
 
 def iterxml(stream_or_file, tag_of_interest):
     """
     """
     if isinstance(stream_or_file, (str, unicode)):
         if stream_or_file.endswith('.bz2'):
-            istream = bz2.BZ2File(stream_or_file, 'r')
+            istream = _bzip_pipe(stream_or_file)
         elif stream_or_file.endswith('.gz'):
-            istream = gzip.GzipFile(stream_or_file, 'r')
+            istream = _gzip_pipe(stream_or_file)
         else:
             istream = open(stream_or_file, 'r')
     else:
             yield node
             root.clear()
 
+def _bzip_pipe(filename):
+    p = subprocess.Popen(['bunzip2', '-c', filename], stdin=subprocess.PIPE,
+        stdout=subprocess.PIPE)
+    p.stdin.close()
+    return p.stdout
+
+def _gzip_pipe(filename):
+    p = subprocess.Popen(['gunzip', '-c', filename], stdin=subprocess.PIPE,
+        stdout=subprocess.PIPE)
+    p.stdin.close()
+    return p.stdout
+
 # vim: ts=4 sw=4 sts=4 et tw=78: