Example #1
0
    def __init__(self, url, lang='en-US', version='2.0.2', timeout=10, skip_caps=False,
                 username=None, password=None, auth=None):
        """

        Construct and process a GetCapabilities request

        Parameters
        ----------

        - url: the URL of the CSW
        - lang: the language (default is 'en-US')
        - version: version (default is '2.0.2')
        - timeout: timeout in seconds
        - skip_caps: whether to skip GetCapabilities processing on init (default is False)
        - username: username for HTTP basic authentication
        - password: password for HTTP basic authentication
        - auth: instance of owslib.util.Authentication

        """
        if auth:
            if username:
                auth.username = username
            if password:
                auth.password = password
        self.url = util.clean_ows_url(url)
        self.lang = lang
        self.version = version
        self.timeout = timeout
        self.auth = auth or Authentication(username, password)
        self.service = 'CSW'
        self.exceptionreport = None
        self.owscommon = ows.OwsCommon('1.0.0')

        if not skip_caps:  # process GetCapabilities
            # construct request

            data = {'service': self.service, 'version': self.version, 'request': 'GetCapabilities'}

            self.request = urlencode(data)

            self._invoke()

            if self.exceptionreport is None:
                self.updateSequence = self._exml.getroot().attrib.get('updateSequence')

                # ServiceIdentification
                val = self._exml.find(util.nspath_eval('ows:ServiceIdentification', namespaces))
                if val is not None:
                    self.identification = ows.ServiceIdentification(val, self.owscommon.namespace)
                else:
                    self.identification = None
                # ServiceProvider
                val = self._exml.find(util.nspath_eval('ows:ServiceProvider', namespaces))
                if val is not None:
                    self.provider = ows.ServiceProvider(val, self.owscommon.namespace)
                else:
                    self.provider = None
                # ServiceOperations metadata
                self.operations = []
                for elem in self._exml.findall(util.nspath_eval('ows:OperationsMetadata/ows:Operation', namespaces)):
                    self.operations.append(ows.OperationsMetadata(elem, self.owscommon.namespace))
                self.constraints = {}
                for elem in self._exml.findall(util.nspath_eval('ows:OperationsMetadata/ows:Constraint', namespaces)):
                    self.constraints[elem.attrib['name']] = ows.Constraint(elem, self.owscommon.namespace)
                self.parameters = {}
                for elem in self._exml.findall(util.nspath_eval('ows:OperationsMetadata/ows:Parameter', namespaces)):
                    self.parameters[elem.attrib['name']] = ows.Parameter(elem, self.owscommon.namespace)

                # FilterCapabilities
                val = self._exml.find(util.nspath_eval('ogc:Filter_Capabilities', namespaces))
                self.filters = fes.FilterCapabilities(val)
Example #2
0
File: csw.py Project: granci/OWSLib
    def __init__(self,
                 url,
                 lang='en-US',
                 version='2.0.2',
                 timeout=10,
                 skip_caps=False,
                 username=None,
                 password=None):
        """

        Construct and process a GetCapabilities request

        Parameters
        ----------

        - url: the URL of the CSW
        - lang: the language (default is 'en-US')
        - version: version (default is '2.0.2')
        - timeout: timeout in seconds
        - skip_caps: whether to skip GetCapabilities processing on init (default is False)
        - username: username for HTTP basic authentication
        - password: password for HTTP basic authentication

        """

        self.url = url
        self.lang = lang
        self.version = version
        self.timeout = timeout
        self.username = username
        self.password = password
        self.service = 'CSW'
        self.exceptionreport = None
        self.owscommon = ows.OwsCommon('1.0.0')

        if not skip_caps:  # process GetCapabilities
            # construct request

            data = {
                'service': self.service,
                'version': self.version,
                'request': 'GetCapabilities'
            }

            self.request = '%s%s' % (bind_url(self.url), urlencode(data))

            self._invoke()

            if self.exceptionreport is None:
                # ServiceIdentification
                val = self._exml.find(
                    util.nspath_eval('ows:ServiceIdentification', namespaces))
                self.identification = ows.ServiceIdentification(
                    val, self.owscommon.namespace)
                # ServiceProvider
                val = self._exml.find(
                    util.nspath_eval('ows:ServiceProvider', namespaces))
                self.provider = ows.ServiceProvider(val,
                                                    self.owscommon.namespace)
                # ServiceOperations metadata
                self.operations = []
                for elem in self._exml.findall(
                        util.nspath_eval(
                            'ows:OperationsMetadata/ows:Operation',
                            namespaces)):
                    self.operations.append(
                        ows.OperationsMetadata(elem, self.owscommon.namespace))

                # FilterCapabilities
                val = self._exml.find(
                    util.nspath_eval('ogc:Filter_Capabilities', namespaces))
                self.filters = fes.FilterCapabilities(val)