2018-09-17 22:13:30 +02:00
|
|
|
from copy import deepcopy
|
2019-02-26 22:26:15 +01:00
|
|
|
from lbrynet.schema.proto2 import source_pb2 as source_pb
|
2018-09-17 22:31:44 +02:00
|
|
|
from lbrynet.schema.schema import SOURCE_TYPES, LBRY_SD_HASH_LENGTH, VERSION_MAP
|
|
|
|
from lbrynet.schema.schema.schema import Schema
|
|
|
|
from lbrynet.schema.error import InvalidSourceHashLength
|
2018-09-17 22:13:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Source(Schema):
|
|
|
|
@classmethod
|
|
|
|
def load(cls, message):
|
|
|
|
_source = deepcopy(message)
|
|
|
|
sd_hash = _source.pop('source')
|
|
|
|
assert len(sd_hash) == LBRY_SD_HASH_LENGTH, InvalidSourceHashLength(len(sd_hash))
|
|
|
|
_message_pb = source_pb.Source()
|
|
|
|
_message_pb.version = VERSION_MAP[_source.pop("version")]
|
|
|
|
_message_pb.sourceType = SOURCE_TYPES[_source.pop('sourceType')]
|
|
|
|
_message_pb.source = sd_hash
|
|
|
|
_message_pb.contentType = _source.pop('contentType')
|
|
|
|
return cls._load(_source, _message_pb)
|