File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
test/resources/testserver Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,12 @@ def send_head(self):
55
55
else :
56
56
return self .list_directory (path )
57
57
ctype = self .guess_type (path )
58
+ if ctype .startswith ('text/' ):
59
+ mode = 'r'
60
+ else :
61
+ mode = 'rb'
58
62
try :
59
- f = open (path , 'rb' )
63
+ f = open (path , mode )
60
64
except IOError :
61
65
self .send_error (404 , "File not found" )
62
66
return None
@@ -85,12 +89,14 @@ def stop_server(port=7000):
85
89
conn .getresponse ()
86
90
87
91
def start_server (port = 7000 ):
92
+ import os
88
93
os .chdir (os .path .join (os .path .dirname (os .path .abspath (sys .argv [0 ])), '..' ))
89
94
server = StoppableHttpServer (('' , port ), StoppableHttpRequestHandler )
90
95
server .serve_forever ()
91
96
92
97
93
98
if __name__ == '__main__' :
99
+ import sys
94
100
if len (sys .argv ) != 2 or sys .argv [1 ] not in [ 'start' , 'stop' ]:
95
101
print ("usage: {0} start|stop" .format (sys .argv [0 ]))
96
102
sys .exit (1 )
You can’t perform that action at this time.
0 commit comments