Skip to content

Commit d50deaa

Browse files
committed
feat: change to compatible with python3
1 parent 66ced6e commit d50deaa

17 files changed

+104
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/
88
*.egg-info/
99
.eggs/
1010
build/
11+
*.so

litefs.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
License: MIT (see LICENSE for details)
1414
'''
1515

16-
__version__ = '0.2.4'
16+
__version__ = '0.3.0'
1717
__author__ = 'Leafcoder'
1818
__license__ = 'MIT'
1919

@@ -163,6 +163,11 @@ def log_error(logger, message=None):
163163
message = 'error occured'
164164
logger.error(message, exc_info=True)
165165

166+
def log_info(logger, message=None):
167+
if message is None:
168+
message = 'info'
169+
logger.info(message)
170+
166171
def log_debug(logger, message=None):
167172
if message is None:
168173
message = 'debug'
@@ -351,6 +356,8 @@ def on_moved(self, event):
351356
return
352357
if not dest_path.startswith(webroot+'/'):
353358
return
359+
log_info(self._app.logger, '%s has been moved to %s' \
360+
% (src_path, dest_path))
354361
src_path = '/%s' % src_path [len(webroot):].strip('/')
355362
dest_path = '/%s' % dest_path[len(webroot):].strip('/')
356363
caches = self._app.caches
@@ -375,6 +382,7 @@ def on_created(self, event):
375382
return
376383
if not src_path.startswith(webroot+'/'):
377384
return
385+
log_info(self._app.logger, '%s has been modified' % src_path)
378386
src_path = '/%s' % src_path[len(webroot):].strip('/')
379387
caches = self._app.caches
380388
files = self._app.files
@@ -1134,7 +1142,7 @@ class Litefs(object):
11341142

11351143
def __init__(self, **kwargs):
11361144
self.config = config = make_config(**kwargs)
1137-
level = logging.DEBUG if config.debug else logging.ERROR
1145+
level = logging.DEBUG if config.debug else logging.INFO
11381146
self.logger = make_logger(__name__, level=level)
11391147
self.server_info = server_info = make_server(
11401148
config.address, request_size=config.request_size

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
argh==0.26.2
2+
argparse==1.2.1
3+
Cython==0.29.14
24
greenlet==0.4.13
35
Mako==1.0.6
46
MarkupSafe==1.0

setup.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from Cython.Build import cythonize
1717

1818
long_description = '''\
19-
使用 Python 从零开始构建一个 Web 服务器框架。 开发 Litefs 的是为了实现一个能快速、安\
20-
全、灵活的构建 Web 项目的服务器框架。 Litefs 是一个高性能的 HTTP 服务器。Litefs 具有高\
21-
稳定性、丰富的功能、系统消耗低的特点。
19+
Build a web server framework using Python. Litefs was developed to imple\
20+
ment a server framework that can quickly, securely, and flexibly build Web \
21+
projects. Litefs is a high-performance HTTP server. Litefs has the characte\
22+
ristics of high stability, rich functions, and low system consumption.
2223
2324
Name: leafcoder
2425
Email: leafcoder@gmail.com
@@ -27,35 +28,34 @@
2728
License: MIT (see LICENSE for details)
2829
'''
2930

30-
__version__ = '0.2.4'
31+
__version__ = '0.3.0'
3132
__author__ = 'Leafcoder'
3233
__license__ = 'MIT'
3334

35+
language_level = 2
36+
if sys.version_info[0] > 2:
37+
language_level = 3
38+
3439
setup(
3540
name='litefs',
3641
version=__version__,
37-
description='使用 Python 从零开始构建一个 Web 服务器框架。',
42+
description='Build a web server framework using Python.',
3843
long_description=__doc__,
3944
author=__author__,
4045
author_email='leafcoder@gmail.com',
4146
url='https://github.com/leafcoder/litefs',
4247
py_modules=['litefs'],
43-
ext_modules=cythonize('litefs.py'),
48+
ext_modules=cythonize(
49+
'litefs.py',
50+
compiler_directives={
51+
'language_level' : language_level
52+
}
53+
),
4454
license=__license__,
4555
platforms='any',
4656
package_data={
4757
'': ["*.txt", 'LICENSE'],
48-
'demo': ['site/*', '*.py']
58+
'site': ['site/*', '*.py']
4959
},
50-
install_requires=[
51-
'Mako==1.0.6',
52-
'MarkupSafe==1.0',
53-
'greenlet==0.4.13',
54-
'PyYAML==3.12',
55-
'argh==0.26.2',
56-
'argparse==1.2.1',
57-
'pathtools==0.1.2',
58-
'watchdog==0.8.3',
59-
'wsgiref==0.1.2'
60-
]
60+
install_requires=open('requirements.txt').read().split('\n')
6161
)

site/database/index.html.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

site/demo.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#-*- coding: utf-8 -*-
22

33
def handler(self):
4-
return '''
5-
<ul>
6-
<li><a href="helloworld">Hello World</a></li>
7-
<li><a href="pathinfo">环境变量 PATH_INFO</a></li>
8-
<li><a href="upload.html">文件上传</a></li>
9-
<li><a href="form.html">表单数据</a></li>
10-
</ul>
11-
'''
4+
yield '<h1>Environ</h1>'
5+
for k, v in self.environ.items():
6+
yield '{}: {}'.format(k, v)
7+
yield '<br>'
8+
9+
yield '<h1>Form</h1>'
10+
yield self.form
11+
yield '<br>'
12+
13+
yield '<h1>Files</h1>'
14+
files = self.files
15+
for fp in files.values():
16+
print(dir(fp))
17+
yield '<div><textarea style="width: 100%" rows=10>'
18+
yield fp.read()
19+
yield '</textarea></div>'
20+
yield '<br>'

site/environ.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

site/form.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

site/form.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

site/helloworld.mako

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<pre>
32
PATH_INFO : ${http.path_info}
43
QUERY_STRING: ${http.query_string}

site/index.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
Hello world
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>demo</title>
6+
</head>
7+
<body>
8+
<h1>Submit form</h1>
9+
<form action="./demo" method="post">
10+
<div>Name: <input type="text" name="name"></div>
11+
<br>
12+
<div>Name: <input type="text" name="name"></div>
13+
<br>
14+
<div><input type="submit"/></div>
15+
</form>
16+
17+
<h1>Upload file</h1>
18+
<form action="./demo" method="post" enctype="multipart/form-data">
19+
<div><input type="file" name="file" /></div>
20+
<br>
21+
<div><input type="file" name="file1" /></div>
22+
<br>
23+
<div><input type="submit" value="upload" /></div>
24+
</form>
25+
</body>
26+
</html>

site/upload.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

site/upload.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

site/user-agent.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
-1.31 MB
Binary file not shown.

test/__init__.py

Whitespace-only changes.

test/test_treecache.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
from litefs import TreeCache
3+
4+
class TestTreeCache(unittest.TestCase):
5+
6+
def setUp(self):
7+
self.cache = TreeCache(clean_period=60, expiration_time=3600)
8+
9+
def test_put(self):
10+
caches = {
11+
'k_int': 1,
12+
'k_str': 'hello',
13+
'k_float': .5
14+
}
15+
cache = TreeCache(clean_period=60, expiration_time=3600)
16+
for k, v in caches.items():
17+
cache.put(k, v)
18+
self.assertEqual(len(cache), len(caches))
19+
20+
def test_delete(self):
21+
cache = self.cache
22+
cache_key = 'delete_key'
23+
cache.put(cache_key, 'delete me')
24+
size_before_delete = len(cache)
25+
cache.delete(cache_key)
26+
size_after_delete = len(cache)
27+
self.assertEqual(size_before_delete, size_after_delete + 1)
28+
29+
if __name__ == '__main__':
30+
unittest.main()

0 commit comments

Comments
 (0)