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)
def __init__(self, url, lang='en-US', version='2.0.2', timeout=10, skip_caps=False): """ 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) """ self.url = url self.lang = lang self.version = version self.timeout = timeout self.service = 'CSW' self.exceptionreport = None self.owscommon = ows.OwsCommon('1.0.0') if not skip_caps: # process GetCapabilities # construct request node0 = self._setrootelement('csw:GetCapabilities') node0.set('service', self.service) node0.set(util.nspath_eval('xsi:schemaLocation', namespaces), schema_location) tmp = etree.SubElement(node0, util.nspath_eval('ows:AcceptVersions', namespaces)) etree.SubElement(tmp, util.nspath_eval('ows:Version', namespaces)).text = self.version tmp2 = etree.SubElement(node0, util.nspath_eval('ows:AcceptFormats', namespaces)) etree.SubElement(tmp2, util.nspath_eval('ows:OutputFormat', namespaces)).text = outputformat self.request = util.xml2string(etree.tostring(node0)) 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)
def __init__(self, url, lang='en-US', version='3.0.0', 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 '3.0.0') - 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('2.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('ows200: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('ows200: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( 'ows200:OperationsMetadata/ows200:Operation', namespaces)): # noqa self.operations.append( ows.OperationsMetadata(elem, self.owscommon.namespace)) self.constraints = {} for elem in self._exml.findall( util.nspath_eval( 'ows200:OperationsMetadata/ows200:Constraint', namespaces)): # noqa self.constraints[elem.attrib['name']] = ows.Constraint( elem, self.owscommon.namespace) self.parameters = {} for elem in self._exml.findall( util.nspath_eval( 'ows200:OperationsMetadata/ows200:Parameter', namespaces)): # noqa self.parameters[elem.attrib['name']] = ows.Parameter( elem, self.owscommon.namespace) # FilterCapabilities val = self._exml.find( util.nspath_eval('fes:Filter_Capabilities', namespaces)) self.filters = fes2.FilterCapabilities(val)