
    f2                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZd Zd Z	d'dZ
d Z ej        d          Z ej        d          Z ej        d          Z ej        d          Z ej        d          Z ej        d          Zd Zd(dZ ej        d          Zd Zd)dZd*dZ G d de          Zd Zd Zd  Z G d! d"e          Z G d# d$e          Z dd%l!m"Z" g d&Z#dS )+a  This module parses and generates contentlines as defined in RFC 5545
(iCalendar), but will probably work for other MIME types with similar syntax.
Eg. RFC 2426 (vCard)

It is stupid in the sense that it treats the content purely as strings. No type
conversion is attempted.
    )CaselessDict)DEFAULT_ENCODING)SEQUENCE_TYPES)
to_unicodeNc                 2   t          | t          t          f          sJ |                     dd                              dd                              dd                              dd                              d	d
                              dd
          S )z=Format value according to iCalendar TEXT escaping rules.
    \N
\\\;\;,\,
\n
isinstancestrbytesreplacetexts    T/var/www/dev/btcams2024/python_venv/lib/python3.11/site-packages/icalendar/parser.pyescape_charr      s     dS%L)))))<<t$$f%%U##U##&&e$$%    c                 ~   t          | t          t          f          sJ t          | t                    rz|                     dd                              dd                              dd                              dd                              dd                              d	d
          S t          | t                    rz|                     dd                              dd                              dd                              dd                              dd                              dd          S d S )Nr   r   r   r	   r   r   r   r   r   r
   s   \Ns   \n   
   
s   \,   ,s   \;   ;s   \\   \r   r   s    r   unescape_charr"      s   dS%L)))))$ ,||E5))GFD))GE4((GE3''GE3''GFD))	* 
D%	 	  ,||FF++GGU++GFE**GFD))GFD))GGU++	,, ,r   K   
 c           	          t           t                    sJ d vsJ 	                      d           |                     fdt	          dt                     dz
            D                       S # t          t          f$ r Y nw xY wg }d} D ]`}t          |                    t                              }||z  }|k    r|	                    |           |}|	                    |           ad                    |          S )a  Make a string folded as defined in RFC5545
    Lines of text SHOULD NOT be longer than 75 octets, excluding the line
    break.  Long content lines SHOULD be split into a multiple line
    representations using a line "folding" technique.  That is, a long
    line can be split between any two characters by inserting a CRLF
    immediately followed by a single linear white-space character (i.e.,
    SPACE or HTAB).
    r	   asciic              3   8   K   | ]}||z   d z
           V  dS )   N ).0ilimitlines     r   	<genexpr>zfoldline.<locals>.<genexpr>C   sE       
 
&'D1u9q=!
 
 
 
 
 
r   r   r(    )
r   r   encodejoinrangelenUnicodeEncodeErrorUnicodeDecodeErrorr   append)r-   r,   fold_sep	ret_chars
byte_countcharchar_byte_lens   ``     r   foldliner<   1   sQ    dC     t
G }} 
 
 
 
 
+0CIIuqy+I+I
 
 
 
 
 	
  23    IJ  DKK(899::m#
X&&&&J779s   A7 7B
Bc                    t          | t                    rt          |           S t          | t                    rt	          |           S t	          |                                                     t                              S )zReturns a parameter value.
    )r   r   q_joinr   dquoteto_icaldecoder   )values    r   param_valuerC   W   sg     %(( @e}}	E3		 @e}}emmoo,,-=>>???r   z[\w.-]+z[ -
-",:;]z
[ -
-"]s
   (?
)+[ 	]z
(?
)+[ 	]z\r?\nc                     t                               |           }t          |          dk    r| |d         k    rd S t          |           )Nr(   r   )NAMEfindallr3   
ValueError)namematchs     r   validate_tokenrJ   o   sC    LLE
5zzQ458++
T

r   Tc                 n    |rt           nt          }|                    |           rt          |           d S N)QUNSAFE_CHARUNSAFE_CHARrF   rG   )rB   quoted	validators      r   validate_param_valuerQ   v   s>     &7KI     r   u
   [,;: ’']c                 r    |                      dd          } t                              |           rd|  dS | S )z@Enclose parameter values containing [,;:] in double quotes.
    "')r   QUOTABLEsearchvals    r   r?   r?      s>    
 ++c3

Cs 3zzzJr   r   c                 <   |dk    r| gS g }d}t          |           }d}d}t          |           D ]k\  }}	|	dk    r| }|s-|	|k    r'|                    | ||                    |dz   }|dz  }|dz   |k    s||k    r|                    | |d                     nl|S )zISplits a string on char, taking double (q)uotes into considderation.
    r   rS   r(   N)r3   	enumerater6   )
stsepmaxsplitresultcursorlengthinquotesplitsr+   chs
             r   q_splitre      s     1}}tFFWWFGF2 	 	299!kG 	299MM"VAX,'''UFaKFq5F??f00MM"VWW+&&&E 1 Mr   c                 @    |                     d | D                       S )z>Joins a list on sep, quoting strings with QUOTABLE chars.
    c              3   4   K   | ]}t          |          V  d S rL   )r?   )r*   itms     r   r.   zq_join.<locals>.<genexpr>   s(      //CF3KK//////r   r1   )lstr]   s     r   r>   r>      s%     88//3//////r   c                   8    e Zd ZdZd ZddZed	d            ZdS )

ParameterszParser and generator of Property parameter strings. It knows nothing of
    datatypes. Its main concern is textual structure.
    c                 *    |                                  S )zpIn RFC 5545 keys are called parameters, so this is to be consitent
        with the naming conventions.
        )keysselfs    r   paramszParameters.params   s     yy{{r   Tc                    g }t          |                                           }|r|                                 |D ]\  }}t          |          }t	          |t
                    r|                    t                    }|                                                    t                    }|	                    |dz   |z              d
                    |          S )N   =r    )listitemssortrC   r   r   r0   r   upperr6   r1   )rp   sortedr_   ru   keyrB   s         r   r@   zParameters.to_ical   s    TZZ\\"" 	JJLLL 	. 	.JC&&E%%% 7%566))++$$%566CMM#*u,----yy   r   Fc                     |             }t          |d          D ]E}	 t          |dd          \  }}t          |           g }t          |d          D ]}|                    d          rQ|                    d          r<|                    d          }t          |d           |                    |           ht          |d	           |r(|                    |                                           |                    |           |s|||<   n$t          |          dk    r|d
         ||<   n|||<   !# t          $ r}	t          |d|	           d}	~	ww xY w|S )z2Parses the parameter format from ical text format.r   =r(   )r^   r   rS   T)rO   Fr   z" is not a valid parameter string: N)
re   rJ   
startswithendswithstriprQ   r6   rw   r3   rG   )
clsr\   strictr_   paramry   rX   valsvexcs
             r   	from_icalzParameters.from_ical   s   
 R%% 	I 	IEI"5#:::Ss###  c** 
+ 
+A||C(( 	+QZZ__ 	+GGCLL,Qt<<<<A,Qu====! + KK		2222 KKNNNN +"%F3KK4yyA~~&*1gs&*s I I I GG#GGI I II s   DD<<
EEENTF)__name__
__module____qualname____doc__rq   r@   classmethodr   r)   r   r   rl   rl      sa           2! ! ! ! ! ! ! [! ! !r   rl   c                     |                      dd                               dd                               dd                               dd          S )	Nr   %2Cz\:%3Ar   %3Br   %5Cr   rW   s    r   escape_stringr      sE    ;;ue$$,,UE::wue$$WWUE%:%:;r   c                     |                      dd                               dd                               dd                               dd          S )	Nr   r   r   :r   r   r   r
   r   rW   s    r   unescape_stringr     sE    ;;uc""**5#66wuc""775$#7#78r   c                 b    t          | t                    rd | D             S t          |           S )Nc                 ,    g | ]}t          |          S r)   )r   )r*   ss     r   
<listcomp>z+unescape_list_or_string.<locals>.<listcomp>
  s     000q""000r   )r   rt   r   rW   s    r   unescape_list_or_stringr     s6    #t $00C0000s###r   c                   d     e Zd ZdZdef fd	Zed	d            Z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.
    Fc                     t          ||          }d|vs
J d            t                                          | |          }||_        |S )N)encodingr	   z;Content line can not contain unescaped new line characters.)r   super__new__r   )r   rB   r   r   rp   	__class__s        r   r   zContentline.__new__  sT    584445    $:   wwsE**r   Tc                    t          |t                    sJ t          |d          r|                                }n!t	          |                                          }t          |          }t          |          }|r6t          |                    |                    } | | d| d|           S  | | d|           S )z*Turn a parts into a content line.
        r@   )rx   r   r   )r   rl   hasattrr@   vTextr   )r   rH   rq   valuesrx   s        r   
from_partszContentline.from_parts  s     &*-----69%% 	-^^%%FF6]]**,,F $F## 	4f = =>>F3$2222&22333sd%%V%%&&&r   c                    	 t          |           }d}d}d}t          |          D ]"\  }}|s|dv r|s|}|dk    r|s|}|dk    r| }#t          |d|                   }|st          d          t	          |           |s|dz   }|r	|dz   |k    rt          d          t
                              ||dz   |         | j        	          }t          d
 t          |	                                          D                       }t          ||dz   d                   }	|||	fS # t          $ r}
t          d|  d|
           d}
~
ww xY w)zISplit the content line up into (name, parameters, values) parts.
        NFz:;r   rS   zKey name is requiredr(   zInvalid content liner   c              3   X   K   | ]%\  }}t          |          t          |          fV  &d S rL   )r   r   )r*   ry   rB   s      r   r.   z$Contentline.parts.<locals>.<genexpr>M  sP          C !%%'>u'E'EF           r   z.Content line could not be parsed into parts: 'z': )
r   r[   r   rG   rJ   rl   r   r   iterru   )rp   r\   
name_splitvalue_split	in_quotesr+   rd   rH   rq   r   r   s              r   partszContentline.parts3  s   	Qt$$BJKI"2 . .2  (Tzz*z%&
Syyy&'99$-I"2kzk?33D 9 !78884    $!e 9a;!>!> !7888))"Z!^[-H*I15 * > >F    "&v||~~"6"6       F %Ra(8(8%9::F&&)) 	Q 	Q 	QOOO#OOQ Q Q	Qs   D!D$ $
E.EEc                 l    t          |          } | t                              d|          |          S )zJUnfold the content lines in an iCalendar into long content lines.
        r/   r   )r   uFOLDsub)r   icalr   s      r   r   zContentline.from_icalW  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<   r0   r   ro   s    r   r@   zContentline.to_ical_  s     ~~$$%5666r   r   r   )r   r   r   r   r   r   r   r   r   r   r@   __classcell__)r   s   @r   r   r     s          $)3C       ' ' ' ['("Q "Q "QH 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.
        r   c              3   B   K   | ]}||                                 V  d S rL   )r@   r*   r-   s     r   r.   z'Contentlines.to_ical.<locals>.<genexpr>o  s/      DDttDDLLNNDDDDDDr   ri   ro   s    r   r@   zContentlines.to_icall  s*     ||DDtDDDDDwNNr   c                    t          |          }	 t                              d|          } | d t                              |          D                       }|                    d           |S # t          $ r t          d          w xY w)z,Parses a string into content lines.
        r/   c              3   8   K   | ]}|t          |          V  d S rL   )r   r   s     r   r.   z)Contentlines.from_ical.<locals>.<genexpr>y  sK       A A4AD)) A A A A A Ar   z&Expected StringType with content lines)r   r   r   NEWLINEsplitr6   	ExceptionrG   )r   r\   unfoldedliness       r   r   zContentlines.from_icalq  s     ^^	GyyR((HC A A 'h 7 7A A A A AELLL 	G 	G 	GEFFF	Gs   AA0 0B
N)r   r   r   r   r@   r   r   r)   r   r   r   r   f  sP         
O O O
 G G [G G Gr   r   )r   )r   r   FOLDrE   r   rl   rM   rU   rN   r?   r   r   r<   rC   r>   re   tzid_from_dtr   r"   r   r   rQ   rJ   )r#   r$   r   )r   rY   )r   )$r   icalendar.caselessdictr   icalendar.parser_toolsr   r   r   rer   r"   r<   rC   compilerE   rN   rM   r   r   r   rJ   rQ   rU   r?   re   r>   rl   r   r   r   r   r   rt   r   icalendar.propr   __all__r)   r   r   <module>r      sm    0 / / / / / 3 3 3 3 3 3 1 1 1 1 1 1 - - - - - - 				
% 
% 
%, , ,&       L@ @ @ rz*bj788rz566rz"##
?##
"*X

          2:l##     00 0 0 0O O O O O O O Od; ; ;8 8 8
$ $ $Q7 Q7 Q7 Q7 Q7# Q7 Q7 Q7hG G G G G4 G G G8 !            r   