infocalypse

(djk)
2009-04-08: Pylint fixes.

Pylint fixes.

diff --git a/infocalypse/__init__.py b/infocalypse/__init__.py
--- a/infocalypse/__init__.py
+++ b/infocalypse/__init__.py
@@ -256,7 +256,7 @@ FCP_OPTS = [('', 'fcphost', '', 'fcp hos
 
 AGGRESSIVE_OPT = [('', 'aggressive', None, 'aggressively search for the '
                    + 'latest USK index'),]
-NOSEARCH_OPT = [('', 'nosearch', None, 'use USK version in URI'),]
+NOSEARCH_OPT = [('', 'nosearch', None, 'use USK version in URI'), ]
 # Allow mercurial naming convention for command table.
 # pylint: disable-msg=C0103
 cmdtable = {
diff --git a/infocalypse/fcpclient.py b/infocalypse/fcpclient.py
--- a/infocalypse/fcpclient.py
+++ b/infocalypse/fcpclient.py
@@ -1,3 +1,4 @@
+# REDFLAG: There are changes here that haven't been pushed back into main repo.
 """ Simplified client interface for common FCP request.
 
     Copyright (C) 2008 Darrell Karbott
@@ -794,3 +795,61 @@ def parse_rollup_filename(filename):
     end_index = int(fields[-5])
     human_readable = '_'.join(fields[:-6]) # REDFLAG: dci obo?
     return (human_readable, start_index, end_index, tip, parent, repo_id)
+
+
+############################################################
+# Stuff moved from updatesm.py, cleanup.
+############################################################
+
+# Hmmm... do better?
+# IIF ends with .R1 second ssk ends with .R0.
+# Makes it easy for paranoid people to disable redundant
+# top key fetching. ie. just request *R0 instead of *R1.
+# Also could intuitively be expanded to higher levels of
+# redundancy.
+def make_redundant_ssk(usk, version):
+    """ Returns a redundant ssk pair for the USK version IFF the file
+        part of usk ends with '.R1', otherwise a single
+        ssk for the usk specified version. """
+    ssk = get_ssk_for_usk_version(usk, version)
+    fields = ssk.split('-')
+    if not fields[-2].endswith('.R1'):
+        return (ssk, )
+    #print "make_redundant_ssk -- is redundant"
+    fields[-2] = fields[-2][:-2] + 'R0'
+    return (ssk, '-'.join(fields))
+
+# For search
+def make_search_uris(uri):
+    """ Returns a redundant USK pair if the file part of uri ends
+        with '.R1', a tuple containing only uri. """
+    if not is_usk_file(uri):
+        return (uri,)
+    fields = uri.split('/')
+    if not fields[-2].endswith('.R1'):
+        return (uri, )
+    #print "make_search_uris -- is redundant"
+    fields[-2] = fields[-2][:-2] + 'R0'
+    return (uri, '/'.join(fields))
+
+def make_frozen_uris(uri, increment=True):
+    """ Returns a possibly redundant SSK tuple for the 'frozen'
+        version of file USK uris, a tuple containing uri for other uris.
+
+        NOTE: This increments the version by 1 if uri is a USK
+              and increment is True.
+    """
+    if uri == 'CHK@':
+        return (uri,)
+    assert is_usk_file(uri)
+    version = get_version(uri)
+    return make_redundant_ssk(uri, version + int(bool(increment)))
+
+def ssk_to_usk(ssk):
+    """ Convert an SSK for a file USK back into a file USK. """
+    fields = ssk.split('-')
+    end = '/'.join(fields[-2:])
+    fields = fields[:-2] + [end, ]
+    return 'USK' + '-'.join(fields)[3:]
+
+
diff --git a/infocalypse/graph.py b/infocalypse/graph.py
--- a/infocalypse/graph.py
+++ b/infocalypse/graph.py
@@ -337,23 +337,23 @@ class UpdateGraph:
         edge_list[ordinal + 1] = chk
         self.edge_table[index_pair] = tuple(edge_list)
 
-    def insert_type_(self, edge_triple):
-        """ Return the kind of insert required to insert the CHK
-            for the edge.
+# def insert_type_(self, edge_triple):
+#         """ Return the kind of insert required to insert the CHK
+#             for the edge.
 
-            INSERT_NORMAL -> No modification to the bundle file.
-            INSERT_PADDED -> Add one trailing pad byte.
-            INSERT_SALTED_METADATA -> Copy and salt the Freenet
-            split file metadata for the normal insert. """
-        edge_info = self.edge_table[edge_triple[:2]]
-        #print "insert_type -- ", edge_triple, entry
-        if edge_info[edge_triple[2] + 1] == PENDING_INSERT:
-            return INSERT_NORMAL
-        if edge_info[edge_triple[2] + 1] != PENDING_INSERT1:
-            raise ValueError("CHK already set?")
-        if edge_info[0] <= FREENET_BLOCK_LEN:
-            return INSERT_PADDED
-        return INSERT_SALTED_METADATA
+#             INSERT_NORMAL -> No modification to the bundle file.
+#             INSERT_PADDED -> Add one trailing pad byte.
+#             INSERT_SALTED_METADATA -> Copy and salt the Freenet
+#             split file metadata for the normal insert. """
+#         edge_info = self.edge_table[edge_triple[:2]]
+#         #print "insert_type -- ", edge_triple, entry
+#         if edge_info[edge_triple[2] + 1] == PENDING_INSERT:
+#             return INSERT_NORMAL
+#         if edge_info[edge_triple[2] + 1] != PENDING_INSERT1:
+#             raise ValueError("CHK already set?")
+#         if edge_info[0] <= FREENET_BLOCK_LEN:
+#             return INSERT_PADDED
+#         return INSERT_SALTED_METADATA
 
     def insert_type(self, edge_triple):
         """ Return the kind of insert required to insert the CHK
diff --git a/infocalypse/infcmds.py b/infocalypse/infcmds.py
--- a/infocalypse/infcmds.py
+++ b/infocalypse/infcmds.py
@@ -361,8 +361,9 @@ def do_key_setup(ui_, update_sm, params,
             # Force the insert URI down to the version in the request URI.
             usks_equal(request_uri, params['INVERTED_INSERT_URI'])):
             params['INVERTED_INSERT_URI'] = request_uri
-            params['INSERT_URI'] = get_usk_for_usk_version(insert_uri,
-                                                           get_version(request_uri))
+            params['INSERT_URI'] = get_usk_for_usk_version(
+                insert_uri,
+                get_version(request_uri))
 
     # Skip key inversion if we already inverted the insert_uri.
     is_keypair = False
diff --git a/infocalypse/topkey.py b/infocalypse/topkey.py
--- a/infocalypse/topkey.py
+++ b/infocalypse/topkey.py
@@ -124,6 +124,7 @@ def bytes_to_top_key_tuple(bytes):
     return (tuple(graph_chks), tuple(updates))
 
 def default_out(text):
+    """ Default output function for dump_top_key_tuple(). """
     if text.endswith('\n'):
         text = text[:-1]
     print text
diff --git a/infocalypse/updatesm.py b/infocalypse/updatesm.py
--- a/infocalypse/updatesm.py
+++ b/infocalypse/updatesm.py
@@ -20,15 +20,14 @@
     Author: djk@isFiaD04zgAgnrEC5XJt1i4IE7AkNPqhBG5bONi6Yks
 """
 
-# Classes for inserting to or updating from freenet
-# REDFLAG: better name.
-
 import os
 import random
 import time
 
 from fcpclient import get_ssk_for_usk_version, get_usk_for_usk_version, \
-     is_usk, is_ssk, is_usk_file, get_version, get_negative_usk
+     is_usk, is_ssk, is_usk_file, get_version, get_negative_usk, \
+     make_search_uris, make_frozen_uris, ssk_to_usk
+
 from fcpconnection import SUCCESS_MSGS
 from fcpmessage import GET_DEF, PUT_FILE_DEF, GET_REQUEST_URI_DEF
 
@@ -56,58 +55,6 @@ HG_MIME_TYPE_FMT = HG_MIME_TYPE + ';%i'
 METADATA_MARKER = HG_MIME_TYPE + ';'
 PAD_BYTE = '\xff'
 
-# Hmmm... do better?
-# IIF ends with .R1 second ssk ends with .R0.
-# Makes it easy for paranoid people to disable redundant
-# top key fetching. ie. just request *R0 instead of *R1.
-# Also could intuitively be expanded to higher levels of
-# redundancy.
-def make_redundant_ssk(usk, version):
-    """ Returns a redundant ssk pair for the USK version IFF the file
-        part of usk ends with '.R1', otherwise a single
-        ssk for the usk specified version. """
-    ssk = get_ssk_for_usk_version(usk, version)
-    fields = ssk.split('-')
-    if not fields[-2].endswith('.R1'):
-        return (ssk, )
-    #print "make_redundant_ssk -- is redundant"
-    fields[-2] = fields[-2][:-2] + 'R0'
-    return (ssk, '-'.join(fields))
-
-# For search
-def make_search_uris(uri):
-    """ Returns a redundant USK pair if the file part of uri ends
-        with '.R1', a tuple containing only uri. """
-    if not is_usk_file(uri):
-        return (uri,)
-    fields = uri.split('/')
-    if not fields[-2].endswith('.R1'):
-        return (uri, )
-    #print "make_search_uris -- is redundant"
-    fields[-2] = fields[-2][:-2] + 'R0'
-    return (uri, '/'.join(fields))
-
-def make_frozen_uris(uri, increment=True):
-    """ Returns a possibly redundant SSK tuple for the 'frozen'
-        version of file USK uris, a tuple containing uri for other uris.
-
-        NOTE: This increments the version by 1 if uri is a USK
-              and increment is True.
-    """
-    if uri == 'CHK@':
-        return (uri,)
-    assert is_usk_file(uri)
-    version = get_version(uri)
-    # REDFLAG: does index increment really belong here?
-    return make_redundant_ssk(uri, version + int(bool(increment)))
-
-def ssk_to_usk(ssk):
-    """ Convert an SSK for a file USK back into a file USK. """
-    fields = ssk.split('-')
-    end = '/'.join(fields[-2:])
-    fields = fields[:-2] + [end, ]
-    return 'USK' + '-'.join(fields)[3:]
-
 class UpdateContext(dict):
     """ A class to hold inter-state data used while the state machine is
         running. """
@@ -591,7 +538,8 @@ class RequestingUri(StaticRequestList):
 
         if (is_usk(request_uri) and self.parent.params['NO_SEARCH']):
             request_uris = make_frozen_uris(request_uri, False)
-            self.parent.ctx.ui_.status("Request URI index searching disabled.\n")
+            self.parent.ctx.ui_.status("Request URI index searching "
+                                       + "disabled.\n")
         else:
             request_uris = make_search_uris(request_uri)