<s> from __future__ import ( absolute_import , division , print_function ) <EOL> from . wcsBase import WCSBase , WCSCapabilitiesReader , ServiceException <EOL> from owslib . util import openURL , testXMLValue <EOL> try : <EOL> from urllib import urlencode <EOL> except ImportError : <EOL> from urllib . parse import urlencode <EOL> from owslib . etree import etree <EOL> import os , errno <EOL> from owslib . coverage import wcsdecoder <EOL> from owslib . crs import Crs <EOL> import logging <EOL> from owslib . util import log <EOL> class Namespaces_1_1_0 ( ) : <EOL> def WCS ( self , tag ) : <EOL> return '<STR_LIT>' + tag <EOL> def WCS_OWS ( self , tag ) : <EOL> return '<STR_LIT>' + tag <EOL> def OWS ( self , tag ) : <EOL> return '<STR_LIT>' + tag <EOL> class WebCoverageService_1_1_0 ( WCSBase ) : <EOL> """<STR_LIT>""" <EOL> version = '<STR_LIT>' <EOL> ns = Namespaces_1_1_0 ( ) <EOL> def __getitem__ ( self , name ) : <EOL> '''<STR_LIT>''' <EOL> if name in self . __getattribute__ ( '<STR_LIT>' ) . keys ( ) : <EOL> return self . __getattribute__ ( '<STR_LIT>' ) [ name ] <EOL> else : <EOL> raise KeyError ( "<STR_LIT>" % name ) <EOL> def __init__ ( self , url , xml , cookies ) : <EOL> self . url = url <EOL> self . cookies = cookies <EOL> reader = WCSCapabilitiesReader ( self . version ) <EOL> if xml : <EOL> self . _capabilities = reader . readString ( xml ) <EOL> else : <EOL> self . _capabilities = reader . read ( self . url ) <EOL> se = self . _capabilities . find ( self . ns . OWS ( '<STR_LIT>' ) ) <EOL> if se is not None : <EOL> err_message = str ( se . text ) . strip ( ) <EOL> raise ServiceException ( err_message , xml ) <EOL> elem = self . _capabilities . find ( self . ns . WCS_OWS ( '<STR_LIT>' ) ) <EOL> if elem is None : <EOL> elem = self . _capabilities . find ( self . ns . OWS ( '<STR_LIT>' ) ) <EOL> self . identification = ServiceIdentification ( elem , self . ns ) <EOL> elem = self . _capabilities . find ( self . ns . OWS ( '<STR_LIT>' ) ) or self . _capabilities . find ( self . ns . OWS ( '<STR_LIT>' ) ) <EOL> self . provider = ServiceProvider ( elem , self . ns ) <EOL> self . operations = [ ] <EOL> for elem in self . _capabilities . findall ( self . ns . WCS_OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + self . ns . WCS_OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' ) : <EOL> self . operations . append ( Operation ( elem , self . ns ) ) <EOL> self . exceptions = [ f . text for f in self . _capabilities . findall ( '<STR_LIT>' ) ] <EOL> self . contents = { } <EOL> top = self . _capabilities . find ( self . ns . WCS ( '<STR_LIT>' ) + '<STR_LIT:/>' + self . ns . WCS ( '<STR_LIT>' ) ) <EOL> for elem in self . _capabilities . findall ( self . ns . WCS ( '<STR_LIT>' ) + '<STR_LIT:/>' + self . ns . WCS ( '<STR_LIT>' ) + '<STR_LIT:/>' + self . ns . WCS ( '<STR_LIT>' ) ) : <EOL> cm = ContentMetadata ( elem , top , self , self . ns ) <EOL> self . contents [ cm . id ] = cm <EOL> if self . contents == { } : <EOL> top = None <EOL> for elem in self . _capabilities . findall ( self . ns . WCS ( '<STR_LIT>' ) + '<STR_LIT:/>' + self . ns . WCS ( '<STR_LIT>' ) ) : <EOL> cm = ContentMetadata ( elem , top , self , self . ns ) <EOL> self . contents [ cm . id ] = cm <EOL> def items ( self ) : <EOL> '''<STR_LIT>''' <EOL> items = [ ] <EOL> for item in self . contents : <EOL> items . append ( ( item , self . contents [ item ] ) ) <EOL> return items <EOL> def getCoverage ( self , identifier = None , bbox = None , time = None , format = None , store = False , rangesubset = None , gridbaseCRS = None , gridtype = None , gridCS = None , gridorigin = None , gridoffsets = None , method = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if log . isEnabledFor ( logging . DEBUG ) : <EOL> log . debug ( '<STR_LIT>' % ( identifier , bbox , time , format , rangesubset , gridbaseCRS , gridtype , gridCS , gridorigin , gridoffsets , method , str ( kwargs ) ) ) <EOL> if method == '<STR_LIT>' : <EOL> method = self . ns . WCS_OWS ( '<STR_LIT>' ) <EOL> try : <EOL> base_url = next ( ( m . get ( '<STR_LIT:url>' ) for m in self . getOperationByName ( '<STR_LIT>' ) . methods if m . get ( '<STR_LIT:type>' ) . lower ( ) == method . lower ( ) ) ) <EOL> except StopIteration : <EOL> base_url = self . url <EOL> request = { '<STR_LIT:version>' : self . version , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> assert len ( identifier ) > <NUM_LIT:0> <EOL> request [ '<STR_LIT>' ] = identifier <EOL> if bbox : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( [ repr ( x ) for x in bbox ] ) <EOL> if time : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( time ) <EOL> request [ '<STR_LIT>' ] = format <EOL> request [ '<STR_LIT:store>' ] = store <EOL> if rangesubset : <EOL> request [ '<STR_LIT>' ] = rangesubset <EOL> if gridbaseCRS : <EOL> request [ '<STR_LIT>' ] = gridbaseCRS <EOL> if gridtype : <EOL> request [ '<STR_LIT>' ] = gridtype <EOL> if gridCS : <EOL> request [ '<STR_LIT>' ] = gridCS <EOL> if gridorigin : <EOL> request [ '<STR_LIT>' ] = gridorigin <EOL> if gridoffsets : <EOL> request [ '<STR_LIT>' ] = gridoffsets <EOL> if kwargs : <EOL> for kw in kwargs : <EOL> request [ kw ] = kwargs [ kw ] <EOL> data = urlencode ( request ) <EOL> u = openURL ( base_url , data , method , self . cookies ) <EOL> return u <EOL> def getOperationByName ( self , name ) : <EOL> """<STR_LIT>""" <EOL> for item in self . operations : <EOL> if item . name == name : <EOL> return item <EOL> raise KeyError ( "<STR_LIT>" % name ) <EOL> class Operation ( object ) : <EOL> """<STR_LIT>""" <EOL> ns = Namespaces_1_1_0 ( ) <EOL> def __init__ ( self , elem , nmSpc ) : <EOL> self . name = elem . get ( '<STR_LIT:name>' ) <EOL> self . formatOptions = [ f . text for f in elem . findall ( nmSpc . WCS_OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . WCS_OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . WCS_OWS ( '<STR_LIT>' ) ) ] <EOL> methods = [ ] <EOL> for verb in elem . findall ( nmSpc . WCS_OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . WCS_OWS ( '<STR_LIT>' ) ) : <EOL> url = verb . attrib [ '<STR_LIT>' ] <EOL> methods . append ( ( verb . tag , { '<STR_LIT:url>' : url } ) ) <EOL> self . methods = dict ( methods ) <EOL> class ServiceIdentification ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , elem , nmSpc ) : <EOL> self . service = "<STR_LIT>" <EOL> self . title = testXMLValue ( elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) ) <EOL> if self . title is None : <EOL> self . title = testXMLValue ( elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) ) <EOL> if self . title is None : <EOL> self . title = testXMLValue ( elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) ) <EOL> self . abstract = testXMLValue ( elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) ) <EOL> if self . abstract is None : <EOL> self . abstract = testXMLValue ( elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) ) <EOL> if self . title is None : <EOL> self . title = testXMLValue ( elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) ) <EOL> if elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) is not None : <EOL> self . abstract = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> else : <EOL> self . abstract = None <EOL> self . keywords = [ f . text for f in elem . findall ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) ] <EOL> if elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) is not None : <EOL> self . fees = elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) . text <EOL> else : <EOL> self . fees = None <EOL> if elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) is not None : <EOL> self . accessConstraints = elem . find ( nmSpc . WCS_OWS ( '<STR_LIT>' ) ) . text <EOL> else : <EOL> self . accessConstraints = None <EOL> class ServiceProvider ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , elem , nmSpc ) : <EOL> name = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) <EOL> if name is not None : <EOL> self . name = name . text <EOL> else : <EOL> self . name = None <EOL> self . contact = ContactMetadata ( elem , nmSpc ) <EOL> self . url = self . name <EOL> class ContactMetadata ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , elem , nmSpc ) : <EOL> try : <EOL> self . name = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . name = None <EOL> try : <EOL> self . organization = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . organization = None <EOL> try : <EOL> self . address = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . address = None <EOL> try : <EOL> self . city = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . city = None <EOL> try : <EOL> self . region = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . region = None <EOL> try : <EOL> self . postcode = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . postcode = None <EOL> try : <EOL> self . country = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . country = None <EOL> try : <EOL> self . email = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> except AttributeError : <EOL> self . email = None <EOL> class ContentMetadata ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , elem , parent , service , nmSpc ) : <EOL> """<STR_LIT>""" <EOL> self . _service = service <EOL> self . _elem = elem <EOL> self . _parent = parent <EOL> self . id = self . _checkChildAndParent ( nmSpc . WCS ( '<STR_LIT>' ) ) <EOL> self . description = self . _checkChildAndParent ( nmSpc . WCS ( '<STR_LIT>' ) ) <EOL> self . title = self . _checkChildAndParent ( nmSpc . OWS ( '<STR_LIT>' ) ) <EOL> self . abstract = self . _checkChildAndParent ( nmSpc . OWS ( '<STR_LIT>' ) ) <EOL> self . keywords = [ ] <EOL> for kw in elem . findall ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) : <EOL> if kw is not None : <EOL> self . keywords . append ( kw . text ) <EOL> if parent is not None : <EOL> for kw in parent . findall ( nmSpc . OWS ( '<STR_LIT>' ) + '<STR_LIT:/>' + nmSpc . OWS ( '<STR_LIT>' ) ) : <EOL> if kw is not None : <EOL> self . keywords . append ( kw . text ) <EOL> self . boundingBox = None <EOL> self . boundingBoxWGS84 = None <EOL> b = elem . find ( nmSpc . OWS ( '<STR_LIT>' ) ) <EOL> if b is not None : <EOL> lc = b . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> uc = b . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> self . boundingBoxWGS84 = ( <EOL> float ( lc . split ( ) [ <NUM_LIT:0> ] ) , float ( lc . split ( ) [ <NUM_LIT:1> ] ) , <EOL> float ( uc . split ( ) [ <NUM_LIT:0> ] ) , float ( uc . split ( ) [ <NUM_LIT:1> ] ) , <EOL> ) <EOL> self . boundingboxes = [ ] <EOL> for bbox in elem . findall ( nmSpc . OWS ( '<STR_LIT>' ) ) : <EOL> if bbox is not None : <EOL> try : <EOL> lc = b . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> uc = b . find ( nmSpc . OWS ( '<STR_LIT>' ) ) . text <EOL> boundingBox = ( <EOL> float ( lc . split ( ) [ <NUM_LIT:0> ] ) , float ( lc . split ( ) [ <NUM_LIT:1> ] ) , <EOL> float ( uc . split ( ) [ <NUM_LIT:0> ] ) , float ( uc . split ( ) [ <NUM_LIT:1> ] ) , <EOL> b . attrib [ '<STR_LIT>' ] ) <EOL> self . boundingboxes . append ( boundingBox ) <EOL> except : <EOL> pass <EOL> self . styles = None <EOL> self . crsOptions = None <EOL> self . supportedCRS = [ ] <EOL> for crs in elem . findall ( nmSpc . WCS ( '<STR_LIT>' ) ) : <EOL> self . supportedCRS . append ( Crs ( crs . text ) ) <EOL> self . supportedFormats = [ ] <EOL> for format in elem . findall ( nmSpc . WCS ( '<STR_LIT>' ) ) : <EOL> self . supportedFormats . append ( format . text ) <EOL> def _getGrid ( self ) : <EOL> grid = None <EOL> return grid <EOL> grid = property ( _getGrid , None ) <EOL> def _getTimeLimits ( self ) : <EOL> timelimits = [ ] <EOL> for elem in self . _service . getDescribeCoverage ( self . id ) . findall ( ns ( '<STR_LIT>' ) + ns ( '<STR_LIT>' ) + ns ( '<STR_LIT>' ) + ns ( '<STR_LIT>' ) ) : <EOL> subelems = elem . getchildren ( ) <EOL> timelimits = [ subelems [ <NUM_LIT:0> ] . text , subelems [ <NUM_LIT:1> ] . text ] <EOL> return timelimits <EOL> timelimits = property ( _getTimeLimits , None ) <EOL> def _getTimePositions ( self ) : <EOL> return [ ] <EOL> timepositions = property ( _getTimePositions , None ) <EOL> def _checkChildAndParent ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> value = self . _elem . find ( path ) . text <EOL> except : <EOL> try : <EOL> value = self . _parent . find ( path ) . text <EOL> except : <EOL> value = None <EOL> return value </s>
