o
    Ph                     @   s   d 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	ddl
Z
dZdZddiZe
j
dd				dd
eje dejdeef deje dejdef
ddZdefddZdS )u  
# 🖋 editor - Open a text editor 🖋

`editor` opens the default text editor or your favorite editor to edit an existing file,
a new file, or a tempfile, blocks while the user edits text, then returns the contents
of the file.

You can pass a parameter `editor=` to specify an editor or leave it empty, in which
case the editor is:

* The contents of the environment variable `VISUAL`, if it's set, otherwise:
* The the contents of the environment variable `EDITOR`, if it's set, otherwise:
* The string `'Notepad'`, if the code is running on Windows, otherwise:
* The string `'vim'`

### Example 1: Using a temporary file

If no filename is provided, a temporary file gets edited, and its contents
returned.

    import editor

    comments = editor.editor(text='Comments here\n\n')
    # Pop up the default editor with a tempfile containing "Comments here",
    # then return the contents and delete the tempfile.

### Example 2: Using a named file

If a filename is provided, then that file gets edited.

    import os

    FILE = 'file.txt'
    assert not os.path.exists(FILE)

    comments = editor.editor(text=MESSAGE, filename=FILE)
    # Pop up an editor for a new FILE containing MESSAGE, user edits
    # This file is saved when the user exits the editor.

    assert os.path.exists(FILE)

    # You can edit an existing file too, and select your own editor.
    comments2 = editor.editor(filename=FILE, editor='emacs -nw')
    N)Path)editordefault_editorvimWindowsnotepadT)mutabletextfilenamer   kwargsreturnc           	      K   s   |pt  }| }|dur|}nt \}}t| z9t|}| dur(||  d|| }t	j
|fi | | W |rSz|  W S  tyR   t  Y S w S |rjz|  W w  tyi   t  Y w w w )a  
    Open a text editor, block while the user edits, then return the results

    Args:

      text: A string which is written to the file before the editor is opened.
          If `None`, the file is left unchanged.

      filename: The name of the file to edit.
          If `None`, a temporary file is used.

      editor: A string containing the command used to invoke the text editor.
         If `None`, use `editor.default_editor()`.

      kwargs: Arguments passed on to `subprocess.call()`Nz{} "{}")r   tempfilemkstemposcloser   
write_textformatresolverunscall	read_textunlink	Exception	traceback	print_exc)	r	   r
   r   r   is_tempfnamefdpathcmd r    J/var/www/html/env_mimamsha/lib/python3.10/site-packages/editor/__init__.pyr   >   s4   


c                   C   s(   t jdpt jdptt tS )z
    Return the default text editor.

    The default text editor is the contents of the environment variable
    `EDITOR`, it it's non-empty, otherwise if the platform is Windows, it's
    `'notepad'`, otherwise `'vim'`.
    VISUALEDITOR)r   environgetEDITORSplatformsystemDEFAULT_EDITORr    r    r    r!   r   m   s   r   )NNN)__doc__r   r'   r   r   typingtpathlibr   r   xmod__all__r)   r&   OptionalstrUnionAnyr   r   r    r    r    r!   <module>   s8    -
.