def got_child(self, node_or_failure, ctx, name): req = IRequest(ctx) method = req.method nonterminal = len(req.postpath) > 1 t = get_arg(req, "t", "").strip() if isinstance(node_or_failure, Failure): f = node_or_failure f.trap(NoSuchChildError) # No child by this name. What should we do about it? if nonterminal: if should_create_intermediate_directories(req): # create intermediate directories d = self.node.create_subdirectory(name) d.addCallback(make_handler_for, self.client, self.node, name) return d else: # terminal node if (method,t) in [ ("POST","mkdir"), ("PUT","mkdir"), ("POST", "mkdir-with-children"), ("POST", "mkdir-immutable") ]: # final directory kids = {} if t in ("mkdir-with-children", "mkdir-immutable"): req.content.seek(0) kids_json = req.content.read() kids = convert_children_json(self.client.nodemaker, kids_json) file_format = get_format(req, None) mutable = True mt = get_mutable_type(file_format) if t == "mkdir-immutable": mutable = False d = self.node.create_subdirectory(name, kids, mutable=mutable, mutable_version=mt) d.addCallback(make_handler_for, self.client, self.node, name) return d if (method,t) in ( ("PUT",""), ("PUT","uri"), ): # we were trying to find the leaf filenode (to put a new # file in its place), and it didn't exist. That's ok, # since that's the leaf node that we're about to create. # We make a dummy one, which will respond to the PUT # request by replacing itself. return PlaceHolderNodeHandler(self.client, self.node, name) # otherwise, we just return a no-such-child error return f node = node_or_failure if nonterminal and should_create_intermediate_directories(req): if not IDirectoryNode.providedBy(node): # we would have put a new directory here, but there was a # file in the way. raise WebError("Unable to create directory '%s': " "a file was in the way" % name, http.CONFLICT) return make_handler_for(node, self.client, self.node, name)
def childFactory(self, ctx, name): req = IRequest(ctx) if should_create_intermediate_directories(req): raise WebError("Cannot create directory '%s', because its " "parent is a file, not a directory" % name) raise WebError("Files have no children, certainly not named '%s'" % name)
def childFactory(self, ctx, name): req = IRequest(ctx) if isinstance(self.node, ProhibitedNode): raise FileProhibited(self.node.reason) if should_create_intermediate_directories(req): raise WebError("Cannot create directory %s, because its " "parent is a file, not a directory" % quote_output(name, encoding='utf-8')) raise WebError("Files have no children, certainly not named %s" % quote_output(name, encoding='utf-8'))
def getChild(self, name, req): if isinstance(self.node, ProhibitedNode): raise FileProhibited(self.node.reason) if should_create_intermediate_directories(req): return ErrorPage( http.CONFLICT, u"Cannot create directory %s, because its parent is a file, " u"not a directory" % quote_output(name, encoding='utf-8'), "no details") return ErrorPage( http.BAD_REQUEST, u"Files have no children named %s" % quote_output(name, encoding='utf-8'), "no details", )
def got_child(self, node_or_failure, ctx, name): DEBUG = False if DEBUG: print "GOT_CHILD", name, node_or_failure req = IRequest(ctx) method = req.method nonterminal = len(req.postpath) > 1 t = get_arg(req, "t", "").strip() if isinstance(node_or_failure, Failure): f = node_or_failure f.trap(NoSuchChildError) # No child by this name. What should we do about it? if DEBUG: print "no child", name if DEBUG: print "postpath", req.postpath if nonterminal: if DEBUG: print " intermediate" if should_create_intermediate_directories(req): # create intermediate directories if DEBUG: print " making intermediate directory" d = self.node.create_subdirectory(name) d.addCallback(make_handler_for, self.client, self.node, name) return d else: if DEBUG: print " terminal" # terminal node if (method,t) in [ ("POST","mkdir"), ("PUT","mkdir"), ("POST", "mkdir-with-children"), ("POST", "mkdir-immutable") ]: if DEBUG: print " making final directory" # final directory kids = {} if t in ("mkdir-with-children", "mkdir-immutable"): req.content.seek(0) kids_json = req.content.read() kids = convert_children_json(self.client.nodemaker, kids_json) file_format = get_format(req, None) mutable = True mt = get_mutable_type(file_format) if t == "mkdir-immutable": mutable = False d = self.node.create_subdirectory(name, kids, mutable=mutable, mutable_version=mt) d.addCallback(make_handler_for, self.client, self.node, name) return d if (method,t) in ( ("PUT",""), ("PUT","uri"), ): if DEBUG: print " PUT, making leaf placeholder" # we were trying to find the leaf filenode (to put a new # file in its place), and it didn't exist. That's ok, # since that's the leaf node that we're about to create. # We make a dummy one, which will respond to the PUT # request by replacing itself. return PlaceHolderNodeHandler(self.client, self.node, name) if DEBUG: print " 404" # otherwise, we just return a no-such-child error return f node = node_or_failure if nonterminal and should_create_intermediate_directories(req): if not IDirectoryNode.providedBy(node): # we would have put a new directory here, but there was a # file in the way. if DEBUG: print "blocking" raise WebError("Unable to create directory '%s': " "a file was in the way" % name, http.CONFLICT) if DEBUG: print "good child" return make_handler_for(node, self.client, self.node, name)