
    i                         d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZ ddlmZmZmZ  ej        d          Z ej        d          Z G d	 d
e          Z G d de          Zd
dgZdS )z'parsing and generation of content lines    N)
Parameters)unescape_backslashunescape_list_or_string)escape_stringfoldlineunescape_stringvalidate_token)DEFAULT_ENCODING	ICAL_TYPE
to_unicodez
(?
)+[ 	]z\r?\nc                        e Zd ZdZdZdef fd	Ze	 ddede	de
fd	            Zd
eee	ef         fdZedd            Zd Z xZS )ContentlinezWA content line is basically a string that can be folded and parsed into
    parts.
    strictFc                     t          ||          }d|vs
J d            t                                          | |          }||_        |S )N)encoding
z;Content line can not contain unescaped new line characters.)r   super__new__r   )clsvaluer   r   self	__class__s        X/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/parser/content_line.pyr   zContentline.__new__   sV    584445   I !   wwsE**    Tnameparamssortedc                    t          |t                    sJ t          |d          r|                                }n#ddlm}  ||                                          }t          |          }t          |          }|r8t          |                    |                    }|r | | d| d|           S  | | d|           S )z!Turn a parts into a content line.to_icalr   )vText)r   ;:)
isinstancer   hasattrr    icalendar.propr!   r   )r   r   r   valuesr   r!   s         r   
from_partszContentline.from_parts#   s     &*-----69%% 	-^^%%FF,,,,,,U6]]**,,F $F## 	8f = =>>F 8sd66V66f66777sd%%V%%&&&r   returnc                    	 d}d}d}d}t          |           D ]4\  }}|dk    r|s| }n!|dk    r|sd}|s|s|dv r||}|dk    r||}d}5|st          |           }|r
| d|         n| }t          |           |r	|dz   |k    rt          d	          t	          | |dz   |                   }t          j        || j        
          }	t          d t          |		                                          D                       }	t          | |dz   d                   }
n(# t          $ r}t          d|  d|           |d}~ww xY w||	|
fS )a  Split the content line into ``name``, ``parameters``, and ``values`` parts.

        Properly handles escaping with backslashes and double-quote sections
        to avoid corrupting URL-encoded characters in values.

        Example with parameter:

        .. code-block:: ics

            DESCRIPTION;ALTREP="cid:part1.0001@example.org":The Fall'98 Wild

        Example without parameters:

        .. code-block:: ics

            DESCRIPTION:The Fall'98 Wild
        NF"\Tz:;r#      zInvalid content liner   c              3   X   K   | ]%\  }}t          |          t          |          fV  &d S N)r   r   ).0keyr   s      r   	<genexpr>z$Contentline.parts.<locals>.<genexpr>z   sP          C !%%'>u'E'EF           r   z.Content line could not be parsed into parts: 'z': )	enumeratelenr	   
ValueErrorr   r   	from_icalr   iteritemsr   )r   
name_splitvalue_split	in_quotesescapedichr   	param_strr   r'   excs               r   partszContentline.partsA   s   $0	%)J&*K#I!G"4    299W9$-II4ZZ	Z"G" (7 (Tzzj&8%&
Syy[%8&'  (!$ii )3<4$$D4    9a;!>!> !7888 &d:>K+G&HIII))DKHHHF    "&v||~~"6"6       F
 ([1_->->(?@@FF 	 	 	OOO#OO 	 ff%%s   DD 
E(D>>Ec                 l    t          |          } | t                              d|          |          S )zAUnfold the content lines in an iCalendar into long content lines. r   )r   UFOLDsub)r   icalr   s      r   r6   zContentline.from_ical   s4     $s599R&&v6666r   c                 P    t          |                               t                    S )zXLong content lines are folded so they are less than 75 characters
        wide.
        )r   encoder
   r   s    r   r    zContentline.to_ical   s     ~~$$%5666r   )T)F)__name__
__module____qualname____doc__	__slots__r
   r   classmethodr   r   boolr(   tuplestrrA   r6   r    __classcell__)r   s   @r   r   r      s          I#(3C        ' '' '
 ' ' ' [':C&uS*c12 C& C& C& C&J 7 7 7 [77 7 7 7 7 7 7r   r   c                   .    e Zd ZdZd Zed             ZdS )ContentlineszI assume that iCalendar files generally are a few kilobytes in size.
    Then this should be efficient. for Huge files, an iterator should probably
    be used instead.
    c                 F    d                     d | D                       dz   S )zSimply join self.s   
c              3   B   K   | ]}||                                 V  d S r/   )r    r0   lines     r   r2   z'Contentlines.to_ical.<locals>.<genexpr>   s/      DDttDDLLNNDDDDDDr   )joinrI   s    r   r    zContentlines.to_ical   s(    ||DDtDDDDDwNNr   c                 &   t          |          }	 t                              d|          } | d t                              |          D                       }|                    d           n"# t          $ r}t          d          |d}~ww xY w|S )z#Parses a string into content lines.rC   c              3   8   K   | ]}|t          |          V  d S r/   )r   rX   s     r   r2   z)Contentlines.from_ical.<locals>.<genexpr>   s0      VVdQUVD))VVVVVVr   z&Expected StringType with content linesN)r   rD   rE   NEWLINEsplitappend	Exceptionr5   )r   stunfoldedlineses        r   r6   zContentlines.from_ical   s     ^^	NyyR((HCVVgmmH6M6MVVVVVELL 	N 	N 	NEFFAM	Ns   AA/ /
B9B		BN)rJ   rK   rL   rM   r    rO   r6    r   r   rU   rU      sK         
O O O 
 
 [
 
 
r   rU   )rM   reicalendar.parser.parameterr   icalendar.parser.propertyr   r   icalendar.parser.stringr   r   r   r	   icalendar.parser_toolsr
   r   r   compilerD   r]   rR   r   listrU   __all__re   r   r   <module>rn      s*   - - 				 1 1 1 1 1 1 Q Q Q Q Q Q Q Q            K J J J J J J J J J
?##
"*X

~7 ~7 ~7 ~7 ~7# ~7 ~7 ~7B    4   0 .
)r   