Skip to content

Commit

Permalink
more smart way
Browse files Browse the repository at this point in the history
  • Loading branch information
lubaskinc0de committed Apr 6, 2024
1 parent bd7f588 commit 8f3dbe4
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/adaptix/_internal/morphing/concrete_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,10 @@ def bytes_base64_loader(data):


@for_predicate(BytesIO)
class BytesIOBase64Provider(LoaderProvider, DumperProvider):
class BytesIOBase64Provider(BytesBase64Provider):
def _provide_loader(self, mediator: Mediator, request: LoaderRequest) -> Loader:
def bytes_io_base64_loader(data):
try:
encoded = data.encode("ascii")
except AttributeError:
raise TypeLoadError(str, data)

if not B64_PATTERN.fullmatch(encoded):
raise ValueLoadError("Bad base64 string", data)

try:
return BytesIO(a2b_base64(encoded))
except binascii.Error as e:
raise ValueLoadError(str(e), data)

return bytes_io_base64_loader
bytes_io_base64_loader = super()._provide_loader(mediator, request)
return lambda x: BytesIO(bytes_io_base64_loader(x))

def _provide_dumper(self, mediator: Mediator, request: DumperRequest) -> Dumper:
def bytes_io_base64_dumper(data: BytesIO):
Expand Down

0 comments on commit 8f3dbe4

Please sign in to comment.