
    ړi                       d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlZddlmZ ddlmZ dd	lmZmZmZmZ g d
Z G d de      Z G d dej4                        ZddZddZddZedk(  r e        yy)a  
ptpython: Interactive Python shell.

positional arguments:
  args                  Script and arguments

optional arguments:
  -h, --help            show this help message and exit
  --vi                  Enable Vi key bindings
  -i, --interactive     Start interactive shell after executing this file.
  --asyncio             Run an asyncio event loop to support top-level "await".
  --light-bg            Run on a light background (use dark colors for text).
  --dark-bg             Run on a dark background (use light colors for text).
  --config-file CONFIG_FILE
                        Location of configuration file.
  --history-file HISTORY_FILE
                        Location of history file.
  -V, --version         show program's version number and exit

environment variables:
  PTPYTHON_CONFIG_HOME: a configuration directory to use
  PYTHONSTARTUP: file executed on interactive startup (no default)
    )annotationsN)metadata)dedent)Protocol)HTML)print_formatted_text)
PythonReplembedenable_deprecation_warnings
run_config)create_parserget_config_and_history_filerunc                      e Zd ZddZy)_SupportsWritec                    y N )selfss     I/tmp/pip-target-20744g9h/lib/python/ptpython/entry_points/run_ptpython.pywritez_SupportsWrite.write/   s        N)r   strreturnobject)__name__
__module____qualname__r   r   r   r   r   r   .   s    -r   r   c                  "     e Zd Zdd fdZ xZS )_Parserc                f    t         |           t        t        d      j	                                y )Nz
                environment variables:
                  PTPYTHON_CONFIG_HOME: a configuration directory to use
                  PYTHONSTARTUP: file executed on interactive startup (no default)
                )super
print_helpprintr   rstrip)r   file	__class__s     r   r$   z_Parser.print_help3   s,     fh	
r   r   )r'   z_SupportsWrite | Noner   None)r   r   r   r$   __classcell__)r(   s   @r   r!   r!   2   s    

 

r   r!   c                    t        d      } | j                  ddd       | j                  dddd	       | j                  d
dd       | j                  ddd       | j                  ddd       | j                  dt        d       | j                  dt        d       | j                  dddt        j                  d             | j                  ddd       | S )Nz#ptpython: Interactive Python shell.)descriptionz--vi
store_truezEnable Vi key bindings)actionhelpz-iz--interactivez2Start interactive shell after executing this file.z	--asyncioz7Run an asyncio event loop to support top-level "await".z
--light-bgz5Run on a light background (use dark colors for text).z	--dark-bgz5Run on a dark background (use light colors for text).z--config-filezLocation of configuration file.)typer/   z--history-filezLocation of history file.z-Vz	--versionversionptpython)r.   r1   args*zScript and arguments)nargsr/   )r!   add_argumentr   r   r1   )parsers    r   r   r   @   s   !FGF
|:RS
A	   F  
 D  
 D  
 c(I   (s9TU
  ,	   c0FGMr   c                   t         j                  j                  dt        j                  dd            }t        j
                  dd      }||fD ](  }t        j                  |      j                  dd       * t         j                  j                  |d      }t         j                  j                  t         j                  j                  d      d      }g }| j                  r*t         j                  j                  | j                        }n>t         j                  j                  |      r|j                  t        d      |z         |}t         j                  j                  |d	      }t         j                  j                  t         j                  j                  d      d	      }| j                   r*t         j                  j                  | j                         }n>t         j                  j                  |      r|j                  t        d
      |z         |}|r&t#        t        d             |D ]  }	t#        |	        ||fS )z
    Check which config/history files to use, ensure that the directories for
    these files exist, and return the config and history path.
    PTPYTHON_CONFIG_HOMEr2   prompt_toolkitT)parentsexist_okz	config.pyz~/.ptpythonzU    <i>~/.ptpython/config.py</i> is deprecated, move your configuration to <i>%s</i>
historyzM    <i>~/.ptpython/history</i> is deprecated, move your history to <i>%s</i>
z<u>Warning:</u>)osenvirongetappdirsuser_config_diruser_data_dirpathlibPathmkdirpathjoin
expanduserconfig_fileisfileappendr   history_filer   )
	namespace
config_dirdata_dirdrJ   legacy_config_filewarningsrM   legacy_history_filews
             r   r   r   f   s   
 
,<=J $$Z1ABH (# ;QdT:; '',,z;7Kbgg&8&8&GUH gg(()>)>?	*	+h 	
 ) 77<<)4L'',,rww'9'9-'H)Tww)))*@*@A	+	,` 	
 + T"345 	$A #	$ $$r   c            
       	 t               j                         t              \  	} g }dt        j                  v r"|j                  t        j                  d          j                  r1j                  r%j                  d   g}j                  t        _	        t        j                  d   dk7  r t        j                  j                  dd       j                  rpj                  sdj                  t        _	        j                  d   }t        |d      5 }t        |j                         |d      }t        |d|d       d d d        y t!                d	fd}dd l}t%        j&                  | ||j(                  |j(                  |d	j*                  
      }j*                  r,t-        d       t-        d       t+        j.                  |       y y # 1 sw Y   y xY w)NPYTHONSTARTUPr    rbexec__main__)r   __file__c                    t         j                  j                        rt        |        j                  rd| _        d| _        y j                  rd| _        d| _        y y )Ng        g333333?g      ?)r>   rG   existsr   light_bgmin_brightnessmax_brightnessdark_bg)replarJ   s    r   	configurezrun.<locals>.configure   sR    ww~~k*4- zz&)#&*#&*#&)# r   zPython REPL (ptpython))vi_modehistory_filenamere   localsglobalsstartup_pathstitlereturn_asyncio_coroutinezStarting ptpython asyncio REPLz0Use "await" directly instead of "asyncio.run()".)rc   r	   r   r)   )r   
parse_argsr   r>   r?   rL   interactiver3   sysargvrG   insertopencompilereadrZ   r   r[   r
   vi__dict__asyncior%   r   )
rM   rj   rG   fcodere   r[   embed_resultrd   rJ   s
           @@r   r   r      s   ""$A ;A >K M"**$RZZ89 	}}66 xx{b2 	vvamm66vvay$ 	C1668T62D
 JDAB	C 	C 	$%
	* 	DD)$$%%'*%&YY	
 9923DEKK% M	C 	Cs   +GG r[   )r   r!   )rN   zargparse.Namespacer   ztuple[str, str])r   r)   ) __doc__
__future__r   argparserw   r>   rD   ro   	importlibr   textwrapr   typingr   rA   prompt_toolkit.formatted_textr   prompt_toolkit.shortcutsr   ptpython.replr	   r
   r   r   __all__r   ArgumentParserr!   r   r   r   r   r   r   r   <module>r      s   0 #   	  
     . 9 T T
A.X .
h%% 
#L<%~A&H zE r   