Parser Module

In this module you can find the parsing of knitting pattern structures.

class knittingpattern.Parser.Parser(specification)[source]

Bases: object

Parses a knitting pattern set and anything in it.


Create a parser with a specification.

Parameters:specification – the types and classes to use for the resulting object structure, preferably a knittingpattern.ParsingSpecification.ParsingSpecification

list of weak references to the object (if defined)

instruction_in_row(row, specification)[source]

Parse an instruction.

  • row – the row of the instruction
  • specification – the specification of the instruction

the instruction in the row


Parse a knitting pattern set.

Parameters:value (dict) – the specification of the knitting pattern set
Return type:knittingpattern.KnittingPatternSet.KnittingPatternSet
Raises:knittingpattern.KnittingPatternSet.ParsingError – if value does not fulfill the specification.
new_pattern(id_, name, rows=None)[source]

Create a new knitting pattern.

If rows is None it is replaced with the new_row_collection().


Create a new row with an id.

Parameters:id_ – the id of the row
Returns:a row
Return type:knittingpattern.Row.Row

Create a new row collection.

Returns:a new specified row collection for the knitting pattern
knittingpattern.Parser.ID = 'id'

the id of a row, an instruction or a pattern

knittingpattern.Parser.NAME = 'name'

the name of a row

knittingpattern.Parser.TYPE = 'type'

the type of an instruction or the knitting pattern set

knittingpattern.Parser.VERSION = 'version'

the version of a knitting pattern set

knittingpattern.Parser.INSTRUCTIONS = 'instructions'

the instructions in a row

knittingpattern.Parser.SAME_AS = 'same as'

pointer to a inherit from

knittingpattern.Parser.PATTERNS = 'patterns'

the patterns in the knitting pattern set

knittingpattern.Parser.ROWS = 'rows'

the rows inside a pattern

knittingpattern.Parser.CONNECTIONS = 'connections'

the connections in a pattern

knittingpattern.Parser.FROM = 'from'

the position and row a connection comes from

knittingpattern.Parser.TO = 'to'

the position and row a connection goes to

knittingpattern.Parser.START = 'start'

the mesh index the connection starts at

knittingpattern.Parser.DEFAULT_START = 0

the default mesh index the connection starts at if none is given

knittingpattern.Parser.MESHES = 'meshes'

the number of meshes of a connection

knittingpattern.Parser.COMMENT = 'comment'

a comment of a row, an instruction, anything

exception knittingpattern.Parser.ParsingError[source]

Bases: ValueError

Mistake in the provided object to parse.

This Error is raised if there is an error during the parsing for Parser.


list of weak references to the object (if defined)


The parser with a default specification.

Returns:a parser using a knittingpattern.ParsingSpecification.DefaultSpecification
Return type:knittingpattern.Parser.Parser