Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Aug 4, 2011
0 parents commit e65e005
Show file tree
Hide file tree
Showing 22 changed files with 1,744 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.gem
*.swp
*.pyc
*#*
build
dist
setuptools-*
.svn/*
.DS_Store
*.so
distribute-0.6.8-py2.6.egg
distribute-0.6.8.tar.gz
pistil.egg-info
nohup.out
.coverage
doc/.sass-cache
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
2011 (c) Benoît Chesneau <[email protected]>
2011 (c) Meebo

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include .gitignore
include LICENSE
include NOTICE
include README.rst
include THANKS

recursive-include examples *
20 changes: 20 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pistil

2011 (c) Benoît Chesneau <[email protected]>
2011 (c) Meebo

Pistil is released under the MIT license. See the LICENSE
file for the complete license.


Following files are under MIT License and copyrights:
2009-2011 (c) Benoît Chesneau <[email protected]>
2009-2011 (c) Paul J. Davis <[email protected]>


pistil/arbiter.py,
pistil/util.py
pistil/sock.py
pistil/pidfile.py
pistil/workertmp.py
pistil/worker.py
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pistil
------


Simple multiprocessing toolkit. This is based on the `Gunicorn <http://gunicorn.orh>`_ multiprocessing engine.
Empty file added THANKS
Empty file.
79 changes: 79 additions & 0 deletions examples/serve_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import mimetypes
import os

from http_parser.http import HttpStream
from http_parser.reader import SocketReader

from pistil import util
from pistil.tcp.arbiter import TcpArbiter
from pistil.tcp.gevent_worker import TcpGeventWorker

CURDIR = os.path.dirname(__file__)


def write_error(sock, status_int, reason, mesg):
html = textwrap.dedent("""\
<html>
<head>
<title>%(reason)s</title>
</head>
<body>
<h1>%(reason)s</h1>
%(mesg)s
</body>
</html>
""") % {"reason": reason, "mesg": mesg}

http = textwrap.dedent("""\
HTTP/1.1 %s %s\r
Connection: close\r
Content-Type: text/html\r
Content-Length: %d\r
\r
%s
""") % (str(status_int), reason, len(html), html)
write_nonblock(sock, http)



class HttpWorker(TcpGeventWorker):

def handle(self, sock, addr):
p = HttpStream(SocketReader(sock))

path = p.path()

if not path or path == "/":
path = "index.html"

if path.startswith("/"):
path = path[1:]

real_path = os.path.join(CURDIR, "static", path)
if not os.path.exists(real_path):
util.write_error(sock, 404, "Not found", real_path + " not found")
else:
ctype = mimetypes.guess_type(real_path)

with open(real_path, 'r') as f:
resp = "".join(["HTTP/1.1 200 OK\r\n",
"Content-Type: " + ctype[0] + "\r\n",
"Connection: close\r\n\r\n",
f.read()])
sock.sendall(resp)


def main():
conf = {"address": ("127.0.0.1", 5000), "debug": True}
print conf
arbiter = TcpArbiter(conf, HttpWorker)
arbiter.run()


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions examples/static/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
3 changes: 3 additions & 0 deletions examples/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Welcome !

Go to <a href="hello.html">Hello world</a>.
10 changes: 10 additions & 0 deletions pistil/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -
#
# This file is part of pistil released under the MIT license.
# See the NOTICE for more information.


version_info = (0, 1,0)
__version__ = ".".join(map(str, version_info))

SERVER_SOFTWARE = "pistil/%s" % __version__
Loading

0 comments on commit e65e005

Please sign in to comment.