Example #1
0
 def __pnmldump__(self):
     """
     >>> p = Place('p', pos=(1, 2))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <graphics>
        <position x="1" y="2"/>
       </graphics>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     try:
         gfx = t.child("graphics")
     except SnakesError:
         gfx = Tree("graphics", None)
         t.add_child(gfx)
     gfx.add_child(
         Tree("position", None, x=str(self.pos.x), y=str(self.pos.y)))
     return t
Example #2
0
 def __pnmldump__(self):
     """
     >>> p = Place('p')
     >>> p.label(foo='bar', spam=42)
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <label name="foo">
        <object type="str">
         bar
        </object>
       </label>
       <label name="spam">
        <object type="int">
         42
        </object>
       </label>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     if hasattr(self, "_labels"):
         for key, val in self._labels.items():
             t.add_child(
                 Tree("label", None, Tree.from_obj(val), name=key))
     return t
Example #3
0
 def __pnmldump__(self):
     """
     >>> Symbol('egg', 'spam').__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="egg">
       <object type="str">
        spam
       </object>
      </symbol>
     </pnml>
     >>> Symbol('foo').__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="foo"/>
     </pnml>
     >>> Symbol('bar', False).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="bar">
       <object type="bool">
        False
       </object>
      </symbol>
     </pnml>
     """
     if self.name == self._export:
         children = []
     else:
         children = [Tree.from_obj(self._export)]
     return Tree(self.__pnmltag__, None, *children, **dict(name=self.name))
Example #4
0
 def __pnmldump__(self):
     """
     >>> t = Transition('t')
     >>> t.label(foo='bar', spam=42)
     >>> t.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <transition id="t">
       <label name="foo">
        <object type="str">
         bar
        </object>
       </label>
       <label name="spam">
        <object type="int">
         42
        </object>
       </label>
      </transition>
     </pnml>
     """
     t = module.Transition.__pnmldump__(self)
     if hasattr(self, "_labels"):
         for key, val in self._labels.items():
             t.add_child(
                 Tree("label", None, Tree.from_obj(val), name=key))
     return t
Example #5
0
 def __pnmldump__ (self) :
     """
     >>> p = Place('p', pos=(1, 2))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <graphics>
        <position x="1" y="2"/>
       </graphics>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     try :
         gfx = t.child("graphics")
     except SnakesError :
         gfx = Tree("graphics", None)
         t.add_child(gfx)
     gfx.add_child(Tree("position", None,
                        x=str(self.pos.x),
                        y=str(self.pos.y)))
     return t
Example #6
0
        def __pnmldump__(self):
            t = module.Transition.__pnmldump__(self)

            t.add_child(Tree("min_time", None, Tree.from_obj(self.min_time)))

            if self.max_time is not None:
                t.add_child(
                    Tree("max_time", None, Tree.from_obj(self.max_time)))

            return t
Example #7
0
 def __pnmldump__(self):
     """
     >>> MultiSet([1, 2, 3, 4, 1, 2]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <multiset>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
      </multiset>
     </pnml>
     """
     nodes = []
     for value in hdict.__iter__(self):
         nodes.append(
             Tree("item", None, Tree("value", None, Tree.from_obj(value)),
                  Tree("multiplicity", str(self[value]))))
     return Tree(self.__pnmltag__, None, *nodes)
Example #8
0
 def __pnmldump__(self):
     """
     >>> Cluster(['a', 'b'],
     ...         [Cluster(['1', '2'],
     ...                  [Cluster(['A'])]),
     ...          Cluster(['3', '4', '5'],
     ...                  [Cluster(['C', 'D'])])]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <clusters>
       <node>
       ...
       </node>
       <node>
       ...
       </node>
       <clusters>
       ...
       </clusters>
      </clusters>
     </pnml>
     """
     result = Tree(self.__pnmltag__, None)
     for node in self._nodes:
         result.add_child(Tree("node", node))
     for child in self._children:
         result.add_child(Tree.from_obj(child))
     return result
Example #9
0
 def __pnmldump__(self):
     """
     >>> m = MultiAction([Action('a', True, [Variable('x')]),
     ...                  Action('b', False, [Variable('y'), Value(2)])])
     >>> Transition('t', actions=m).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <transition id="t">
       <multiaction>
        <action name="a" send="True">
         <variable>x</variable>
        </action>
        <action name="b" send="False">
         <variable>y</variable>
         <value>
          <object type="int">2</object>
         </value>
        </action>
       </multiaction>
      </transition>
     </pnml>
     """
     result = module.Transition.__pnmldump__(self)
     result.add_child(Tree.from_obj(self.actions))
     return result
Example #10
0
 def __pnmldump__ (self) :
     """
     >>> p = Place('p', status=Status('foo', 42))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <status>
        <name>
         foo
        </name>
        <value>
         <object type="int">
          42
         </object>
        </value>
       </status>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     t.add_child(Tree.from_obj(self.status))
     return t
Example #11
0
 def __pnmldump__ (self) :
     """
     >>> Symbol('egg', 'spam').__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="egg">
       <object type="str">spam</object>
      </symbol>
     </pnml>
     >>> Symbol('foo').__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="foo"/>
     </pnml>
     >>> Symbol('bar', False).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <symbol name="bar">
       <object type="bool">False</object>
      </symbol>
     </pnml>
     """
     if self.name == self._export :
         children = []
     else :
         children = [Tree.from_obj(self._export)]
     return Tree(self.__pnmltag__, None, *children, **dict(name=self.name))
Example #12
0
    def __pnmldump__ (self) :
        """Dumps a substitution to a PNML tree

        >>> Substitution(x=1, y=2).__pnmldump__()
        <?xml version="1.0" encoding="utf-8"?>
        <pnml>
         <substitution>
          <item>
           <name>...</name>
           <value>
            <object type="int">...</object>
           </value>
          </item>
          <item>
           <name>...</name>
           <value>
            <object type="int">...</object>
           </value>
          </item>
         </substitution>
        </pnml>

        @return: PNML representation
        @rtype: `snakes.pnml.Tree`
        """
        nodes = []
        for name, value in self._dict.items() :
            nodes.append(Tree("item", None,
                              Tree("name", name),
                              Tree("value", None,
                                   Tree.from_obj(value))))
        return Tree(self.__pnmltag__, None, *nodes)
Example #13
0
 def __pnmldump__ (self) :
     """
     >>> p = Place('p')
     >>> p.label(foo='bar', spam=42)
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <label name="spam">
        <object type="int">42</object>
       </label>
       <label name="foo">
        <object type="str">bar</object>
       </label>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     if hasattr(self, "_labels") :
         for key, val in self._labels.items() :
             t.add_child(Tree("label", None,
                              Tree.from_obj(val),
                              name=key))
     return t
Example #14
0
 def __pnmldump__ (self) :
     """
     >>> m = MultiAction([Action('a', True, [Variable('x')]),
     ...                  Action('b', False, [Variable('y'), Value(2)])])
     >>> Transition('t', actions=m).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <transition id="t">
       <multiaction>
        <action name="a" send="True">
         <variable>x</variable>
        </action>
        <action name="b" send="False">
         <variable>y</variable>
         <value>
          <object type="int">2</object>
         </value>
        </action>
       </multiaction>
      </transition>
     </pnml>
     """
     result = module.Transition.__pnmldump__(self)
     result.add_child(Tree.from_obj(self.actions))
     return result
Example #15
0
 def __pnmldump__ (self) :
     """
     >>> t = Transition('t')
     >>> t.label(foo='bar', spam=42)
     >>> t.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <transition id="t">
       <label name="foo">
        <object type="str">
         bar
        </object>
       </label>
       <label name="spam">
        <object type="int">
         42
        </object>
       </label>
      </transition>
     </pnml>
     """
     t = module.Transition.__pnmldump__(self)
     if hasattr(self, "_labels") :
         for key, val in self._labels.items() :
             t.add_child(Tree("label", None,
                              Tree.from_obj(val),
                              name=key))
     return t
Example #16
0
 def __pnmldump__(self):
     """
     >>> p = Place('p', status=Status('foo', 42))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <place id="p">
       <type domain="universal"/>
       <initialMarking>
        <multiset/>
       </initialMarking>
       <status>
        <name>
         foo
        </name>
        <value>
         <object type="int">
          42
         </object>
        </value>
       </status>
      </place>
     </pnml>
     """
     t = module.Place.__pnmldump__(self)
     t.add_child(Tree.from_obj(self.status))
     return t
Example #17
0
 def __pnmlload__(cls, tree):
     """
     >>> t = Action('a', True, [Value(1), Variable('x')]).__pnmldump__()
     >>> Action.__pnmlload__(t)
     Action('a', True, [Value(1), Variable('x')])
     """
     params = [Tree.to_obj(child) for child in tree.children]
     return cls(tree["name"], tree["send"] == "True", params)
Example #18
0
 def __pnmlload__ (cls, tree) :
     """
     >>> t = Action('a', True, [Value(1), Variable('x')]).__pnmldump__()
     >>> Action.__pnmlload__(t)
     Action('a', True, [Value(1), Variable('x')])
     """
     params = [Tree.to_obj(child) for child in tree.children]
     return cls(tree["name"], tree["send"] == "True", params)
Example #19
0
 def __pnmldump__(self):
     """
     >>> Action('a', True, [Value(1), Variable('x')]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <action name="a" send="True">
       <value>
        <object type="int">1</object>
       </value>
       <variable>x</variable>
      </action>
     </pnml>
     """
     result = Tree(
         self.__pnmltag__, None, name=self.name, send=str(self.send))
     for param in self.params:
         result.add_child(Tree.from_obj(param))
     return result
Example #20
0
 def __pnmldump__ (self) :
     """
     >>> t = Transition('t', pos=(2, 1))
     >>> t.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <transition id="t">
       <graphics>
        <position x="2" y="1"/>
       </graphics>
      </transition>
     </pnml>
     """
     t = module.Transition.__pnmldump__(self)
     t.add_child(Tree("graphics", None,
                      Tree("position", None,
                           x=str(self.pos.x),
                           y=str(self.pos.y))))
     return t
Example #21
0
 def __pnmldump__ (self) :
     """
     >>> Action('a', True, [Value(1), Variable('x')]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <action name="a" send="True">
       <value>
        <object type="int">1</object>
       </value>
       <variable>x</variable>
      </action>
     </pnml>
     """
     result = Tree(self.__pnmltag__, None,
                   name=self.name,
                   send=str(self.send))
     for param in self.params :
         result.add_child(Tree.from_obj(param))
     return result
Example #22
0
 def __pnmldump__ (self) :
     """
     >>> MultiSet([1, 2, 3, 4, 1, 2]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <multiset>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
       <item>
        <value>
         <object type="int">
         ...
         </object>
        </value>
        <multiplicity>
        ...
        </multiplicity>
       </item>
      </multiset>
     </pnml>
     """
     nodes = []
     for value in hdict.__iter__(self) :
         nodes.append(Tree("item", None,
                           Tree("value", None, Tree.from_obj(value)),
                           Tree("multiplicity", str(self[value]))))
     return Tree(self.__pnmltag__, None, *nodes)
Example #23
0
 def __pnmlload__(cls, tree):
     """
     >>> m = MultiAction([Action('a', True, [Variable('x')]),
     ...                  Action('b', False, [Variable('y'), Value(2)])])
     >>> t = Transition('t', actions=m).__pnmldump__()
     >>> Transition.__pnmlload__(t).actions
     MultiAction([Action('a', True, [Variable('x')]),
                  Action('b', False, [Variable('y'), Value(2)])])
     """
     result = new_instance(cls, module.Transition.__pnmlload__(tree))
     result.actions = Tree.to_obj(tree.child(MultiAction.__pnmltag__))
     return result
Example #24
0
 def __pnmlload__ (cls, tree) :
     """
     >>> m = MultiAction([Action('a', True, [Variable('x')]),
     ...                  Action('b', False, [Variable('y'), Value(2)])])
     >>> t = Transition('t', actions=m).__pnmldump__()
     >>> Transition.__pnmlload__(t).actions
     MultiAction([Action('a', True, [Variable('x')]),
                  Action('b', False, [Variable('y'), Value(2)])])
     """
     result = new_instance(cls, module.Transition.__pnmlload__(tree))
     result.actions = Tree.to_obj(tree.child(MultiAction.__pnmltag__))
     return result
Example #25
0
    def __pnmldump__ (self) :
        """Dumps a substitution to a PNML tree

        >>> Substitution(x=1, y=2).__pnmldump__()
        <?xml version="1.0" encoding="utf-8"?>
        <pnml>
         <substitution>
          <item>
           <name>
           ...
           </name>
           <value>
            <object type="int">
            ...
            </object>
           </value>
          </item>
          <item>
           <name>
           ...
           </name>
           <value>
            <object type="int">
            ...
            </object>
           </value>
          </item>
         </substitution>
        </pnml>

        @return: PNML representation
        @rtype: `snakes.pnml.Tree`
        """
        nodes = []
        for name, value in self._dict.items() :
            nodes.append(Tree("item", None,
                              Tree("name", name),
                              Tree("value", None,
                                   Tree.from_obj(value))))
        return Tree(self.__pnmltag__, None, *nodes)
Example #26
0
 def run (self) :
     while True :
         data, address = self.recvfrom()
         data = data.strip()
         if self._verbose :
             print("# query from %s:%u" % address)
         try :
             if self._verbose > 1 :
                 print(data)
             res = loads(data).run(self._env)
             if res is None :
                 res = Tree("answer", None, status="ok")
             else :
                 res = Tree("answer", None, Tree.from_obj(res),
                            status="ok")
         except :
             cls, val, tb = sys.exc_info()
             res = Tree("answer", str(val).strip(),
                        error=cls.__name__, status="error")
             if self._verbose > 1 :
                 print("# error")
                 for entry in traceback.format_exception(cls, val, tb) :
                     for line in entry.splitlines() :
                         print("## %s" % line)
         if self._verbose :
             if self._verbose > 1 :
                 print("# answer")
                 print(res.to_pnml())
             elif res["status"] == "error" :
                 print("# answer: %s: %s" % (res["error"], res.data))
             else :
                 print("# answer: %s" % res["status"])
         self.sendto(res.to_pnml(), address)
Example #27
0
 def __pnmldump__ (self) :
     """
     >>> Cluster(['a', 'b'],
     ...         [Cluster(['1', '2'],
     ...                  [Cluster(['A'])]),
     ...          Cluster(['3', '4', '5'],
     ...                  [Cluster(['C', 'D'])])]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <clusters>
       <node>
       ...
       </node>
       <node>
       ...
       </node>
       <clusters>
       ...
       </clusters>
      </clusters>
     </pnml>
     """
     result = Tree(self.__pnmltag__, None)
     for node in self._nodes :
         result.add_child(Tree("node", node))
     for child in self._children :
         result.add_child(Tree.from_obj(child))
     return result
Example #28
0
 def __pnmldump__(self):
     """
     >>> MultiAction([Action('a', True, [Variable('x')]),
     ...              Action('b', False, [Variable('y'), Value(2)])
     ...             ]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <multiaction>
       <action name="a" send="True">
        <variable>x</variable>
       </action>
       <action name="b" send="False">
        <variable>y</variable>
        <value>
         <object type="int">2</object>
        </value>
       </action>
      </multiaction>
     </pnml>
     """
     return Tree(self.__pnmltag__, None,
                 *(Tree.from_obj(action) for action in self._actions))
Example #29
0
    def __pnmldump__(self):
        """Dump a `Status` as a PNML tree

        @return: PNML tree
        @rtype: `pnml.Tree`

        >>> Status('foo', 42).__pnmldump__()
        <?xml version="1.0" encoding="utf-8"?>
        <pnml>...
         <status>
          <name>
           foo
          </name>
          <value>
           <object type="int">
            42
           </object>
          </value>
         </status>
        </pnml>
        """
        return Tree(self.__pnmltag__, None, Tree("name", self._name),
                    Tree("value", None, Tree.from_obj(self._value)))
Example #30
0
 def run(self):
     while True:
         data, address = self.recvfrom()
         data = data.strip()
         if self._verbose:
             print("# query from %s:%u" % address)
         try:
             if self._verbose > 1:
                 print(data)
             res = loads(data).run(self._env)
             if res is None:
                 res = Tree("answer", None, status="ok")
             else:
                 res = Tree("answer",
                            None,
                            Tree.from_obj(res),
                            status="ok")
         except:
             cls, val, tb = sys.exc_info()
             res = Tree("answer",
                        str(val).strip(),
                        error=cls.__name__,
                        status="error")
             if self._verbose > 1:
                 print("# error")
                 for entry in traceback.format_exception(cls, val, tb):
                     for line in entry.splitlines():
                         print("## %s" % line)
         if self._verbose:
             if self._verbose > 1:
                 print("# answer")
                 print(res.to_pnml())
             elif res["status"] == "error":
                 print("# answer: %s: %s" % (res["error"], res.data))
             else:
                 print("# answer: %s" % res["status"])
         self.sendto(res.to_pnml(), address)
Example #31
0
 def __pnmldump__ (self) :
     """
     >>> p = Transition('p', status=Status('foo', 42))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <transition id="p">
       <status>
        <name>foo</name>
        <value>
         <object type="int">42</object>
        </value>
       </status>
      </transition>
     </pnml>
     """
     t = module.Transition.__pnmldump__(self)
     t.add_child(Tree.from_obj(self.status))
     return t
Example #32
0
    def __pnmldump__ (self) :
        """Dump a `Status` as a PNML tree

        @return: PNML tree
        @rtype: `pnml.Tree`

        >>> Status('foo', 42).__pnmldump__()
        <?xml version="1.0" encoding="utf-8"?>
        <pnml>...
         <status>
          <name>foo</name>
          <value>
           <object type="int">42</object>
          </value>
         </status>
        </pnml>
        """
        return Tree(self.__pnmltag__, None,
                    Tree("name", self._name),
                    Tree("value", None, Tree.from_obj(self._value)))
Example #33
0
 def __pnmldump__ (self) :
     """
     >>> MultiAction([Action('a', True, [Variable('x')]),
     ...              Action('b', False, [Variable('y'), Value(2)])
     ...             ]).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <multiaction>
       <action name="a" send="True">
        <variable>x</variable>
       </action>
       <action name="b" send="False">
        <variable>y</variable>
        <value>
         <object type="int">2</object>
        </value>
       </action>
      </multiaction>
     </pnml>
     """
     return Tree(self.__pnmltag__, None,
                 *(Tree.from_obj(action) for action in self._actions))
Example #34
0
 def __pnmldump__(self):
     """
     >>> p = Transition('p', status=Status('foo', 42))
     >>> p.__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>...
      <transition id="p">
       <status>
        <name>
         foo
        </name>
        <value>
         <object type="int">
          42
         </object>
        </value>
       </status>
      </transition>
     </pnml>
     """
     t = module.Transition.__pnmldump__(self)
     t.add_child(Tree.from_obj(self.status))
     return t
Example #35
0
 def __pnmldump__(self):
     """
     >>> Query('set', 'x', 42).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="set">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <object type="int">
         42
        </object>
       </argument>
      </query>
     </pnml>
     >>> Query('test', x=1).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="test">
       <keyword name="x">
        <object type="int">
         1
        </object>
       </keyword>
      </query>
     </pnml>
     >>> Query('test', 'x', 42, y=1).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="test">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <object type="int">
         42
        </object>
       </argument>
       <keyword name="y">
        <object type="int">
         1
        </object>
       </keyword>
      </query>
     </pnml>
     >>> Query('set', 'x', Query('call', 'x.upper')).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="set">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <query name="call">
         <argument>
          <object type="str">
           x.upper
          </object>
         </argument>
        </query>
       </argument>
      </query>
     </pnml>
     """
     children = []
     for arg in self._larg:
         children.append(Tree("argument", None, Tree.from_obj(arg)))
     for name, value in self._karg.items():
         children.append(
             Tree("keyword", None, Tree.from_obj(value), name=name))
     return Tree(self.__pnmltag__, None, *children, **{"name": self._name})
Example #36
0
 def __pnmldump__ (self) :
     result = module.PetriNet.__pnmldump__(self)
     result.add_child(Tree.from_obj(self.clusters))
     return result
Example #37
0
 def __pnmldump__ (self) :
     """
     >>> Query('set', 'x', 42).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="set">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <object type="int">
         42
        </object>
       </argument>
      </query>
     </pnml>
     >>> Query('test', x=1).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="test">
       <keyword name="x">
        <object type="int">
         1
        </object>
       </keyword>
      </query>
     </pnml>
     >>> Query('test', 'x', 42, y=1).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="test">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <object type="int">
         42
        </object>
       </argument>
       <keyword name="y">
        <object type="int">
         1
        </object>
       </keyword>
      </query>
     </pnml>
     >>> Query('set', 'x', Query('call', 'x.upper')).__pnmldump__()
     <?xml version="1.0" encoding="utf-8"?>
     <pnml>
      <query name="set">
       <argument>
        <object type="str">
         x
        </object>
       </argument>
       <argument>
        <query name="call">
         <argument>
          <object type="str">
           x.upper
          </object>
         </argument>
        </query>
       </argument>
      </query>
     </pnml>
     """
     children = []
     for arg in self._larg :
         children.append(Tree("argument", None,
                              Tree.from_obj(arg)))
     for name, value in self._karg.items() :
         children.append(Tree("keyword", None,
                              Tree.from_obj(value),
                              name=name))
     return Tree(self.__pnmltag__, None, *children, **{"name": self._name})
Example #38
0
 def __pnmldump__(self):
     result = module.PetriNet.__pnmldump__(self)
     result.add_child(Tree.from_obj(self.clusters))
     return result