def handle_url(self, url, signode): if url is None: raise ValueError # Split URL into path, query, and fragment _, _, path, query, fragment = urlsplit(url) urlnode = desc_http_url() # Create nodes for the path if path: pathnode = desc_http_path(path) path_segments = self.path_re.findall(path)[:-1] for text, arg in path_segments: pathnode += Text(text) if arg: arg = arg[1:-1] # Strip off { and } pathnode += desc_http_patharg(arg, arg) urlnode += pathnode else: raise ValueError # Create nodes for the query string if query: querynode = desc_http_query(query) query_params = query.split('&') for p in query_params: querynode += desc_http_queryparam(p, p) urlnode += querynode # Create a node for the fragment if fragment: urlnode += desc_http_fragment(fragment, fragment) # Add urlnode to signode signode += urlnode
def node_from_url(self, url): """Returns a ``desc_http_url`` Node from a ``url`` string.""" if url is None: raise ValueError # Split URL into path, query, and fragment path, query, fragment = self.split_url(url) urlnode = desc_http_url() urlnode += self.node_from_path(path) node = self.node_from_query(query) if node: urlnode += node node = self.node_from_fragment(fragment) if node: urlnode += node return urlnode