o
    ïÇhò	  ã                   @  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„Zd"dd„Zd#dd„Zd$dd„ZdS )%é    )ÚannotationsN)Úexists)Újoin)Úsplitext)Ú
check_call)ÚDict)ÚList)ÚMapping)ÚOptionalé   ©Úis_posix)ÚCommandErrorÚfilenameÚstrÚenvironúOptional[Dict[str, str]]ÚreturnÚNonec              
   C  sV   |du rt jn|}zt|ƒ}t|| gƒ W dS  ty* } ztd|f ƒ|‚d}~ww )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   úg/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/alembic/util/editor.pyÚopen_in_editor   s   €ÿr   úMapping[str, str]c                 C  sz   t ƒ }tdƒD ]\}}|| v r&| | }t|ƒr|  S tj|vr&| ||¡ q|D ]}t|| ƒ}|d ur8|  S q)tdƒ‚)N)ÚEDITORÚVISUALzSNo suitable editor found. Please set the "EDITOR" or "VISUAL" environment variables)Ú_default_editorsÚ	enumerater   r   ÚsepÚinsertÚ_find_executableÚOSError)r   Ú
candidatesÚiÚvarÚuser_choiceÚ	candidateÚpathr   r   r   r   )   s"   
€
ÿÿr   r+   úOptional[str]c                 C  sT   t st| ƒd dkr| d7 } | dd¡ tj¡D ]}t|| ƒ}t|ƒr'|  S qd S )Nr   z.exeÚPATHÚ )r   r   ÚgetÚsplitr   Úpathsepr   r   )r+   r   r,   Úvaluer   r   r   r%   =   s   
ÿr%   ú	List[str]c                   C  s   t rg d¢S g d¢S )N)zsensible-editorr   ÚnanoÚvimÚcode)zcode.exeznotepad++.exeznotepad.exer   r   r   r   r   r!   K   s   r!   )N)r   r   r   r   r   r   )r   r   r   r   )r+   r   r   r   r   r-   )r   r4   )Ú
__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"    ÿ

