From 6ce933a32fda56860bc9ca05d2553255a820a635 Mon Sep 17 00:00:00 2001
From: Rob Austein <sra@hactrn.net>
Date: Tue, 16 Oct 2007 22:51:18 +0000
Subject: Formatting

svn path=/scripts/rpki/cms.py; revision=1163
---
 scripts/rpki/sql.py | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

(limited to 'scripts/rpki/sql.py')

diff --git a/scripts/rpki/sql.py b/scripts/rpki/sql.py
index 713a6e85..f47c6572 100644
--- a/scripts/rpki/sql.py
+++ b/scripts/rpki/sql.py
@@ -20,8 +20,11 @@ class template(object):
     self.index   = index_column
     self.columns = columns
     self.select  = "SELECT %s FROM %s" % (", ".join(columns), table_name)
-    self.insert  = "INSERT %s (%s) VALUES (%s)" % (table_name, ", ".join(data_columns), ", ".join("%(" + s + ")s" for s in data_columns))
-    self.update  = "UPDATE %s SET %s WHERE %s = %%(%s)s" % (table_name, ", ".join(s + " = %(" + s + ")s" for s in data_columns), index_column, index_column)
+    self.insert  = "INSERT %s (%s) VALUES (%s)" % (table_name, ", ".join(data_columns),
+                                                   ", ".join("%(" + s + ")s" for s in data_columns))
+    self.update  = "UPDATE %s SET %s WHERE %s = %%(%s)s" % \
+                   (table_name, ", ".join(s + " = %(" + s + ")s" for s in data_columns),
+                    index_column, index_column)
     self.delete  = "DELETE FROM %s WHERE %s = %%s" % (table_name, index_column)
 
 ## @var sql_cache
@@ -70,7 +73,8 @@ class sql_persistant(object):
     elif len(results) == 1:
       return results[0]
     else:
-      raise rpki.exceptions.DBConsistancyError, "Database contained multiple matches for %s.%s" % (cls.__name__, id)
+      raise rpki.exceptions.DBConsistancyError, \
+            "Database contained multiple matches for %s.%s" % (cls.__name__, id)
 
   @classmethod
   def sql_fetch_all(cls, gctx):
@@ -183,7 +187,8 @@ class sql_persistant(object):
 class ca_obj(sql_persistant):
   """Internal CA object."""
 
-  sql_template = template("ca", "ca_id", "last_crl_sn", "next_crl_update", "last_issued_sn", "last_manifest_sn", "next_manifest_update", "sia_uri", "parent_id")
+  sql_template = template("ca", "ca_id", "last_crl_sn", "next_crl_update", "last_issued_sn",
+                          "last_manifest_sn", "next_manifest_update", "sia_uri", "parent_id")
 
   def construct_sia_uri(self, gctx, parent, rc):
     """Construct the sia_uri value for this CA given configured
@@ -209,22 +214,30 @@ class ca_obj(sql_persistant):
     cert_map = dict((c.get_SKI(), c) for c in rc.certs)
     ca_details = ca_detail_obj.sql_fetch_where(gctx, "ca_id = %s AND latest_ca_cert IS NOT NULL", ca.ca_id)
     as, v4, v6 = ca_detail_obj.sql_fetch_active(gctx, ca_id).latest_ca_cert.get_3779resources()
-    undersized = not rc.resource_set_as.issubset(as) or not rc.resource_set_ipv4.issubset(v4) or not rc.resource_set_ipv6.issubset(v6)
-    oversized  = not as.issubset(rc.resource_set_as) or not v4.issubset(rc.resource_set_ipv4) or not v6.issubset(rc.resource_set_ipv6)
+    undersized = not rc.resource_set_as.issubset(as) or \
+                 not rc.resource_set_ipv4.issubset(v4) or not rc.resource_set_ipv6.issubset(v6)
+    oversized  = not as.issubset(rc.resource_set_as) or \
+                 not v4.issubset(rc.resource_set_ipv4) or not v6.issubset(rc.resource_set_ipv6)
     sia_uri = self.construct_sia_uri()
     sia_uri_changed = self.sia_uri != sia_uri
     if sia_uri_changed:
       self.sia_uri = sia_uri
       self.sql_mark_dirty()
     for ca_detail in ca_details:
-      assert ca_detail.state != "pending" or (as, v4, v6) == ca_detail.get_3779resources(), "Resource mismatch for pending cert"
+      assert ca_detail.state != "pending" or (as, v4, v6) == ca_detail.get_3779resources(), \
+             "Resource mismatch for pending cert"
     for ca_detail in ca_details:
       ski = ca_detail.latest_ca_cert.get_SKI()
-      assert ski in cert_map, "Certificate in our database missing from list_response, SKI %s" % ca_detail.latest_ca_cert.hSKI()
-      if ca_detail.state != "deprecated" and (undersized or oversized or sia_uri_changed or ca_detail.latest_ca_cert != cert_map[ski]):
-        ca_detail.update(gctx, parent, self, rc, cert_map[ski], undersized, oversized, sia_uri_changed, as, v4, v6)
+      assert ski in cert_map, \
+             "Certificate in our database missing from list_response, SKI %s" % \
+             ca_detail.latest_ca_cert.hSKI()
+      if ca_detail.state != "deprecated" and \
+           (undersized or oversized or sia_uri_changed or ca_detail.latest_ca_cert != cert_map[ski]):
+        ca_detail.update(gctx, parent, self, rc, cert_map[ski], undersized, oversized, sia_uri_changed,
+                         as, v4, v6)
       del cert_map[ski]
-    assert not cert_map, "Certificates in list_response missing from our database, SKIs %s" % ", ".join(c.hSKI() for c in cert_map.values())
+    assert not cert_map, "Certificates in list_response missing from our database, SKIs %s" % \
+           ", ".join(c.hSKI() for c in cert_map.values())
 
   @classmethod
   def create(cls, gctx, parent, rc):
@@ -270,8 +283,9 @@ class ca_obj(sql_persistant):
 class ca_detail_obj(sql_persistant):
   """Internal CA detail object."""
 
-  sql_template = template("ca", "ca_detail_id", "private_key_id", "public_key", "latest_ca_cert", "manifest_private_key_id",
-                          "manifest_public_key", "latest_manifest_cert", "latest_manifest", "latest_crl", "state", "ca_cert_uri", "ca_id")
+  sql_template = template("ca", "ca_detail_id", "private_key_id", "public_key", "latest_ca_cert",
+                          "manifest_private_key_id", "manifest_public_key", "latest_manifest_cert",
+                          "latest_manifest", "latest_crl", "state", "ca_cert_uri", "ca_id")
 
   def sql_decode(self, vals):
     """Decode SQL representation of a ca_detail_obj."""
@@ -290,7 +304,8 @@ class ca_detail_obj(sql_persistant):
   def sql_encode(self):
     """Encode SQL representation of a ca_detail_obj."""
     d = sql_persistant.sql_encode(self)
-    for i in ("private_key_id", "public_key", "latest_ca_cert", "manifest_private_key_id", "manifest_public_key", "latest_manifest_cert", "latest_manifest", "latest_crl"):
+    for i in ("private_key_id", "public_key", "latest_ca_cert", "manifest_private_key_id",
+              "manifest_public_key", "latest_manifest_cert", "latest_manifest", "latest_crl"):
       d[i] = getattr(self, i).get_DER()
     return d
 
@@ -327,7 +342,8 @@ class ca_detail_obj(sql_persistant):
     if oversized or sia_uri_changed:
       for child_cert in child_cert_obj.sql_fetch_where(gctx, "ca_detail_id = %s" % self.ca_detail_id):
         child_as, child_v4, child_v6 = child_cert.cert.get_3779resources()
-        if sia_uri_changed or not child_as.issubset(as) or not child_v4.issubset(v4) or not child_v6.issubset(v6):
+        if sia_uri_changed or not child_as.issubset(as) or \
+             not child_v4.issubset(v4) or not child_v6.issubset(v6):
           child_cert.reissue(gctx, self, as, v4, v6)
 
   @classmethod
-- 
cgit v1.2.3