Changeset d8ba8c2 in trunk
- Timestamp:
- 2009-07-15T06:45:10Z (16 years ago)
- Branches:
- master
- Children:
- 7950fc0
- Parents:
- 760bab7
- Location:
- src/allmydata
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/client.py ¶
r760bab7 rd8ba8c2 28 28 from allmydata.history import History 29 29 from allmydata.interfaces import IURI, INewDirectoryURI, IStatsProducer, \ 30 IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient 30 IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, RIStubClient, \ 31 UnhandledCapTypeError 31 32 32 33 KiB=1024 … … 430 431 else: 431 432 node = FileNode(u, self, self.download_cache_dirman) # CHK 433 elif IMutableFileURI.providedBy(u): 434 node = MutableFileNode(self).init_from_uri(u) 432 435 else: 433 assert IMutableFileURI.providedBy(u), u 434 node = MutableFileNode(self).init_from_uri(u) 436 raise UnhandledCapTypeError("cap is recognized, but has no Node") 435 437 self._node_cache[u_s] = node # note: WeakValueDictionary 436 438 return self._node_cache[u_s] -
TabularUnified src/allmydata/interfaces.py ¶
r760bab7 rd8ba8c2 482 482 """UnknownNodes (using filecaps from the future that we don't understand) 483 483 cannot yet be copied safely, so I refuse to copy them.""" 484 485 class UnhandledCapTypeError(Exception): 486 """I recognize the cap/URI, but I cannot create an IFilesystemNode for 487 it.""" 484 488 485 489 class IFilesystemNode(Interface): -
TabularUnified src/allmydata/mutable/common.py ¶
r760bab7 rd8ba8c2 54 54 self.reason) 55 55 56 56 class UnknownVersionError(Exception): 57 """The share we received was of a version we don't recognize.""" 57 58 58 59 class ResponseCache: -
TabularUnified src/allmydata/mutable/layout.py ¶
r760bab7 rd8ba8c2 1 1 2 2 import struct 3 from common import NeedMoreDataError 3 from common import NeedMoreDataError, UnknownVersionError 4 4 5 5 PREFIX = ">BQ32s16s" # each version has a different prefix … … 35 35 o) = unpack_header(data) 36 36 37 assert version == 0 37 if version != 0: 38 raise UnknownVersionError("got mutable share version %d, but I only understand version 0" % version) 39 38 40 if len(data) < o['share_hash_chain']: 39 41 raise NeedMoreDataError(o['share_hash_chain'], … … 61 63 o['EOF']) = struct.unpack(HEADER, data[:HEADER_LENGTH]) 62 64 63 assert version == 0 65 if version != 0: 66 raise UnknownVersionError("got mutable share version %d, but I only understand version 0" % version) 67 64 68 if len(data) < o['EOF']: 65 69 raise NeedMoreDataError(o['EOF'], … … 133 137 cs_len = struct.calcsize(PREFIX) 134 138 version, seqnum, root_hash, IV = struct.unpack(PREFIX, checkstring[:cs_len]) 135 assert version == 0 # TODO: just ignore the share 139 if version != 0: # TODO: just ignore the share 140 raise UnknownVersionError("got mutable share version %d, but I only understand version 0" % version) 136 141 return (seqnum, root_hash, IV) 137 142 -
TabularUnified src/allmydata/test/test_mutable.py ¶
r760bab7 rd8ba8c2 1031 1031 if substring: 1032 1032 allproblems = [str(f) for f in servermap.problems] 1033 self.failUnless (substring in"".join(allproblems))1033 self.failUnlessIn(substring, "".join(allproblems)) 1034 1034 return servermap 1035 1035 if should_succeed: … … 1050 1050 1051 1051 def test_corrupt_all_verbyte(self): 1052 # when the version byte is not 0, we hit an assertion error in1053 # unpack_share().1054 d = self._test_corrupt_all(0, " AssertionError")1052 # when the version byte is not 0, we hit an UnknownVersionError error 1053 # in unpack_share(). 1054 d = self._test_corrupt_all(0, "UnknownVersionError") 1055 1055 def _check_servermap(servermap): 1056 1056 # and the dump should mention the problems -
TabularUnified src/allmydata/test/test_uri.py ¶
r760bab7 rd8ba8c2 187 187 good="http://127.0.0.1:3456/uri/URI%3ADIR2%3Agh3l5rbvnv2333mrfvalmjfr4i%3Alz6l7u3z3b7g37s4zkdmfpx5ly4ib4m6thrpbusi6ys62qtc6mma/" 188 188 uri.NewDirectoryURI.init_from_human_encoding(good) 189 self.failUnlessRaises( AssertionError, uri.NewDirectoryURI.init_from_string, good)189 self.failUnlessRaises(uri.BadURIError, uri.NewDirectoryURI.init_from_string, good) 190 190 bad = good + '===' 191 self.failUnlessRaises( AssertionError, uri.NewDirectoryURI.init_from_human_encoding, bad)192 self.failUnlessRaises( AssertionError, uri.NewDirectoryURI.init_from_string, bad)191 self.failUnlessRaises(uri.BadURIError, uri.NewDirectoryURI.init_from_human_encoding, bad) 192 self.failUnlessRaises(uri.BadURIError, uri.NewDirectoryURI.init_from_string, bad) 193 193 fileURI = 'URI:CHK:gh3l5rbvnv2333mrfvalmjfr4i:lz6l7u3z3b7g37s4zkdmfpx5ly4ib4m6thrpbusi6ys62qtc6mma:3:10:345834' 194 194 uri.CHKFileURI.init_from_string(fileURI) -
TabularUnified src/allmydata/test/test_web.py ¶
r760bab7 rd8ba8c2 20 20 FakeMutableFileNode, create_chk_filenode, WebErrorMixin, ShouldFailMixin 21 21 from allmydata.interfaces import IURI, INewDirectoryURI, \ 22 IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, IMutableFileNode 22 IReadonlyNewDirectoryURI, IFileURI, IMutableFileURI, IMutableFileNode, \ 23 UnhandledCapTypeError 23 24 from allmydata.mutable import servermap, publish, retrieve 24 25 import common_util as testutil … … 75 76 if IFileURI.providedBy(u): 76 77 return FakeCHKFileNode(u, self) 77 assert IMutableFileURI.providedBy(u), u 78 return FakeMutableFileNode(self).init_from_uri(u) 78 if IMutableFileURI.providedBy(u): 79 return FakeMutableFileNode(self).init_from_uri(u) 80 raise UnhandledCapTypeError("cap '%s' is recognized, but has no Node" % auri) 79 81 80 82 def create_empty_dirnode(self): -
TabularUnified src/allmydata/uri.py ¶
r760bab7 rd8ba8c2 7 7 from allmydata.interfaces import IURI, IDirnodeURI, IFileURI, IImmutableFileURI, \ 8 8 IVerifierURI, IMutableFileURI, INewDirectoryURI, IReadonlyNewDirectoryURI 9 10 class BadURIError(Exception): 11 pass 9 12 10 13 # the URI shall be an ascii representation of the file. It shall contain … … 61 64 self.size = size 62 65 self.storage_index = hashutil.storage_index_hash(self.key) 63 assert len(self.storage_index) == 16 64 self.storage_index = hashutil.storage_index_hash(key) 65 assert len(self.storage_index) == 16 # sha256 hash truncated to 128 66 if not len(self.storage_index) == 16: # sha256 hash truncated to 128 67 raise BadURIError("storage index must be 16 bytes long") 66 68 67 69 @classmethod 68 70 def init_from_human_encoding(cls, uri): 69 71 mo = cls.HUMAN_RE.search(uri) 70 assert mo, uri 72 if not mo: 73 raise BadURIError("%s doesn't look like a cap" % (uri,)) 71 74 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2)), 72 75 int(mo.group(3)), int(mo.group(4)), int(mo.group(5))) … … 75 78 def init_from_string(cls, uri): 76 79 mo = cls.STRING_RE.search(uri) 77 assert mo, uri 80 if not mo: 81 raise BadURIError("%s doesn't look like a cap" % (uri,)) 78 82 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2)), 79 83 int(mo.group(3)), int(mo.group(4)), int(mo.group(5))) … … 213 217 def init_from_human_encoding(cls, uri): 214 218 mo = cls.HUMAN_RE.search(uri) 215 assert mo, uri 219 if not mo: 220 raise BadURIError("'%s' doesn't look like a cap" % (uri,)) 216 221 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2))) 217 222 … … 219 224 def init_from_string(cls, uri): 220 225 mo = cls.STRING_RE.search(uri) 221 assert mo, (uri, cls) 226 if not mo: 227 raise BadURIError("'%s' doesn't look like a %s cap" % (uri, cls)) 222 228 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2))) 223 229 … … 261 267 def init_from_human_encoding(cls, uri): 262 268 mo = cls.HUMAN_RE.search(uri) 263 assert mo, uri 269 if not mo: 270 raise BadURIError("'%s' doesn't look like a cap" % (uri,)) 264 271 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2))) 265 272 … … 267 274 def init_from_string(cls, uri): 268 275 mo = cls.STRING_RE.search(uri) 269 assert mo, uri 276 if not mo: 277 raise BadURIError("'%s' doesn't look like a cap" % (uri,)) 270 278 return cls(base32.a2b(mo.group(1)), base32.a2b(mo.group(2))) 271 279 … … 334 342 def init_from_string(cls, uri): 335 343 mo = cls.BASE_STRING_RE.search(uri) 336 assert mo, (uri, cls) 344 if not mo: 345 raise BadURIError("'%s' doesn't look like a %s cap" % (uri, cls)) 337 346 bits = uri[mo.end():] 338 347 fn = cls.INNER_URI_CLASS.init_from_string( … … 343 352 def init_from_human_encoding(cls, uri): 344 353 mo = cls.BASE_HUMAN_RE.search(uri) 345 assert mo, (uri, cls) 354 if not mo: 355 raise BadURIError("'%s' doesn't look like a %s cap" % (uri, cls)) 346 356 bits = uri[mo.end():] 347 357 while bits and bits[-1] == '/': -
TabularUnified src/allmydata/web/root.py ¶
r760bab7 rd8ba8c2 13 13 from allmydata import provisioning 14 14 from allmydata.util import idlib, log 15 from allmydata.interfaces import IFileNode 15 from allmydata.interfaces import IFileNode, UnhandledCapTypeError 16 16 from allmydata.web import filenode, directory, unlinked, status, operations 17 17 from allmydata.web import reliability, storage … … 80 80 node = self.client.create_node_from_uri(name) 81 81 return directory.make_handler_for(node, self.client) 82 except (TypeError, AssertionError):82 except (TypeError, UnhandledCapTypeError, AssertionError): 83 83 raise WebError("'%s' is not a valid file- or directory- cap" 84 84 % name) … … 99 99 try: 100 100 node = self.client.create_node_from_uri(name) 101 except (TypeError, AssertionError):101 except (TypeError, UnhandledCapTypeError, AssertionError): 102 102 raise WebError("'%s' is not a valid file- or directory- cap" 103 103 % name)
Note: See TracChangeset
for help on using the changeset viewer.