Package trac ::
Package web ::
Module cgi_frontend
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C)2005-2009 Edgewall Software
5 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
6 # Copyright (C) 2005 Matthew Good <trac@matt-good.net>
7 # All rights reserved.
8 #
9 # This software is licensed as described in the file COPYING, which
10 # you should have received as part of this distribution. The terms
11 # are also available at http://trac.edgewall.org/wiki/TracLicense.
12 #
13 # This software consists of voluntary contributions made by many
14 # individuals. For the exact contribution history, see the revision
15 # history and logs, available at http://trac.edgewall.org/log/.
16 #
17 # Author: Christopher Lenz <cmlenz@gmx.de>
18 # Matthew Good <trac@matt-good.net>
19
20 import os
21 import pkg_resources
22 import sys
23
24 from trac import __version__ as VERSION
25 from trac .web .main import dispatch_request
26 from trac .web .wsgi import WSGIGateway
27
28
30
31 wsgi_multithread = False
32 wsgi_multiprocess = False
33 wsgi_run_once = True
34
37
39 assert self.headers_set, 'Response not started'
40
41 if not self.headers_sent:
42 status, headers = self.headers_sent = self.headers_set
43 sys.stdout.write ('Status: %s\r\n' % status)
44 for header in headers:
45 sys.stdout.write ('%s: %s\r\n' % header)
46 sys.stdout.write ('\r\n')
47 sys.stdout.flush()
48
49 sys.stdout.write (data )
50 sys.stdout.flush()
51
52
54 try: # Make FreeBSD use blocking I/O like other platforms
55 import fcntl
56 for stream in [sys.stdin, sys.stdout]:
57 fd = stream.fileno()
58 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
59 fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)
60 except (ImportError, AttributeError):
61 pass
62
63 try: # Use binary I/O on Windows
64 import msvcrt
65 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
66 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
67 except ImportError:
68 pass
69
70 gateway = CGIGateway ()
71 gateway.run (dispatch_request )
72
73 if __name__ == '__main__':
74 pkg_resources.require ('Trac==%s' % VERSION)
75 run ()
76