From: Zooko O'Whielacronx Date: Wed, 19 Dec 2007 00:44:24 +0000 (-0700) Subject: remove the DirnodeURI foolscap schema and mv those regexes into uri.py X-Git-Url: https://git.rkrishnan.org/vdrive/provisioning?a=commitdiff_plain;h=a5a54ac5ca5db6f930d7251ce4acb668eec1c491;p=tahoe-lafs%2Ftahoe-lafs.git remove the DirnodeURI foolscap schema and mv those regexes into uri.py We currently do not pass dirnode uris over foolscap. --- diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 2a23391e..f8ef5acd 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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) diff --git a/src/allmydata/test/test_uri.py b/src/allmydata/test/test_uri.py index 0d2a8f96..3151dc9b 100644 --- a/src/allmydata/test/test_uri.py +++ b/src/allmydata/test/test_uri.py @@ -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): diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index a9485622..962091c6 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -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)