Update cloudinary==1.28.0

This commit is contained in:
JonnyWong16 2021-11-28 14:12:44 -08:00
parent 0325e9327f
commit dcfd8abddd
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
7 changed files with 196 additions and 21 deletions

View file

@ -3,15 +3,14 @@ import json
import os
import socket
import certifi
from six import string_types
from urllib3 import PoolManager, ProxyManager
from urllib3.exceptions import HTTPError
import cloudinary
from cloudinary import utils
from cloudinary.exceptions import Error
from cloudinary.cache.responsive_breakpoints_cache import instance as responsive_breakpoints_cache_instance
from cloudinary.exceptions import Error
from cloudinary.utils import build_eager
try:
from urllib3.contrib.appengine import AppEngineManager, is_appengine_sandbox
@ -24,6 +23,11 @@ try: # Python 2.7+
except ImportError:
from urllib3.packages.ordered_dict import OrderedDict
try: # Python 3.4+
from pathlib import Path as PathLibPathType
except ImportError:
PathLibPathType = None
if is_appengine_sandbox():
# AppEngineManager uses AppEngine's URLFetch API behind the scenes
_http = AppEngineManager()
@ -58,7 +62,12 @@ def upload_image(file, **options):
def upload_resource(file, **options):
result = upload_large(file, **options)
upload_func = upload
if hasattr(file, 'size') and file.size > UPLOAD_LARGE_CHUNK_SIZE:
upload_func = upload_large
result = upload_func(file, **options)
return cloudinary.CloudinaryResource(
result["public_id"], version=str(result["version"]),
format=result.get("format"), type=result["type"],
@ -363,6 +372,39 @@ def text(text, **options):
return call_api("text", params, **options)
_SLIDESHOW_PARAMS = [
"notification_url",
"public_id",
"overwrite",
"upload_preset",
]
def create_slideshow(**options):
"""
Creates auto-generated video slideshows.
:param options: The optional parameters. See the upload API documentation.
:return: a dictionary with details about created slideshow
"""
options["resource_type"] = options.get("resource_type", "video")
params = {param_name: options.get(param_name) for param_name in _SLIDESHOW_PARAMS}
serialized_params = {
"timestamp": utils.now(),
"transformation": build_eager(options.get("transformation")),
"manifest_transformation": build_eager(options.get("manifest_transformation")),
"manifest_json": options.get("manifest_json") and utils.json_encode(options.get("manifest_json")),
"tags": options.get("tags") and utils.encode_list(utils.build_array(options["tags"])),
}
params.update(serialized_params)
return call_api("create_slideshow", params, **options)
def _save_responsive_breakpoints_to_cache(result):
"""
Saves responsive breakpoints parsed from upload result to cache
@ -427,7 +469,10 @@ def call_api(action, params, http_headers=None, return_error=False, unsigned=Fal
if file:
filename = options.get("filename") # Custom filename provided by user (relevant only for streams and files)
if isinstance(file, string_types):
if PathLibPathType and isinstance(file, PathLibPathType):
name = filename or file.name
data = file.read_bytes()
elif isinstance(file, string_types):
if utils.is_remote_url(file):
# URL
name = None