U
    jK                     @   s   d dl mZmZ eefZdZeeef Z	de	edddZ
de	edddZefee	eef eeee ef d	d
dZddddddgZdS )    )ListUnionutf-8)valuereturnc                 C   sP   t | tr| S t | trHz| |W S  tk
rD   | dd Y S X n| S dS )z
    Converts a value to bytes, even if it already is bytes
    :param value: The value to convert
    :param encoding: The encoding to use in the conversion
    :return: The bytes representation of the value
    r   replaceN)
isinstancebytesstrencodeUnicodeEncodeErrorr   encoding r   :/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/parser_tools.pyfrom_unicode   s    

r   	utf-8-sigc                 C   sP   t | tr| S t | trHz| |W S  tk
rD   | dd Y S X n| S dS )zDConverts a value to unicode, even if it is already a unicode string.r   r   N)r   r
   r	   decodeUnicodeDecodeErrorr   r   r   r   
to_unicode   s    

r   )datar   c                 C   s^   t | tr| |S t | tr4tttt|  S t | tsHt | t	rVttt| S | S dS )zsEncode all datastructures to the given encoding.
    Currently unicode strings, dicts and lists are supported.
    N)
r   r
   r   dictmapdata_encodeiteritemslisttuple)r   r   r   r   r   r   '   s    


r   DEFAULT_ENCODINGSEQUENCE_TYPES	ICAL_TYPEN)r   )r   )typingr   r   r   r   r   r   r
   r	   r    r   r   r   r   __all__r   r   r   r   <module>   s"   