File: base.py

package info (click to toggle)
python-ledger-bitcoin 0.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: python: 9,357; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from io import BytesIO
from ..base import EmbitBase


class DescriptorBase(EmbitBase):
    """
    Descriptor is purely text-based, so parse/serialize do
    the same as from/to_string, just returning ascii bytes
    instead of ascii string.
    """

    @classmethod
    def from_string(cls, s: str, *args, **kwargs):
        return cls.parse(s.encode(), *args, **kwargs)

    def serialize(self, *args, **kwargs) -> bytes:
        stream = BytesIO()
        self.write_to(stream)
        return stream.getvalue()

    def to_string(self, *args, **kwargs) -> str:
        return self.serialize().decode()