Changeset 1092
- Timestamp:
- 05/08/08 12:03:23
- Files:
-
- OWSLib/trunk/owslib/wms.py (modified) (11 diffs)
- OWSLib/trunk/setup.py (modified) (2 diffs)
- OWSLib/trunk/tests/__init__.py (modified) (1 diff)
- OWSLib/trunk/tests/JPLCapabilities.txt (modified) (1 diff)
- OWSLib/trunk/tests/TelaCapabilities.txt (modified) (2 diffs)
- OWSLib/trunk/tests/test_doctests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OWSLib/trunk/owslib/wms.py
r984 r1092 19 19 from urllib import urlencode 20 20 from urllib2 import urlopen 21 from urllib2 import HTTPPasswordMgrWithDefaultRealm 22 from urllib2 import HTTPBasicAuthHandler 23 from urllib2 import build_opener 24 from urllib2 import install_opener 21 25 22 26 from etree import etree … … 37 41 """ 38 42 39 def __init__(self, url, version='1.1.1', xml=None): 43 def __init__(self, url, version='1.1.1', xml=None, 44 username=None, password=None 45 ): 40 46 """Initialize.""" 41 47 self.url = url 48 self.username = username 49 self.password = password 42 50 self.version = version 43 51 self._capabilities = None 52 self._open = urlopen 53 54 if self.username and self.password: 55 # Provide login information in order to use the WMS server 56 # Create an OpenerDirector with support for Basic HTTP 57 # Authentication... 58 passman = HTTPPasswordMgrWithDefaultRealm() 59 passman.add_password(None, self.url, self.username, self.password) 60 auth_handler = HTTPBasicAuthHandler(passman) 61 opener = build_opener(auth_handler) 62 self._open = opener.open 63 44 64 # initialize from saved capability document 45 if xml: 46 reader = WMSCapabilitiesReader(self.version) 65 elif xml: 66 reader = WMSCapabilitiesReader( 67 self.version, url=self.url, un=self.username, pw=self.password 68 ) 47 69 self._capabilities = ServiceMetadata(reader.readString(xml)) 48 70 49 71 def _getcapproperty(self): 50 72 if not self._capabilities: 51 reader = WMSCapabilitiesReader(self.version) 73 reader = WMSCapabilitiesReader( 74 self.version, url=self.url, un=self.username, pw=self.password 75 ) 52 76 self._capabilities = ServiceMetadata(reader.read(self.url)) 53 77 return self._capabilities … … 57 81 """Request and return capabilities document from the WMS as a 58 82 file-like object.""" 59 reader = WMSCapabilitiesReader(self.version) 60 u = urlopen(reader.capabilities_url(self.url)) 83 84 reader = WMSCapabilitiesReader( 85 self.version, url=self.url, un=self.username, pw=self.password 86 ) 87 u = self._open(reader.capabilities_url(self.url)) 61 88 # check for service exceptions, and return 62 89 if u.info().gettype() == 'application/vnd.ogc.se_xml': … … 68 95 69 96 def getmap(self, layers=None, styles=None, srs=None, bbox=None, 70 format=None, size=None, transparent=False, bgcolor='#FFFFFF', 97 format=None, size=None, time=None, transparent=False, 98 bgcolor='#FFFFFF', 71 99 exceptions='application/vnd.ogc.se_xml', 72 method='Get'): 100 method='Get' 101 ): 73 102 """Request and return an image from the WMS as a file-like object. 74 103 … … 109 138 >>> out.close() 110 139 111 """ 140 """ 112 141 md = self.capabilities 113 142 base_url = md.getOperationByName('GetMap').methods[method]['url'] … … 134 163 request['exceptions'] = str(exceptions) 135 164 165 if time is not None: 166 request['time'] = str(time) 167 136 168 data = urlencode(request) 137 169 if method == 'Post': 138 u = urlopen(base_url, data=data)170 u = self._open(base_url, data=data) 139 171 else: 140 u = urlopen(base_url + data)172 u = self._open(base_url + data) 141 173 142 174 # check for service exceptions, and return … … 223 255 raise KeyError, "No operation named %s" % name 224 256 225 #def toXML(self):226 # """x227 # """228 # top = etree.Element('a')229 # top.text = self.getName()230 # return etree.tostring(top)231 232 257 233 258 class ContentMetadata: … … 313 338 def __str__(self): 314 339 return 'Layer Name: %s Title: %s' % (self.name, self.title) 340 315 341 316 342 class OperationMetadata: … … 365 391 else: self.position = None 366 392 367 # Deprecated classes follow368 # TODO: remove369 393 370 394 class WMSCapabilitiesInfoset: … … 465 489 """ 466 490 467 def __init__(self, version='1.1.1' ):491 def __init__(self, version='1.1.1', url=None, un=None, pw=None): 468 492 """Initialize""" 469 493 self.version = version 470 494 self._infoset = None 495 self.url = url 496 self.username = un 497 self.password = pw 498 self._open = urlopen 499 500 if self.username and self.password: 501 # Provide login information in order to use the WMS server 502 # Create an OpenerDirector with support for Basic HTTP 503 # Authentication... 504 passman = HTTPPasswordMgrWithDefaultRealm() 505 passman.add_password(None, self.url, self.username, self.password) 506 auth_handler = HTTPBasicAuthHandler(passman) 507 opener = build_opener(auth_handler) 508 self._open = opener.open 471 509 472 510 def capabilities_url(self, service_url): … … 497 535 """ 498 536 request = self.capabilities_url(service_url) 499 u = urlopen(request)537 u = self._open(request) 500 538 return WMSCapabilitiesInfoset(etree.fromstring(u.read())) 501 539 OWSLib/trunk/setup.py
r799 r1092 3 3 4 4 setup(name = 'OWSLib', 5 version = '0. 2.1',5 version = '0.3', 6 6 description = 'OGC Web Service utility library', 7 7 license = 'BSD', … … 11 11 maintainer = 'Sean Gillies', 12 12 maintainer_email = 'sgillies@frii.com', 13 url = 'http://trac.gispython.org/projects/PCL/wiki/O wsLib',13 url = 'http://trac.gispython.org/projects/PCL/wiki/OWSLib', 14 14 packages = ['owslib'], 15 test s_require = ['zope.testing'],15 test_suite = 'tests.test_suite', 16 16 classifiers = [ 17 17 'Development Status :: 3 - Alpha', OWSLib/trunk/tests/__init__.py
r799 r1092 1 1 # package 2 from test_doctests import test_suite OWSLib/trunk/tests/JPLCapabilities.txt
r799 r1092 38 38 39 39 >>> [layer.name for layer in wms.capabilities.contents] 40 [ 'global_mosaic', 'global_mosaic_base', 'us_landsat_wgs84', 'srtm_mag', 'daily_terra_721', 'daily_aqua_721', 'daily_terra_ndvi', 'daily_aqua_ndvi', 'daily_terra', 'daily_aqua', 'BMNG', 'modis', 'huemapped_srtm', 'srtmplus', 'worldwind_dem', 'us_ned', 'us_elevation', 'us_colordem']40 [None, 'global_mosaic', 'global_mosaic_base', 'us_landsat_wgs84', 'srtm_mag', 'daily_terra_721', 'daily_aqua_721', 'daily_terra_ndvi', 'daily_aqua_ndvi', 'daily_terra', 'daily_aqua', 'BMNG', 'modis', 'huemapped_srtm', 'srtmplus', 'worldwind_dem', 'us_ned', 'us_elevation', 'us_colordem'] 41 41 42 42 >>> [layer.title for layer in wms.capabilities.contents] 43 [' WMS Global Mosaic, pan sharpened', 'WMS Global Mosaic, not pan sharpened', 'CONUS mosaic of 1990 MRLC dataset', 'SRTM reflectance magnitude, 30m', 'Daily composite of MODIS-TERRA 721 pseudocolor', 'Daily composite of MODIS-AQUA 721 pseudocolor', 'Daily composite of MODIS-TERRA images, NDVI processing', 'Daily composite of MODIS-AQUA images, NDVI processing', 'Daily composite of MODIS-TERRA images', 'Daily composite of MODIS-AQUA images', 'Blue Marble Next Generation, Global MODIS derived image', 'Blue Marble, Global MODIS derived image', 'SRTM derived global elevation, 3 arc-second, hue mapped', 'Global 1km elevation, seamless SRTM land elevation and ocean depth', 'SRTM derived global elevation, 3 arc-second', 'United States elevation, 30m', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, grayscale', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, hue mapped']43 ['OnEarth Web Map Server', 'WMS Global Mosaic, pan sharpened', 'WMS Global Mosaic, not pan sharpened', 'CONUS mosaic of 1990 MRLC dataset', 'SRTM reflectance magnitude, 30m', 'Daily composite of MODIS-TERRA 721 pseudocolor', 'Daily composite of MODIS-AQUA 721 pseudocolor', 'Daily composite of MODIS-TERRA images, NDVI processing', 'Daily composite of MODIS-AQUA images, NDVI processing', 'Daily composite of MODIS-TERRA images', 'Daily composite of MODIS-AQUA images', 'Blue Marble Next Generation, Global MODIS derived image', 'Blue Marble, Global MODIS derived image', 'SRTM derived global elevation, 3 arc-second, hue mapped', 'Global 1km elevation, seamless SRTM land elevation and ocean depth', 'SRTM derived global elevation, 3 arc-second', 'United States elevation, 30m', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, grayscale', 'Digital Elevation Map of the United States, DTED dataset, 3 second resolution, hue mapped'] 44 44 45 45 Test single item accessor OWSLib/trunk/tests/TelaCapabilities.txt
r799 r1092 36 36 37 37 >>> [layer.name for layer in wms.capabilities.contents] 38 [' world.topo.bathy.200409', 'USGS_1ft_San_Diego']38 ['ngBM', 'world.topo.bathy.200409', 'USGS_1ft_San_Diego'] 39 39 40 40 >>> [layer.title for layer in wms.capabilities.contents] 41 [' world.topo.bathy.200409', 'USGS 1ft San Diego']41 ['BM', 'world.topo.bathy.200409', 'USGS 1ft San Diego'] 42 42 43 43 Test single item accessor … … 53 53 54 54 >>> wms.capabilities.getContentByName('world.topo.bathy.200409').crsOptions 55 [' EPSG:4326']55 ['init=epsg:4326'] 56 56 57 57 >>> wms.capabilities.getContentByName('world.topo.bathy.200409').styles OWSLib/trunk/tests/test_doctests.py
r799 r1092 24 24 import glob 25 25 import os 26 27 from zope.testing import doctest 26 import doctest 28 27 29 28 optionflags = (doctest.REPORT_ONLY_FIRST_FAILURE |
