|
30 | 30 | from gzip import GzipFile |
31 | 31 | from hashlib import sha1 |
32 | 32 | from imp import find_module, load_module, new_module as imp_new_module |
| 33 | +from io import RawIOBase, BufferedRWPair, DEFAULT_BUFFER_SIZE |
33 | 34 | from mako import exceptions |
34 | 35 | from mako.lookup import TemplateLookup |
35 | 36 | from mimetypes import guess_type |
|
49 | 50 | from watchdog.observers import Observer |
50 | 51 | from weakref import proxy as weakref_proxy |
51 | 52 | from zlib import compress as zlib_compress |
52 | | -from io import RawIOBase, BufferedRWPair, DEFAULT_BUFFER_SIZE |
53 | 53 |
|
54 | 54 | PY3 = sys.version_info.major > 2 |
55 | 55 |
|
56 | 56 | if PY3: |
57 | 57 | # Import modules in py3 |
58 | 58 | import socket |
| 59 | + from collections import UserDict |
59 | 60 | from http.client import responses as http_status_codes |
60 | 61 | from http.cookies import SimpleCookie |
61 | 62 | from io import BytesIO as StringIO |
62 | 63 | from urllib.parse import splitport, unquote_plus |
63 | | - from collections import UserDict |
64 | 64 | def is_unicode(s): |
65 | 65 | return isinstance(s, str) |
66 | 66 | def is_bytes(s): |
67 | 67 | return isinstance(s, bytes) |
68 | 68 | else: |
69 | 69 | # Import modules in py2 |
70 | 70 | import _socket as socket |
71 | | - from Cookie import SimpleCookie |
72 | 71 | from cStringIO import StringIO |
73 | 72 | from httplib import responses as http_status_codes |
74 | 73 | from urllib import splitport, unquote_plus |
| 74 | + from Cookie import SimpleCookie |
75 | 75 | from UserDict import UserDict |
76 | 76 | def is_unicode(s): |
77 | 77 | return isinstance(s, unicode) |
78 | 78 | def is_bytes(s): |
79 | 79 | return isinstance(s, basestring) |
80 | 80 |
|
81 | 81 | server_name = 'litefs' |
82 | | -server_software = 'litefs %s' % __version__ |
| 82 | +server_software = '%s %s' % (server_name, __version__) |
83 | 83 |
|
84 | 84 | default_404 = 'not_found' |
85 | 85 | default_sid = '%s.sid' % server_name |
86 | | -default_content_type = 'text/plain' |
| 86 | +default_content_type = 'text/plain; charset=utf-8' |
87 | 87 |
|
88 | 88 | EOFS = ('', '\n', '\r\n') |
89 | | -FILES_HEADER_NAME = 'litefs.files' |
| 89 | +FILES_HEADER_NAME = '%s.files' % server_name |
90 | 90 | date_format = '%Y/%m/%d %H:%M:%S' |
91 | 91 | should_retry_error = (EWOULDBLOCK, EAGAIN) |
92 | 92 | double_slash_sub = re.compile(r'\/{2,}').sub |
93 | 93 | startswith_dot_sub = re.compile(r'\/\.+').sub |
94 | 94 | suffixes = ('.py', '.pyc', '.pyo', '.so', '.mako') |
95 | 95 | cgi_suffixes = ('.pl', '.py', '.pyc', '.pyo', '.php') |
96 | 96 | form_dict_match = re.compile(r'(.+)\[([^\[\]]+)\]').match |
97 | | -server_info = 'litefs/%s python/%s' % (__version__, sys.version.split()[0]) |
| 97 | +server_info = '%s/%s python/%s' \ |
| 98 | + % (server_name, __version__, sys.version.split()[0]) |
98 | 99 | cgi_runners = { |
99 | 100 | '.pl' : '/usr/bin/perl', |
100 | 101 | '.py' : '/usr/bin/python', |
@@ -1028,7 +1029,7 @@ def _handler(self): |
1028 | 1029 | fp, pathname, description = find_module(name, [realbase]) |
1029 | 1030 | except ImportError: |
1030 | 1031 | return None |
1031 | | - module_name = 'litefs_%s' % uuid4().hex |
| 1032 | + module_name = '%s_%s' % (server_name, uuid4().hex) |
1032 | 1033 | sys.dont_write_bytecode = True |
1033 | 1034 | try: |
1034 | 1035 | module = load_module(module_name, fp, pathname, description) |
|
0 commit comments