[Code-review] review: Gadget act-props branch

Dafydd Harries dafydd.harries at collabora.co.uk
Mon Aug 11 09:07:21 EDT 2008


act-props:

>+        properties = activity_elem.addElement((ns.ACTIVITY_PROP, 'properties'))
>+        for node in properties_to_xml(activity.properties):
>+            properties.addChild(node)

We seem to do this a lot. Let's change it so properties_to_xml returns the
<properties> element, then we can just say:

  activity_elem.addChild(properties_to_xml(activity.properties))

>+    for child in node.elements():
>+        if child.uri == ns.ACTIVITY_PROP and child.name == 'properties':
>+            for child in child.elements():
>+                assert child.name == 'property'

I think it's better to just ignore unexpected elements:

  for child in child.elements():
      if child.name != 'property':
          continue

We could have a convenience function:

  def elem_find_children(elem, uri, name):
      for child in elem.elements():
          if (child.uri, child.name) == (uri, name):
              yield child

      ...

So we could then write:

  for child in elem_find_chidlren(ns.ACTIVITY_PROP, 'property'):
      ...

This also handles namespaces more correctly.

Otherwise, looks fine.

-- 
Dafydd


More information about the Code-review mailing list