def canonicalize(self, include_nodes=True, sorted=False):
node_class = Directory if self.dir else Value<EOL>kwargs = {attr: getattr(self, attr) for attr in node_class.__slots__}<EOL>if self.dir:<EOL><INDENT>if include_nodes:<EOL><INDENT>nodes = [node.canonicalize() for node in<EOL>six.viewvalues(kwargs['<STR_LIT>'])]<EOL>if sorted:<EOL><INDENT>nodes.sort(key=lambda n: n.key)<EOL><DEDENT>kwargs['<STR_LIT>'] = nodes<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = []<EOL><DEDENT><DEDENT>return node_class(**kwargs)<EOL>
Generates a canonical :class:`etc.Node` object from this mock node.