-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (22 loc) · 770 Bytes
/
utils.py
File metadata and controls
30 lines (22 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import base64
class Router(object):
def __init__(self, routes={}):
self.routing_table = {}
def add_route(self, path, host):
path = self.parse_path(path)
self.routing_table[path] = host
def get_route(self, path):
path = self.parse_path(path)
return self.routing_table[path]
def exist_route(self, path):
path = self.parse_path(path)
return path in self.routing_table
def parse_path(self, url_with_argument):
if '?' in url_with_argument:
return url_with_argument.split('?')[-1]
else:
return url_with_argument
def message_encode(msg):
return base64.b64encode(msg)
def message_decode(encoded_msg):
return base64.b64decode(encoded_msg)