U
    ^g%iò	  ã                   @  sÔ   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dl	mZ d d	l	mZ d d
l	mZ ddlmZ ddlmZ d ddddœdd„Zdddœdd„Zddddœdd„Zddœdd„ZdS )!é    )ÚannotationsN)Úexists)Újoin)Úsplitext)Ú
check_call)ÚDict)ÚList)ÚMapping)ÚOptionalé   ©Úis_posix)ÚCommandErrorÚstrzOptional[Dict[str, str]]ÚNone)ÚfilenameÚenvironÚreturnc              
   C  sb   |dkrt jn|}zt|ƒ}t|| gƒ W n2 tk
r\ } ztd|f ƒ|‚W 5 d}~X Y nX dS )aÇ  
    Opens the given file in a text editor. If the environment variable
    ``EDITOR`` is set, this is taken as preference.

    Otherwise, a list of commonly installed editors is tried.

    If no editor matches, an :py:exc:`OSError` is raised.

    :param filename: The filename to open. Will be passed  verbatim to the
        editor command.
    :param environ: An optional drop-in replacement for ``os.environ``. Used
        mainly for testing.
    NzError executing editor (%s))Úosr   Ú_find_editorr   Ú	Exceptionr   )r   r   ÚenvÚeditorÚexc© r   úR/var/www/html/api-medvista/venv/lib/python3.8/site-packages/alembic/util/editor.pyÚopen_in_editor   s    r   zMapping[str, str])r   r   c                 C  s~   t ƒ }tdƒD ]>\}}|| kr| | }t|ƒr6|  S tj|kr| ||¡ q|D ]}t|| ƒ}|d k	rR|  S qRtdƒ‚d S )N)ZEDITORZVISUALzSNo suitable editor found. Please set the "EDITOR" or "VISUAL" environment variables)Ú_default_editorsÚ	enumerater   r   ÚsepÚinsertÚ_find_executableÚOSError)r   Ú
candidatesÚiÚvarZuser_choiceÚ	candidateÚpathr   r   r   r   )   s    


ÿr   zOptional[str])r&   r   r   c                 C  sT   t st| ƒd dkr| d7 } | dd¡ tj¡D ]}t|| ƒ}t|ƒr0|  S q0d S )Nr   z.exeÚPATHÚ )r   r   ÚgetÚsplitr   Úpathsepr   r   )r&   r   r'   Úvaluer   r   r   r!   =   s    

r!   z	List[str])r   c                   C  s    t rdddddgS dddgS d S )	Nzsensible-editorr   ZnanoÚvimÚcodezcode.exeznotepad++.exeznotepad.exer   r   r   r   r   r   K   s    r   )N)Ú
__future__r   r   Úos.pathr   r   r   Ú
subprocessr   Útypingr   r   r	   r
   Úcompatr   r   r   r   r   r!   r   r   r   r   r   Ú<module>   s     ÿ