a c @sRUddlZddlmZmZmZmZmZmZmZm Z m Z ddl m Z m Z mZmZddlmZmZmZmZmZddlmZddlmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%d gZ&e'e (d Z)e'd Z*ee+ee+d d dZ,ee+eee+e+fd ddZ-e'e(d Z.eeedddZ/e'e(d Z0ee eedfdddZ1GdddZ2e'e (d Z3GdddZ4GdddZ5eddddZ6ee e e$ee e$e e$ffe edefee7edeffffZ8eefe/e efe1e efe1eefe6eefe6eefe6e efe6e efe6e efe6ee4e2e5di Z9e8e:d <dS) N) AnyCallableDictIterableNoReturnOptionalTupleTypeUnion) chunk_header header_field request_line status_line)Data EndOfMessageInformationalResponseRequestResponse) ReceiveBuffer)CLIENTCLOSEDDONEIDLE MUST_CLOSE SEND_BODY SEND_RESPONSESERVER)LocalProtocolErrorRemoteProtocolErrorSentinelvalidateREADERSasciis[ \t]+)linesreturnccst|}d}|D]d}t|}|rb|dur2tdt|tsDt|}|d7}|||d7}q|durp|V|}q|dur|VdS)Nz%continuation line at start of headers )iter obs_fold_rematchr isinstance bytearrayend)r$itlastliner)r0Y/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/h11/_readers.py_obsolete_line_fold+s   r2ccs2t|D]$}tt|d|}|d|dfVqdS)Nzillegal header line: {!r} field_nameZ field_value)r2r!header_field_re)r$r/matchesr0r0r1_decode_header_lines@s r6bufr%cCsj|}|dur$|r tddS|s0tdtt|dd|d}tftt|dddd|S)Nillegal request linezno request line receivedrzillegal request line: {!r}r T)headers_parsed)maybe_extract_lines+is_next_line_obviously_invalid_request_linerr!request_line_rerlistr6)r8r$r5r0r0r1maybe_read_from_IDLE_clientKsr@cCs|}|dur$|r tddS|s0tdtt|dd|d}|ddurVdn|d}|ddurndn|d}t|d }|d krtnt}|tt |d dd |||d S)Nr9zno response line receivedrzillegal status line: {!r} http_versions1.1reason status_coder T)r:r;rDrBrA) r<r=rr!status_line_reintrrr?r6)r8r$r5rArBrDclass_r0r0r1$maybe_read_from_SEND_RESPONSE_server^s* rIc@sDeZdZeddddZeeeedfdddZ e dd d Z dS) ContentLengthReaderN)lengthr%cCs||_||_dSN)_length _remaining)selfrKr0r0r1__init__{szContentLengthReader.__init__r7cCsD|jdkrtS||j}|dur(dS|jt|8_t|dS)Nrdata)rNrmaybe_extract_at_mostlenrrOr8rRr0r0r1__call__s  zContentLengthReader.__call__r%cCstd|j|j|jdS)Nz]peer closed connection without sending complete message body (received {} bytes, expected {}))rformatrMrNrOr0r0r1read_eofs zContentLengthReader.read_eof) __name__ __module__ __qualname__rGrPrr rrrVrrZr0r0r0r1rJzs rJc@sBeZdZddddZeeeedfdddZe ddd Z dS) ChunkedReaderNrWcCsd|_d|_d|_dS)NrF)_bytes_in_chunk_bytes_to_discard_reading_trailerrYr0r0r1rPszChunkedReader.__init__r7cCs@|jr,|}|durdSttt|dS|jdkrn||j}|durNdS|jt|8_|jdkrndS|jdks|J|jdkr| }|durdSt t |d|}t |ddd|_|jdkrd|_||Sd}nd}|jdksJ||j}|durdS|jt|8_|jdkr.d |_d}nd}t |||d S) N)r:rzillegal chunk header: {!r} chunk_size)baseTF)rR chunk_start chunk_end)rar<rr?r6r`rSrTr_Zmaybe_extract_next_liner!chunk_header_rerGr)rOr8r$rRr r5rfrgr0r0r1rVsN        zChunkedReader.__call__cCs tddS)NzVpeer closed connection without sending complete message body (incomplete chunked read))rrYr0r0r1rZszChunkedReader.read_eof) r[r\r]rPrr rrrVrrZr0r0r0r1r^s.r^c@s.eZdZeeedddZedddZdS) Http10Readerr7cCs |d}|durdSt|dS)Niɚ;rQ)rSrrUr0r0r1rVs zHttp10Reader.__call__rWcCstSrL)rrYr0r0r1rZszHttp10Reader.read_eofN) r[r\r]rrrrVrrZr0r0r0r1risricCs|r tddS)NzGot data when expecting EOF)r)r8r0r0r1expect_nothingsrj.)chunkedzcontent-lengthzhttp/1.0);retypingrrrrrrrr r Z_abnfr r rrZ_eventsrrrrrZ_receivebufferr_staterrrrrrrrZ_utilrrr r!__all__compileencoder4r(bytesr2r6r>r@rFrIrJrhr^rirjstrZ ReadersTyper"__annotations__r0r0r0r1sX , (    > "