Package wtf :: Package app :: Package sample :: Module index
[hide private]
[frames] | no frames]

Source Code for Module wtf.app.sample.index

 1  # -*- coding: ascii -*- 
 2  # 
 3  # Copyright 2007-2012 
 4  # Andr\xe9 Malo or his licensors, as applicable 
 5  # 
 6  # Licensed under the Apache License, Version 2.0 (the "License"); 
 7  # you may not use this file except in compliance with the License. 
 8  # You may obtain a copy of the License at 
 9  # 
10  #     http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  # Unless required by applicable law or agreed to in writing, software 
13  # distributed under the License is distributed on an "AS IS" BASIS, 
14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  # See the License for the specific language governing permissions and 
16  # limitations under the License. 
17  """ 
18  Sample application package 
19  ========================== 
20   
21  This package contains a sample application. 
22  """ 
23  __author__ = u"Andr\xe9 Malo" 
24  __docformat__ = "restructuredtext en" 
25   
26  from wtf.app.decorators import Method 
27  from wtf import webutil as _webutil 
28   
29  from __svc__.wtf import static as _static 
30 31 32 @Method('GET') 33 -def hello_world(request, response):
34 """ Hello world output """ 35 if request.match is not None: 36 name = request.match.group('name') 37 else: 38 name = u'World' 39 name = name.encode('utf-8') 40 salutation = (request.param['s'] or u'Hello!').encode('utf-8') 41 response.content_type(charset='utf-8') 42 response.cache(0) 43 44 return [""" 45 <html> 46 <head> 47 <title>Hi</title> 48 <link rel="stylesheet" type="text/css" href="/static/layout.css" /> 49 </head> 50 <body><h1>%s</h1><p>%s</p></body> 51 </html> 52 """.strip() % tuple(map(_webutil.escape_html, [salutation, name]))]
53 54 55 __staticmap__ = { 56 '/': hello_world, 57 #'/layout.css': _static.controller('static'), 58 } 59 __dynamicmap__ = [ 60 (r'/(?P<name>[^./]+)\.html$', hello_world), 61 (r'/static/(?P<filename>.+)', _static.controller('static', 'filename')), 62 ] 63