[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Decompress bz2 responses



commit 6120d0603bacf439ea7f21c79c87d3dba4d1e68e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Dec 25 13:29:07 2017 -0800

    Decompress bz2 responses
---
 stem/descriptor/collector.py       | 3 +++
 test/integ/descriptor/collector.py | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/stem/descriptor/collector.py b/stem/descriptor/collector.py
index abd666ab..4af35827 100644
--- a/stem/descriptor/collector.py
+++ b/stem/descriptor/collector.py
@@ -50,6 +50,7 @@ With this you can either download and read directly from CollecTor...
 .. versionadded:: 1.7.0
 """
 
+import bz2
 import gzip
 import io
 import json
@@ -149,6 +150,8 @@ class CollecTor(object):
         else:
           # prior to python 3.2 gzip only had GzipFile
           response = gzip.GzipFile(fileobj = io.BytesIO(response)).read()
+      elif self.compression == Compression.BZ2:
+        response = bz2.decompress(response)
 
       self._cached_index = json.loads(stem.util.str_tools._to_unicode(response))
       self._cached_index_at = time.time()
diff --git a/test/integ/descriptor/collector.py b/test/integ/descriptor/collector.py
index c481b8c7..d79197c2 100644
--- a/test/integ/descriptor/collector.py
+++ b/test/integ/descriptor/collector.py
@@ -18,7 +18,12 @@ class TestCollector(unittest.TestCase):
   @test.require.only_run_once
   @test.require.online
   def test_index_gzip(self):
-    self._test_index(Compression.NONE)
+    self._test_index(Compression.GZ)
+
+  @test.require.only_run_once
+  @test.require.online
+  def test_index_bz2(self):
+    self._test_index(Compression.BZ2)
 
   def _test_index(self, compression):
     collector = CollecTor(compression = compression)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits