1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Application wrapper package
19 ===========================
20
21 This package contains application wrappers and related stuff, plus a
22 sample hello-world-application.
23 """
24 __author__ = u"Andr\xe9 Malo"
25 __docformat__ = "restructuredtext en"
29 """
30 Application wrapper
31
32 :IVariables:
33 - `shutdown`: Shutdown callable
34 - `call`: Application callable
35
36 :Types:
37 - `shutdown`: ``callable``
38 - `call`: ``callable``
39 """
40 shutdown = None
41
42 @classmethod
43 - def factory(cls, config, opts, args):
44 """
45 Call the main application factory based on the configuration
46
47 :Parameters:
48 - `config`: Configuration
49 - `opts`: Command line options
50 - `args`: Positioned command line arguments
51
52 :Types:
53 - `config`: `wtf.config.Config`
54 - `opts`: ``optparse.OptionContainer``
55 - `args`: ``list``
56
57 :return: New Application instance
58 :rtype: `Application`
59 """
60 from wtf import services, util
61
62
63
64
65 manager = services.init(
66 config, opts, args, config.wtf('services', ())
67 )
68 app = manager.apply(
69 util.load_dotted(config.wtf.application)(config, opts, args)
70 )
71 return cls(manager, app)
72
74 """
75 Initialization
76
77 :Parameters:
78 - `manager`: Service manager
79 - `app`: WSGI callable
80
81 :Types:
82 - `manager`: `ServiceManager`
83 - `app`: ``callable``
84 """
85 self.shutdown = manager.shutdown
86 self.call = app
87
89 """ Destruction """
90 func, self.shutdown = self.shutdown, None
91 if func is not None:
92 func()
93
94 factory = Application.factory
98 """
99 Sample application bootstrapper
100
101 :Parameters:
102 - `config`: Configuration
103 - `opts`: Command line options
104 - `args`: Positioned command line arguments
105
106 :Types:
107 - `config`: `wtf.config.Config`
108 - `opts`: ``optparse.OptionContainer``
109 - `args`: ``list``
110
111 :return: WSGI application function
112 :rtype: ``callable``
113 """
114 def myapp(environ, start_response):
115 """
116 WSGI sample application
117
118 :Parameters:
119 - `environ`: Request WSGI environment
120 - `start_response`: response starter function
121
122 :Types:
123 - `environ`: ``dict``
124 - `start_response`: ``callable``
125
126 :return: Response body iterator
127 :rtype: ``iterable``
128 """
129
130
131 start_response("200 OK", [("Content-Type", "text/plain")])
132 return ["Hello World\n"]
133
134 return myapp
135