Skip to content

Commit e65e005

Browse files
author
benoitc
committed
initial commit
0 parents  commit e65e005

22 files changed

+1744
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.gem
2+
*.swp
3+
*.pyc
4+
*#*
5+
build
6+
dist
7+
setuptools-*
8+
.svn/*
9+
.DS_Store
10+
*.so
11+
distribute-0.6.8-py2.6.egg
12+
distribute-0.6.8.tar.gz
13+
pistil.egg-info
14+
nohup.out
15+
.coverage
16+
doc/.sass-cache

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2011 (c) Benoît Chesneau <[email protected]>
2+
2011 (c) Meebo
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include .gitignore
2+
include LICENSE
3+
include NOTICE
4+
include README.rst
5+
include THANKS
6+
7+
recursive-include examples *

NOTICE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Pistil
2+
3+
2011 (c) Benoît Chesneau <[email protected]>
4+
2011 (c) Meebo
5+
6+
Pistil is released under the MIT license. See the LICENSE
7+
file for the complete license.
8+
9+
10+
Following files are under MIT License and copyrights:
11+
2009-2011 (c) Benoît Chesneau <[email protected]>
12+
2009-2011 (c) Paul J. Davis <[email protected]>
13+
14+
15+
pistil/arbiter.py,
16+
pistil/util.py
17+
pistil/sock.py
18+
pistil/pidfile.py
19+
pistil/workertmp.py
20+
pistil/worker.py

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pistil
2+
------
3+
4+
5+
Simple multiprocessing toolkit. This is based on the `Gunicorn <http://gunicorn.orh>`_ multiprocessing engine.

THANKS

Whitespace-only changes.

examples/serve_file.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -
2+
#
3+
# This file is part of gunicorn released under the MIT license.
4+
# See the NOTICE for more information.
5+
6+
import mimetypes
7+
import os
8+
9+
from http_parser.http import HttpStream
10+
from http_parser.reader import SocketReader
11+
12+
from pistil import util
13+
from pistil.tcp.arbiter import TcpArbiter
14+
from pistil.tcp.gevent_worker import TcpGeventWorker
15+
16+
CURDIR = os.path.dirname(__file__)
17+
18+
19+
def write_error(sock, status_int, reason, mesg):
20+
html = textwrap.dedent("""\
21+
<html>
22+
<head>
23+
<title>%(reason)s</title>
24+
</head>
25+
<body>
26+
<h1>%(reason)s</h1>
27+
%(mesg)s
28+
</body>
29+
</html>
30+
""") % {"reason": reason, "mesg": mesg}
31+
32+
http = textwrap.dedent("""\
33+
HTTP/1.1 %s %s\r
34+
Connection: close\r
35+
Content-Type: text/html\r
36+
Content-Length: %d\r
37+
\r
38+
%s
39+
""") % (str(status_int), reason, len(html), html)
40+
write_nonblock(sock, http)
41+
42+
43+
44+
class HttpWorker(TcpGeventWorker):
45+
46+
def handle(self, sock, addr):
47+
p = HttpStream(SocketReader(sock))
48+
49+
path = p.path()
50+
51+
if not path or path == "/":
52+
path = "index.html"
53+
54+
if path.startswith("/"):
55+
path = path[1:]
56+
57+
real_path = os.path.join(CURDIR, "static", path)
58+
if not os.path.exists(real_path):
59+
util.write_error(sock, 404, "Not found", real_path + " not found")
60+
else:
61+
ctype = mimetypes.guess_type(real_path)
62+
63+
with open(real_path, 'r') as f:
64+
resp = "".join(["HTTP/1.1 200 OK\r\n",
65+
"Content-Type: " + ctype[0] + "\r\n",
66+
"Connection: close\r\n\r\n",
67+
f.read()])
68+
sock.sendall(resp)
69+
70+
71+
def main():
72+
conf = {"address": ("127.0.0.1", 5000), "debug": True}
73+
print conf
74+
arbiter = TcpArbiter(conf, HttpWorker)
75+
arbiter.run()
76+
77+
78+
if __name__ == '__main__':
79+
main()

examples/static/hello.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

examples/static/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Welcome !
2+
3+
Go to <a href="hello.html">Hello world</a>.

pistil/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -
2+
#
3+
# This file is part of pistil released under the MIT license.
4+
# See the NOTICE for more information.
5+
6+
7+
version_info = (0, 1,0)
8+
__version__ = ".".join(map(str, version_info))
9+
10+
SERVER_SOFTWARE = "pistil/%s" % __version__

0 commit comments

Comments
 (0)