InstructionSVGCache Module

This module provides functionality to cache instruction SVGs.

class knittingpattern.convert.InstructionSVGCache.InstructionSVGCache(instruction_to_svg=None)[source]

Bases: object

This class is a cache for SVG instructions.

If you plan too use only instruction_to_svg_dict(), you are save to replace a knittingpsttern.convert.InstructionToSVG.InstructionToSVG with this cache to get faster results.

__init__(instruction_to_svg=None)[source]

Create the InstructionSVGCache.

Parameters:instruction_to_svg – an InstructionToSVG object. If None is given, the default_instructions_to_svg is used.
__weakref__

list of weak references to the object (if defined)

get_instruction_id(instruction_or_id)[source]

The id that identifies the instruction in this cache.

Parameters:instruction_or_id – an instruction or an instruction id
Returns:a hashable object
Return type:tuple
instruction_to_svg_dict(instruction_or_id, copy_result=True)[source]

Return the SVG dict for the SVGBuilder.

Parameters:
Return type:

dict

The result is cached.

to_svg(instruction_or_id, i_promise_not_to_change_the_result=False)[source]

Return the SVG for an instruction.

Parameters:
  • instruction_or_id – either an Instruction or an id returned by get_instruction_id()
  • i_promise_not_to_change_the_result (bool) –
    • False: the result is copied, you can alter it.
    • True: the result is directly from the cache. If you change the result, other calls of this function get the changed result.
Returns:

an SVGDumper

Return type:

knittingpattern.Dumper.SVGDumper

knittingpattern.convert.InstructionSVGCache.default_instruction_svg_cache()[source]

Return the default InstructionSVGCache.

Return type:knittingpattern.convert.InstructionSVGCache.InstructionSVGCache
knittingpattern.convert.InstructionSVGCache.default_svg_cache()

Return the default InstructionSVGCache.

Return type:knittingpattern.convert.InstructionSVGCache.InstructionSVGCache