load_and_dump Module

convinience methods for conversion

Best to use decorate_load_and_dump().

knittingpattern.convert.load_and_dump.load_and_dump(create_loader, create_dumper, load_and_dump_)[source]
Returns:

a function that has the doc string of load_and_dump_ additional arguments to this function are passed on to load_and_dump_.

Parameters:
  • create_loader – a loader, e.g. knittingpattern.Loader.PathLoader
  • create_dumper – a dumper, e.g. knittingpattern.Dumper.ContentDumper
  • load_and_dump_ – a function to call with the loaded content. The arguments to both, create_dumper and, create_loader will be passed to load_and_dump_. Any additional arguments to the return value are also passed to load_and_dump_. The return value of load_and_dump_ is passed back to the Dumper.
knittingpattern.convert.load_and_dump.decorate_load_and_dump(create_loader, create_dumper)[source]

Same as load_and_dump() but returns a function to enable decorator syntax.

Examples:

@decorate_load_and_dump(ContentLoader, JSONDumper)
def convert_from_loader_to_dumper(loaded_stuff, other="arguments"):
    # convert
    return converted_stuff

@decorate_load_and_dump(PathLoader, lambda dump: ContentDumper(dump,
    encoding=None))
def convert_from_loader_to_dumper(loaded_stuff, to_file):
    # convert
    to_file.write(converted_stuff)