From 45c2132fbd3e0621c403496b51b5b56e1c174a22 Mon Sep 17 00:00:00 2001 From: Alex Cabrera Date: Fri, 1 Nov 2024 11:25:55 -0700 Subject: [PATCH] udpates --- streaming/base/format/mds/encodings.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/streaming/base/format/mds/encodings.py b/streaming/base/format/mds/encodings.py index 70466d170..ed2bc6ca9 100644 --- a/streaming/base/format/mds/encodings.py +++ b/streaming/base/format/mds/encodings.py @@ -467,12 +467,14 @@ class JPEG(Encoding): """Store PIL image as JPEG. Optionally specify quality.""" def __init__(self, quality: int = 75): + if not isinstance(quality, int): + raise ValueError('JPEG quality must be an integer') if not (0 <= quality <= 100): raise ValueError('JPEG quality must be between 0 and 100') self.quality = quality @classmethod - def from_str(cls, text: str) -> Self: + def from_str(cls, config: str) -> Self: """Parse this encoding from string. Args: @@ -481,17 +483,10 @@ def from_str(cls, text: str) -> Self: Returns: Self: The initialized Encoding. """ - args = text.split(':') if text else [] - if len(args) not in {0, 1}: - raise ValueError('JPEG encoding string must have 0 or 1 arguments') - if len(args) == 1: - try: - quality = int(args[0]) - except ValueError: - raise ValueError('JPEG quality must be an integer between 0 and 100') + if config == '': + return cls() else: - quality = 75 - return cls(quality) + return cls(int(config)) def encode(self, obj: Image.Image) -> bytes: self._validate(obj, Image.Image)