Handlers

PyFDL provides a set of functions to read and write files. These functions will pick the appropriate handler based on path.suffix or handler name.


pyfdl.read_from_file(path, handler_name=None, **handler_kwargs)

Handler agnostic function for producing an FDL from a file. A suitable handler will be chosen based on path or handler_name.

Parameters:
  • path (Union[Path, str]) –

    to the file in question

  • handler_name (Optional[str], default: None ) –

    name of handler to use

  • **handler_kwargs (Optional[Any], default: {} ) –

    arguments passed to handler

Returns:
  • FDL( FDL ) –

pyfdl.read_from_string(s, handler_name='fdl', **handler_kwargs)

Handler agnostic function for producing an FDL based on a string. A suitable handler will be chosen based on handler_name. Defaults to "fdl".

Parameters:
  • s (str) –

    string to convert into an FDL

  • handler_name (str, default: 'fdl' ) –

    name of handler to use

  • **handler_kwargs (Optional[Any], default: {} ) –

    arguments passed to handler

Returns:
  • FDL( FDL ) –

pyfdl.write_to_file(fdl, path, handler_name=None, **handler_kwargs)

Handler agnostic function to write a file based on an FDL. A suitable handler will be chosen based on path or handler_name

Parameters:
  • fdl (FDL) –

    to write

  • path (Union[Path, str]) –

    to file

  • handler_name (Optional[str], default: None ) –

    name of handler to use

  • **handler_kwargs (Optional[Any], default: {} ) –

    arguments passed to handler

pyfdl.write_to_string(fdl, handler_name='fdl', **handler_kwargs)

Handler agnostic function for producing a string representation of an FDL. A suitable handler will be chosen based on handler_name.

Parameters:
  • fdl (FDL) –

    to write

  • handler_name (str, default: 'fdl' ) –

    name of hanlder to use

  • **handler_kwargs (Optional[Any], default: {} ) –

    arguments passed to handler

Returns:

FDLHandler

This is the built-in handler for reading and writing fdl files. No need to call this directly. Use the functions above.

pyfdl.handlers.fdl_handler

FDLHandler()

The default built-in FDL handler. Takes care of reading and writing FDL files

read_from_file(path, validate=True)

Read an FDL from a file.

Parameters:
  • path (Path) –

    to fdl file

  • validate (bool, default: True ) –

    validate incoming json with jsonschema

Raises:
  • ValidationError

    if the contents doesn't follow the spec

Returns:
  • FDL( FDL ) –

read_from_string(s, validate=True)

Read an FDL from a string.

Parameters:
  • s (str) –

    string representation of an FDL

  • validate (bool, default: True ) –

    validate incoming json with jsonschema

Raises:
  • ValidationError

    if the contents doesn't follow the spec

Returns:
  • FDL( FDL ) –

write_to_file(fdl, path, validate=True, indent=2)

Dump an FDL to a file.

Parameters:
  • fdl (FDL) –

    object to serialize

  • path (Path) –

    path to store fdl file

  • validate (bool, default: True ) –

    validate outgoing json with jsonschema

  • indent (Union[int, None], default: 2 ) –

    amount of spaces

Raises:
  • ValidationError

    if the contents doesn't follow the spec

write_to_string(fdl, validate=True, indent=2)

Dump an FDL to string

Parameters:
  • fdl (FDL) –

    object to serialize

  • validate (bool, default: True ) –

    validate outgoing json with jsonschema

  • indent (Union[int, None], default: 2 ) –

    amount of spaces

Raises:
  • ValidationError

    if the contents doesn't follow the spec

Returns:
  • string( str ) –

    representation of the resulting json

register_plugin(registry)

Mandatory function to register handler in the registry. Called by the PluginRegistry itself.

Parameters:
  • registry (PluginRegistry) –

    The PluginRegistry passes itself to this function