Mercurial > hg > decoupage
comparison decoupage/web.py @ 64:613ffeec2be5
return exceptions rather than just raise them; needed for wsgiref and who knows what other servers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 15 Dec 2010 09:30:32 -0800 |
parents | 9c570aed2246 |
children | ac1dc088e37e |
comparison
equal
deleted
inserted
replaced
63:9c570aed2246 | 64:613ffeec2be5 |
---|---|
94 auto_reload=self.auto_reload) | 94 auto_reload=self.auto_reload) |
95 | 95 |
96 | 96 |
97 | 97 |
98 ### methods dealing with HTTP | 98 ### methods dealing with HTTP |
99 | |
99 def __call__(self, environ, start_response): | 100 def __call__(self, environ, start_response): |
101 | |
102 # boilerplate: request and filename | |
100 request = Request(environ) | 103 request = Request(environ) |
101 filename = request.path_info.strip('/') | 104 filename = request.path_info.strip('/') |
102 path = os.path.join(self.directory, filename) | 105 path = os.path.join(self.directory, filename) |
106 | |
107 # check to see what we have to serve | |
103 if os.path.exists(path): | 108 if os.path.exists(path): |
109 | |
104 if os.path.isdir(path): | 110 if os.path.isdir(path): |
105 | 111 # serve an index |
106 if not request.path_info.endswith('/'): | 112 if request.path_info.endswith('/'): |
107 raise exc.HTTPMovedPermanently(add_slash=True) | 113 res = self.get(request) |
108 | 114 else: |
109 res = self.get(request) | 115 res = exc.HTTPMovedPermanently(add_slash=True) |
110 return res(environ, start_response) | 116 return res(environ, start_response) |
117 | |
111 else: | 118 else: |
119 # serve a file | |
112 conf = self.conf(request.path_info.rsplit('/',1)[0]) | 120 conf = self.conf(request.path_info.rsplit('/',1)[0]) |
113 if '/transformer' in conf: | 121 if '/transformer' in conf: |
114 args = [i.split('=', 1) for i in conf['/transformer'].split(',') if '=' in i] | 122 args = [i.split('=', 1) for i in conf['/transformer'].split(',') if '=' in i] |
115 kwargs = {} | 123 kwargs = {} |
116 for i in conf: | 124 for i in conf: |
123 fileserver = self.fileserver | 131 fileserver = self.fileserver |
124 | 132 |
125 fileserver = fileserver(path) | 133 fileserver = fileserver(path) |
126 return fileserver(environ, start_response) | 134 return fileserver(environ, start_response) |
127 else: | 135 else: |
128 raise exc.HTTPNotFound() | 136 # file does not exist |
137 response = exc.HTTPNotFound() | |
138 return response(environ, start_response) | |
129 | 139 |
130 | 140 |
131 def get(self, request): | 141 def get(self, request): |
132 """ | 142 """ |
133 return response to a GET requst | 143 return response to a GET requst |