def test_gen_unique_uid(): id1 = gen_unique_id() assert len(id1) == 32 id2 = gen_unique_id() assert len(id2) == 32 assert id1 != id2
def from_text(cls, text, human_name='plaintext.txt'): with io.BytesIO(text.encode('utf8')) as open_file: num_bytes = len(text) if num_bytes > app.config['MAX_UPLOAD_SIZE']: raise FileTooLargeError(num_bytes) yield cls( human_name=human_name, num_bytes=num_bytes, open_file=open_file, unique_id=gen_unique_id(), )
def from_text(cls, text): with io.BytesIO(text.encode('utf8')) as open_file: num_bytes = len(text) if num_bytes > app.config['MAX_UPLOAD_SIZE']: raise FileTooLargeError() yield cls( human_name='plaintext.txt', num_bytes=num_bytes, open_file=open_file, unique_id=gen_unique_id(), )
def from_http_file(cls, f): with tempfile.NamedTemporaryFile() as tf: # We don't know the file size until we start to save the file (the # client can lie about the uploaded size, and some browsers don't # even send it). f.save(tf) num_bytes = f.tell() if num_bytes > app.config['MAX_UPLOAD_SIZE']: raise FileTooLargeError(num_bytes) tf.seek(0) yield cls( human_name=f.filename, num_bytes=num_bytes, open_file=tf, unique_id=gen_unique_id(), )
def from_http_file(cls, f): with tempfile.NamedTemporaryFile() as tf: # We don't know the file size until we start to save the file (the # client can lie about the uploaded size, and some browsers don't # even send it). f.save(tf) num_bytes = f.tell() if num_bytes > app.config['MAX_UPLOAD_SIZE']: raise FileTooLargeError() tf.seek(0) yield cls( human_name=f.filename, num_bytes=num_bytes, open_file=tf, unique_id=gen_unique_id(), )
def from_html(cls, html): with io.BytesIO(html.encode('utf8')) as open_file: yield cls( name=gen_unique_id() + '.html', open_file=open_file, )