From 37b7f136ce2542c2cae938c916e88c2d5dd3f93b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 14 Jan 2008 14:12:27 -0700 Subject: [PATCH] 'tahoe dump-cap': accept http:// -prefixed URLs too --- src/allmydata/scripts/debug.py | 9 ++++++++- src/allmydata/test/test_cli.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index d2c3365a..cf08a206 100644 --- a/src/allmydata/scripts/debug.py +++ b/src/allmydata/scripts/debug.py @@ -201,9 +201,9 @@ def dump_cap(config, out=sys.stdout, err=sys.stderr): from allmydata import uri from allmydata.util.idlib import a2b from base64 import b32decode + import urlparse, urllib cap = config.cap - u = uri.from_string(cap) nodeid = None if config['nodeid']: nodeid = b32decode(config['nodeid'].upper()) @@ -217,6 +217,13 @@ def dump_cap(config, out=sys.stdout, err=sys.stderr): except EnvironmentError: pass + if cap.startswith("http"): + scheme, netloc, path, params, query, fragment = urlparse.urlparse(cap) + assert path.startswith("/uri/") + cap = urllib.unquote(path[len("/uri/"):]) + + u = uri.from_string(cap) + print >>out dump_uri_instance(u, nodeid, secret, out, err) diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 60a7c2ec..bb1d704b 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -1,6 +1,7 @@ from twisted.trial import unittest from cStringIO import StringIO +import urllib from allmydata.util import fileutil, hashutil from allmydata import uri @@ -105,6 +106,15 @@ class CLI(unittest.TestCase): self.failUnless("k/N: 25/100" in output) self.failUnless("storage index: p3w849k9whqhw6b9fkf4xjs5xc" in output) + prefixed_u = "http://127.0.0.1/uri/%s" % urllib.quote(u.to_string()) + output = self._dump_cap(prefixed_u) + self.failUnless("CHK File:" in output) + self.failUnless("key: yyyoryarywdyqnyjbefoadeqbh" in output) + self.failUnless("UEB hash: hd7rwri6djiapo6itg5hcxa7ze5im7z9qwcdu8oka6qinahsbiuo" in output) + self.failUnless("size: 1234" in output) + self.failUnless("k/N: 25/100" in output) + self.failUnless("storage index: p3w849k9whqhw6b9fkf4xjs5xc" in output) + def test_dump_cap_lit(self): u = uri.LiteralFileURI("this is some data") output = self._dump_cap(u.to_string()) -- 2.45.2