
    U>qj                     \   d Z ddlZddlZddlmZ ej
                  j                  dd      j                         dv Zes	 ddl	m
Z eZd	Znddl
ZeZd
ZeZ
ej                   j"                  ZdZd
ad Zd Zd Z ej.                  d      defd       ZdefdZy# e$ r ddl
ZeZd
ZY Ww xY w)u  HTTP backend abstraction.

Prefers ``curl_cffi`` for browser TLS impersonation. Falls back to plain
``requests`` with a realistic ``User-Agent`` when ``curl_cffi`` cannot be
imported (e.g. binary not buildable on the host platform — see issue #2692)
or when ``YF_DISABLE_CURL_CFFI`` is set in the environment (downstream
packagers may ship without ``curl_cffi`` even if it is installed).

The fallback is best-effort: plain ``requests`` cannot replicate the
JA3/JA4 fingerprint and HTTP/2 settings that ``curl_cffi`` provides, so
Yahoo Finance may rate-limit or block this client. ``curl_cffi`` remains
the preferred backend and the default install dependency.
    N   )utilsYF_DISABLE_CURL_CFFI )1trueyes)requestsTFzoMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36c                  h    t         st        ry dat        j                         j	                  d       y )NTzcurl_cffi not available; falling back to requests without browser TLS impersonation. Yahoo Finance may rate-limit or block this client. Install curl_cffi (>=0.15) for the supported configuration.)HAS_CURL_CFFI_fallback_warnedr   get_yf_loggerwarning     M/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/yfinance/_http.py_warn_once_on_fallbackr   .   s.    (	!!	Fr   c                      t         rt        j                  d      S t                t        j                         } | j                  j                  t        ddd       | S )z0Create a default Session for the active backend.chrome)impersonatez?text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8zen-US,en;q=0.5)z
User-AgentAcceptzAccept-Language)r   _backendSessionr   headersupdate_FALLBACK_USER_AGENT)ss    r   new_sessionr   :   sT    H55AII*S+ 
 Hr   c                 4    | j                   }t        |d|      S )zReturn the underlying ``http.cookiejar.CookieJar`` for either backend.

    ``curl_cffi`` exposes the jar as ``session.cookies.jar``; ``requests``
    uses ``session.cookies`` directly (it subclasses ``CookieJar``).
    jar)cookiesgetattr)sessionr!   s     r   
cookie_jarr$   H   s     ooG7E7++r   )maxsizereturnc                      g } 	 ddl m} | j                  |       	 ddlm} | j                  |       t        |       S # t        $ r Y .w xY w# t        $ r Y t        |       S w xY w)Nr   )r   )curl_cffi.requests.sessionr   appendImportErrorrequests.sessionstuple)classes_CurlSession_ReqSessions      r   _supported_session_classesr0   R   sl    GF|$<{# >  
  >s    > A 	A
	A
	A#"A#c                 H    t               }t        |      xr t        | |      S )z;True if ``obj`` is a Session from either supported backend.)r0   bool
isinstance)objr-   s     r   is_supported_sessionr5   b   s     (*G=5ZW55r   )__doc__	functoolsosr   r   environgetlower_DISABLE	curl_cffir
   _curl_backendr   r   r*   _requests_backend
exceptions	HTTPErrorr   r   r   r   r$   	lru_cacher,   r0   r2   r5   r   r   r   <module>rC      s     	 ::>>0"5;;=AUU7  ) HM))	9 
  	, QE   6 6Q  ,$s    
B B+*B+