o
    .j                     @   sv   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ G dd deZG d	d
 d
Zdd
gZdS )zN property from :rfc:`6350`.    )AnyClassVar
NamedTuple)Self)JCalParsingError)
Parameters)DEFAULT_ENCODING
to_unicodec                   @   sB   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< 	 eed< dS )NFieldszNamed fields for vCard N (Name) property per :rfc:`6350#section-6.2.2`.

    Provides named access to the five name components.
    familygiven
additionalprefixsuffixN)__name__
__module____qualname____doc__str__annotations__ r   r   E/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/n.pyr
      s   
 r
   c                   @   s  e Zd ZU dZdZee ed< eed< e	ed< 	d!de
eef dB deedf ee B eB e	B fdd	Zd
efddZedeeB d
e	fddZded
efddZd
efddZed
e	fddZddlmZ ded
efddZeded
efddZed
ee fdd ZdS )"vNa
  vCard N (Name) structured property per :rfc:`6350#section-6.2.2`.

    The N property represents a person's name.
    It consists of a single structured text value.
    Each component in the structure may have multiple values, separated by commas.

    The structured property value corresponds, in sequence, to the following fields:

    -   family names (also known as surnames)
    -   given names
    -   additional names
    -   honorific prefixes
    -   honorific suffixes

    Semicolons are field separators and are NOT escaped.
    Commas and backslashes within field values ARE escaped per :rfc:`6350`.

    Examples:

        .. code-block:: pycon

            >>> from icalendar.prop import vN
            >>> n = vN(("Doe", "John", "M.", "Dr.", "Jr.,M.D.,A.C.P."))
            >>> n.to_ical()
            b'Doe;John;M.;Dr.;Jr.\\,M.D.\\,A.C.P.'
            >>> vN.from_ical(r"Doe;John;M.;Dr.;Jr.\,M.D.\,A.C.P.")
            NFields(family='Doe', given='John', additional='M.', prefix='Dr.', suffix='Jr.,M.D.,A.C.P.')
    TEXTdefault_valueparamsfieldsN.c                C   sf   t |tr
| |}t |tr|| _nt|dkr"tdt| tdd |D  | _t|| _dS )a2  Initialize N with five fields or parse from vCard format string.

        Parameters:
            fields: Either an NFields, tuple, or list of five strings, one per field,
                    or a vCard format string with semicolon-separated fields
            params: Optional property parameters
           "N must have exactly 5 fields, got c                 s   s    | ]}t |V  qd S N)r   .0fr   r   r   	<genexpr>S   s    zvN.__init__.<locals>.<genexpr>N)	
isinstancer   	from_icalr
   r   len
ValueErrorr   r   )selfr   r   r   r   r   __init__?   s   


zvN.__init__returnc                    s0   ddl m   fdd| jD }d|tS )z6Generate vCard format with semicolon-separated fields.r   vTextc                    s   g | ]} |  tqS r   )to_icaldecoder   r    r+   r   r   
<listcomp>Z   s    zvN.to_ical.<locals>.<listcomp>;)icalendar.prop.textr,   r   joinencoder   )r(   partsr   r+   r   r-   V   s   z
vN.to_icalicalc                 C   sH   ddl m} t| } || }t|dkr tdt| d|  t| S )zParse vCard N format into an NFields named tuple.

        Parameters:
            ical: vCard format string with semicolon-separated fields

        Returns:
            NFields named tuple with five field values.
        r   )split_on_unescaped_semicolonr   r   z: )icalendar.parserr6   r	   r&   r'   r
   )r5   r6   r   r   r   r   r%   ]   s   
zvN.from_icalotherc                 C   s   t |to
| j|jkS )zself == other)r$   r   r   )r(   r8   r   r   r   __eq__o   s   z	vN.__eq__c                 C   s   | j j d| j d| j dS )zString representation.(z	, params=))	__class__r   r   r   r(   r   r   r   __repr__s   s   zvN.__repr__c                 C   s   | j S )z!The name fields as a named tuple.)r   r=   r   r   r   
ical_valuew   s   zvN.ical_valuer   )VALUEnamec                 C   s&   || j  | j g}|| j |S )zBThe jCal representation of this property according to :rfc:`7265`.)r   to_jcalr@   lowerextendr   )r(   rA   resultr   r   r   rB   ~   s   z
vN.to_jcaljcal_propertyc                 C   st   t ||  t|dkrt dt| t|dd ddD ]\}}t |t| | q| t|dd t|S )zParse jCal from :rfc:`7265`.

        Parameters:
            jcal_property: The jCal property to parse.

        Raises:
            ~error.JCalParsingError: If the provided jCal is invalid.
           zAN must have 8 elements (name, params, value_type, 5 fields), got    N)start)	r   validate_propertyr&   	enumeratevalidate_value_typer   tupler   from_jcal_property)clsrF   ifieldr   r   r   	from_jcal   s   
zvN.from_jcalc                 C   s
   | dgS )zExamples of vN.)DoeJohnzM.zDr.zJr.r   )rO   r   r   r   examples   s   
zvN.examplesr   ) r   r   r   r   r   r   r   r   r   r
   dictr   rM   listr)   bytesr-   staticmethodr%   objectboolr9   r>   propertyr?   icalendar.paramr@   rB   classmethodr   rR   rU   r   r   r   r   r      s0   
 
r   N)r   typingr   r   r   icalendar.compatibilityr   icalendar.errorr   r7   r   icalendar.parser_toolsr   r	   r
   r   __all__r   r   r   r   <module>   s     