Add File.read()

master
Sven Slootweg 12 years ago
parent ddd72ab412
commit ba25546a6c

@ -316,6 +316,7 @@ class File:
"""Represents a file node in a Tahoe-LAFS grid.""" """Represents a file node in a Tahoe-LAFS grid."""
mutable = False mutable = False
writable = False writable = False
request = None
def __init__(self, filesystem, uri, data=None): def __init__(self, filesystem, uri, data=None):
"""Create a new File object. """Create a new File object.
@ -384,3 +385,18 @@ class File:
""" """
return self.filesystem.attach(self, directory, filename, **kwargs) return self.filesystem.attach(self, directory, filename, **kwargs)
def read(self, length=None):
"""Read from the File and return the output.
Keyword arguments:
length -- The amount of bytes to read.
"""
if self.request is None:
self.request = requests.get("%s/uri/%s" % (self.filesystem.url, self.uri), prefetch=False)
if length is None:
return self.request.content
else:
return self.request.raw.read(amt=length)

@ -1,6 +1,6 @@
import pytahoe import pytahoe
fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/")
#fs = pytahoe.Filesystem("http://localhost:3456/") #fs = pytahoe.Filesystem("http://localhost:3456/")
#print fs #print fs
#tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa") #tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa")
@ -11,7 +11,22 @@ fs = pytahoe.Filesystem("http://tahoe.ccnmtl.columbia.edu/")
#print fs.create_directory().mount("test") #print fs.create_directory().mount("test")
#print fs.upload("test.py") #print fs.upload("test.py")
tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa")
#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/")
tfile = fs.File("URI:CHK:iyq5houj2fqavmnqccqezcssle:5px5tdctmmvci4al2r3vskpblhrepuugfe6ghiuutpe6cllvo36a:3:10:997")
print tfile.read(65)
#print fs
#
#tfile = fs.upload("test.py")
#print tfile
#
#tdir = fs.Directory("URI:DIR2:cbk47f5lybaj5qh6bm6eedezwe:m525plntx47u44xvf44r6rliec3gp6yeyio7olndibtke75zb6fa")
#print tdir
#
#print tfile.attach(tdir, "sample // file 2.py")

Loading…
Cancel
Save