
    L^i                     6   d dl Z d dlZd dlZd dlm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 d dlmZ d dlmZ 	 d d	lmZmZ n# e$ r d
 ZY nw xY w	 d dlmZ n# e$ r	 d dlmZ Y nw xY w e            r e            Zn# ej         ej                    ej                  Zg dZdZd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d/dZ,d/dZ-d/dZ.d/dZ/d Z0d0dZ1d0d Z2d0d!Z3d" Z4d# Z5d$ Z6d0d%Z7d0d&Z8g d'Z9d( Z:g d)Z;d* Z<d+ Z=d1d-Z>	 	 d2d.Z?dS )3    N)string_types)	HTTPError)utils)EXCEPTION_CODES)instance)Error)build_eager)AppEngineManageris_appengine_sandboxc                      dS )NF r       6D:\Nbitz\venv\Lib\site-packages\cloudinary/uploader.pyr   r      s    ur   )OrderedDict)filenametimeout
chunk_size	use_cachei -1c                 D    t          j        di |}t          d|fd| i|S )a   
    Uploads a file (image, video, or raw) to your Cloudinary product environment.


    See: https://cloudinary.com/documentation/image_upload_api_reference#upload

    :param file:
        The asset to upload. This can be:
         - A local file path (string)
         - A file-like object / stream
         - A Data URI (Base64 encoded)
         - A remote FTP, HTTP, or HTTPS URL
         - A private storage bucket (S3 or Google Storage) URL from a whitelisted bucket
    :type file: str or file-like object

    :param options:
        Additional parameters and configuration for the upload call.

    :keyword str public_id:
        Overrides the default public ID for the uploaded file.
    :keyword str public_id_prefix:
        Prepends a given prefix to the public ID of all uploaded assets.
    :keyword str callback:
        Callback URL or function for asynchronous notifications.
    :keyword str format:
        Force a specific asset format (e.g., "jpg", "png").
    :keyword str type:
        The storage type (default: "upload"). Possible values:
         - "upload" (publicly accessible)
         - "private"
         - "authenticated" (JWT or token-based access)
    :keyword bool backup:
        Whether to back up the asset.
    :keyword bool faces:
        If True, return face coordinates in the response (if faces are detected).
    :keyword bool image_metadata:
        If True, return image metadata (EXIF, etc.) in the response.
    :keyword bool media_metadata:
        If True, return media metadata for file types like PDF or AI.
    :keyword bool exif:
        If True, return EXIF metadata in the response.
    :keyword bool colors:
        If True, return a list of colors predominant in the image.
    :keyword bool use_filename:
        If True, derive the public ID from the file name's basename.
    :keyword bool unique_filename:
        If True, add random characters to the public ID to ensure uniqueness.
    :keyword str display_name:
        A user-friendly name for the asset, displayed in the Media Library.
    :keyword bool use_filename_as_display_name:
        If True, sets the display_name to the file's original filename.
    :keyword bool discard_original_filename:
        If True, do not include the original filename in the public ID.
    :keyword str filename_override:
        Manually override the final filename (instead of deriving from file).
    :keyword bool invalidate:
        If True, invalidates the cached copies on the CDN after upload or transformation.
    :keyword str notification_url:
        A URL to notify when the upload or related process is completed.
    :keyword str eager_notification_url:
        A URL to notify when eager transformations have completed.
    :keyword bool eager_async:
        If True, performs eager transformations asynchronously.
    :keyword str eval:
        Run custom JavaScript (for video or media) at certain processing steps (Advanced).
    :keyword str on_success:
        A function/URL that triggers upon successful processing (Advanced).
    :keyword str proxy:
        A proxy server address if needed for the upload request.
    :keyword str folder:
        The folder path in your Cloudinary product environment to store the asset.
    :keyword str asset_folder:
        A subfolder path for advanced use-cases.
    :keyword bool use_asset_folder_as_public_id_prefix:
        If True, treat the asset_folder path as part of the public ID.
    :keyword bool unique_display_name:
        If True, ensures that the display_name is unique across the product environment.
    :keyword bool overwrite:
        If True, overwrite an existing asset with the same public ID.
    :keyword str moderation:
        The moderation type (e.g., "manual", "webpurify", "aws_rek").
    :keyword str raw_convert:
        Raw file conversion type (e.g., "aspose").
    :keyword str quality_override:
        Overrides the auto-quality or transformation-based quality setting.
    :keyword bool quality_analysis:
        If True, return the advanced quality analysis results in the response.
    :keyword str ocr:
        OCR extraction setting (e.g., "adv_ocr").
    :keyword str categorization:
        Sets categorization mode (e.g., "google_tagging").
    :keyword str detection:
        Sets detection mode (e.g., "adv_face").
    :keyword str similarity_search:
        Reserved for advanced similarity search tasks.
    :keyword str visual_search:
        Reserved for visual search tasks.
    :keyword str background_removal:
        Background removal feature (e.g., "cloudinary_ai", "pixelz").
    :keyword str upload_preset:
        The name of the upload preset to apply. If omitted, defaults to
        ``cloudinary.config().upload_preset`` if configured.
    :keyword bool phash:
        If True, return the perceptual hash (pHash) for the image.
    :keyword bool return_delete_token:
        If True, returns a token that can be used to delete the asset without authentication.
    :keyword float auto_tagging:
        (Range 0.0-1.0) If set, automatically tag the image based on content analysis.
    :keyword bool async:
        If True, requests asynchronous processing (where applicable).
    :keyword bool cinemagraph_analysis:
        If True, performs analysis for cinemagraph creation.
    :keyword bool accessibility_analysis:
        If True, performs accessibility (image alt text) analysis.
    :keyword int timestamp:
        A UNIX timestamp to sign the request. Defaults to now().
    :keyword dict or list transformation:
        A transformation or list of transformations to apply. Internally merged into a single string.
    :keyword dict headers:
        Additional HTTP headers to store with the asset (Advanced usage).
    :keyword list eager:
        A list of eager transformations to generate during the upload.
    :keyword list tags:
        A list of tags (or a comma-delimited string) to assign to the uploaded asset.
    :keyword list allowed_formats:
        A list of file formats allowed for this upload (e.g., ["jpg", "png"]).
    :keyword list or tuple face_coordinates:
        Face rectangle coordinates, encoded into the upload if required.
    :keyword list or tuple custom_coordinates:
        Custom rectangle coordinates, stored with the asset.
    :keyword dict regions:
        Arbitrary region data for advanced transformations or processing.
    :keyword dict or str context:
        Adds or updates contextual metadata (key-value pairs).
    :keyword str responsive_breakpoints:
        A JSON string or list describing how to create responsive breakpoints for the image.
    :keyword list or dict access_control:
        Access control rules (ACL) for the asset, e.g. restricting or allowing access.
    :keyword dict metadata:
        Key-value pairs for structured metadata fields (by external_id).
    :keyword bool use_cache:
        (Uploader-specific) If True, store responsive breakpoints in the local cache.

    :return:
        The result of the Upload API call, typically including:
        - "public_id"
        - "version"
        - "url", "secure_url"
        - etc.
    :rtype: dict
    uploadfiler   r   build_upload_paramscall_cacheable_apir   optionsparamss      r   r   r   -   s8    p &1111FhEETEWEEEr   c                 "    t          | f|dd|S )a  
    Uploads an asset to Cloudinary without requiring authentication.

    See: https://cloudinary.com/documentation/image_upload_api_reference#unsigned_upload_syntax

    :param file: The asset to upload (local path, file-like object, Data URI, remote URL, or bucket URL).
    :type file: str or file-like object
    :param upload_preset: The unsigned upload preset name to use.
    :type upload_preset: str
    :param options: Additional options for the upload.
    :return: The result of the upload API call.
    :rtype: dict
    T)upload_presetunsigned)r   )r   r   r   s      r   unsigned_uploadr!      s!     $NmdNNgNNNr   c                     t          | fi |}t          j        |d         t          |d                   |                    d          |          S )a}  
    Uploads a file and returns a CloudinaryImage object.

    See: https://cloudinary.com/documentation/image_upload_api_reference#upload

    :param file: The asset to upload.
    :type file: Any or str
    :param options: Additional parameters for the upload call.
    :return: A CloudinaryImage object referencing the uploaded image.
    :rtype: cloudinary.CloudinaryImage
    	public_idversionformat)r$   r%   metadata)r   
cloudinaryCloudinaryImagestrget)r   r   results      r   upload_imager,      s[     D$$G$$F%{S	):%;%;zz(##f   r   c                    t           }t          | d          r| j        t          k    rt          } || fi |}t          j        |d         t          |d                   |                    d          |d         |d         |          S )a  
    Uploads a file and returns a CloudinaryResource object (image, raw, or video).

    See: https://cloudinary.com/documentation/image_upload_api_reference#upload

    :param file: The asset to upload.
    :type file: Any or str
    :param options: Additional parameters for the upload call.
    :return: A CloudinaryResource object referencing the uploaded asset.
    :rtype: cloudinary.CloudinaryResource
    sizer#   r$   r%   typeresource_type)r$   r%   r/   r0   r&   )	r   hasattrr.   UPLOAD_LARGE_CHUNK_SIZEupload_larger'   CloudinaryResourcer)   r*   )r   r   upload_funcr+   s       r   upload_resourcer6      s     KtV #-D!D!D"[))))F({F9%&&zz(##F^_-   r   c                 4   t          j        |           rt          | fi |S t          | d          rt	          | j                  r| }nt          | d          }d}|5  t          j                    }d}|                    dt                    }t          j
        |          }|                    dt          |d          r!t          |j        t                    r|j        nd          }|                    |          }	|	rd	                    ||t          |	          z   d
z
  |          }
|t          |	          z  }|
|d}t!          ||	ffd|i|}|                    d          |d<   |                    |          }	|	ddd           n# 1 swxY w Y   |S )a_  
    Uploads a large file (in chunks) to Cloudinary.

    See: https://cloudinary.com/documentation/image_upload_api_reference#upload

    :param file: The file to upload (local path or file-like object).
    :type file: str or file-like object
    :param options: Additional options for the upload.
    :keyword str filename: Override for the file name (for streams).
    :keyword int chunk_size: Size of each uploaded chunk (default=20000000).
    :keyword bool use_cache: Whether to store responsive breakpoints in cache after upload.
    :return: The result of the upload API call.
    :rtype: dict
    readrbNr   r   r   namestreamzbytes {0}-{1}/{2}   )zContent-RangezX-Unique-Upload-Idhttp_headersr#   )r   is_remote_urlr   r1   callabler8   openrandom_public_idr*   r2   file_io_size
isinstancer:   r)   r%   lenupload_large_part)r   r   file_ioupload_result	upload_idcurrent_locr   	file_size	file_namechunkcontent_ranger=   s               r   r3   r3   	  s    4   'd&&g&&&tV #$)!4!4 #tT""M	 - -*,,	[[/FGG
&w//	KK#GV44dGLRU9V9VdGLL\d
 
	
 Z(( 	-/66{KRUV[R\R\D\_`D`bkllM3u::%K!.&/ L
 .y%.@gg|g_fggM#0#4#4[#A#AGK LL,,E  	-- - - - - - - - - - - - - - -6 s   D$FFFc                 V    t          j        di |}d|vrd|d<   t          d|fd| i|S )a~  
    Uploads a large chunk (part) of a file to Cloudinary.

    See: https://cloudinary.com/documentation/image_upload_api_reference#upload

    :param file: A tuple of (filename, chunk_data) for the file part to upload.
    :type file: tuple
    :param options: Additional parameters for the chunk upload.
    :return: The result of the chunk upload API call.
    :rtype: dict
    r0   rawr   r   r   r   r   s      r   rE   rE   @  sL     &1111Fg%%#( hEETEWEEEr   c                     t          j                    |                    d          |                    d          | d}t          d|fi |S )a  
    Deletes a resource (asset) from Cloudinary by public ID.

    See: https://cloudinary.com/documentation/image_upload_api_reference#destroy

    :param public_id: The public ID of the resource to delete.
    :type public_id: str
    :param options: Additional options for the deletion.
    :keyword str type: The storage type (upload, private, authenticated).
    :keyword bool invalidate: Invalidate cached copies on the CDN if True.
    :return: The result of the API call.
    :rtype: dict
    r/   
invalidate)	timestampr/   rQ   r#   destroyr   nowr*   call_apir#   r   r   s      r   rS   rS   T  sT     Y[[F##kk,//	 F Iv11111r   c                 <   t          j                    |                    d          |                    d          |                    d          | ||                    d          |                    d          |                    d          d	}t          d|fi |S )	a|  
    Renames a resource (asset) in Cloudinary.

    See: https://cloudinary.com/documentation/image_upload_api_reference#rename_public_id

    :param from_public_id: The current public ID of the resource.
    :type from_public_id: str
    :param to_public_id: The new public ID for the resource.
    :type to_public_id: str
    :param options: Additional options for the rename operation.
    :keyword str type: The storage type of the original asset. Default=upload.
    :keyword bool overwrite: Whether to overwrite if the to_public_id already exists.
    :keyword bool invalidate: Invalidate cached copies on the CDN if True.
    :keyword str to_type: Change the resource to the specified upload type.
    :keyword dict context: Set or update contextual metadata.
    :keyword dict metadata: Set or update structured metadata.
    :return: The result of the API call.
    :rtype: dict
    r/   	overwriterQ   to_typecontextr&   )	rR   r/   rY   rQ   from_public_idto_public_idrZ   r[   r&   renamerT   )r\   r]   r   r   s       r   r^   r^   k  s    * Y[[F##[[--kk,//($;;y));;y))KK
++
 
F Hf00000r   c                     t          j                    t          j        |           t          j        |          |                    d          |                    d          d}t          d|fi |S )a  
    Populates or updates metadata fields with the given values.

    See: https://cloudinary.com/documentation/image_upload_api_reference#metadata

    :param metadata: Key-value pairs for custom metadata fields (by external_id).
    :type metadata: dict
    :param public_ids: A list of public IDs (assets) to update.
    :type public_ids: list[str]
    :param options: Additional options such as resource_type or type.
    :keyword str resource_type: The resource type (image, raw, video). Default="image".
    :keyword str type: The storage type (upload, private, authenticated).
    :keyword bool clear_invalid: If True, remove keys that are not valid.
    :return: A list of public IDs that were updated.
    :rtype: dict
    r/   clear_invalid)rR   r&   
public_idsr/   r`   r&   r   rU   encode_contextbuild_arrayr*   rV   )r&   ra   r   r   s       r   update_metadatare     sm    $ Y[[(22'
33F## _55 F J22'222r   c                 J    t          j        di |}| |d<   t          d|fi |S )a  
    Applies actions to already uploaded assets (raw, image, or video) via an explicit call.

    See: https://cloudinary.com/documentation/image_upload_api_reference#explicit

    :param public_id: The public ID of the asset to process.
    :type public_id: str
    :param options: Additional options for the explicit API call.
    :return: The result of the API call.
    :rtype: dict
    r#   explicitr   r   rW   s      r   rg   rg     s<     &1111F#F;j&<<G<<<r   c                      t          j        di | }|                     d          |                     d          |d<   t          d|fi | S )an  
    Creates an archive of assets in Cloudinary.

    See: https://cloudinary.com/documentation/image_upload_api_reference#generate_archive

    :param options: Additional options for the archive creation (filters, transformations, etc.).
    :keyword str target_format: Archive format (zip, tgz, etc.).
    :return: The result of the API call.
    :rtype: dict
    target_formatNgenerate_archiver   )r   archive_paramsr*   rV   )r   r   s     r   create_archiverl     s[     !,,G,,F{{?##/")++o">">&::':::r   c                      t          dddi| S )a  
    Creates a ZIP archive of assets in Cloudinary.

    See: https://cloudinary.com/documentation/image_upload_api_reference#create_zip_syntax

    :param options: Additional options for archive creation.
    :return: The result of the API call.
    :rtype: dict
    ri   zipr   )rl   )r   s    r   
create_zipro     s     999999r   c                 F    t          j        d| |d|}t          d|fi |S )a  
    Generates sprites by merging multiple images into a single large image.

    See: https://cloudinary.com/documentation/image_upload_api_reference#sprite

    :param tag: Images with this tag will be used to create the sprite (if set).
    :type tag: str
    :param urls: List of URLs to create a sprite from (only if tag not set).
    :type urls: list[str], optional
    :param options: Additional sprite configuration.
    :return: Dictionary with metadata and URLs of generated sprite resources.
    :rtype: dict
    tagurlsspriter   r   build_multi_and_sprite_paramsrV   rr   rs   r   r   s       r   generate_spriterx     s9     0OStOOwOOFHf00000r   c                 R    t          j        d| |d|}t          j        dd|d|S )a  
    Generates a downloadable URL for the sprite (with `mode=download`).

    :param tag: Images with this tag will be used to create the sprite (if set).
    :type tag: str
    :param urls: List of URLs to create a sprite from (only if tag not set).
    :type urls: list[str], optional
    :param options: Additional sprite configuration.
    :return: The signed URL to download the sprite.
    :rtype: str
    rq   rt   actionr   r   r   rv   cloudinary_api_download_urlrw   s       r   download_generated_spriter~     s?     0OStOOwOOF,WHVWWwWWWr   c                 F    t          j        d| |d|}t          d|fi |S )a  
    Creates an animated image, video, or PDF from a set of images.

    See: https://cloudinary.com/documentation/image_upload_api_reference#multi

    :param tag: Assets with this tag will be used (if set).
    :type tag: str
    :param urls: A list of image URLs (if no tag is set).
    :type urls: list[str], optional
    :param options: Additional multi-configuration options.
    :return: Dictionary with metadata and URLs of the generated file.
    :rtype: dict
    rq   multir   ru   rw   s       r   r   r     s9     0OStOOwOOFGV//w///r   c                 R    t          j        d| |d|}t          j        dd|d|S )ay  
    Generates a downloadable URL for the multi (with `mode=download`).

    :param tag: Assets with this tag will be used (if set).
    :type tag: str
    :param urls: A list of image URLs (if no tag is set).
    :type urls: list[str], optional
    :param options: Additional multi-configuration options.
    :return: The signed URL to download the multi.
    :rtype: str
    rq   r   rz   r   r|   rw   s       r   download_multir     s?     0OStOOwOOF,VGFVVgVVVr   c           	          t          j                    | |                    d          |                    d          t          j        di |d         d}t	          d|fi |S )a  
    Creates derived images for all the individual pages in a multi-page file (PDF or animated GIF).

    See: https://cloudinary.com/documentation/image_upload_api_reference#explode

    :param public_id: The public ID of the file to explode.
    :type public_id: str
    :param options: Additional explode options (format, notification_url, transformation).
    :return: The result of the API call.
    :rtype: dict
    r%   notification_urlr   )rR   r#   r%   r   transformationexploder   )r   rU   r*   generate_transformation_stringrV   rW   s      r   r   r     sn     Y[[++h''#KK(:;;>IIII!L F Iv11111r   c                 X    |                     dd          }|rdnd}t          | ||fi |S )aX  
    Adds one or more tags to the specified assets.

    See: https://cloudinary.com/documentation/image_upload_api_reference#adding_tags_syntax

    :param tag: A single tag or multiple tags (comma-separated string or list).
    :type tag: str or list[str]
    :param public_ids: A list of public IDs (up to 1000).
    :type public_ids: list[str], optional
    :param options: Additional options (e.g., exclusive).
    :keyword bool exclusive: If True, clears this tag from all other assets in the product environment.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    	exclusiveNset_exclusiveadd)popcall_tags_api)rr   ra   r   r   commands        r   add_tagr   1  s?     K..I!*5ooGgz==W===r   c                      t          | d|fi |S )a  
    Removes one or more tags from the specified assets.

    See: https://cloudinary.com/documentation/image_upload_api_reference#removing_tags_syntax

    :param tag: A single tag or multiple tags (comma-separated string or list).
    :type tag: str or list[str]
    :param public_ids: A list of public IDs (up to 1000).
    :type public_ids: list[str], optional
    :param options: Additional options.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    remover   rr   ra   r   s      r   
remove_tagr   E  s     h
>>g>>>r   c                      t          | d|fi |S )a  
    Replaces all existing tags on the specified assets with a given tag (or tags).

    See: https://cloudinary.com/documentation/image_upload_api_reference#replacing_tags_syntax

    :param tag: A single tag or multiple tags (comma-separated string or list).
    :type tag: str or list[str]
    :param public_ids: A list of public IDs (up to 1000).
    :type public_ids: list[str], optional
    :param options: Additional options.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    replacer   r   s      r   replace_tagr   V  s     i??w???r   c                      t          dd| fi |S )af  
    Removes all tags from the specified public IDs.

    See: https://cloudinary.com/documentation/image_upload_api_reference#removing_all_tags_syntax

    :param public_ids: The public IDs of the assets.
    :type public_ids: list[str]
    :param options: Additional options.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    N
remove_allr   ra   r   s     r   remove_all_tagsr   g  s     |ZCC7CCCr   c                      t          | d|fi |S )a  
    Adds contextual metadata (key-value pairs) to the specified assets.

    See: https://cloudinary.com/documentation/image_upload_api_reference#adding_context_syntax

    :param context: A dictionary of context key-value pairs.
    :type context: dict
    :param public_ids: The public IDs of the assets to update.
    :type public_ids: list[str]
    :param options: Additional options.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    r   call_context_api)r[   ra   r   s      r   add_contextr   v  s     GUJBB'BBBr   c                      t          dd| fi |S )a  
    Removes all custom contextual metadata from the specified public IDs.

    See: https://cloudinary.com/documentation/image_upload_api_reference#removing_all_context_syntax

    :param public_ids: The public IDs of the assets to update.
    :type public_ids: list[str]
    :param options: Additional options.
    :return: Dictionary with a list of updated public IDs.
    :rtype: dict
    Nr   r   r   s     r   remove_all_contextr     s     D,
FFgFFFr   c                     t          j                    | t          j        |          ||                    d          d}t	          d|fi |S )a6  
    Internal helper function for adding/removing/replacing tags on assets.

    See: https://cloudinary.com/documentation/image_upload_api_reference#tags

    :param tag: A single tag or multiple tags.
    :type tag: str or list[str], optional
    :param command: The command to execute ("add", "remove", "replace", or "remove_all").
    :type command: str
    :param public_ids: A list of asset public IDs.
    :type public_ids: list[str], optional
    :param options: Additional options (e.g., type).
    :return: The result of the API call.
    :rtype: dict
    r/   )rR   rr   ra   r   r/   tags)r   rU   rd   r*   rV   )rr   r   ra   r   r   s        r   r   r     sV    " Y[['
33F## F FF..g...r   c                     t          j                    t          j        |           t          j        |          ||                    d          d}t          d|fi |S )a
  
    Internal helper for adding/removing context on assets.

    See: https://cloudinary.com/documentation/image_upload_api_reference#context

    :param context: A dictionary of context or None.
    :type context: dict or None
    :param command: The context command ("add", "remove_all").
    :type command: str
    :param public_ids: A list of asset public IDs.
    :type public_ids: list[str], optional
    :param options: Additional options (e.g., type).
    :return: The result of the API call.
    :rtype: dict
    r/   )rR   r[   ra   r   r/   r[   rb   )r[   r   ra   r   r   s        r   r   r     sa    " Y[['00'
33F## F Iv11111r   )
r#   font_family	font_size
font_color
text_alignfont_weight
font_style
backgroundopacitytext_decorationc                     t          j                    | d}t          D ]}|                    |          ||<   t	          d|fi |S )ak  
    Dynamically generates an image of a given text string.

    See: https://cloudinary.com/documentation/image_upload_api_reference#text

    :param text: The text string to generate an image for.
    :type text: str
    :param options: Additional options (e.g., font_family, font_size, etc.).
    :return: The result of the text API call.
    :rtype: dict
    )rR   textr   )r   rU   TEXT_PARAMSr*   rV   )r   r   r   keys       r   r   r     sU     !9;;55F ' 'kk#&&sFF..g...r   )r   r#   rY   r   c            
      F                          dd           d<    fdt          D             }t          j                    t	                                d                    t	                                d                                          d          o&t          j                              d                                          d          o+t          j        t          j         d                             d}|                    |           t          d	|fi  S )
a  
    Creates an auto-generated video slideshow from existing assets.

    :param options: Additional parameters for the slideshow creation.
    :keyword str resource_type: The resource type, defaults to "video".
    :keyword str notification_url: A URL to be notified when the processing is completed.
    :keyword str public_id: The public ID to assign to the generated slideshow.
    :keyword bool overwrite: Whether to overwrite the slideshow if public_id already exists.
    :keyword str upload_preset: An upload preset to apply to the slideshow creation.
    :keyword list transformation: A list or dict describing transformations to apply.
    :keyword list manifest_transformation: A list or dict transformations for the manifest.
    :keyword dict manifest_json: A JSON specification for advanced slideshow creation.
    :keyword list tags: A list of tags for the slideshow.
    :return: Dictionary with details about the created slideshow.
    :rtype: dict
    r0   videoc                 <    i | ]}|                     |          S r   )r*   ).0
param_namer   s     r   
<dictcomp>z$create_slideshow.<locals>.<dictcomp>  s'    VVVjj'++j11VVVr   r   manifest_transformationmanifest_jsonr   )rR   r   r   r   r   create_slideshow)
r*   _SLIDESHOW_PARAMSr   rU   r	   json_encodeencode_listrd   updaterV   )r   r   serialized_paramss   `  r   r   r     s   "  '{{?GDDGOVVVVDUVVVF Y[[%gkk2B&C&CDD#.w{{;T/U/U#V#V _55i%:KGKKXgLhLh:i:iF##](9%:KGTZO:\:\(](]  MM#$$$&::':::r   c                     d vrdS d vrdS t           fddD                       }                     dg           D ]}|                    dd          |d<   t          j                            |d	         d
         d                   d         dd         |d<   d |d	         D             }t          j         d         |fi | dS )z
    Saves any responsive breakpoints parsed from an upload result to the local cache.

    :param result: The upload result dictionary.
    :type result: dict
    responsive_breakpointsNr#   c              3   4   K   | ]}|v ||         fV  d S Nr   )r   kr+   s     r   	<genexpr>z8_save_responsive_breakpoints_to_cache.<locals>.<genexpr>"  s/      TTaVAvay>TTr   )r/   r0   r    raw_transformationbreakpointsr   urlr<   r%   c                     g | ]
}|d          S )widthr   )r   bps     r   
<listcomp>z9_save_responsive_breakpoints_to_cache.<locals>.<listcomp>'  s    KKKrr'{KKKr   )dictr*   ospathsplitext%responsive_breakpoints_cache_instanceset)r+   r   r   r   s   `   r   %_save_responsive_breakpoints_to_cacher     s     v--&  TTTT+DTTTTTG **%=rBB _ _(6(:(:;KR(P(P$%G,,^M-J1-Me-TUUVWXYZY[Y[\KK^M-JKKK-1&2E{^^V]^^^^	_ _r   Fc           	          t          | ||||||fi |}d|v st          j                    j        rt	          |           |S )a  
    Calls the Upload API and caches responsive breakpoints if enabled.

    :param action: The Cloudinary API endpoint to call (e.g., "upload", "explicit").
    :type action: str
    :param params: The parameters for the API call (already built and signed if needed).
    :type params: dict
    :param http_headers: Optional HTTP headers to send.
    :type http_headers: dict, optional
    :param return_error: If True, returns errors in the response instead of raising them.
    :type return_error: bool
    :param unsigned: If True, the request is not signed (unsigned upload).
    :type unsigned: bool
    :param file: A file-like object or path to send to the endpoint.
    :type file: Any, optional
    :param timeout: Request timeout in seconds.
    :type timeout: int, optional
    :param options: Additional Cloudinary configuration or parameters.
    :return: The parsed JSON response from Cloudinary.
    :rtype: dict
    r   )rV   r'   configr   r   )	r{   r   r=   return_errorr    r   r   r   r+   s	            r   r   r   +  sV    . fflL(DRYee]deeFg!2!4!4!>-f555Mr   c                    t          j        |          }dt          j                    i}	||	                    |           ||	                    |           |                    dt          j                    j                  }
|
rd                    |
          |	d<   n|st          j	        ||          }g }|
                                D ]c\  }}t          |t                    r0|D ],}|                    d                    |          |f           -J|r|                    ||f           dt          j        | fi |}|r?|                    d          }|                    dt          j        ||          f           i }|||d	<   	 t!          j        dd
|||	d|}nh# t$          $ r'}t'          d                    |                    d}~wt(          j        $ r'}t'          d                    |                    d}~ww xY w	 t-          j        |j                            d                    }n@# t4          $ r3}t'          d                    |j        |j        |                    d}~ww xY wd|v rK|r|j        |d         d<   |S t9          j        |j                  pt&          } ||d         d                   |S )a<  
    A low-level helper to call the Cloudinary Upload API.

    :param action: The specific endpoint to call (e.g. "upload", "destroy").
    :type action: str
    :param params: The dictionary of parameters to send to the endpoint.
    :type params: dict
    :param http_headers: HTTP headers to include in the request.
    :type http_headers: dict, optional
    :param return_error: If True, returns the error in the response instead of raising an exception.
    :type return_error: bool
    :param unsigned: If True, this call is not signed (unsigned upload).
    :type unsigned: bool
    :param file: File data or path to upload if relevant.
    :type file: Any, optional
    :param timeout: Timeout (in seconds) for the request.
    :type timeout: int, optional
    :param extra_headers: Additional headers to add/override.
    :type extra_headers: dict, optional
    :param options: Additional Cloudinary config or advanced parameters.
    :return: The parsed JSON response from Cloudinary.
    :rtype: dict

    :raises Error: If an HTTP error or a Cloudinary error occurs.
    z
User-AgentNoauth_tokenz	Bearer {}authorizationz{0}[]r   r   r   POST)methodr   fieldsheaderszUnexpected error - {0!r}zSocket error: {0!r}zutf-8z4Error parsing server response ({0}) - {1}. Got - {2}error	http_codemessager   )r   cleanup_paramsr'   get_user_agentr   r*   r   r   r%   sign_requestitemsrC   listappendcloudinary_api_urlhandle_file_parameter_httprequestr   r   socketr   jsonloadsdatadecode	Exceptionstatusr   )r{   r   r=   r   r    r   r   extra_headersr   r   r   
param_listr   viapi_urlr   kwresponseer+   exception_classs                         r   rV   rV   H  s   6 !&))FZ6889G|$$$ }%%%++mZ->-@-@-LMMK 5#.#5#5k#B#B   5#FG44J & &1a 	& : :!!7>>!#4#4a"89999: 	&q!f%%%&v9999G Q;;z**65#>tX#N#NOPPP	B95=fGJX_ffceff : : :.55a88999< 5 5 5)00334445@HM0099:: @ @ @JVHOX]A>>@ @ 	@@ & 	+3?F7OK(M)-ho>>G%ofWoi8999Ms<   F$ $
H	."GH	""HH	,H: :
I7.I22I7)NNr   )NFFNN)NFFNNN)@r   r   r   sixr   urllib3.exceptionsr   r'   r   %cloudinary.api_client.execute_requestr   -cloudinary.cache.responsive_breakpoints_cacher   r   cloudinary.exceptionsr   cloudinary.utilsr	   urllib3.contrib.appenginer
   r   r   collectionsr   ImportErrorurllib3.packages.ordered_dictr   get_http_connectorr   CERT_KWARGSupload_optionsr2   r   r!   r,   r6   r3   rE   rS   r^   re   rg   rl   ro   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rV   r   r   r   <module>r	     s    				        ( ( ( ( ( (           A A A A A A k k k k k k ' ' ' ' ' ' ( ( ( ( ( (PPPPPPPPP       :''''''' : : :99999999:  REE %E$%6Z%6%8%8*:PQQE   # YF YF YFxO O O"  &  84 4 4nF F F(2 2 2.1 1 1D3 3 36= = ="; ; ;"
: 
: 
:1 1 1 1$X X X X 0 0 0 0$W W W W 2 2 2,> > > >(? ? ? ?"@ @ @ @"D D DC C C"G G G/ / / /42 2 2 24  / / /$   ; ; ;D_ _ _.   : hlS S S S S Ss#   A AAA A)(A)