ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
ryah (author)
Mon Apr 07 09:52:20 -0700 2008
commit  f16270d317fca555c68a294db72a0db1d4767dee
tree    8f42dfae9f83549ad87b236c4d0df1d83f974ef7
parent  7393e3658c5b1bc422047df6bf40e0f08568af37
ebb / python_lib / __init__.py
100644 40 lines (27 sloc) 0.821 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""ebb
 
A WSGI web server!
"""
import ebb_ffi
from signal import *
 
def interupt_handler(signum, frame):
  ebb_ffi.server_stop()
  
signal(SIGINT, interupt_handler)
signal(SIGTERM, interupt_handler)
 
 
def wsgi2_request_cb(app, client):
  status_string, headers, body = app.__call__(client.env())
  
  status, status_human = status_string.split(" ")
  
  client.write_status(int(status), status_human)
  
  for field, value in headers:
    client.write_header(field, value)
    
  for part in body:
    client.write_body(part)
  
  client.release()
  return True
  
  
def start_server(app, args = {}):
  if args['port']:
    ebb_ffi.listen_on_port(int(args['port']))
  else:
    print "no port given!"
    exit(1)
  
  print "Ebb listening on port %d" % args['port']
  ebb_ffi.process_connections(app, wsgi2_request_cb)