
    +h	                        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ZddZ	 	 	 	 	 	 ddZddZy)    )annotationsN)exists)join)splitext)
check_call)Dict)List)Mapping)Optional   is_posix)CommandErrorc                    |t         j                  n|}	 t        |      }t        || g       y# t        $ r}t        d|d      |d}~ww xY 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 ())osenviron_find_editorr   	Exceptionr   )filenamer   enveditorexcs        F/var/www/html/venv/lib/python3.12/site-packages/alembic/util/editor.pyopen_in_editorr      sR       "**WCLc"FH%& LCABKLs   / 	AAAc                    t               }t        d      D ]C  \  }}|| v s| |   }t        |      r|c S t        j                  |vs2|j                  ||       E |D ]  }t        ||       }||c S  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paths          r   r   r   )   s    !#J01 23'>!#,Kk"""vv[(!!![12   		73K 	5     c                    t         st        |       d   dk7  r| dz  } |j                  dd      j                  t        j
                        D ]  }t        ||       }t        |      s|c S  y )Nr   z.exePATH )r   r   getsplitr   pathsepr   r   )r)   r   r*   values       r   r#   r#   =   sh    
 +A.&8V	FB'--bjj9 T9%%=L r+   c                     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   K   s     CC;;r+   )N)r   strr   zOptional[Dict[str, str]]returnNone)r   Mapping[str, str]r9   r8   )r)   r8   r   r;   r9   zOptional[str])r9   z	List[str])
__future__r   r   os.pathr   r   r   
subprocessr   typingr   r	   r
   r   compatr   r   r   r   r   r#   r   r7   r+   r   <module>rA      sv    " 	    !       8<LL4L	L0(.<r+   