Streams n random bytes generated with given seed, at given chunk size per packet.
(n)
| 673 | |
| 674 | @app.route('/stream-bytes/<int:n>') |
| 675 | def stream_random_bytes(n): |
| 676 | """Streams n random bytes generated with given seed, at given chunk size per packet.""" |
| 677 | n = min(n, 100 * 1024) # set 100KB limit |
| 678 | |
| 679 | params = CaseInsensitiveDict(request.args.items()) |
| 680 | if 'seed' in params: |
| 681 | random.seed(int(params['seed'])) |
| 682 | |
| 683 | if 'chunk_size' in params: |
| 684 | chunk_size = max(1, int(params['chunk_size'])) |
| 685 | else: |
| 686 | chunk_size = 10 * 1024 |
| 687 | |
| 688 | def generate_bytes(): |
| 689 | chunks = bytearray() |
| 690 | |
| 691 | for i in xrange(n): |
| 692 | chunks.append(random.randint(0, 255)) |
| 693 | if len(chunks) == chunk_size: |
| 694 | yield(bytes(chunks)) |
| 695 | chunks = bytearray() |
| 696 | |
| 697 | if chunks: |
| 698 | yield(bytes(chunks)) |
| 699 | |
| 700 | headers = {'Content-Type': 'application/octet-stream'} |
| 701 | |
| 702 | return Response(generate_bytes(), headers=headers) |
| 703 | |
| 704 | @app.route('/range/<int:numbytes>') |
| 705 | def range_request(numbytes): |
nothing calls this directly
no test coverage detected
searching dependent graphs…