o
    tf                     @   s   d Z ddlZddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ ddlmZ dd Zdd Zdd Zdd ZeedZeG dd deeeZ dS )z4FileUpload class.

Represents a file upload button.
    N)observedefaultUnicodeDictIntBoolBytesCaselessStrEnum   )DescriptionWidget)ValueWidget)
CoreWidget)ButtonStyle)registerwidget_serialization)InstanceDict
TypedTuple)Bunchc                 C   s@   t  }dD ]}| | ||< qtjj| d d tjjd|d< |S )Nnametypesizecontentlast_modified  )tz)r   dtdatetimefromtimestamptimezoneutc)jsuploaded_file	attribute r$   i/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/ipywidgets/widgets/widget_upload.py_deserialize_single_file   s   

r&   c                 C      dd | D S )Nc                 S      g | ]}t |qS r$   )r&   .0entryr$   r$   r%   
<listcomp>#       z&_deserialize_value.<locals>.<listcomp>r$   )r!   _r$   r$   r%   _deserialize_value"      r/   c                 C   s6   i }dD ]}| | ||< qt | d  d |d< |S )Nr   r   r   )int	timestamp)r"   r!   r#   r$   r$   r%   _serialize_single_file&   s
   r3   c                 C   r'   )Nc                 S   r(   r$   )r3   r)   r$   r$   r%   r,   /   r-   z$_serialize_value.<locals>.<listcomp>r$   )valuer.   r$   r$   r%   _serialize_value.   r0   r5   )	from_jsonto_jsonc                   @   s   e Zd ZdZedjddZedjddZeddjddZe	ddjddZ
e	d	djddZed
ddjddZeg ddddjddZeejdddieZeddjddZee ddjddddeZeddd ZdS )
FileUploada.  File upload widget

    This creates a file upload input that allows the user to select
    one or more files to upload. The file metadata and content
    can be retrieved in the kernel.

    Examples
    --------

    >>> import ipywidgets as widgets
    >>> uploader = widgets.FileUpload()

    # After displaying `uploader` and uploading a file:

    >>> uploader.value
    [
      {
        'name': 'example.txt',
        'type': 'text/plain',
        'size': 36,
        'last_modified': datetime.datetime(2020, 1, 9, 15, 58, 43, 321000, tzinfo=datetime.timezone.utc),
        'content': <memory at 0x10c1b37c8>
      }
    ]
    >>> uploader.value[0].content.tobytes()
    b'This is the content of example.txt.
'

    Parameters
    ----------

    accept: str, optional
        Which file types to accept, e.g. '.doc,.docx'. For a full
        description of how to specify this, see
        https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept
        Defaults to accepting all file types.

    multiple: bool, optional
        Whether to accept multiple files at the same time. Defaults to False.

    disabled: bool, optional
        Whether user interaction is enabled.

    icon: str, optional
        The icon to use for the button displayed on the screen.
        Can be any Font-awesome icon without the fa- prefix.
        Defaults to 'upload'. If missing, no icon is shown.

    description: str, optional
        The text to show on the label. Defaults to 'Upload'.

    button_style: str, optional
        One of 'primary', 'success', 'info', 'warning', 'danger' or ''.

    style: widgets.widget_button.ButtonStyle, optional
        Style configuration for the button.

    value: Tuple[Dict], optional
        The value of the last uploaded file or set of files. See the
        documentation for details of how to use this to retrieve file
        content and metadata:
        https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#File-Upload

    error: str, optional
        Whether the last upload triggered an error.
    ZFileUploadModelT)syncZFileUploadViewz*File types to accept, empty string for all)helpz(If True, allow for multiple files uploadzEnable or disable buttonZuploadz1Font-awesome icon name, without the 'fa-' prefix.)primarysuccessinfowarningZdanger r?   z(Use a predefined styling for the button.)valuesdefault_valuer:   r9   zError messagezThe file upload valueF)r9   Zecho_updatedescriptionc                 C   s   dS )NZUploadr$   )selfr$   r$   r%   _default_description   s   zFileUpload._default_descriptionNr$   )__name__
__module____qualname____doc__r   tagZ_model_nameZ
_view_nameacceptr   Zmultipledisablediconr	   Zbutton_styler   r   r   styleerrorr   r   _value_serializationr4   r   rD   r$   r$   r$   r%   r8   8   s.    Ar8   )!rH   r   r   Z	traitletsr   r   r   r   r   r   r   r	   Zwidget_descriptionr   Zvaluewidgetr   Zwidget_corer   Zwidget_buttonr   Zwidgetr   r   Ztrait_typesr   r   r   r&   r/   r3   r5   rO   r8   r$   r$   r$   r%   <module>   s&   (