]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
remove the DirnodeURI foolscap schema and mv those regexes into uri.py
authorZooko O'Whielacronx <zooko@zooko.com>
Wed, 19 Dec 2007 00:44:24 +0000 (17:44 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Wed, 19 Dec 2007 00:44:24 +0000 (17:44 -0700)
We currently do not pass dirnode uris over foolscap.

src/allmydata/interfaces.py
src/allmydata/test/test_uri.py
src/allmydata/uri.py

index 2a23391e81f615e6de4cf23bc698a2ea28b34cd3..f8ef5acd2e8eb9484012234760fe9452bba389b5 100644 (file)
@@ -14,30 +14,6 @@ FURL = StringConstraint(1000)
 StorageIndex = StringConstraint(16)
 URI = StringConstraint(300) # kind of arbitrary
 
-ZBASE32CHAR = "[ybndrfg8ejkmcpqxot1uwisza345h769]" # excludes l, 0, 2, and v
-ZBASE32CHAR_3bits = "[yoearcwh]"
-ZBASE32CHAR_1bits = "[yo]"
-ZBASE32STR_128bits = "%s{25}%s" % (ZBASE32CHAR, ZBASE32CHAR_3bits)
-ZBASE32STR_256bits = "%s{51}%s" % (ZBASE32CHAR, ZBASE32CHAR_1bits)
-COLON="(:|%3A)"
-
-# Writeable SSK bits
-WSSKBITS= "%s%s%s" % (ZBASE32STR_128bits, COLON, ZBASE32STR_256bits)
-
-# URIs (soon to be renamed "caps") are always allowed to come with a leading
-# "http://127.0.0.1:8123/uri/" that will be ignored.
-OPTIONALHTTPLEAD=r'(https?://(127.0.0.1|localhost):8123/uri/)?'
-
-# Writeable SSK URI
-WSSKURI="^%sURI%sSSK%s%s$" % (OPTIONALHTTPLEAD, COLON, COLON, WSSKBITS)
-
-WriteableSSKFileURI = StringConstraint(300, regexp=WSSKURI)
-
-# NewDirectory Read-Write URI
-NDRWURI="^%sURI%sDIR2%s%s/?$" % (OPTIONALHTTPLEAD, COLON, COLON, WSSKBITS)
-
-DirnodeURI = StringConstraint(300,  regexp=NDRWURI)
-
 MAX_BUCKETS = 200  # per peer
 
 # MAX_SEGMENT_SIZE in encode.py is 1 MiB (this constraint allows k = 1)
index 0d2a8f960b07dd4c8d3571f47dafd5a580f4c6f7..3151dc9b13e8b0c081046b6328d8cc1d9c470857 100644 (file)
@@ -2,8 +2,8 @@
 from twisted.trial import unittest
 from allmydata import uri
 from allmydata.util import hashutil
-from allmydata.interfaces import IURI, IFileURI, IDirnodeURI, DirnodeURI, \
-     IMutableFileURI, IVerifierURI
+from allmydata.interfaces import IURI, IFileURI, IDirnodeURI, IMutableFileURI, \
+    IVerifierURI
 from foolscap.schema import Violation
 
 class Literal(unittest.TestCase):
@@ -169,11 +169,11 @@ class Invalid(unittest.TestCase):
 class Constraint(unittest.TestCase):
     def test_constraint(self):
        good="http://127.0.0.1:8123/uri/URI%3ADIR2%3Aqo8ayna47cpw3rx3kho3mu7q4h%3Abk9qbgx76gh6eyj5ps8p6buz8fffw1ofc37e9w9d6ncsfpuz7icy/"
-       DirnodeURI.checkObject(good, False)
+       self.failUnless(uri.DirnodeURI_RE.search(good))
        bad = good + '==='
-       self.failUnlessRaises(Violation, DirnodeURI.checkObject, bad, False)
+       self.failIf(uri.DirnodeURI_RE.search(bad))
        fileURI = 'URI:CHK:f3mf6az85wpcai8ma4qayfmxuc:nnw518w5hu3t5oohwtp7ah9n81z9rfg6c1ywk33ia3m64o67nsgo:3:10:345834'
-       self.failUnlessRaises(Violation, DirnodeURI.checkObject, fileURI, False)
+       self.failIf(uri.DirnodeURI_RE.search(fileURI))
 
 
 class Mutable(unittest.TestCase):
index a94856222ed4c80861cf9c7a4984ac8704214b04..962091c6a170576cef46124072517e819ab67ce2 100644 (file)
@@ -4,13 +4,33 @@ from zope.interface import implements
 from twisted.python.components import registerAdapter
 from allmydata.util import idlib, hashutil
 from allmydata.interfaces import IURI, IDirnodeURI, IFileURI, IVerifierURI, \
-     IMutableFileURI, INewDirectoryURI, IReadonlyNewDirectoryURI, DirnodeURI
+     IMutableFileURI, INewDirectoryURI, IReadonlyNewDirectoryURI
 import foolscap
 
 # the URI shall be an ascii representation of the file. It shall contain
 # enough information to retrieve and validate the contents. It shall be
 # expressed in a limited character set (namely [TODO]).
 
+ZBASE32CHAR = "[ybndrfg8ejkmcpqxot1uwisza345h769]" # excludes l, 0, 2, and v
+ZBASE32CHAR_3bits = "[yoearcwh]"
+ZBASE32CHAR_1bits = "[yo]"
+ZBASE32STR_128bits = "%s{25}%s" % (ZBASE32CHAR, ZBASE32CHAR_3bits)
+ZBASE32STR_256bits = "%s{51}%s" % (ZBASE32CHAR, ZBASE32CHAR_1bits)
+COLON="(:|%3A)"
+
+# Writeable SSK bits
+WSSKBITS= "%s%s%s" % (ZBASE32STR_128bits, COLON, ZBASE32STR_256bits)
+
+# URIs (soon to be renamed "caps") are always allowed to come with a leading
+# "http://127.0.0.1:8123/uri/" that will be ignored.
+OPTIONALHTTPLEAD=r'(https?://(127.0.0.1|localhost):8123/uri/)?'
+
+# Writeable SSK URI
+WriteableSSKFileURI_RE=re.compile("^%sURI%sSSK%s%s$" % (OPTIONALHTTPLEAD, COLON, COLON, WSSKBITS))
+
+# NewDirectory Read-Write URI
+DirnodeURI_RE=re.compile("^%sURI%sDIR2%s%s/?$" % (OPTIONALHTTPLEAD, COLON, COLON, WSSKBITS))
+
 
 class _BaseURI:
     def __hash__(self):
@@ -418,11 +438,7 @@ def from_string_dirnode(s):
 registerAdapter(from_string_dirnode, str, IDirnodeURI)
 
 def is_string_newdirnode_rw(s):
-    try:
-        DirnodeURI.checkObject(s, inbound=False)
-        return True
-    except foolscap.tokens.Violation, v:
-        return False
+    return DirnodeURI_RE.search(s)
 
 def from_string_filenode(s):
     u = from_string(s)