
    i9                        d dl Z d dlZd dlZd dlmZ ddlmZ dZ ej                    Z	da
dej        j        defd	Zd
 Ze j        ad Zd Zd Z G d dej                  Z e            Z e              e             dS )    N)Console   )SHOW_TICKFLOW_PROMPTz(https://tickflow.org?utm_source=efinanceFexcreturnc                 T    t          |                                           }d|v pd|v S )Nzmax retries exceededzremote end closed connection)strlower)r   msgs     J/usr/local/lib/python3.11/dist-packages/efinance/shared/tickflow_prompt.py!is_connection_error_show_tickflowr      s-    
c((..

C!S(Q,Jc,QQ    c                  &   t                      } |                                  |                     d                    t                               |                     d                    t                               |                                  d S )Nun   [bold red]网络连接异常[/bold red]，可尝试使用 [link={}]TickFlow[/link] 获取更稳定的数据。u     → {})r   printformatTICKFLOW_URL)consoles    r   _print_tickflow_promptr      sw    iiGMMOOOMMx	
 	
  
 MM*##L11222MMOOOOOr   c                     t          | ||           | t          j        j        u r(t          r#|#t          |          rt                       d S d S d S d S d S N)_original_excepthookrequests
exceptionsConnectionErrorr   r   r   )exc_type	exc_valuetbs      r   _excepthookr   #   sq    9b111H'777  	8!-i88 " 	      	8777!!!!r   c                  j    t           j        t          urt           j        at          t           _        d S d S r   )sys
excepthookr   r    r   r   _install_excepthookr#   .   s*    
~[(("~$ )(r   c                     	 ddl m}   |             }n# t          $ r Y d S w xY w|d S d d }fd}fd}|j                            d|           |j                            d|           |j                            d	|           d S )
Nr   )get_ipythonc                      t           rd S t          sd S t          t          dd           } | @t	          | t
          j        j                  r#t          |           rda t                       d S d S d S d S )N
last_valueT)
_ipython_tickflow_shownr   getattrr    
isinstancer   r   r   r   r   )r   s    r   _ipython_maybe_show_tickflowz:_install_ipython_exc.<locals>._ipython_maybe_show_tickflow?   s    " 	F# 	Fc<..O3 3 CDD 1#66  '+#"$$$$$ OOOOOr   c                  
    da d S NF)r(   r"   r   r   pre_executez)_install_ipython_exc.<locals>.pre_executeN   s    "'r   c                 F    | j         dt          _                      d S d S r-   )error_in_exec_tickflow_after_tracebackshow)resultr+   s    r   post_run_cellz+_install_ipython_exc.<locals>.post_run_cellR   s2    +-2%*((***** ,+r   c                  d    t          t          dd          rdt          _                       d S d S )Nr2   F)r)   r1   r2   )r+   s   r   post_executez*_install_ipython_exc.<locals>.post_executeW   s@    ,fe<< 	+-2%*((*****	+ 	+r   r.   r4   r6   )IPythonr%   	Exceptioneventsregister)r%   ipr.   r4   r6   r+   s        @r   _install_ipython_excr<   5   s    ''''''[]]   	z% % %( ( (+ + + + +
+ + + + +
 I}k222I666I~|44444s    
""c                        e Zd Z fdZ xZS )CustomedSessionc                     |                     dd           	  t          t          |           j        |i |S # t          j        j        $ r(}t          rt          |          rdt          _
         d }~ww xY w)Ntimeout   T)
setdefaultsuperr>   requestr   r   r   r   r   r1   r2   )selfargskwargse	__class__s       r   rD   zCustomedSession.requestb   s    )S)))	75$//7HHHH"2 	 	 	# 6(I!(L(L 615).	s   9 A5#A00A5)__name__
__module____qualname__rD   __classcell__)rI   s   @r   r>   r>   a   s8                r   r>   )r    	threadingr   rich.consoler   configr   r   localr1   r(   r   r   boolr   r   r!   r   r   r#   r<   Sessionr>   sessionr"   r   r   <module>rU      s8   



                  ) ) ) ) ) )9+IO--  R8+>+N RSW R R R R
	 	 	 ~ ! ! !% % %)5 )5 )5X    h&    /

            r   