Return status code or random status code if more than one are given
(codes)
| 348 | |
| 349 | @app.route('/status/<codes>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE']) |
| 350 | def view_status_code(codes): |
| 351 | """Return status code or random status code if more than one are given""" |
| 352 | |
| 353 | if ',' not in codes: |
| 354 | try: |
| 355 | code = int(codes) |
| 356 | except ValueError: |
| 357 | return Response('Invalid status code', status=400) |
| 358 | return status_code(code) |
| 359 | |
| 360 | choices = [] |
| 361 | for choice in codes.split(','): |
| 362 | if ':' not in choice: |
| 363 | code = choice |
| 364 | weight = 1 |
| 365 | else: |
| 366 | code, weight = choice.split(':') |
| 367 | |
| 368 | try: |
| 369 | choices.append((int(code), float(weight))) |
| 370 | except ValueError: |
| 371 | return Response('Invalid status code', status=400) |
| 372 | |
| 373 | code = weighted_choice(choices) |
| 374 | |
| 375 | return status_code(code) |
| 376 | |
| 377 | |
| 378 | @app.route('/response-headers', methods=['GET', 'POST']) |
nothing calls this directly
no test coverage detected
searching dependent graphs…