2018-09-17 17:13:30 -03:00
|
|
|
from copy import deepcopy
|
2019-02-26 18:26:15 -03:00
|
|
|
from lbrynet.schema.proto2 import source_pb2 as source_pb
|
2019-02-28 18:21:42 -03:00
|
|
|
from lbrynet.schema.legacy_schema_v1 import SOURCE_TYPES, LBRY_SD_HASH_LENGTH, VERSION_MAP
|
2019-03-05 23:37:44 -03:00
|
|
|
from lbrynet.schema.baseschema import Schema
|
2018-09-17 17:31:44 -03:00
|
|
|
from lbrynet.schema.error import InvalidSourceHashLength
|
2018-09-17 17:13:30 -03: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)
|