def prepare(self): global TOP_LEVEL_ACTION super(ActionHandler, self).prepare() self.set_header('Server', "UpLib/%s (Tornado %s)" % (self.repo.get_version(), TornadoVersion)) self.angel_action = None scheme, netloc, path, params, query, fragment = urlparse.urlparse(self.request.uri) parts = [x for x in path.split('/') if x.strip()] if len(parts) == 3 and parts[0] == 'action': self.angel_action = (parts[1:], params, query, fragment) elif (len(parts)==4 and parts[0] == 'action' and parts[3][0:3]=='seq'): note(2, "in match with 4 parts, parts = %s", str(parts)) self.angel_action = (parts[1:3], params, query, fragment) elif (len(parts) > 3) and (parts[0] == 'action') and (is_hierarchical_extension(parts[1])): # to support extensions with hierarchical static elements, like GWT-generated UIs note(4, "hierarchical request, parts = %s", str(parts)) self.angel_action = ((parts[1], '/'.join(parts[2:])), params, query, fragment) elif path == '/': self.redirect('/'.join(("/action",) + TOP_LEVEL_ACTION)) else: raise HTTPError(HTTPCodes.BAD_REQUEST, "Invalid /action request %s received", self.request.uri)
def match (self, request): # make sure the command is GET, HEAD, or POST: if request.command not in self.valid_commands: return 0 path, params, query, fragment = request.split_uri() if '%' in path: path = unquote (path) request.angel_action = None if len(path) > 1: # strip off all leading slashes while path and path[0] == '/': path = path[1:] if path: parts = path.split('/') if len(parts) == 3 and parts[0] == 'action': request.angel_action = (parts[1:], params, query, fragment) return 1 elif (len(parts)==4 and parts[0] == 'action' and parts[3][0:3]=='seq'): note(2, "in match with 4 parts, parts = %s", str(parts)) request.angel_action = (parts[1:3], params, query, fragment) return 1 elif (len(parts) > 3) and (parts[0] == 'action') and (is_hierarchical_extension(parts[1])): # to support extensions with hierarchical static elements, like GWT-generated UIs note(4, "hierarchical request, parts = %s", str(parts)) request.angel_action = ((parts[1], '/'.join(parts[2:])), params, query, fragment) return 1 else: # This case occurs when the browser requests that an image # be downloaded. In that case parts look like: # parts = ['docs', '01070-41-2044-555', 'thumbnails', '1.png'] pass elif path == '/': request.angel_action = (TOP_LEVEL_ACTION, params, query, fragment) return 1 return 0