# Path: dapbench/thredds/lib/dataset_config.py
# class Dataset(object):
#     '''Dataset entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, name, url_path, service_name):
#         """
#         @param name - name attribute
#         @param url_path - urlPath attribute
#         @param service_name - name of service applicable to the dataset
#         """
#         self.name = name
#         self.url_path = url_path
#         self.service_name = service_name
#         self.access = []
#         self.properties = {}
#         self.is_container = False
# 
#     def get_accesses(self):
#         """Returns access entities for the default service/URL and for each additional access
#         method.
#         @return list of access entities
#         """
#         accesses = []
#         if self.service_name and self.url_path:
#             accesses.append(Access(self.url_path, self.service_name))
#         accesses.extend(self.access)
#         return accesses
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'  '%s'" % (self.name, self.url_path, self.service_name, [a.__str__() for a in self.access]))
# 
# class Access(object):
#     '''Access entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, url_path, service_name):
#         """
#         @param url_path - URL path
#         @param service_name - name of service
#         """
#         self.url_path = url_path
#         self.service_name = service_name
# 
#     def __str__(self):
#         return ("'%s'  '%s'" % (self.url_path, self.service_name))
# 
# class CatalogRef(object):
#     '''Catalog ref entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, href, title, url):
#         self.href = href
#         self.title = title
#         self.url = url
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'" % (self.href, self.title, self.url))
# 
# Path: dapbench/thredds/lib/service_config.py
# class Service(object):
#     # Extensions to be appended to URLs for particular services to access different types of data.
#     _default_extensions = {
#         'OPENDAP': [".html", ".dds", ".das", ".asc", ".ascii", ".dods"],
#         'HTTPServer': None
#     }
# 
#     _default_public_extensions = {
#         'OPENDAP': [".html"]
#     }
# 
#     def __init__(self, name, service_type, base_url, suffix, extensions, public_extensions=None,
#                  forbidden_extensions=None):
#         """
#         @param name - name attribute
#         @param service_type - serviceType attribute
#         @param base_url - base attribute
#         @param suffix - suffix attribute
#         @param extensions - extensions to be appended to URLs to override defaults
#         @param public_extensions - extensions for which public access is to be assumed
#         @param forbidden_extensions - extensions for which no access is to be assumed
#         """
#         self.name = name
#         self.service_type = service_type
#         self.base_url = base_url
#         self.suffix = suffix
#         self.extensions = (extensions if extensions is not None
#                            else self._default_extensions.get(service_type, None))
#         self.public_extensions = (public_extensions if public_extensions is not None
#                                   else self._default_public_extensions.get(service_type, None))
#         self.forbidden_extensions = (forbidden_extensions if forbidden_extensions is not None
#                                      else None)
#         self.children = []
# 
#     def is_public(self, extension):
#         if self.public_extensions is not None:
#             if extension in self.public_extensions:
#                 return True
#         return False
# 
#     def is_forbidden(self, extension):
#         if self.forbidden_extensions is not None:
#             if extension in self.forbidden_extensions:
#                 return True
#         return False
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'  '%s'  '%s'  '%s'" % (self.name, self.service_type, self.base_url,
#                                                         self.suffix, self.extensions.__str__(),
#                 [s.name for s in self.children]))


import xml.dom.minidom as minidom
import dapbench.thredds.lib.url_util as url_util
import dapbench.thredds.lib.xml_util as xml_util
from dapbench.thredds.lib.dataset_config import Dataset, Access, CatalogRef
from dapbench.thredds.lib.service_config import Service
                              service_name)
            for access_el in xml_util.getChildrenByNameNS(el, self.ns, 'access'):
                dataset.access.append(Access(access_el.getAttribute('urlPath'),
                                             access_el.getAttribute('serviceName')))
            if required_properties:
                for property_el in xml_util.getChildrenByNameNS(el, self.ns, 'property'):
                    name = property_el.getAttribute('name')
                    if name in required_properties:
                        dataset.properties[name] = property_el.getAttribute('value')
            child_datasets = self.get_datasets(required_properties, el, inherited_metadata_service_name)
            dataset.is_container = (len(child_datasets) > 0)
            datasets.append(dataset)

            # Recurse into child datasets.
            datasets.extend(child_datasets)
        return datasets

    def get_catalog_refs(self, base_url, rootElement=None):
        """Gets the catalogRef elements from the catalog XML document or optionally those within a
            specified element.
        @param rootElement - element within which to find dataset elements or None to find them
            within the root catalog element.
        @return list of catalogRef entities
        """
        root = self.dom.documentElement if rootElement is None else rootElement
        cr_elements = xml_util.getChildrenByNameNS(root, self.ns, 'catalogRef')
        catalog_refs = []
        for el in cr_elements:
            ref_url = xml_util.getAttributeByLocalName(el, 'href')
            url = url_util.make_url(base_url, ref_url)

# Path: dapbench/thredds/lib/dataset_config.py
# class Dataset(object):
#     '''Dataset entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, name, url_path, service_name):
#         """
#         @param name - name attribute
#         @param url_path - urlPath attribute
#         @param service_name - name of service applicable to the dataset
#         """
#         self.name = name
#         self.url_path = url_path
#         self.service_name = service_name
#         self.access = []
#         self.properties = {}
#         self.is_container = False
# 
#     def get_accesses(self):
#         """Returns access entities for the default service/URL and for each additional access
#         method.
#         @return list of access entities
#         """
#         accesses = []
#         if self.service_name and self.url_path:
#             accesses.append(Access(self.url_path, self.service_name))
#         accesses.extend(self.access)
#         return accesses
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'  '%s'" % (self.name, self.url_path, self.service_name, [a.__str__() for a in self.access]))
# 
# class Access(object):
#     '''Access entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, url_path, service_name):
#         """
#         @param url_path - URL path
#         @param service_name - name of service
#         """
#         self.url_path = url_path
#         self.service_name = service_name
# 
#     def __str__(self):
#         return ("'%s'  '%s'" % (self.url_path, self.service_name))
# 
# class CatalogRef(object):
#     '''Catalog ref entity as read from a THREDDS catalog.
#     '''
#     def __init__(self, href, title, url):
#         self.href = href
#         self.title = title
#         self.url = url
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'" % (self.href, self.title, self.url))
# 
# Path: dapbench/thredds/lib/service_config.py
# class Service(object):
#     # Extensions to be appended to URLs for particular services to access different types of data.
#     _default_extensions = {
#         'OPENDAP': [".html", ".dds", ".das", ".asc", ".ascii", ".dods"],
#         'HTTPServer': None
#     }
# 
#     _default_public_extensions = {
#         'OPENDAP': [".html"]
#     }
# 
#     def __init__(self, name, service_type, base_url, suffix, extensions, public_extensions=None,
#                  forbidden_extensions=None):
#         """
#         @param name - name attribute
#         @param service_type - serviceType attribute
#         @param base_url - base attribute
#         @param suffix - suffix attribute
#         @param extensions - extensions to be appended to URLs to override defaults
#         @param public_extensions - extensions for which public access is to be assumed
#         @param forbidden_extensions - extensions for which no access is to be assumed
#         """
#         self.name = name
#         self.service_type = service_type
#         self.base_url = base_url
#         self.suffix = suffix
#         self.extensions = (extensions if extensions is not None
#                            else self._default_extensions.get(service_type, None))
#         self.public_extensions = (public_extensions if public_extensions is not None
#                                   else self._default_public_extensions.get(service_type, None))
#         self.forbidden_extensions = (forbidden_extensions if forbidden_extensions is not None
#                                      else None)
#         self.children = []
# 
#     def is_public(self, extension):
#         if self.public_extensions is not None:
#             if extension in self.public_extensions:
#                 return True
#         return False
# 
#     def is_forbidden(self, extension):
#         if self.forbidden_extensions is not None:
#             if extension in self.forbidden_extensions:
#                 return True
#         return False
# 
#     def __str__(self):
#         return ("'%s'  '%s'  '%s'  '%s'  '%s'  '%s'" % (self.name, self.service_type, self.base_url,
#                                                         self.suffix, self.extensions.__str__(),
#                 [s.name for s in self.children]))


# Path: dapbench/thredds/lib/catalog_parser.py
import xml.dom.minidom as minidom
import dapbench.thredds.lib.url_util as url_util
import dapbench.thredds.lib.xml_util as xml_util
from dapbench.thredds.lib.dataset_config import Dataset, Access, CatalogRef
from dapbench.thredds.lib.service_config import Service

                              service_name)
            for access_el in xml_util.getChildrenByNameNS(el, self.ns, 'access'):
                dataset.access.append(Access(access_el.getAttribute('urlPath'),
                                             access_el.getAttribute('serviceName')))
            if required_properties:
                for property_el in xml_util.getChildrenByNameNS(el, self.ns, 'property'):
                    name = property_el.getAttribute('name')
                    if name in required_properties:
                        dataset.properties[name] = property_el.getAttribute('value')
            child_datasets = self.get_datasets(required_properties, el, inherited_metadata_service_name)
            dataset.is_container = (len(child_datasets) > 0)
            datasets.append(dataset)

            # Recurse into child datasets.
            datasets.extend(child_datasets)
        return datasets

    def get_catalog_refs(self, base_url, rootElement=None):
        """Gets the catalogRef elements from the catalog XML document or optionally those within a
            specified element.
        @param rootElement - element within which to find dataset elements or None to find them
            within the root catalog element.
        @return list of catalogRef entities
        """
        root = self.dom.documentElement if rootElement is None else rootElement
        cr_elements = xml_util.getChildrenByNameNS(root, self.ns, 'catalogRef')
        catalog_refs = []
        for el in cr_elements:
            ref_url = xml_util.getAttributeByLocalName(el, 'href')
            url = url_util.make_url(base_url, ref_url)

            catalog_ref = CatalogRef(xml_util.getAttributeByLocalName(el, 'href'),