Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions dropbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ def files_get_thumbnail_v2(
mode=files.ThumbnailMode.strict,
quality=files.ThumbnailQuality.quality_80,
exclude_media_info=None,
preserve_transparency=False,
):
"""
Get a thumbnail for an image. This method currently supports files with
Expand Down Expand Up @@ -2104,6 +2105,11 @@ def files_get_thumbnail_v2(
``FileMetadata.media_info`` is not populated. This improves latency
for use cases where `media_info` is not needed.
:type exclude_media_info: Nullable[bool]
:param preserve_transparency: Whether to preserve the original image's
transparency in the thumbnail. This is supported only when the
output format is PNG or WebP. Requests that set this flag with JPEG
output return an error.
:type preserve_transparency: bool
:rtype: (:class:`dropbox.files.PreviewResult`,
:class:`requests.models.Response`)
:raises: :class:`.exceptions.ApiError`
Expand All @@ -2117,7 +2123,9 @@ def files_get_thumbnail_v2(
<https://docs.python.org/2/library/contextlib.html#contextlib.closing>`_
context manager to ensure this.
"""
arg = files.ThumbnailV2Arg(resource, format, size, mode, quality, exclude_media_info)
arg = files.ThumbnailV2Arg(
resource, format, size, mode, quality, exclude_media_info, preserve_transparency
)
r = self.request(
files.get_thumbnail_v2,
"files",
Expand All @@ -2135,6 +2143,7 @@ def files_get_thumbnail_to_file_v2(
mode=files.ThumbnailMode.strict,
quality=files.ThumbnailQuality.quality_80,
exclude_media_info=None,
preserve_transparency=False,
):
"""
Get a thumbnail for an image. This method currently supports files with
Expand Down Expand Up @@ -2168,13 +2177,20 @@ def files_get_thumbnail_to_file_v2(
``FileMetadata.media_info`` is not populated. This improves latency
for use cases where `media_info` is not needed.
:type exclude_media_info: Nullable[bool]
:param preserve_transparency: Whether to preserve the original image's
transparency in the thumbnail. This is supported only when the
output format is PNG or WebP. Requests that set this flag with JPEG
output return an error.
:type preserve_transparency: bool
:rtype: :class:`dropbox.files.PreviewResult`
:raises: :class:`.exceptions.ApiError`

If this raises, ApiError will contain:
:class:`dropbox.files.ThumbnailV2Error`
"""
arg = files.ThumbnailV2Arg(resource, format, size, mode, quality, exclude_media_info)
arg = files.ThumbnailV2Arg(
resource, format, size, mode, quality, exclude_media_info, preserve_transparency
)
r = self.request(
files.get_thumbnail_v2,
"files",
Expand Down
31 changes: 31 additions & 0 deletions dropbox/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9913,6 +9913,10 @@ class ThumbnailV2Arg(bb.Struct):
Normally, ``FileMetadata.media_info`` is set for photo and video. When
this flag is true, ``FileMetadata.media_info`` is not populated. This
improves latency for use cases where `media_info` is not needed.
:ivar ThumbnailV2Arg.preserve_transparency:
Whether to preserve the original image's transparency in the thumbnail.
This is supported only when the output format is PNG or WebP. Requests
that set this flag with JPEG output return an error.
"""

__slots__ = [
Expand All @@ -9922,6 +9926,7 @@ class ThumbnailV2Arg(bb.Struct):
"_mode_value",
"_quality_value",
"_exclude_media_info_value",
"_preserve_transparency_value",
]

_has_required_fields = True
Expand All @@ -9934,13 +9939,15 @@ def __init__(
mode=None,
quality=None,
exclude_media_info=None,
preserve_transparency=None,
):
self._resource_value = bb.NOT_SET
self._format_value = bb.NOT_SET
self._size_value = bb.NOT_SET
self._mode_value = bb.NOT_SET
self._quality_value = bb.NOT_SET
self._exclude_media_info_value = bb.NOT_SET
self._preserve_transparency_value = bb.NOT_SET
if resource is not None:
self.resource = resource
if format is not None:
Expand All @@ -9953,6 +9960,8 @@ def __init__(
self.quality = quality
if exclude_media_info is not None:
self.exclude_media_info = exclude_media_info
if preserve_transparency is not None:
self.preserve_transparency = preserve_transparency

# Instance attribute type: PathOrLink (validator is set below)
resource = bb.Attribute("resource", user_defined=True)
Expand All @@ -9972,6 +9981,9 @@ def __init__(
# Instance attribute type: bool (validator is set below)
exclude_media_info = bb.Attribute("exclude_media_info", nullable=True)

# Instance attribute type: bool (validator is set below)
preserve_transparency = bb.Attribute("preserve_transparency")

def _process_custom_annotations(self, annotation_type, field_path, processor):
super(ThumbnailV2Arg, self)._process_custom_annotations(
annotation_type, field_path, processor
Expand Down Expand Up @@ -10002,6 +10014,8 @@ class ThumbnailV2Error(bb.Union):
Access to this shared link is forbidden.
:ivar ThumbnailV2Error.not_found:
The shared link does not exist.
:ivar ThumbnailV2Error.unsupported_output_format:
Transparency preservation is supported only for PNG and WebP output.
"""

_catch_all = "other"
Expand All @@ -10018,6 +10032,8 @@ class ThumbnailV2Error(bb.Union):
# Attribute is overwritten below the class definition
not_found = None
# Attribute is overwritten below the class definition
unsupported_output_format = None
# Attribute is overwritten below the class definition
other = None

@classmethod
Expand Down Expand Up @@ -10087,6 +10103,14 @@ def is_not_found(self):
"""
return self._tag == "not_found"

def is_unsupported_output_format(self):
"""
Check if the union tag is ``unsupported_output_format``.

:rtype: bool
"""
return self._tag == "unsupported_output_format"

def is_other(self):
"""
Check if the union tag is ``other``.
Expand Down Expand Up @@ -14751,13 +14775,15 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
ThumbnailV2Arg.mode.validator = ThumbnailMode_validator
ThumbnailV2Arg.quality.validator = ThumbnailQuality_validator
ThumbnailV2Arg.exclude_media_info.validator = bv.Nullable(bv.Boolean())
ThumbnailV2Arg.preserve_transparency.validator = bv.Boolean()
ThumbnailV2Arg._all_field_names_ = set(
[
"resource",
"format",
"size",
"mode",
"exclude_media_info",
"preserve_transparency",
]
)
ThumbnailV2Arg._all_fields_ = [
Expand All @@ -14766,6 +14792,7 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
("size", ThumbnailV2Arg.size.validator),
("mode", ThumbnailV2Arg.mode.validator),
("exclude_media_info", ThumbnailV2Arg.exclude_media_info.validator),
("preserve_transparency", ThumbnailV2Arg.preserve_transparency.validator),
]
ThumbnailV2Arg._all_internal_field_names_ = set(["quality"])
ThumbnailV2Arg._all_internal_fields_ = [("quality", ThumbnailV2Arg.quality.validator)]
Expand All @@ -14777,6 +14804,7 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
ThumbnailV2Error._conversion_error_validator = bv.Void()
ThumbnailV2Error._access_denied_validator = bv.Void()
ThumbnailV2Error._not_found_validator = bv.Void()
ThumbnailV2Error._unsupported_output_format_validator = bv.Void()
ThumbnailV2Error._other_validator = bv.Void()
ThumbnailV2Error._tagmap = {
"path": ThumbnailV2Error._path_validator,
Expand All @@ -14786,6 +14814,7 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
"conversion_error": ThumbnailV2Error._conversion_error_validator,
"access_denied": ThumbnailV2Error._access_denied_validator,
"not_found": ThumbnailV2Error._not_found_validator,
"unsupported_output_format": ThumbnailV2Error._unsupported_output_format_validator,
"other": ThumbnailV2Error._other_validator,
}

Expand All @@ -14795,6 +14824,7 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
ThumbnailV2Error.conversion_error = ThumbnailV2Error("conversion_error")
ThumbnailV2Error.access_denied = ThumbnailV2Error("access_denied")
ThumbnailV2Error.not_found = ThumbnailV2Error("not_found")
ThumbnailV2Error.unsupported_output_format = ThumbnailV2Error("unsupported_output_format")
ThumbnailV2Error.other = ThumbnailV2Error("other")

UnlockFileArg.path.validator = WritePathOrId_validator
Expand Down Expand Up @@ -15349,6 +15379,7 @@ def _process_custom_annotations(self, annotation_type, field_path, processor):
ThumbnailV2Arg.size.default = ThumbnailSize.w64h64
ThumbnailV2Arg.mode.default = ThumbnailMode.strict
ThumbnailV2Arg.quality.default = ThumbnailQuality.quality_80
ThumbnailV2Arg.preserve_transparency.default = False
UploadSessionAppendArg.close.default = False
UploadSessionAppendBatchArgEntry.close.default = False
UploadSessionStartArg.close.default = False
Expand Down
2 changes: 1 addition & 1 deletion spec
Submodule spec updated 1 files
+6 −1 files.stone
Loading