-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
47 lines (42 loc) · 985 Bytes
/
util.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
# HTTP request methods
req_methods = {
'GET',
'HEAD'
}
# HTTP response codes
resp_codes = {
200: '200 OK',
400: '400 Bad Request',
401: '401 Unauthorized',
403: '403 Forbidden',
404: '404 Not Found',
405: '405 Method Not Allowed'
}
# Content-Type
content_type = {
'text' : 'text/plain',
'html' : 'text/html',
'css' : 'text/css',
'gif' : 'image/gif',
'jpg' : 'image/jpeg',
'jpeg' : 'image/jpeg',
'ico' : 'image/x-con',
'png': 'image/png',
'pdf' : 'application/pdf',
'mp3' : 'audio/mpeg'
}
def get_content_type(filename):
'''
Returns the content-type that goes in the header based on @filename's extension
'''
ext = filename[filename.rfind('.')+1:] # rfind returns the last index of specified substring
return content_type.get(ext, 'xxx')
def create_path(*subpaths):
'''
Creates an absolute path based on subpaths given
'''
path = os.path.dirname(os.path.abspath(__file__))
for file in subpaths:
path += file
return path