o
    .j                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ded	efd
dZdeeB eB d	efddZded	efddZdd ZddgZedkrZe  dS dS )z=Utility program that allows user to preview calendar's events    N)datetime)Path)__version__vCalAddress)Calendar)Eventaddressreturnc                 C   s8   | j dddd }|dd }|sdS | d| d	S )
a  Format a display name and email from an address string.

    Parameters:
        address: An address object, such as mailto:name@example.com.

    Returns:
        A formatted string, like 'name <name@example.com>',
        or an empty string if no email is found.
    :   )maxsplit@r    z <>)rsplitsplit)r   emailname r   B/home/thesage/.local/lib/python3.10/site-packages/icalendar/cli.py_format_name   s
   
r   	attendeesc                 C   s*   t | tr| g} ddd tt| D S )zFormat the list of attendees.

    Parameters:
        attendees: Either a list, a string, or a vCalAddress object.

    Returns:
        A formatted string of attendees, each indented by 5 spaces.
    
c                 s   "    | ]}| t|d  V  qdS    Nrjustlen.0sr   r   r   	<genexpr>*        z$_format_attendees.<locals>.<genexpr>)
isinstancestrjoinmapr   )r   r   r   r   _format_attendees   s   
	r)   eventc           
      C   s0  | j ddd}t| j ddd}t| j dg d}| j ddd}|  dd}|  ddd	}d	d
d |D }| d}d| v rO| jd|| d d}n| jd|d}| jd|| d}	t|trh| }|	d}t|trv| }|	d}d| d| d| d| d| d|	 d| d| d| S )a  Make a human readable summary of an iCalendar file.

    Parameters:
        event: An iCalendar event containing fields such as
               summary, organizer, attendees, location, and timing.

    Returns:
        A human readable summary of the event.
    summaryr   )default	organizerattendeelocationcommentdescriptionr   c                 s   r   r   r   r    r   r   r   r#   =   r$   zview.<locals>.<genexpr>dtstartdurationdtendz%cz    Organizer: z
    Attendees:
z
    Summary    : z
    Starts     : z
    End        : z
    Duration   : z
    Location   : z
    Comment    : z
    Description:
)
getr   r)   r   r'   decodedr%   r   
astimezonestrftime)
r*   r+   r-   r   r/   r0   r1   startendr3   r   r   r   view-   sF   






r;   c               	   C   s&  t jtd} | jdddd | jdddd	d
 | jddd| j dt d |  }|jdkr5tj	}d}nt
|jjddd}d}zI|jD ]:}|dkrQtj}d}n
t
|jdd}d}zt| }|dd |dD  W |rw|  qE|r|  w w W |r|  d S d S |r|  w w )N)r1   calendar_files+z*one or more .ics files (use '-' for stdin))nargshelpz--outputz-o-z%output file path (use '-' for stdout))r,   r?   z-vz	--versionversionz	 version )actionrA   Fwzutf-8)encodingTz	utf-8-sigc                 s   s    | ]	}t |d  V  qdS )z

N)r;   )r!   r*   r   r   r   r#      s    
zmain.<locals>.<genexpr>vevent)argparseArgumentParser__doc__add_argumentprogr   
parse_argsoutputsysstdoutr   openr<   stdinr   	from_icalread
writelineswalkclose)parserargvoutput_fileclose_outputpathfclose_inputcalendarr   r   r   mainY   sV   





r^   __main__)rH   rF   rM   r   pathlibr   	icalendarr   r   icalendar.cal.calendarr   icalendar.cal.eventr   r&   r   listr)   r;   r^   __all____name__r   r   r   r   <module>   s    ,3
