[python] Use a bit more generic RDF container handling code.