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

[tor-commits] [stem/master] Using server descriptor when parsing



commit 3b657b57b4cb4ce5304145a7a55051e758cf9cbd
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Mar 23 09:28:55 2012 -0700

    Using server descriptor when parsing
    
    Parsing server descriptors via the new server descriptor class. This breaks the
    tests and will need quite a bit of work. :)
---
 stem/descriptor/__init__.py          |    2 +-
 stem/descriptor/descriptor.py        |   14 ++++++++++++--
 stem/descriptor/server_descriptor.py |    6 +++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 33970ef..0a5ba81 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -2,5 +2,5 @@
 Utilities for parsing and processing descriptor data.
 """
 
-__all__ = ["descriptor", "reader"]
+__all__ = ["descriptor", "reader", "server_descriptor"]
 
diff --git a/stem/descriptor/descriptor.py b/stem/descriptor/descriptor.py
index a89e5e5..f535afc 100644
--- a/stem/descriptor/descriptor.py
+++ b/stem/descriptor/descriptor.py
@@ -4,6 +4,8 @@ Common functionality for descriptors.
 
 import os
 
+import stem.descriptor.server_descriptor
+
 def parse_descriptors(path, descriptor_file):
   """
   Provides an iterator for the descriptors within a given file.
@@ -28,13 +30,21 @@ def parse_descriptors(path, descriptor_file):
   filename = os.path.basename(path)
   
   if filename == "cached-descriptors":
-    pass # server descriptors from tor's data directory
+    # server descriptors from tor's data directory
+    while descriptor_file:
+      yield stem.descriptor.server_descriptor.parse_server_descriptors_v2(path, descriptor_file)
+    
+    return
   
   first_line = descriptor_file.readline()
   descriptor_file.seek(0)
   
   if first_line.startswith("router "):
-    pass # server descriptor
+    # server descriptor
+    while descriptor_file:
+      yield stem.descriptor.server_descriptor.parse_server_descriptors_v2(path, descriptor_file)
+    
+    return
   
   # TODO: implement actual descriptor type recognition and parsing
   # TODO: add integ test for non-descriptor text content
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index a60e9f2..40124f5 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -14,7 +14,7 @@ import datetime
 import stem.version
 import stem.util.connection
 import stem.util.tor_tools
-from stem.descriptor.descriptor import Descriptor
+import stem.descriptor.descriptor
 
 ENTRY_START = "router"
 ENTRY_END   = "router-signature"
@@ -164,7 +164,7 @@ def _get_psudo_pgp_block(remaining_contents):
   else:
     return (None, None)
 
-class ServerDescriptorV2(Descriptor):
+class ServerDescriptorV2(stem.descriptor.descriptor.Descriptor):
   """
   Version 2 server descriptor, as specified in...
   https://gitweb.torproject.org/torspec.git/blob/HEAD:/dir-spec-v2.txt
@@ -230,7 +230,7 @@ class ServerDescriptorV2(Descriptor):
       ValueError if the contents is malformed and validate is True
     """
     
-    Descriptor.__init__(self, contents)
+    stem.descriptor.descriptor.Descriptor.__init__(self, contents)
     
     self._annotation_lines = annotations
     self._annotation_dict = {}



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