ncdiff.Model class

class ncdiff.Model(tree)[source]

Bases: object

Abstraction of a YANG module. It supports str() which returns a string similar to the output of ‘pyang -f tree’.

name

Model name.

Type:str
prefix

Prefix of the model.

Type:str
prefixes

All prefixes used in the model. Dictionary keys are prefixes, and values are URLs.

Type:dict
url

URL of the model.

Type:str
urls

All URLs used in the model. Dictionary keys are URLs, and values are prefixes.

Type:dict
tree

The model tree as an Element object.

Type:Element
roots

All root nodes of the model. Each node is an Element object.

Type:list
width

This is used to facilitate pretty print of a model. Dictionary keys are nodes in the model tree, and values are indents.

Type:dict

__init__ instantiates a Model instance.

emit_tree(tree)[source]

High-level api: Emit a string presentation of the model.

Parameters:tree (Element) – The model.
Returns:A string presentation of the model that is very similar to the output of ‘pyang -f tree’
Return type:str
emit_children(tree, type='other')[source]

High-level api: Emit a string presentation of a part of the model.

Parameters:
  • tree (Element) – The model.
  • type (str) – Type of model content required. Its value can be ‘other’, ‘rpc’, or ‘notification’.
Returns:

A string presentation of the model that is very similar to the output of ‘pyang -f tree’

Return type:

str

get_width(element)[source]

High-level api: Calculate how much indent is needed for a node.

Parameters:element (Element) – A node in model tree.
Returns:Start position from the left margin.
Return type:int
static get_depth_str(element, type='other')[source]

High-level api: Produce a string that represents tree hierarchy.

Parameters:
  • element (Element) – A node in model tree.
  • type (str) – Type of model content required. Its value can be ‘other’, ‘rpc’, or ‘notification’.
Returns:

A string that represents tree hierarchy.

Return type:

str

static get_flags_str(element)[source]

High-level api: Produce a string that represents the type of a node.

Parameters:element (Element) – A node in model tree.
Returns:A string that represents the type of a node.
Return type:str
get_name_str(element)[source]

High-level api: Produce a string that represents the name of a node.

Parameters:element (Element) – A node in model tree.
Returns:A string that represents the name of a node.
Return type:str
get_datatype_str(element, length)[source]

High-level api: Produce a string that indicates the data type of a node.

Parameters:
  • element (Element) – A node in model tree.
  • length (int) – String length that has been consumed.
Returns:

A string that indicates the data type of a node.

Return type:

str

prefix_to_url(id)[source]

High-level api: Convert an identifier from prefix:tagname notation to {namespace}tagname notation. If the identifier does not have a prefix, it is assumed that the whole identifier is a tag name.

Parameters:id (str) – Identifier in prefix:tagname notation.
Returns:Identifier in {namespace}tagname notation.
Return type:str
url_to_prefix(id)[source]

High-level api: Convert an identifier from {namespace}tagname notation to prefix:tagname notation. If the identifier does not have a namespace, it is assumed that the whole identifier is a tag name.

Parameters:id (str) – Identifier in {namespace}tagname notation.
Returns:Identifier in prefix:tagname notation.
Return type:str
remove_model_prefix(id)[source]

High-level api: If prefix is the model prefix, return tagname without prefix. If prefix is not the model prefix, simply return the identifier without modification.

Parameters:id (str) – Identifier in prefix:tagname notation.
Returns:Identifier in prefix:tagname notation if prefix is not the model prefix. Or identifier in tagname notation if prefix is the model prefix.
Return type:str
convert_tree()[source]

High-level api: Convert cxml tree to an internal schema tree.

Parameters:None
Returns:This is the tree after convertion.
Return type:Element