python-benedict/benedict/serializers/plist.py

27 lines
708 B
Python

import plistlib
from benedict.serializers.abstract import AbstractSerializer
class PListSerializer(AbstractSerializer):
"""
This class describes a p list serializer.
https://docs.python.org/3/library/plistlib.html
"""
def __init__(self):
super().__init__(
extensions=[
"plist",
],
)
def decode(self, s, **kwargs):
kwargs.setdefault("fmt", plistlib.FMT_XML)
encoding = kwargs.pop("encoding", "utf-8")
return plistlib.loads(s.encode(encoding), **kwargs)
def encode(self, d, **kwargs):
encoding = kwargs.pop("encoding", "utf-8")
return plistlib.dumps(d, **kwargs).decode(encoding)