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

[tor-commits] [ooni-probe/master] Make getDiff take as required argument a TrueHeaders object instead of a dict



commit a3025bf24be234c6fbb6b9fad251ad5fa0ef4e6f
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Thu Nov 29 13:13:46 2012 +0100

    Make getDiff take as required argument a TrueHeaders object instead of a dict
---
 ooni/templates/httpt.py        |    3 ++-
 ooni/utils/txagentwithsocks.py |   20 +++++++++++++-------
 tests/test_trueheaders.py      |    8 ++++----
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index dcd8ff9..804a3e4 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -115,9 +115,10 @@ class HTTPTest(NetTestCase):
             failure (instance): An instance of :class:twisted.internet.failure.Failure
         """
         log.debug("Adding %s to report" % request)
+        request_headers = TrueHeaders(request['headers'])
         request_response = {
             'request': {
-                'headers': request['headers'],
+                'headers': list(request_headers.getAllRawHeaders()),
                 'body': request['body'],
                 'url': request['url'],
                 'method': request['method']
diff --git a/ooni/utils/txagentwithsocks.py b/ooni/utils/txagentwithsocks.py
index ffaa733..7c34288 100644
--- a/ooni/utils/txagentwithsocks.py
+++ b/ooni/utils/txagentwithsocks.py
@@ -149,18 +149,25 @@ class TrueHeaders(http_headers.Headers):
         self._rawHeaders[name.lower()]['name'] = name
         self._rawHeaders[name.lower()]['values'] = values
 
-    def getDiff(self, header_dict, ignore=[]):
+    def getDiff(self, headers, ignore=[]):
         """
-        ignore: specify a list of header fields to ignore
 
-        Returns a set containing the header names that are not present in
-        header_dict or not present in self.
+        Args:
+
+            headers: a TrueHeaders object
+
+            ignore: specify a list of header fields to ignore
+
+        Returns:
+
+            a set containing the header names that are not present in
+            header_dict or not present in self.
         """
         diff = set()
         field_names = []
 
         headers_a = copy(self)
-        headers_b = TrueHeaders(header_dict)
+        headers_b = copy(headers)
         for name in ignore:
             try:
                 del headers_a._rawHeaders[name.lower()]
@@ -176,8 +183,7 @@ class TrueHeaders(http_headers.Headers):
             field_names.append(k)
 
         for name in field_names:
-            if self.getRawHeaders(name) and \
-                name in header_dict:
+            if self.getRawHeaders(name) and headers.getRawHeaders(name):
                 pass
             else:
                 diff.add(name)
diff --git a/tests/test_trueheaders.py b/tests/test_trueheaders.py
index 33521b8..9ac0a27 100644
--- a/tests/test_trueheaders.py
+++ b/tests/test_trueheaders.py
@@ -23,18 +23,18 @@ dummy_headers_dict3 = {
 class TestTrueHeaders(unittest.TestCase):
     def test_names_match(self):
         th = TrueHeaders(dummy_headers_dict)
-        self.assertEqual(th.getDiff(dummy_headers_dict), set())
+        self.assertEqual(th.getDiff(TrueHeaders(dummy_headers_dict)), set())
 
     def test_names_not_match(self):
         th = TrueHeaders(dummy_headers_dict)
-        self.assertEqual(th.getDiff(dummy_headers_dict2), set(['Header3']))
+        self.assertEqual(th.getDiff(TrueHeaders(dummy_headers_dict2)), set(['Header3']))
 
         th = TrueHeaders(dummy_headers_dict3)
-        self.assertEqual(th.getDiff(dummy_headers_dict2), set(['Header3', 'Header4']))
+        self.assertEqual(th.getDiff(TrueHeaders(dummy_headers_dict2)), set(['Header3', 'Header4']))
 
     def test_names_match_expect_ignore(self):
         th = TrueHeaders(dummy_headers_dict)
-        self.assertEqual(th.getDiff(dummy_headers_dict2, ignore=['Header3']), set())
+        self.assertEqual(th.getDiff(TrueHeaders(dummy_headers_dict2), ignore=['Header3']), set())
 
 
 



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