class TSTRouter(URLRouter): def __init__(self): self.urls = TSTree() def add(self, url, value): self.urls.set(url, value) def exact_match(self, url): return self.urls.get(url) def best_match(self, url): return self.urls.find_part(url) def match_all(self, url): results = self.urls.find_all(url) return results
class TSTRouter(URLRouter): def __init__(self): self.urls = TSTree() def add(self, key, value): self.urls.set(key, value) def match_url(self, url_to_find): return self.urls.get(url_to_find) def url_starts_with(self, url_to_find): return self.urls.find_all(url_to_find) def shortest_url(self, url_to_find): return self.urls.find_shortest(url_to_find) def longest_url(self, url_to_find): return self.urls.find_longest(url_to_find)
def test_TSTree_get_set(): urls = TSTree() urls.set("/apple/", "Apple") urls.set("/grape/", "Grape") urls.set("/kiwi/", "Kiwi") urls.set("/kumquat/", "Kumquat") urls.set("/pineapple/", "Pineapple") urls.set('abc', 'ABC') urls.set('abd', 'ABD') urls.set('abcd', 'ABCD') assert urls.get("/apple/") == "Apple" assert urls.get("/grape/") == "Grape" assert urls.get("/kiwi/") == "Kiwi" assert urls.get("/") == None assert urls.get('abd') == 'ABD' assert urls.get('abcd') == 'ABCD' return urls
def test_set(): names = TSTree() names.set("MM", "Mad MAX") names.set("OO", "YUAN YUAN") names.set("CM", "CHEN MING") names.set("CMO", "CHEN MING") names.set("CMOET", "CHEN MING") names.set("ZZ", "ZHI ZHANG") return names
def __init__(self): self.urls = TSTree()
def test_set_get(): names = TSTree() names.set('emil', 'myname') assert names.get('emil') == 'myname' names.set('eddie', 'murphy') assert names.get('emil') == 'myname' assert names.get('eddie') == 'murphy' names.set('bill', 'hicks') assert names.get('bill') == 'hicks' names.set('eddie', 'money') assert names.get('eddie') == 'money' assert names.get('eddi') == None return names
def test_find_shortest(): things = TSTree() things.set('apple', 'Apple') things.set('application', 'Application') things.set('applaus', 'Applaus') things.set('applicant', 'Applicant') assert things.find_shortest('appl') == "Apple" return things