22 lines
580 B
Python
22 lines
580 B
Python
import json
|
|
|
|
from pyinfra.parser.blob_parser import BlobParser, ParsingError
|
|
from pyinfra.server.packing import string_to_bytes
|
|
|
|
|
|
class JsonBlobParser(BlobParser):
|
|
|
|
def parse(self, data: bytes):
|
|
try:
|
|
data = data.decode()
|
|
data = json.loads(data)
|
|
except (UnicodeDecodeError, json.JSONDecodeError, AttributeError) as err:
|
|
raise ParsingError from err
|
|
|
|
try:
|
|
data["data"] = string_to_bytes(data["data"])
|
|
except (KeyError, TypeError) as err:
|
|
raise ParsingError from err
|
|
|
|
return data
|