o
    .j                     @   s`   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ZdgZd	S )
z"The ORG property from :rfc:`6350`.    )AnyClassVar)Self)JCalParsingError)
Parameters)DEFAULT_ENCODING
to_unicodec                   @   sP  e Zd ZU dZdZee ed< eed< e	edf ed< 	d%de
eef dB de	edf ee B eB fdd	Zd
efddZedeeB d
e	edf 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ed
e	edf fddZed
e	edf 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 )&vOrga  vCard ORG (Organization) structured property per :rfc:`6350#section-6.6.4`.

    The ORG property specifies the organizational name and units
    associated with the vCard.

    Its value is a structured type consisting of components separated
    by semicolons. The components are the organization name, followed
    by zero or more levels of organizational unit names:

    .. code-block:: text

        organization-name; organizational-unit-1; organizational-unit-2; ...

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

    Examples:
        A property value consisting of an organizational name,
        organizational unit #1 name, and organizational unit #2 name.

        .. code-block:: ics

            ORG:ABC\, Inc.;North American Division;Marketing

        The same example in icalendar.

        .. code-block:: pycon

            >>> from icalendar.prop import vOrg
            >>> org = vOrg(("ABC, Inc.", "North American Division", "Marketing"))
            >>> org.to_ical()
            b'ABC\\, Inc.;North American Division;Marketing'
            >>> vOrg.from_ical(r"ABC\, Inc.;North American Division;Marketing")
            ('ABC, Inc.', 'North American Division', 'Marketing')
    TEXTdefault_valueparams.fieldsNc                C   sJ   t |tr
| |}t|dk rtdtdd |D | _t|| _dS )a%  Initialize ORG with variable fields or parse from vCard format string.

        Parameters:
            fields: Either a tuple or list of one or more strings, or a
                    vCard format string with semicolon-separated fields
            params: Optional property parameters
           z2ORG must have at least 1 field (organization name)c                 s   s    | ]}t |V  qd S N)str.0f r   G/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/org.py	<genexpr>E   s    z vOrg.__init__.<locals>.<genexpr>N)	
isinstancer   	from_icallen
ValueErrortupler   r   r   )selfr   r   r   r   r   __init__4   s   

zvOrg.__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>L   s    z vOrg.to_ical.<locals>.<listcomp>;)icalendar.prop.textr    r   joinencoder   )r   partsr   r   r   r!   H   s   zvOrg.to_icalicalc                 C   s>   ddl m} t| } || }t|dk rtd|  t|S )zParse vCard ORG format into a tuple of fields.

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

        Returns:
            Tuple of field values with one or more fields
        r   )split_on_unescaped_semicolonr   z ORG must have at least 1 field: )icalendar.parserr*   r   r   r   r   )r)   r*   r   r   r   r   r   O   s   
zvOrg.from_icalotherc                 C   s   t |to
| j|jkS )zself == other)r   r	   r   )r   r,   r   r   r   __eq__a   s   zvOrg.__eq__c                 C   s   | j j d| j d| j dS )zString representation.(z	, params=))	__class____name__r   r   r   r   r   r   __repr__e   s   zvOrg.__repr__c                 C   s
   | j d S )z$The organization name (first field).r   r   r2   r   r   r   namei      
z	vOrg.namec                 C   s   | j dd S )z@The organizational unit names (remaining fields after the name).r   Nr4   r2   r   r   r   unitsn   s   z
vOrg.unitsc                 C   s   | j S )z#The organization fields as a tuple.r4   r2   r   r   r   
ical_values   s   zvOrg.ical_valuer   )VALUEr5   c                 C   s&   || j  | j g}|| j |S )zBThe jCal representation of this property according to :rfc:`7265`.)r   to_jcalr9   lowerextendr   )r   r5   resultr   r   r   r:   z   s   zvOrg.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.
           zLORG must have at least 4 elements (name, params, value_type, org name), got    N)start)	r   validate_propertyr   	enumeratevalidate_value_typer   r   r   from_jcal_property)clsr>   ifieldr   r   r   	from_jcal   s   
zvOrg.from_jcalc                 C   s
   | dgS )zExamples of vOrg.)zABC Inc.zNorth American Division	Marketingr   )rF   r   r   r   examples   r6   zvOrg.examplesr   )!r1   
__module____qualname____doc__r   r   r   __annotations__r   r   dictr   listr   bytesr!   staticmethodr   objectboolr-   r3   propertyr5   r7   r8   icalendar.paramr9   r:   classmethodr   rI   rK   r   r   r   r   r	      s8   
 $
 r	   N)rN   typingr   r   icalendar.compatibilityr   icalendar.errorr   r+   r   icalendar.parser_toolsr   r   r	   __all__r   r   r   r   <module>   s     
