1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from blockdiag import plugins171819class NodeAttributes(plugins.NodeHandler):20 def __init__(self, diagram, **kwargs):21 super(NodeAttributes, self).__init__(diagram, **kwargs)2223 node_klass = diagram._DiagramNode24 for name, label in kwargs.items():25 if label is None:26 label = name27 if name not in node_klass.desctable:28 node_klass.desctable.insert(-1, name)2930 node_klass.attrname[name] = label31 if not hasattr(node_klass, name):32 setattr(node_klass, name, None)333435def setup(self, diagram, **kwargs):36 plugins.install_node_handler(NodeAttributes(diagram, **kwargs))