
    i                     n    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          ZdgZd	S )
z"The ORG property from :rfc:`6350`.    )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<   e	edf         ed<   	 dde
eef         dz  de	edf         ee         z  ez  fdZd	efd
Zedeez  d	e	edf         fd            Zded	efdZd	efdZed	efd            Zed	e	edf         fd            Zed	e	edf         fd            ZddlmZ ded	efdZeded	efd            Zed	ee         f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                   t          |t                    r|                     |          }t          |          dk     rt	          d          t          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              3   4   K   | ]}t          |          V  d S N)str).0fs     M/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/prop/org.py	<genexpr>z vOrg.__init__.<locals>.<genexpr>E   s(      33qCFF333333    N)	
isinstancer   	from_icallen
ValueErrortupler   r   r   )selfr   r   s      r   __init__zvOrg.__init__4   sv     fc"" 	,^^F++Fv;;??QRRR33F33333 ((r   returnc                     ddl m fd| j        D             }d                    |                              t
                    S )z6Generate vCard format with semicolon-separated fields.r   )vTextc                 z    g | ]7} |                                                               t                    8S  )to_icaldecoder   )r   r   r#   s     r   
<listcomp>z vOrg.to_ical.<locals>.<listcomp>L   s<    RRRq!!##**+;<<RRRr   ;)icalendar.prop.textr#   r   joinencoder   )r   partsr#   s     @r   r&   zvOrg.to_icalH   sO    ------RRRRdkRRRxx%%&6777r   icalc                     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.parserr0   r	   r   r   r   )r.   r0   r   s      r   r   zvOrg.from_icalO   sf     	BAAAAA$--d33v;;??FFFGGGV}}r   otherc                 L    t          |t                    o| j        |j        k    S )zself == other)r   r   r   )r   r2   s     r   __eq__zvOrg.__eq__a   s     %&&F4;%,+FFr   c                 @    | j         j         d| j         d| j         dS )zString representation.(z	, params=))	__class____name__r   r   r   s    r   __repr__zvOrg.__repr__e   s*    .)PPDKPP$+PPPPr   c                     | j         d         S )z$The organization name (first field).r   r   r:   s    r   namez	vOrg.namei   s     {1~r   c                      | j         dd         S )z@The organizational unit names (remaining fields after the name).r   Nr=   r:   s    r   unitsz
vOrg.unitsn   s     {122r   c                     | j         S )z#The organization fields as a tuple.r=   r:   s    r   
ical_valuezvOrg.ical_values   s     {r   r   )VALUEr>   c                     || j                                         | j                                        g}|                    | j                   |S )zBThe jCal representation of this property according to :rfc:`7265`.)r   to_jcalrC   lowerextendr   )r   r>   results      r   rE   zvOrg.to_jcalz   sC    ++--tz/?/?/A/ABdk"""r   jcal_propertyc                 l   t          j        ||            t          |          dk     rt          dt          |                     t          |dd         d          D ]!\  }}t          j        |t
          | |           " | 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.
           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)clsrI   ifields       r   	from_jcalzvOrg.from_jcal   s     	*=#>>>}!!"-M**- -  
 "-"31=== 	E 	EHAu0S!DDDDs-#$$)-88
 
 	
r   c                      | d          gS )zExamples of vOrg.)zABC Inc.zNorth American Division	Marketingr%   )rR   s    r   exampleszvOrg.examples   s     HIIJJr   r   )!r9   
__module____qualname____doc__r   r   r   __annotations__r   r   dictr   listr    bytesr&   staticmethodr   objectboolr4   r;   propertyr>   r@   rB   icalendar.paramrC   rE   classmethodr   rU   rX   r%   r   r   r   r      sb        " "H $*M8C=)))#s(O )-	) ) S#X%	)c3h$s)+c1) ) ) )(8 8 8 8 8 e c3h    \"GF Gt G G G GQ# Q Q Q Q c    X uS#X    X E#s(O    X &%%%%%C D     
d 
t 
 
 
 [
. Kd K K K [K K Kr   r   N)r[   typingr   r   icalendar.compatibilityr   icalendar.errorr   r1   r   icalendar.parser_toolsr   r	   r   __all__r%   r   r   <module>rk      s    ( (                 ( ( ( ( ( ( , , , , , , ' ' ' ' ' ' ? ? ? ? ? ? ? ?PK PK PK PK PK PK PK PKf (r   