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ADR property of :rfc:`6350`.    )AnyClassVar
NamedTuple)Self)JCalParsingError)
Parameters)DEFAULT_ENCODING
to_unicodec                   @   sV   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< 	 eed< 	 eed< 	 eed< d	S )
	AdrFieldszNamed fields for vCard ADR (Address) property per :rfc:`6350#section-6.3.1`.

    Provides named access to the seven address components.
    po_boxextendedstreetlocalityregionpostal_codecountryN)__name__
__module____qualname____doc__str__annotations__ r   r   G/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/adr.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 )"vAdra  vCard ADR (Address) structured property per :rfc:`6350#section-6.3.1`.

    The ADR property represents a delivery address as a single text value.
    The structured type value consists of a sequence of seven address components.
    The component values must be specified in their corresponding position.

    -   post office box
    -   extended address (e.g., apartment or suite number)
    -   street address
    -   locality (e.g., city)
    -   region (e.g., state or province)
    -   postal code
    -   country name (full name)

    When a component value is missing, the associated component separator
    MUST still be specified.

    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 vAdr
            >>> adr = vAdr(("", "", "123 Main St", "Springfield", "IL", "62701", "USA"))
            >>> adr.to_ical()
            b';;123 Main St;Springfield;IL;62701;USA'
            >>> vAdr.from_ical(";;123 Main St;Springfield;IL;62701;USA")
            AdrFields(po_box='', extended='', street='123 Main St', locality='Springfield', region='IL', postal_code='62701', country='USA')
    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 )a8  Initialize ADR with seven fields or parse from vCard format string.

        Parameters:
            fields: Either an AdrFields, tuple, or list of seven strings, one per field,
                    or a vCard format string with semicolon-separated fields
            params: Optional property parameters
           $ADR must have exactly 7 fields, got c                 s   s    | ]}t |V  qd S N)r   .0fr   r   r   	<genexpr>Y   s    z vAdr.__init__.<locals>.<genexpr>N)	
isinstancer   	from_icalr
   r   len
ValueErrorr   r   )selfr   r   r   r   r   __init__E   s   


zvAdr.__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>b   s    z vAdr.to_ical.<locals>.<listcomp>;)icalendar.prop.textr.   r   joinencoder   )r*   partsr   r-   r   r/   \   s   zvAdr.to_icalicalc                 C   sH   ddl m} t| } || }t|dkr tdt| d|  t| S )zParse vCard ADR format into an AdrFields named tuple.

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

        Returns:
            AdrFields named tuple with seven field values.
        r   )split_on_unescaped_semicolonr   r    z: )icalendar.parserr8   r	   r(   r)   r
   )r7   r8   r   r   r   r   r'   e   s   
zvAdr.from_icalotherc                 C   s   t |to
| j|jkS )zself == other)r&   r   r   )r*   r:   r   r   r   __eq__y   s   zvAdr.__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   zvAdr.__repr__c                 C   s   | j S )z$The address fields as a named tuple.)r   r?   r   r   r   
ical_value   s   zvAdr.ical_valuer   )VALUEnamec                 C   s&   || j  | j g}|| j |S )zBThe jCal representation of this property according to :rfc:`7265`.)r   to_jcalrB   lowerextendr   )r*   rC   resultr   r   r   rD      s   zvAdr.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.
        
   zDADR must have 10 elements (name, params, value_type, 7 fields), got    N)start)	r   validate_propertyr(   	enumeratevalidate_value_typer   tupler   from_jcal_property)clsrH   ifieldr   r   r   	from_jcal   s   
zvAdr.from_jcalc                 C   s
   | dgS )zExamples of vAdr.) rU   z123 Main StSpringfieldIL62701USAr   )rQ   r   r   r   examples   s   
zvAdr.examplesr!   ) r   r   r   r   r   r   r   r   r   r
   dictr   rO   listr+   bytesr/   staticmethodr'   objectboolr;   r@   propertyrA   icalendar.paramrB   rD   classmethodr   rT   rZ   r   r   r   r   r   !   s0   
 
	r   N)r   typingr   r   r   icalendar.compatibilityr   icalendar.errorr   r9   r   icalendar.parser_toolsr   r	   r
   r   __all__r   r   r   r   <module>   s     