o
    ÌÄ.ja  ã                   @   sŠ   d Z ddlZddlmZ deee B deee B fdd„Ze d¡Zdefd	d
„Z	dedee fdd„Z
dedee fdd„Zg d¢ZdS )zTools for parsing properties.é    N©Ú_unescape_stringÚvalÚreturnc                 C   s    t | tƒrdd„ | D ƒS t| ƒS )a  Unescape a value that may be a string or list of strings.

    Applies :func:`_unescape_string` to the value. If the value is a list,
    unescapes each element.

    Parameters:
        val: A string or list of strings to unescape.

    Returns:
        The unescaped values.
    c                 S   s   g | ]}t |ƒ‘qS © r   )Ú.0Úsr   r   úN/home/thesage/.local/lib/python3.10/site-packages/icalendar/parser/property.pyÚ
<listcomp>   s    z+unescape_list_or_string.<locals>.<listcomp>)Ú
isinstanceÚlistr   ©r   r   r   r	   Úunescape_list_or_string   s   
r   z\\([\\,;:nN])c                 C   s   t  dd„ | ¡S )a;  Unescape backslash sequences in iCalendar text.

    Unlike :py:meth:`unescape_string`, this only handles actual backslash escapes
    per :rfc:`5545`, not URL encoding. This preserves URL-encoded values
    like ``%3A`` in URLs.

    Processes backslash escape sequences in a single pass using regex matching.
    c                 S   s   |   d¡dv r	dS |   d¡S )Né   ÚnNÚ
)Úgroup)Úmr   r   r	   Ú<lambda>&   s    z$unescape_backslash.<locals>.<lambda>)Ú_unescape_backslash_regexÚsubr   r   r   r	   Úunescape_backslash   s   	ÿr   Útextc                 C   óÐ   | sdgS g }g }d}|t | ƒk r\| | dkr4|d t | ƒk r4| | | ¡ | | |d  ¡ |d7 }n"| | dkrK| td |¡ƒ¡ g }|d7 }n| | | ¡ |d7 }|t | ƒk s| td |¡ƒ¡ |S )a  Split text on unescaped commas and unescape each part.

    Splits only on commas not preceded by backslash.
    After splitting, unescapes backslash sequences in each part.

    Parameters:
        text: Text with potential escaped commas (e.g., "foo\\, bar,baz")

    Returns:
        List of unescaped category strings

    Examples:
        .. code-block:: pycon

            >>> from icalendar.parser import split_on_unescaped_comma
            >>> split_on_unescaped_comma(r"foo\, bar,baz")
            ['foo, bar', 'baz']
            >>> split_on_unescaped_comma("a,b,c")
            ['a', 'b', 'c']
            >>> split_on_unescaped_comma(r"a\,b\,c")
            ['a,b,c']
            >>> split_on_unescaped_comma(r"Work,Personal\,Urgent")
            ['Work', 'Personal,Urgent']
    Ú r   ú\r   é   ú,©ÚlenÚappendr   Újoin©r   ÚresultÚcurrentÚir   r   r	   Úsplit_on_unescaped_comma*   s&   

ór&   c                 C   r   )a›  Split text on unescaped semicolons and unescape each part.

    Splits only on semicolons not preceded by a backslash.
    After splitting, unescapes backslash sequences in each part.
    Used by vCard structured properties (ADR, N, ORG) per :rfc:`6350`.

    Parameters:
        text: Text with potential escaped semicolons (e.g., "field1\\;with;field2")

    Returns:
        List of unescaped field strings

    Examples:
        .. code-block:: pycon

            >>> from icalendar.parser import split_on_unescaped_semicolon
            >>> split_on_unescaped_semicolon(r"field1\;with;field2")
            ['field1;with', 'field2']
            >>> split_on_unescaped_semicolon("a;b;c")
            ['a', 'b', 'c']
            >>> split_on_unescaped_semicolon(r"a\;b\;c")
            ['a;b;c']
            >>> split_on_unescaped_semicolon(r"PO Box 123\;Suite 200;City")
            ['PO Box 123;Suite 200', 'City']
    r   r   r   r   r   ú;r   r"   r   r   r	   Úsplit_on_unescaped_semicolon_   s&   

ór(   )r&   r(   r   r   )Ú__doc__ÚreÚicalendar.parser.stringr   Ústrr   r   Úcompiler   r   r&   r(   Ú__all__r   r   r   r	   Ú<module>   s    "
56