1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 WSGI Implementations
19 ====================
20
21 This package holds implementations of specific WSGI bridges.
22 """
23 __author__ = u"Andr\xe9 Malo"
24 __docformat__ = "restructuredtext en"
25
26 from wtf.config import ConfigurationError
27
28
30 """
31 Interface for WSGI server implementations
32 """
33
35 """
36 Initialization
37
38 :Parameters:
39 - `config`: The application config
40 - `opts`: Command line option container
41 - `args`: Fixed commandline arguments
42
43 :Types:
44 - `config`: `wtf.config.Config`
45 - `opts`: ``optparse.OptionContainer``
46 - `args`: ``list``
47 """
48
49 - def handle(self, accepted, application, flags):
50 """
51 Handle an accepted socket
52
53 :Parameters:
54 - `accepted`: The accepted socket, being a tuple of socket object and
55 peername
56 - `application`: The WSGI application to call
57 - `flags`: Worker flags
58
59 :Types:
60 - `accepted`: ``tuple``
61 - `application`: ``callable``
62 - `flags`: `FlagsInterface`
63 """
64
65
67 """
68 Interface for worker flag containers
69
70 :CVariables:
71 - `multithread`: Is it a multithreaded server?
72 - `multiprocess`: Is it a multiprocessed server?
73 - `run_once`: Is the server supposed to run once?
74
75 :Types:
76 - `multithread`: ``bool``
77 - `multiprocess`: ``bool``
78 - `run_once`: ``bool``
79 """
80
82 """
83 Retrieve shutdown-pending flag
84
85 :return: The state of the flag
86 :rtype: ``bool``
87 """
88
89
91 """
92 Create the server instance selected by configuration
93
94 :Parameters:
95 - `config`: configuration
96 - `opts`: Option container
97 - `args`: Fixed arguments
98
99 :Types:
100 - `config`: `config.Config`
101 - `opts`: ``optparse.OptionContainer``
102 - `args`: ``list``
103
104 :return: server instance
105 :rtype: `ServerInterface`
106 """
107 self = factory
108
109 try:
110 protocol = config.wtf.protocol
111 except KeyError:
112 raise ConfigurationError("Missing protocol configuration")
113
114 if protocol not in self.impl:
115 raise ConfigurationError("Unknown protocol %s" % protocol)
116
117 return self.impl[protocol](config, opts, args)
118 factory.impl = {}
119
120
122 """
123 Register a server implementation
124
125 :Parameters:
126 - `name`: The name (in the config)
127 - `klass`: The implementation class
128
129 :Types:
130 - `name`: ``str``
131 - `klass`: `ServerInterface`
132 """
133 factory.impl[name] = klass
134