U e8@sddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddlmZddlmZddlmZeZedZGd d d ejeZGd d d eZGd dde ZddddZddddZdS)) annotationsN)BaseHTTPResponse)HTTPHeaderDict)HTTPSConnection)HTTPSConnectionPoolTc@s@eZdZdZddddZddddZd d d d d ddZdS) _LockedObjectaY A wrapper class that hides a specific object behind a lock. The goal here is to provide a simple way to protect access to an object that cannot safely be simultaneously accessed from multiple threads. The intended use of this class is simple: take hold of it with a context manager, which returns the protected object. r)objcCst|_||_dSN) threadingRLocklock_obj)selfr r;/opt/hc_python/lib/python3.8/site-packages/urllib3/http2.py__init__"s z_LockedObject.__init__returncCs|j|jSr )racquirerrrrr __enter__&s z_LockedObject.__enter__ztype[BaseException] | NonezBaseException | Noneztypes.TracebackType | NoneNone)exc_typeexc_valexc_tbrcCs|jdSr )rrelease)rrrrrrr__exit__*sz_LockedObject.__exit__N)__name__ __module__ __qualname____doc__rrrrrrrr s r cseZdZd"dddddfdd Zd d d d Zdd fd d Zd#ddddddddZddddddZdd ddZdddddZ dd ddZ dd fd d! Z Z S)$HTTP2ConnectionNstrz int | Nonez typing.Anyr)hostportkwargsrc sD||_d|_g|_d|ks&d|kr.tdtj||f|dS)Nproxy proxy_configz$Proxies aren't supported with HTTP/2) _new_h2_conn_h2_conn _h2_stream _h2_headersNotImplementedErrorsuperr)rr%r&r' __class__rrr4s  zHTTP2Connection.__init__z)_LockedObject[h2.connection.H2Connection]rcCs tjjdd}ttjj|dS)NT)Z client_side)config)h2r2ZH2Configurationr connectionZ H2Connection)rr2rrrr*@szHTTP2Connection._new_h2_connc s8t|j}||j|W5QRXdSr )r/connectr+Zinitiate_connectionsocksendall data_to_send)rh2_connr0rrr5Ds zHTTP2Connection.connectFbool)methodurl skip_hostskip_accept_encodingrc Cs|j|}||_||_d|jkrr9 authorityrrr putrequestKs     zHTTP2Connection.putrequest)headervaluesrcGs.|D]$}|j|d|dfqdS)Nzutf-8)r-appendrClower)rrFrGvaluerrr putheaderdszHTTP2Connection.putheaderc CsB|j2}|j|j|jdd|}r4|j|W5QRXdS)NT) stream_idheaders end_stream)r+ send_headersr,r-r8r6r7)rr9r8rrr endheadersjs zHTTP2Connection.endheadersbytes)datarcCs|sdStddS)Nz Sending data isn't supported yet)r.)rrRrrrsendtszHTTP2Connection.send HTTP2Responsec Csd}t}|j}d}|s|jd}r||}|D]}t|tjjrt }|j D]6\} } | dkrtt | }qV| | d| dqVq8t|tjjr||j7}||j|jq8t|tjjr8d}q8|} r|j| qW5QRX||dk stt|||jt|dS)NFis:statusasciiT)statusrM request_urlrR) bytearrayr+r6recvZ receive_data isinstancer3eventsZResponseReceivedrrMintdecodeaddZ DataReceivedrRZacknowledge_received_dataZflow_controlled_lengthrLZ StreamEndedr8r7closeAssertionErrorrTrArQ) rrVrRr9rNZ received_datar[eventrMrFrJr8rrr getresponseysF   zHTTP2Connection.getresponsec sp|j@}z$||}r*|j|Wntk r@YnXW5QRX||_d|_g|_t dSr ) r+Zclose_connectionr8r6r7 Exceptionr*r,r-r/r_)rr9rRr0rrr_s  zHTTP2Connection.close)N)FF) rr r!rr*r5rErKrPrSrbr_ __classcell__rrr0rr#3s   -r#cs\eZdZddddddddfd d Zedd d d Zdd ddZdd ddZZS)rTFr\rr$rQr:r)rVrMrWrRdecode_contentrcs(tj||dd||d||_d|_dS)N)rVrMversionreasonrerWr)r/r_datalength_remaining)rrVrMrWrRrer0rrrs zHTTP2Response.__init__rcCs|jSr )rirrrrrRszHTTP2Response.datacCsdSr rrrrrget_redirect_locationsz#HTTP2Response.get_redirect_locationcCsdSr rrrrrr_szHTTP2Response.close)F) rr r!rpropertyrRrkr_rdrrr0rrTs rTrrcCstt_ttj_dgtjj_dS)Nr3) r#r ConnectionClsurllib3r4rutilssl_ALPN_PROTOCOLSrrrrinject_into_urllib3srrcCstt_ttj_dgtjj_dS)Nzhttp/1.1) orig_HTTPSConnectionrrmrnr4rrorprqrrrrextract_from_urllib3srt) __future__rr typestypingZ h2.configr3Z h2.connectionZ h2.eventsZurllib3.connectionrnZurllib3.util.ssl_Zurllib3.responser _collectionsrr4rconnectionpoolrrsTypeVarrGenericr r#rTrrrtrrrrs(      "