equal
deleted
inserted
replaced
158 if os.path.exists(path): |
158 if os.path.exists(path): |
159 break |
159 break |
160 try: |
160 try: |
161 os.stat(path) |
161 os.stat(path) |
162 ct = mimetypes.guess_type(path)[0] or "text/plain" |
162 ct = mimetypes.guess_type(path)[0] or "text/plain" |
163 fp = open(path, 'rb') |
163 with open(path, 'rb') as fh: |
164 data = fp.read() |
164 data = fh.read() |
165 fp.close() |
165 |
166 req.respond(HTTP_OK, ct, body=data) |
166 req.respond(HTTP_OK, ct, body=data) |
167 except TypeError: |
167 except TypeError: |
168 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
168 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
169 except OSError as err: |
169 except OSError as err: |
170 if err.errno == errno.ENOENT: |
170 if err.errno == errno.ENOENT: |