ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Search Repo:
ryah (author)
Mon Apr 07 16:28:09 -0700 2008
commit  dc4a7e28337306378a008aa9d7e205a306e79934
tree    dbdebfdd3e23c2b01b4ab4134ebb8e64c97f7d68
parent  38185f36847ca1315f9241302d6bab7f2f7b1495
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)