Skip to content

Implement from_object/from_string method in Metadata class #1336

Closed

Description

@sechkova

Description of feature request:
Implement a class method in Metadata class, similar to the existing from_file method but taking a file object as an argument.

See #1304 for context.

Activity

  1. added
    experimental-clientItems related to the development of a new client (see milestone/8 and theexperimental-client branch)
    on Apr 7, 2021
  2. added this to the Client Refactor milestone on Apr 7, 2021
  3. jku commented on Apr 7, 2021

    @jku
    Member

    I assume this is useful because client does not write new metadata to disk before it's verified so at that point there's only a file-like object but we want to instantiate the Metadata to verify it is correct?

    I guess the other alternative to from_object() is from_string() (and client would then call from_string(tmp_file.read())). I don't think it's clearly better just thinking out loud.

  4. sechkova commented on Apr 7, 2021

    @sechkova
    ContributorAuthor

    I assume this is useful because client does not write new metadata to disk before it's verified so at that point there's only a file-like object but we want to instantiate the Metadata to verify it is correct?

    Yes, exactly.

    I guess the other alternative to from_object() is from_string() (and client would then call from_string(tmp_file.read())). I don't think it's clearly better just thinking out loud.

    You don't like a function signature with the vague definition of a file object? :)
    String would be ok, raw bytes too, no need to be a file object with its associated methods.

    Now that a separate serialisation was implemented, all we need is basically a method that calls deserialize.

  5. sechkova commented on Apr 7, 2021

    @sechkova
    ContributorAuthor

    Something like the existing from_file but without the actual file read from the file system:

      @classmethod
       def from_string/from_bytes/from_raw(
           cls,
           raw_data: str/bytes,
           deserializer: Optional[MetadataDeserializer] = None
       ) -> "Metadata":
    
           if deserializer is None:
               deserializer = JSONDeserializer()
    
           return deserializer.deserialize(raw_data)
  6. added
    good first issueBite-sized items for first time contributors
    and removed
    experimental-clientItems related to the development of a new client (see milestone/8 and theexperimental-client branch)
    on Apr 13, 2021
  7. jku commented on Apr 16, 2021

    @jku
    Member

    looks good to me -- str seems to make sense as type to me

  8. changed the title [-]Implement from_object method in Metadata class[/-] [+]Implement from_object/from_string method in Metadata class[/+] on Apr 16, 2021
  9. self-assigned this
    on Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions