Mercurial > hg > decoupage
comparison decoupage/web.py @ 82:8596a1d97740
unicode
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 29 Nov 2013 20:45:20 -0800 |
parents | 5330cd62e179 |
children | 95820b36d7e3 |
comparison
equal
deleted
inserted
replaced
81:bb289832e061 | 82:8596a1d97740 |
---|---|
1 """ | 1 """ |
2 decoupage: a view with webob to index and serve static content | 2 decoupage: a view with webob to index and serve static content |
3 """ | 3 """ |
4 | 4 |
5 # TODO: | 5 # TODO: |
6 # files like `index.ini` | 6 # handle files with `#`s like like `#index.ini` |
7 # -> http://k0s.org/portfolio/ideas/#index.ini# | 7 # -> http://k0s.org/portfolio/ideas/#index.ini# |
8 # | 8 # |
9 # oops. Handle it better | 9 # oops. Handle it better |
10 # - either # is a magic hide character | 10 # - either # is a magic hide character |
11 # - or you urlescape that guy | 11 # - or you urlescape that guy |
36 defaults = { 'auto_reload': 'False', | 36 defaults = { 'auto_reload': 'False', |
37 'configuration': None, | 37 'configuration': None, |
38 'directory': None, # directory to serve | 38 'directory': None, # directory to serve |
39 'cascade': 'True', # whether to cascade configuration | 39 'cascade': 'True', # whether to cascade configuration |
40 'template': 'index.html', # XXX see below | 40 'template': 'index.html', # XXX see below |
41 'template_directories': '' # list of directories to look for templates | 41 'template_directories': '', # list of directories to look for templates |
42 'charset': 'utf-8', # content encoding for index.html files; -> `Content-Type: text/html; charset=ISO-8859-1` | |
42 } | 43 } |
43 | 44 |
44 def __init__(self, **kw): | 45 def __init__(self, **kw): |
45 | 46 |
46 # set defaults from app configuration | 47 # set defaults from app configuration |
99 | 100 |
100 # template loader | 101 # template loader |
101 self.loader = TemplateLoader(self.template_directories, | 102 self.loader = TemplateLoader(self.template_directories, |
102 variable_lookup="lenient", | 103 variable_lookup="lenient", |
103 auto_reload=self.auto_reload) | 104 auto_reload=self.auto_reload) |
104 | |
105 | 105 |
106 | 106 |
107 ### methods dealing with HTTP | 107 ### methods dealing with HTTP |
108 | 108 |
109 def __call__(self, environ, start_response): | 109 def __call__(self, environ, start_response): |
232 if local_index: | 232 if local_index: |
233 print repr(e) | 233 print repr(e) |
234 return self.fileserver(local_index) | 234 return self.fileserver(local_index) |
235 raise | 235 raise |
236 | 236 |
237 # set charset if given | |
238 kw = {} | |
239 if self.charset: | |
240 kw['charset'] = self.charset | |
241 | |
237 # return response | 242 # return response |
238 return Response(content_type='text/html', body=res) | 243 return Response(content_type='text/html', body=res, **kw) |
239 | 244 |
240 | 245 |
241 ### internal methods | 246 ### internal methods |
242 | 247 |
243 def filedata(self, path, directory, conf=None): | 248 def filedata(self, path, directory, conf=None): |