equal
deleted
inserted
replaced
34 return os.stat(cl_path).st_mtime |
34 return os.stat(cl_path).st_mtime |
35 else: |
35 else: |
36 return os.stat(store_path).st_mtime |
36 return os.stat(store_path).st_mtime |
37 |
37 |
38 def staticfile(directory, fname, req): |
38 def staticfile(directory, fname, req): |
39 """return a file inside directory with guessed content-type header |
39 """return a file inside directory with guessed Content-Type header |
40 |
40 |
41 fname always uses '/' as directory separator and isn't allowed to |
41 fname always uses '/' as directory separator and isn't allowed to |
42 contain unusual path components. |
42 contain unusual path components. |
43 Content-type is guessed using the mimetypes module. |
43 Content-Type is guessed using the mimetypes module. |
44 Return an empty string if fname is illegal or file not found. |
44 Return an empty string if fname is illegal or file not found. |
45 |
45 |
46 """ |
46 """ |
47 parts = fname.split('/') |
47 parts = fname.split('/') |
48 path = directory |
48 path = directory |
52 return "" |
52 return "" |
53 path = os.path.join(path, part) |
53 path = os.path.join(path, part) |
54 try: |
54 try: |
55 os.stat(path) |
55 os.stat(path) |
56 ct = mimetypes.guess_type(path)[0] or "text/plain" |
56 ct = mimetypes.guess_type(path)[0] or "text/plain" |
57 req.header([('Content-type', ct), |
57 req.header([ |
58 ('Content-length', str(os.path.getsize(path)))]) |
58 ('Content-Type', ct), |
|
59 ('Content-Length', str(os.path.getsize(path))) |
|
60 ]) |
59 return file(path, 'rb').read() |
61 return file(path, 'rb').read() |
60 except TypeError: |
62 except TypeError: |
61 raise ErrorResponse(500, 'illegal file name') |
63 raise ErrorResponse(500, 'illegal file name') |
62 except OSError, err: |
64 except OSError, err: |
63 if err.errno == errno.ENOENT: |
65 if err.errno == errno.ENOENT: |