
    i                    r    d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 erddl
mZ  G d d	          Zd	gZdS )
z2This contains the IMAGE property from :rfc:`7986`.    )annotationsN)TYPE_CHECKING)vBinary)vUri)vTextc                  V    e Zd ZdZedd            Z	 	 	 	 	 dddZedd            ZdS )Imagea`  An image as URI or BINARY according to :rfc:`7986`.

    Value Type:
        URI or BINARY -- no default.  The value MUST be data
        with a media type of "image" or refer to such data.

    Description:
        This property specifies an image for an iCalendar
        object or a calendar component via a URI or directly with inline
        data that can be used by calendar user agents when presenting the
        calendar data to a user.  Multiple properties MAY be used to
        specify alternative sets of images with, for example, varying
        media subtypes, resolutions, or sizes.  When multiple properties
        are present, calendar user agents SHOULD display only one of them,
        picking one that provides the most appropriate image quality, or
        display none.  The "DISPLAY" parameter is used to indicate the
        intended display mode for the image.  The "ALTREP" parameter,
        defined in :rfc:`5545`, can be used to provide a "clickable" image
        where the URI in the parameter value can be "launched" by a click
        on the image in the calendar user agent.

    Parameters:
        uri: The URI of the image.
        b64data: The data of the image, base64 encoded.
        fmttype: The format type, e.g. ``"image/png"``.
        altrep: Link target of the image.
        display: The display mode, e.g. ``"BADGE"``.

    valuevUri | vBinary | vTextreturnc                   i }t          |d          st          d          	 |j                            dd                                          }n)# t
          t          f$ r}t          d          |d}~ww xY w|dk    st          |t                    rt          |          |d<   nLt          |t                    r|j
        |d	<   n,|d
k    rt          |          |d	<   nt          d|d          |                    |j                            d          |j                            d          |j                            d          d            | di |S )z&Create an Image from a property value.paramszValue must be URI or BINARY.VALUE z)Value must have a valid params attribute.NURIurib64dataBINARYz/The VALUE parameter must be URI or BINARY, not .FMTTYPEALTREPDISPLAY)fmttypealtrepdisplay )hasattr	TypeErrorr   getupperAttributeError
isinstancer   strr   objupdate)clsr
   r   
value_typeerrs        O/root/projects/butler/venv/lib/python3.11/site-packages/icalendar/prop/image.pyfrom_property_valuezImage.from_property_value.   s    "$uh'' 	<:;;;	R))'266<<>>JJ	* 	R 	R 	RGHHcQ	R*UD"9"9JJF5MMw'' 	 %	F98## #E

F9Q*QQQ   	 <++I66,**844 <++I66 	
 	
 	
 s}}V}}s   -A A7"A22A7Nr   
str | Noner   r   r   r   Nonec                    ||t          d          ||t          d          || _        || _        || _        || _        || _        dS )z,Create a new image according to :rfc:`7986`.Nz5Image cannot have both URI and binary data (RFC 7986)z)Image must have either URI or binary data)
ValueErrorr   r   r   r   r   )selfr   r   r   r   r   s         r)   __init__zImage.__init__K   s\     ?w2TUUU;7?HIII    bytes | Nonec                F    | j         dS t          j        | j                   S )z%Return the binary data, if available.N)r   base64	b64decode)r/   s    r)   dataz
Image.data^   s$     <4---r1   )r
   r   r   r	   )NNNNN)r   r+   r   r+   r   r+   r   r+   r   r+   r   r,   )r   r2   )	__name__
__module____qualname____doc__classmethodr*   r0   propertyr6   r   r1   r)   r	   r	      s         <    [< ""!"    & . . . X. . .r1   r	   )r:   
__future__r   r4   typingr   icalendar.prop.binaryr   icalendar.prop.urir   icalendar.prop.textr   r	   __all__r   r1   r)   <module>rC      s    8 8 " " " " " "              ) ) ) ) ) ) # # # # # # *))))))T. T. T. T. T. T. T. T.n )r1   