def process(self): """ Working through the process chain. This method returns either a dictionary for a folder node containing objects implementing the L{IResource} interface or a single object for a leaf node, like a file or document resource. """ if isinstance(self.path, unicode): raise TypeError("URL must be a str instance, not unicode!") # unquote url self.path = urllib.unquote(self.path) # check for URI length if len(self.path) >= MAXIMAL_URL_LENGTH: raise SeisHubError(code=http.REQUEST_URI_TOO_LONG) # post process path self.postpath = splitPath(self.path) # we like upper case method names self.method = self.method.upper() # check for valid methods if self.method not in ALLOWED_HTTP_METHODS: msg = 'HTTP %s is not implemented.' % self.method raise SeisHubError(code=http.NOT_ALLOWED, message=msg) # read content self.content.seek(0, 0) self.data = self.content.read() # easy args handler for id in self.args: if not len(self.args[id]): continue self.args0[id] = self.args[id][0] return self.render()
def process(self): """ Working through the process chain. This method returns either a dictionary for a folder node containing objects implementing the L{IResource} interface or a single object for a leaf node, like a file or document resource. """ if isinstance(self.path, unicode): raise TypeError("URL must be a str instance, not unicode!") # unquote url self.path = urllib.unquote(self.path) # check for URI length if len(self.path) >= MAXIMAL_URL_LENGTH: raise SeisHubError(code=http.REQUEST_URI_TOO_LONG) # post process path self.postpath = splitPath(self.path) # we like upper case method names self.method = self.method.upper() # check for valid methods if self.method not in ALLOWED_HTTP_METHODS: msg = 'HTTP %s is not implemented.' % self.method raise SeisHubError(code=http.NOT_ALLOWED, message=msg) # read content self.content.seek(0, 0) self.data = self.content.read() # easy args handler for id in self.args: if not len(self.args[id]): continue self.args0[id] = self.args[id][0] return self.render()
def render_MOVE(self, request): """ Processes a resource move/rename request. @see: U{http://msdn.microsoft.com/en-us/library/aa142926(EXCHG.65).aspx} """ self._checkPermissions(request, 777) # seishub directory is not directly changeable if self.package_id == 'seishub': msg = "SeisHub resources may not be moved directly." raise ForbiddenError(msg) # test if destination is set destination = request.received_headers.get('Destination', False) if not destination: msg = "Expected a destination header." raise SeisHubError(msg, code=http.BAD_REQUEST) if not destination.startswith(request.env.getRestUrl()): if destination.startswith('http'): msg = "Destination URI is located on a different server." raise SeisHubError(msg, code=http.BAD_GATEWAY) msg = "Expected a complete destination path." raise SeisHubError(msg, code=http.BAD_REQUEST) # test size of destination URI if len(destination) >= MAXIMAL_URL_LENGTH: msg = "Destination URI is to long." raise SeisHubError(msg, code=http.REQUEST_URI_TOO_LONG) # strip host destination = destination[len(request.env.getRestUrl()):] # source URI and destination URI must not be the same value parts = splitPath(destination) if parts == request.prepath: msg = "Source URI and destination URI must not be the same value." raise ForbiddenError(msg) # test if valid destination path if len(parts) < 1 or parts[:-1] != request.prepath[:-1]: msg = "Destination %s not allowed." % destination raise ForbiddenError(msg) # rename resource request.env.catalog.renameResource(self.res, parts[-1]) # on successful creation - set status code and location header request.code = http.CREATED url = request.env.getRestUrl() + destination # won't accept Unicode request.headers['Location'] = str(url) return ''
def putChild(self, path, obj): """ Register a static child for this resource. The resource node also accepts absolute paths. Missing sub folders are automatically generated. """ if '/' not in path: # we got a single id self.children[path] = obj else: # we got some absolute path parts = splitPath(path) temp = self for part in parts[:-1]: if part not in temp.children: temp.children[part] = StaticFolder() temp = temp.children.get(part) temp.children[parts[-1]] = obj
def putChild(self, path, obj): """ Register a static child for this resource. The resource node also accepts absolute paths. Missing sub folders are automatically generated. """ if '/' not in path: # we got a single id self.children[path] = obj else: # we got some absolute path parts = splitPath(path) temp = self for part in parts[:-1]: if part not in temp.children: temp.children[part] = StaticFolder() temp = temp.children.get(part) temp.children[parts[-1]] = obj