Quick fix for requests API update

master
Sven Slootweg 12 years ago
parent 1133430856
commit 0c3a90e523

@ -54,11 +54,10 @@ class Filesystem:
url = url[:-1] url = url[:-1]
try: try:
data = requests.get("%s/statistics?t=json" % url).json data = requests.get("%s/statistics?t=json" % url).json()
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
raise FilesystemException("The provided WAPI URL is either not reachable, or not running a recent version of Tahoe-LAFS.") raise FilesystemException("The provided WAPI URL is either not reachable, or not running a recent version of Tahoe-LAFS.")
except:
if data is None:
raise FilesystemException("The provided URL is not running a recent version of Tahoe-LAFS.") raise FilesystemException("The provided URL is not running a recent version of Tahoe-LAFS.")
self.url = url self.url = url
@ -77,9 +76,9 @@ class Filesystem:
""" """
if data is None: if data is None:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json try:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json()
if data is None: except:
raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") raise FilesystemException("Could not reach the WAPI or did not receive a valid response.")
return Directory(self, uri, data) return Directory(self, uri, data)
@ -94,9 +93,9 @@ class Filesystem:
""" """
if data is None: if data is None:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json try:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json()
if data is None: except:
raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") raise FilesystemException("Could not reach the WAPI or did not receive a valid response.")
return File(self, uri, data) return File(self, uri, data)
@ -111,9 +110,9 @@ class Filesystem:
""" """
if data is None: if data is None:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json try:
data = requests.get("%s/uri/%s?t=json" % (self.url, urllib.quote(uri))).json()
if data is None: except:
raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") raise FilesystemException("Could not reach the WAPI or did not receive a valid response.")
if "filenode" in data: if "filenode" in data:
@ -232,9 +231,9 @@ class Directory:
def _get_data(self): def _get_data(self):
"""Actually retrieves the data for this Directory.""" """Actually retrieves the data for this Directory."""
data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(self.uri))).json try:
data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(self.uri))).json()
if data is None: except:
raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") raise FilesystemException("Could not reach the WAPI or did not receive a valid response.")
if "dirnode" in data: if "dirnode" in data:
@ -367,9 +366,9 @@ class File:
self.uri = uri self.uri = uri
if data is None: if data is None:
data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(uri))).json try:
data = requests.get("%s/uri/%s?t=json" % (self.filesystem.url, urllib.quote(uri))).json()
if data is None: except:
raise FilesystemException("Could not reach the WAPI or did not receive a valid response.") raise FilesystemException("Could not reach the WAPI or did not receive a valid response.")
if "filenode" in data: if "filenode" in data:

@ -1,7 +1,8 @@
import pytahoe import pytahoe
#fs = pytahoe.Filesystem("http://localhost:3456/") fs = pytahoe.Filesystem("http://localhost:3456/")
print "Get filesystem"
#print fs #print fs
#tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa") #tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa")
#print tdir #print tdir
@ -16,7 +17,7 @@ import pytahoe
#print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "derp.py") #print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "derp.py")
#print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "This is just a (*@Y#%)()@#&%)(*@&#% test to see how well it sanitizes a filename..py") #print tdir.attach(fs.File("URI:CHK:j3jkuy73tnkj7glyatasluq2xe:hcluqizbrhdpqa7fugmiwtaxf42f2ssvk7emyyat7wm4xr3ehgfa:3:10:534"), "This is just a (*@Y#%)()@#&%)(*@&#% test to see how well it sanitizes a filename..py")
fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/") #fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/")
#tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997") #tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997")
#print tfile.read(65) #print tfile.read(65)
@ -26,11 +27,14 @@ fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/")
#tfile = fs.upload("test.py") #tfile = fs.upload("test.py")
#print tfile #print tfile
# #
tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa") tdir = fs.Directory("URI:DIR2:73a5pbgk2wpgtjylw4x6d3p4ne:ygfn7uzmpyzrat7u2yigalhqlf77xq5uavc3fvaphsnlncoy5hnq")
print "Get dir"
print tdir.create_directory("testing subdir4") print tdir.create_directory("testing subdir4")
print "Create dir"
tdir.refresh() tdir.refresh()
print "Refresh"
print tdir.children print tdir.children
print "Children"
#print tdir.upload("test.py") #print tdir.upload("test.py")
#print tdir #print tdir

Loading…
Cancel
Save