3
_Af                 @   s\   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	Z	G dd de
ZdS )    )print_functionN)EditorErrorc               @   s<   e Zd ZdZdZdZedd Zedd Zedd Z	dS )	Editorz)Manages the user's preferred text editor.Nc             C   s   | j d kr| j | _ | j S )N)_editor_SelectEditor)cls r   8/home/qytech/356xLinux510-101server/.repo/repo/editor.py
_GetEditor"   s    

zEditor._GetEditorc             C   sz   t jd}|r|S | jr,| jjd}|r,|S t jd}|r>|S t jd}|rP|S t jddkrvtdtjd tjd	 d
S )N
GIT_EDITORzcore.editorZVISUALZEDITORZTERMZdumbzNo editor specified in GIT_EDITOR, core.editor, VISUAL or EDITOR.
Tried to fall back to vi but terminal is dumb.  Please configure at
least one of these before using this command.)file   vi)osgetenvglobalConfig	GetStringprintsysstderrexit)r   er   r   r	   r   (   s$    



zEditor._SelectEditorc             C   sL  | j  }|dkr|S tj \}}ztj||jd tj| d}tj rdddl	}|j
|}d}n,tjdj|r|d dg}d	}n
|g}d}|j| ytj||d
j }W n8 tk
r }	 ztdt|	||f W Y dd}	~	X nX |dkrtd|||f t|dd}
|
j jdS Q R X W d|r<tj| tj| X dS )zOpens an editor to edit the given content.

    Args:
      data: The text to edit.

    Returns:
      New value of edited text.

    Raises:
      EditorError: The editor failed to run.
    :zutf-8Nr   Fz^.*[$ 	'].*$z "$@"shT)shellzeditor failed, %s: %s %sz(editor failed with exit status %d: %s %srb)mode)r
   tempfilemkstempr   writeencodecloseplatform_utils	isWindowsshlexsplitrecompilematchappend
subprocessPopenwaitOSErrorr   stropenreaddecoderemove)r   dataeditorfdpathr$   argsr   rcr   Zfd2r   r   r	   
EditStringD   s>    


$

zEditor.EditString)
__name__
__module____qualname____doc__r   r   classmethodr
   r   r9   r   r   r   r	   r      s   r   )
__future__r   r   r&   r   r*   r   errorr   r"   objectr   r   r   r   r	   <module>   s   