(payload)
return Scrap(name=payload.get("name"), data=payload.get("data"), encoder=payload.get("encoder"))
Translates data output format to a scrap
Translates data output format to a scrap
Translates data output format to a scrap
def payload_to_scrap(payload):
    """Translates data output format to a scrap"""
    if "version" not in payload:
        raise ScrapbookDataException(
            "Scrap payload (name={}) has no version indicator. "
            "This scrap is invalid and cannot be loaded".format(payload.get("name", "None"))
        )
    if payload["version"] > LATEST_SCRAP_VERSION:
        logger.warning(
            "Scrap being loaded was saved with a later payload version ({version})"
            "than is known by this version of scrapbook ({latest_version}). "
            "Upgrade scrapbook to ensure data is being loaded as intended".format(
                version=payload["version"], latest_version=LATEST_SCRAP_VERSION
            )
        )
    else:
        try:
            json_validate(payload, scrap_schema(payload["version"]))
        except ValidationError as e:
            raise ScrapbookDataException(
                "Scrap payload (name={name}) contents do not conform to required "
                "type structures: {error}".format(name=payload.get("name", "None"), error=str(e)),
                [e],
            )
    # If future schema versions would require further manipulation
    # then implement various version loaders here
    return Scrap(name=payload.get("name"), data=payload.get("data"), encoder=payload.get("encoder"))
def payload_to_scrap ( payload ) : if "version" not in payload : raise ScrapbookDataException ( "Scrap payload (name={}) has no version indicator. " "This scrap is invalid and cannot be loaded" . format ( payload . get ( "name" , "None" ) ) ) if payload [ "version" ] > LATEST_SCRAP_VERSION : logger . warning ( "Scrap being loaded was saved with a later payload version ({version})" "than is known by this version of scrapbook ({latest_version}). " "Upgrade scrapbook to ensure data is being loaded as intended" . format ( version = payload [ "version" ] , latest_version = LATEST_SCRAP_VERSION ) ) else : try : json_validate ( payload , scrap_schema ( payload [ "version" ] ) ) except ValidationError as e : raise ScrapbookDataException ( "Scrap payload (name={name}) contents do not conform to required " "type structures: {error}" . format ( name = payload . get ( "name" , "None" ) , error = str ( e ) ) , [ e ] , ) # If future schema versions would require further manipulation # then implement various version loaders here return Scrap ( name = payload . get ( "name" ) , data = payload . get ( "data" ) , encoder = payload . get ( "encoder" ) )