Skip to content

Commit

Permalink
Added deserializer for Bytes field
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed May 2, 2020
1 parent 66f1617 commit 2d0748e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions labthings/server/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Marshmallow fields
from marshmallow import ValidationError

from base64 import b64decode

from marshmallow.fields import (
Field,
Raw,
Expand Down Expand Up @@ -75,3 +78,11 @@ def _validate(self, value):

if value is None or value == b"":
raise ValidationError("Invalid value")

def _deserialize(self, value, attr, data, **kwargs):
if isinstance(value, bytes):
return value
if isinstance(value, str):
return b64decode(value)
else:
raise self.make_error("invalid", input=value)

0 comments on commit 2d0748e

Please sign in to comment.