
    i=                     p    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e          ZdgZd	S )
z$CAL-ADDRESS values from :rfc:`5545`.    )AnyClassVar)Self)JCalParsingError)
Parameters)DEFAULT_ENCODING
to_unicodec                   @    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z  deez  ded	ef fd
Zd	efdZd	efdZedeez  d	efd            Zed	efd            Zed	ef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            Z%e	 	 	 	 	 	 	 	 	 	 d%dedz  dedz  dedz  dedz  dedz  dedz  dedz  dedz  de&dz  dedz  ded	efd            Z'd ed	e(fd!Z)ed	e(e         fd"            Z*ed#e(d	efd$            Z+ xZ,S )&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                    t          ||          }t                                          | |          }t          |          |_        |S )N)r   )r	   super__new__r   r   )clsr   r   r   self	__class__s        U/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/prop/cal_address.pyr   zvCalAddress.__new__>   sB     58444wwsE** ((    c                     d|  dS )NzvCalAddress('z') r   s    r   __repr__zvCalAddress.__repr__J   s    't''''r   c                 6    |                      t                    S N)encoder   r   s    r   to_icalzvCalAddress.to_icalM   s    {{+,,,r   icalc                      | |          S r   r   )r   r"   s     r   	from_icalzvCalAddress.from_icalP   s    s4yyr   c                      t          |           S )z$The ``mailto:`` part of the address.)strr   s    r   
ical_valuezvCalAddress.ical_valueT   s     4yyr   c                     |                                                      d          r
| dd         S t          |           S )z3The email address without ``mailto:`` at the start.mailto:   N)lower
startswithr&   r   s    r   emailzvCalAddress.emailY   s;     ::<<""9-- 	8O4yyr   r   )CNCUTYPEDELEGATED_FROMDELEGATED_TODIRLANGUAGEPARTSTATROLERSVPSENT_BYVALUEr-   c                 ^    |                                                      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-   s    r   
_get_emailzvCalAddress._get_emailp   s5     {{}}''	22 	%$U$$$r   cncutypedelegated_fromdelegated_to	directorylanguagepartstatrolersvpsent_byc                "   t          |t                    s$t          dt          |          j                   |                     |          } | |          }|
||j        d<   |
||j        d<   ||                     |          |j        d<   ||                     |          |j        d<   |
||j        d<   |
||j        d<   |
||j        d	<   |	
|	|j        d
<   |
|
rdnd|j        d<   ||                     |          |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-TOr2   r3   r4   r5   TRUEFALSEr6   zSENT-BY)
isinstancer&   	TypeErrortype__name__r:   r   )r   r-   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   email_with_prefixaddrs                 r   newzvCalAddress.new   sF   p %%% 	SQ4;;;OQQRRR  NN511 s$%% > "DK$*DK!%,/NN>,J,JDK()#*-..*F*FDK' !*DK&.DK
#&.DK
#"&DK,0"=&&gDK%(^^G%<%<DK	"r   namec                 t    || j                                         | j                                        | j        gS )z$Return this property in jCal format.)r   to_jcalr8   r+   r'   )r   rO   s     r   rQ   zvCalAddress.to_jcal   s/    dk))++TZ-=-=-?-?QQr   c                 2    |                      dd          gS )zExamples of vCalAddress.zyou@example.orgz	You There)r;   )rN   )r   s    r   exampleszvCalAddress.examples   s     )k::;;r   jcal_propertyc                     t          j        ||            t          j        |d         t          | d            | |d         t	          j        |                    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   rT   s     r   	from_jcalzvCalAddress.from_jcal   sb     	*=#>>>,]1-=sCKKKs!0??
 
 
 	
r   )
NNNNNNNNNN)-rK   
__module____qualname____doc__r   r   r&   __annotations__r   	__slots__r   dictr   bytesr   r   r   r!   classmethodr$   propertyr'   r-   icalendar.paramr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   rO   staticmethodr:   boolrN   listrQ   rS   rZ   __classcell__)r   s   @r   r   r      s        , ,\ $1M8C=000I
 )(,
 

 S#X%
U{
 
 

 
 
 
 
 
(# ( ( ( (- - - - - S5[ T    [ C    X s    X                          D# #    \ 
 !%)#' $## "V V $J	V
 d
V d
V DjV :V *V *V DjV TkV tVV 
V V V [VpRC RD R R R R <d < < < [< 
d 
t 
 
 
 [
 
 
 
 
r   r   N)r]   typingr   r   icalendar.compatibilityr   icalendar.errorr   icalendar.parserr   icalendar.parser_toolsr   r	   r&   r   __all__r   r   r   <module>ro      s    * *                 ( ( ( ( ( ( , , , , , , ' ' ' ' ' ' ? ? ? ? ? ? ? ?f
 f
 f
 f
 f
# f
 f
 f
R /r   