[Pkg-privacy-commits] [txtorcon] 56/96: lazy-parse router.modified attribute

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Sep 6 18:33:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository txtorcon.

commit 047c22ef8385634c89eae91c5ef7ac31b51b71af
Author: meejah <meejah at meejah.ca>
Date:   Thu Feb 5 18:27:06 2015 -0700

    lazy-parse router.modified attribute
---
 test/test_router.py  |  5 +++++
 txtorcon/router.py   | 14 +++++++++++++-
 txtorcon/torstate.py | 14 +++++++-------
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/test/test_router.py b/test/test_router.py
index c23ba36..743f707 100644
--- a/test/test_router.py
+++ b/test/test_router.py
@@ -1,3 +1,4 @@
+from datetime import datetime
 from twisted.trial import unittest
 from twisted.internet import defer
 
@@ -42,6 +43,10 @@ class RouterTests(unittest.TestCase):
             router.id_hex,
             "$00786E43CCC5409753F25E36031C5CEA6EA43702"
         )
+        self.assertTrue(
+            isinstance(router.modified,
+                       datetime)
+        )
         self.assertEqual(router.policy, '')
 
     def test_unique_name(self):
diff --git a/txtorcon/router.py b/txtorcon/router.py
index aac4d71..f0e935e 100644
--- a/txtorcon/router.py
+++ b/txtorcon/router.py
@@ -1,3 +1,4 @@
+from datetime import datetime
 from util import NetLocation
 import types
 
@@ -69,11 +70,22 @@ class Router(object):
     unique_name = property(lambda x: x.name_is_unique and x.name or x.id_hex)
     "has the hex id if this router's name is not unique, or its name otherwise"
 
+    @property
+    def modified(self):
+        if self._modified is None:
+            self._modified = datetime.strptime(
+                self._modified_unparsed,
+                '%Y-%m-%f %H:%M:%S'
+            )
+        return self._modified
+
     def update(self, name, idhash, orhash, modified, ip, orport, dirport):
         self.name = name
         self.id_hash = idhash
         self.or_hash = orhash
-        self.modified = modified
+        # modified is lazy-parsed, approximately doubling router-parsing time
+        self._modified_unparsed = modified
+        self._modified = None
         self.ip = ip
         self.or_port = orport
         self.dir_port = dirport
diff --git a/txtorcon/torstate.py b/txtorcon/torstate.py
index c117a85..0207a83 100644
--- a/txtorcon/torstate.py
+++ b/txtorcon/torstate.py
@@ -284,13 +284,13 @@ class TorState(object):
         self._router = Router(self.protocol)
         self._router.from_consensus = True
         self._router.update(
-            args[1],         # nickname
-            args[2],         # idhash
-            args[3],         # orhash
-            datetime.datetime.strptime(args[4] + args[5], '%Y-%m-%f%H:%M:%S'),
-            args[6],         # ip address
-            args[7],         # ORPort
-            args[8],         # DirPort
+            args[1],                 # nickname
+            args[2],                 # idhash
+            args[3],                 # orhash
+            args[4] + ' ' + args[5], # modified (like '%Y-%m-%f %H:%M:%S')
+            args[6],                 # ip address
+            args[7],                 # ORPort
+            args[8],                 # DirPort
         )
 
         if self._router.id_hex in self.routers:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/txtorcon.git



More information about the Pkg-privacy-commits mailing list