XylotrechusZ
�
�g� � �� � d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl m
Z
d dl mZ d d l mZ d d
l m
Z
ddlmZ dd
lmZ d dd�Zdd�Z dd�Zdd�Zy)� )�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}~ww xY 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.
NzError executing editor (�))�os�environ�_find_editorr � Exceptionr )�filenamer �env�editor�excs �B/opt/hc_python/lib/python3.12/site-packages/alembic/util/editor.py�open_in_editorr sR � � ��"�*�*�W�C�L��c�"���F�H�%�&��� L��C�A�B��K��L�s �/ � A
�A�A
c � � t � }t d� D ]C \ }}|| v s�| | }t |� r|c S t j |vs�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���3��'�>�!�#�,�K��k�"�"�"��v�v�[�(��!�!�!�[�1�
2� � �� �7�3�����K� � � 5�� � c �� � t st | � d dk7 r| dz
} |j dd� 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# = sc � �
���+�A�.�&�8��V�� ����F�B�'�-�-�b�j�j�9���T�9�%���%�=��L� :� r+ c � � t rg d�S g d�S )N)zsensible-editorr �nano�vim�code)zcode.exez
notepad++.exeznotepad.exer
� r+ r r r K s � � �C�C�;�;r+ )N)r �strr zOptional[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+