def _parse_container_listing(self, account, listing_dict, output_format,
                                 only_cdn_enabled=None):
        """
        :param only_cdn_enabled: should be a bool or None
        :returns: For xml format: an XML str, json: a dict, otherwise container
                  name. Returns None if only_cdn_enabled is specified and
                  listing_data does not match.
        :raises: InvalidContentType
        """
        container = listing_dict['name']
        if isinstance(container, unicode):
            container = container.encode('utf-8')

        cdn_data = listing_dict['content_type']
        hsh = self.hash_path(account, container)
        if not cdn_data.startswith('x-cdn/'):
            raise InvalidContentType('Invalid Content-Type: %s/%s: %s' %
                                     (account, container, cdn_data))
        try:
            cdn_enabled, ttl, log_ret = cdn_data[len('x-cdn/'):].split('-')
            cdn_enabled = cdn_enabled.lower() in TRUE_VALUES
            log_ret = log_ret.lower() in TRUE_VALUES
            ttl = int(ttl)
            if (only_cdn_enabled is not None and
                    only_cdn_enabled != cdn_enabled):
                return None
        except ValueError:
            raise InvalidContentType(
                'Invalid Content-Type: %s/%s: %s' % (account, container,
                                                     cdn_data))
        if output_format not in ('json', 'xml'):
            return container
        cdn_url_dict = self.get_cdn_urls(
            hsh, 'GET', request_format_tag=output_format)
        output_dict = {'name': container.decode('utf-8'),
                       'cdn_enabled': cdn_enabled,
                       'ttl': ttl, 'log_retention': log_ret}
        output_dict.update(cdn_url_dict)

        def sos_escape(val):
            if isinstance(val, basestring):
                return saxutils.escape(val)
            return val

        if output_format == 'xml':
            xml_data = '\n'.join(
                ['<%s>%s</%s>' % (tag, sos_escape(val), tag)
                 for tag, val in output_dict.items()])
            return """  <container>
            %s
  </container>""" % xml_data
        return output_dict
dataset/ETHPy150Open dpgoetz/sos/sos/origin.py/OriginDbHandler._parse_container_listing/original