MCPcopy
hub / github.com/postmanlabs/httpbin / stream_random_bytes

Function stream_random_bytes

httpbin/core.py:675–702  ·  view source on GitHub ↗

Streams n random bytes generated with given seed, at given chunk size per packet.

(n)

Source from the content-addressed store, hash-verified

673
674@app.route('/stream-bytes/<int:n>')
675def 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>')
705def range_request(numbytes):

Callers

nothing calls this directly

Calls 2

CaseInsensitiveDictClass · 0.85
generate_bytesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…