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

[tor-commits] [stem/master] Stub class constants for cell attributes



commit b3ede37e0aa4910fb0fad78ed4d8d8e5796fab7b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Jan 8 11:56:07 2018 -0800

    Stub class constants for cell attributes
    
    Stem's Event subclsses do a similar pattern. Think this will make things
    cleaner...
---
 stem/client/cell.py      | 14 ++++++++++++++
 test/unit/client/cell.py |  8 ++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index 5cd23c0e..1f10a524 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -25,6 +25,11 @@ class Cell(collections.namedtuple('Cell', ['name', 'value', 'fixed_size', 'for_c
     **False** otherwise
   """
 
+  NAME = 'UNKNOWN'
+  VALUE = -1
+  IS_FIXED_SIZE = False
+  IS_FOR_CIRCUIT = False
+
   @staticmethod
   def by_name(name):
     """
@@ -35,6 +40,9 @@ class Cell(collections.namedtuple('Cell', ['name', 'value', 'fixed_size', 'for_c
     :raise: **ValueError** if cell type is invalid
     """
 
+    if name == 'NETINFO':
+      return NetinfoCell
+
     for cell_type in CELL_TYPES:
       if name == cell_type.name:
         return cell_type
@@ -129,6 +137,12 @@ class VersionCell(Cell):
     return Cell.pack('VERSIONS', 3, payload)
 
 
+class NetinfoCell(Cell):
+  NAME = 'NETINFO'
+  VALUE = 8
+  IS_FIXED_SIZE = True
+
+
 CELL_TYPES = (
   Cell('PADDING', 0, True, False),              # Padding                  (section 7.2)
   Cell('CREATE', 1, True, True),                # Create a circuit         (section 5.1)
diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index 8093b8d9..8a461aba 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -12,10 +12,10 @@ from stem.client.cell import Cell
 class TestCell(unittest.TestCase):
   def test_by_name(self):
     cell = Cell.by_name('NETINFO')
-    self.assertEqual('NETINFO', cell.name)
-    self.assertEqual(8, cell.value)
-    self.assertEqual(True, cell.fixed_size)
-    self.assertEqual(False, cell.for_circuit)
+    self.assertEqual('NETINFO', cell.NAME)
+    self.assertEqual(8, cell.VALUE)
+    self.assertEqual(True, cell.IS_FIXED_SIZE)
+    self.assertEqual(False, cell.IS_FOR_CIRCUIT)
 
     self.assertRaises(ValueError, Cell.by_name, 'NOPE')
     self.assertRaises(ValueError, Cell.by_name, 85)



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