Returns response object of given status code.
(code)
| 206 | |
| 207 | |
| 208 | def status_code(code): |
| 209 | """Returns response object of given status code.""" |
| 210 | |
| 211 | redirect = dict(headers=dict(location=REDIRECT_LOCATION)) |
| 212 | |
| 213 | code_map = { |
| 214 | 301: redirect, |
| 215 | 302: redirect, |
| 216 | 303: redirect, |
| 217 | 304: dict(data=''), |
| 218 | 305: redirect, |
| 219 | 307: redirect, |
| 220 | 401: dict(headers={'WWW-Authenticate': 'Basic realm="Fake Realm"'}), |
| 221 | 402: dict( |
| 222 | data='Fuck you, pay me!', |
| 223 | headers={ |
| 224 | 'x-more-info': 'http://vimeo.com/22053820' |
| 225 | } |
| 226 | ), |
| 227 | 406: dict(data=json.dumps({ |
| 228 | 'message': 'Client did not request a supported media type.', |
| 229 | 'accept': ACCEPTED_MEDIA_TYPES |
| 230 | }), |
| 231 | headers={ |
| 232 | 'Content-Type': 'application/json' |
| 233 | }), |
| 234 | 407: dict(headers={'Proxy-Authenticate': 'Basic realm="Fake Realm"'}), |
| 235 | 418: dict( # I'm a teapot! |
| 236 | data=ASCII_ART, |
| 237 | headers={ |
| 238 | 'x-more-info': 'http://tools.ietf.org/html/rfc2324' |
| 239 | } |
| 240 | ), |
| 241 | |
| 242 | } |
| 243 | |
| 244 | r = make_response() |
| 245 | r.status_code = code |
| 246 | |
| 247 | if code in code_map: |
| 248 | |
| 249 | m = code_map[code] |
| 250 | |
| 251 | if 'data' in m: |
| 252 | r.data = m['data'] |
| 253 | if 'headers' in m: |
| 254 | r.headers = m['headers'] |
| 255 | |
| 256 | return r |
| 257 | |
| 258 | |
| 259 | def check_basic_auth(user, passwd): |
no outgoing calls
no test coverage detected
searching dependent graphs…