o
    .j=                     @   sb   d Z ddl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dgZd	S )
z$CAL-ADDRESS values from :rfc:`5545`.    )AnyClassVar)Self)JCalParsingError)
Parameters)DEFAULT_ENCODING
to_unicodec                       s  e Zd ZU dZdZee ed< eed< dZ	e
dfdeeef dB deeB ded	ef fd
dZd	efddZd	efddZedeeB d	efddZed	efddZed	efddZddlmZmZmZmZmZmZmZmZm Z m!Z!m"Z" eZ#e$ded	efddZ%e										d0dedB dedB dedB dedB d edB d!edB d"edB d#edB d$e&dB d%edB ded	efd&d'Z'd(ed	e(fd)d*Z)ed	e(e fd+d,Z*ed-e(d	efd.d/Z+  Z,S )1vCalAddressa(  Calendar User Address

    Value Name:
        CAL-ADDRESS

    Purpose:
        This value type is used to identify properties that contain a
        calendar user address.

    Description:
        The value is a URI as defined by [RFC3986] or any other
        IANA-registered form for a URI.  When used to address an Internet
        email transport address for a calendar user, the value MUST be a
        mailto URI, as defined by [RFC2368].

    Example:
        ``mailto:`` is in front of the address.

        .. code-block:: ics

            mailto:jane_doe@example.com

        Parsing:

        .. code-block:: pycon

            >>> from icalendar import vCalAddress
            >>> cal_address = vCalAddress.from_ical('mailto:jane_doe@example.com')
            >>> cal_address
            vCalAddress('mailto:jane_doe@example.com')

        Encoding:

        .. code-block:: pycon

            >>> from icalendar import vCalAddress, Event
            >>> event = Event()
            >>> jane = vCalAddress("mailto:jane_doe@example.com")
            >>> jane.name = "Jane"
            >>> event["organizer"] = jane
            >>> print(event.to_ical().decode().replace('\\r\\n', '\\n').strip())
            BEGIN:VEVENT
            ORGANIZER;CN=Jane:mailto:jane_doe@example.com
            END:VEVENT
    zCAL-ADDRESSdefault_valueparamsr   Nvalueencodingreturnc                   s(   t ||d}t | |}t||_|S )N)r   )r   super__new__r   r   )clsr   r   r   self	__class__ O/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/cal_address.pyr   >   s   
zvCalAddress.__new__c                 C   s   d|  dS )NzvCalAddress('z')r   r   r   r   r   __repr__J   s   zvCalAddress.__repr__c                 C   s
   |  tS N)encoder   r   r   r   r   to_icalM   s   
zvCalAddress.to_icalicalc                 C   s   | |S r   r   )r   r   r   r   r   	from_icalP   s   zvCalAddress.from_icalc                 C   s   t | S )z$The ``mailto:`` part of the address.)strr   r   r   r   
ical_valueT   s   zvCalAddress.ical_valuec                 C   s"   |   dr| dd S t| S )z3The email address without ``mailto:`` at the start.mailto:   N)lower
startswithr   r   r   r   r   emailY   s   zvCalAddress.emailr   )CNCUTYPEDELEGATED_FROMDELEGATED_TODIRLANGUAGEPARTSTATROLERSVPSENT_BYVALUEr%   c                 C   s   |   dsd|  S | S )a  Extract email and add mailto: prefix if needed.

        Handles case-insensitive mailto: prefix checking.

        Parameters:
            email: Email string that may or may not have mailto: prefix

        Returns:
            Email string with mailto: prefix
        r!   )r#   r$   )r%   r   r   r   
_get_emailp   s   
zvCalAddress._get_emailcncutypedelegated_fromdelegated_to	directorylanguagepartstatrolersvpsent_byc                C   s  t |tstdt|j | |}| |}|dur!||jd< |dur*||jd< |dur6| ||jd< |durB| ||jd< |durK||jd< |durT||jd< |dur]||jd	< |	durf|	|jd
< |
durs|
rndnd|jd< |dur| ||jd< |S )a  Create a new vCalAddress with RFC 5545 parameters.

        Creates a vCalAddress instance with automatic mailto: prefix handling
        and support for all standard RFC 5545 parameters.

        Parameters:
            email: The email address (mailto: prefix added automatically if missing)
            cn: Common Name parameter
            cutype: Calendar user type (INDIVIDUAL, GROUP, RESOURCE, ROOM)
            delegated_from: Email of the calendar user that delegated
            delegated_to: Email of the calendar user that was delegated to
            directory: Reference to directory information
            language: Language for text values
            partstat: Participation status (NEEDS-ACTION, ACCEPTED, DECLINED, etc.)
            role: Role (REQ-PARTICIPANT, OPT-PARTICIPANT, NON-PARTICIPANT, CHAIR)
            rsvp: Whether RSVP is requested
            sent_by: Email of the calendar user acting on behalf of this user

        Returns:
            vCalAddress: A new calendar address with specified parameters

        Raises:
            TypeError: If email is not a string

        Examples:
            Basic usage:

            >>> from icalendar.prop import vCalAddress
            >>> addr = vCalAddress.new("test@test.com")
            >>> str(addr)
            'mailto:test@test.com'

            With parameters:

            >>> addr = vCalAddress.new("test@test.com", cn="Test User", role="CHAIR")
            >>> addr.params["CN"]
            'Test User'
            >>> addr.params["ROLE"]
            'CHAIR'
        zEmail must be a string, not Nr&   r'   zDELEGATED-FROMzDELEGATED-TOr*   r+   r,   r-   TRUEFALSEr.   zSENT-BY)
isinstancer   	TypeErrortype__name__r1   r   )r   r%   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   email_with_prefixaddrr   r   r   new   s2   
8






zvCalAddress.newnamec                 C   s   || j  | j | jgS )z$Return this property in jCal format.)r   to_jcalr0   r#   r    )r   rE   r   r   r   rF      s   zvCalAddress.to_jcalc                 C   s   | j dddgS )zExamples of vCalAddress.zyou@example.orgz	You There)r2   )rD   )r   r   r   r   examples   s   zvCalAddress.examplesjcal_propertyc                 C   s6   t ||  t |d t| d | |d t|dS )zParse jCal from :rfc:`7265`.

        Parameters:
            jcal_property: The jCal property to parse.

        Raises:
            ~error.JCalParsingError: If the provided jCal is invalid.
           r   )r   validate_propertyvalidate_value_typer   r   from_jcal_property)r   rH   r   r   r   	from_jcal   s   
zvCalAddress.from_jcal)
NNNNNNNNNN)-rA   
__module____qualname____doc__r
   r   r   __annotations__r   	__slots__r   dictr   bytesr   r   r   r   classmethodr   propertyr    r%   icalendar.paramr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   rE   staticmethodr1   boolrD   listrF   rG   rM   __classcell__r   r   r   r   r	      s   
 .4	
Xr	   N)rP   typingr   r   icalendar.compatibilityr   icalendar.errorr   icalendar.parserr   icalendar.parser_toolsr   r   r   r	   __all__r   r   r   r   <module>   s     
j