<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_capability_list(self, capabilities=None, outfile=None, links=None):
 """Write a Capability List to outfile or STDOUT."""

        capl = CapabilityList(ln=links)
        capl.pretty_xml = self.pretty_xml
        if (capabilities is not None):
            for name in capabilities.keys():
                capl.add_capability(name=name, uri=capabilities[name])
        if (outfile is None):
            print(capl.as_xml())
        else:
            capl.write(basename=outfile)