"""Bounded multipart reader for image edit requests.""" import base64 from email import policy from email.parser import BytesParser MAX_IMAGE=10*1024*1024 MAX_BODY=4*MAX_IMAGE+65536 def read_image_upload(handler,profile_field='model'): handler.connection.settimeout(45) if handler.headers.get('Transfer-Encoding'):raise ValueError('Chunked Upload wird nicht unterstützt.') try:length=int(handler.headers.get('Content-Length','0')) except ValueError:raise ValueError('Ungültige Upload-Länge.') from None content_type=handler.headers.get('Content-Type','') if not 0=4 or not 04096:raise ValueError('Ungültiges oder doppeltes Formularfeld.') try:fields[name]=data.decode('utf-8') except UnicodeError:raise ValueError('Ungültiges Textfeld.') from None if profile_field not in fields:raise ValueError('Bildprofil fehlt.') return fields,images