self.files = files
def download(self, uri, target):
- print "DOWNLOADING", uri
if uri not in self.files:
e = NotEnoughPeersError()
f = failure.Failure(e)
body = "\r\n".join(form) + "\r\n"
headers = {"content-type": "multipart/form-data; boundary=%s" % sepbase,
}
- print "BODY", body
return client.getPage(url, method="POST", postdata=body,
headers=headers, followRedirect=False)
def shouldFail(self, res, expected_failure, which, substring=None):
- print "SHOULDFAIL", res
if isinstance(res, failure.Failure):
res.trap(expected_failure)
if substring:
def test_GET_FILEURL_missing(self): # YES
d = self.GET("/vdrive/global/foo/missing")
- def _oops(f):
- print f
- print dir(f)
- print f.value
- print dir(f.value)
- print f.value.args
- print f.value.response
- print f.value.status
- return f
- #d.addBoth(_oops)
d.addBoth(self.should404, "test_GET_FILEURL_missing")
return d
self.failIf(os.path.exists(localfile))
d.addCallback(_check)
def _reset(res):
- print "RESETTING", res
webish.LOCALHOST = old_LOCALHOST
return res
d.addBoth(_reset)
res.trap(error.PageRedirect)
# the PageRedirect does not seem to capture the uri= query arg
# properly, so we can't check for it.
- print "location:", res.value.location
realtarget = self.webish_url + target
self.failUnlessEqual(res.value.location, realtarget)
return d
def log(self, res, msg):
- print "MSG: %s RES: %s" % (msg, res)
+ #print "MSG: %s RES: %s" % (msg, res)
log.msg(msg)
return res
self._dirpath = dirpath
def childFactory(self, ctx, name):
- print "Directory.childFactory", name
if name.startswith("freeform"): # ick
return None
#if name == "@manifest": # ick, this time it's my fault
return "/" + "/".join(self._dirpath)
def render_title(self, ctx, data):
- print "DIRECTORY.render_title"
return ctx.tag["Directory '%s':" % self.dirpath_as_string()]
def render_header(self, ctx, data):
link = "/".join( ("..",) * upness )
else:
link = "."
- print "LINK", link, d
header.append(T.a(href=link)[d])
if upness != 0:
header.append("/")
self._filenode = filenode
def render(self, req):
- print "LOCALFILEDOWNLOADER", self._local_filename
target = download.FileName(self._local_filename)
d = self._filenode.download(target)
def _done(res):
self._localdir = localdir
def _handle(self, path, node):
- print "DONWLOADING", path, node
localfile = os.path.join(self._localdir, os.sep.join(path))
if IDirectoryNode.providedBy(node):
fileutil.make_dirs(localfile)
class POSTHandler(rend.Page):
def __init__(self, node):
self._node = node
- # TODO: handler methods
+
def renderHTTP(self, ctx):
req = inevow.IRequest(ctx)
- print "POST", req, req.args#, req.content.read()
- #print " ", req.requestHeaders
- #print req.__class__
- #print req.fields
- #print dir(req.fields)
- print req.fields.keys()
t = req.fields["t"].value
if t == "mkdir":
name = req.fields["name"].value
- print "CREATING DIR", name
d = self._node.create_empty_directory(name)
def _done(res):
return "directory created"
elif t == "upload":
contents = req.fields["file"]
name = contents.filename
- print "filename", name
if "name" in req.fields:
name = req.fields["name"].value
- print "NAME WAS", name
uploadable = upload.FileHandle(contents.file)
d = self._node.add_file(name, uploadable)
def _done(newnode):
- print "UPLOAD DONW", name
return newnode.get_uri()
d.addCallback(_done)
return d
self._name = name
def renderHTTP(self, ctx):
- print "DELETEHandler.renderHTTP", self._name
req = inevow.IRequest(ctx)
d = self._node.delete(self._name)
def _done(res):
return "%s deleted" % self._name
d.addCallback(_done)
def _trap_missing(f):
- print "TRAPPED MISSING"
f.trap(KeyError)
req.setResponseCode(http.NOT_FOUND)
req.setHeader("content-type", "text/plain")
d = node.get(path[0])
def _maybe_create(f):
f.trap(KeyError)
- print "CREATING", path[0]
return node.create_empty_directory(path[0])
d.addErrback(_maybe_create)
d.addCallback(self._get_or_create_directories, path[1:])
return d
def _upload_localdir(self, node, localdir):
- print "PUTHandler._upload_localdir", localdir
# build up a list of files to upload
all_files = []
all_dirs = []
for root, dirs, files in os.walk(localdir):
- print "walking", root
if root == localdir:
path = ()
else:
relative_root = root[len(localdir)+1:]
path = tuple(relative_root.split(os.sep))
- print " path", path
for d in dirs:
all_dirs.append(path + (d,))
for f in files:
return d
def _makedir(self, res, node, dir):
- print "_makedir", node, dir
d = defer.succeed(None)
# get the parent. As long as os.walk gives us parents before
# children, this ought to work
return d
def _upload_one_file(self, res, node, localdir, f):
- print "_upload_one_file", node, localdir, f
# get the parent. We can be sure this exists because we already
# went through and created all the directories we require.
localfile = os.path.join(localdir, *f)
if path and path[-1] == '':
path = path[:-1]
- print "VDrive.locateChild", method, segments, req.args
t = ""
if "t" in req.args:
t = req.args["t"][0]
return LocalFileDownloader(node, localfile), ()
elif t == "":
# send contents as the result
- print "FileDownloader"
return FileDownloader(node, filename), ()
elif t == "json":
- print "Localfilejsonmetadata"
return FileJSONMetadata(node), ()
elif t == "xml":
return FileXMLMetadata(node), ()
else:
raise RuntimeError("bad t=%s" % t)
elif IDirectoryNode.providedBy(node):
- print "GOT DIR"
if localdir:
# recursive download to a local directory
return LocalDirectoryDownloader(node, localdir), ()
elif t == "":
# send an HTML representation of the directory
- print "GOT HTML DIR"
return Directory(node, path), ()
elif t == "json":
return DirectoryJSONMetadata(node), ()
# the node must exist, and our operation will be performed on its
# parent node.
assert path # you can't delete the root
- print "AT DELETE"
d = self.get_child_at_path(path[:-1])
def _got(node):
return DELETEHandler(node, path[-1]), ()
client = IClient(ctx)
req = inevow.IRequest(ctx)
vdrive = client.getServiceNamed("vdrive")
- print "Root.locateChild", segments
if segments[0] == "vdrive":
if len(segments) < 2:
d.addCallback(lambda vd: vd.locateChild(ctx, segments[2:]))
return d
elif segments[0] == "uri":
- print "looking at /uri", segments, req.args
if len(segments) == 1:
if "uri" in req.args:
uri = req.args["uri"][0]
- print "REDIRECTING"
there = url.URL.fromContext(ctx)
there = there.clear("uri")
there = there.child("uri").child(uri)
- print " TO", there
return there, ()
if len(segments) < 2:
return rend.NotFound