[GRASS-SVN] r53412 - grass-addons/grass7/raster/r.in.wms2

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 15 14:02:46 PDT 2012


Author: turek
Date: 2012-10-15 14:02:46 -0700 (Mon, 15 Oct 2012)
New Revision: 53412

Modified:
   grass-addons/grass7/raster/r.in.wms2/wms_base.py
   grass-addons/grass7/raster/r.in.wms2/wms_drv.py
Log:
r.in.wms2: headers used for authorization

Modified: grass-addons/grass7/raster/r.in.wms2/wms_base.py
===================================================================
--- grass-addons/grass7/raster/r.in.wms2/wms_base.py	2012-10-15 18:35:05 UTC (rev 53411)
+++ grass-addons/grass7/raster/r.in.wms2/wms_base.py	2012-10-15 21:02:46 UTC (rev 53412)
@@ -86,6 +86,10 @@
             if self.params[key] != "" and 'GRASS' not in self.params['driver']:
                 grass.warning(_("Parameter '%s' is relevant only for %s drivers.") % (key, '*_GRASS'))
         
+        if (self.params ['password'] and self.params ['username'] == '') or \
+           (self.params ['password'] == '' and self.params ['username']):
+                grass.fatal(_("Please insert both password and username parameters or none of them."))
+      
         self.params['bgcolor'] = options['bgcolor'].strip()
         if self.params['bgcolor'] != "" and 'WMS_GRASS' not in self.params['driver']:
             grass.warning(_("Parameter '%s' is relevant only for %s driver.") % ('bgcolor', 'WMS_GRASS'))

Modified: grass-addons/grass7/raster/r.in.wms2/wms_drv.py
===================================================================
--- grass-addons/grass7/raster/r.in.wms2/wms_drv.py	2012-10-15 18:35:05 UTC (rev 53411)
+++ grass-addons/grass7/raster/r.in.wms2/wms_drv.py	2012-10-15 21:02:46 UTC (rev 53412)
@@ -32,14 +32,6 @@
         elif self.params['driver'] == 'WMS_GRASS':
             req_mgr = WMSRequestMgr(self.params, self.bbox, self.region, self.tile_size, self.proj_srs)
 
-        # set password and username to urlib2
-        if self.params['username']:
-            passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
-            passman.add_password(None, self.params['url'], self.params['username'], self.params['password'])
-            auth_handler = urllib2.HTTPBasicAuthHandler(passman)
-            opener = urllib2.build_opener(auth_handler)
-            urllib2.install_opener(opener)
-
         # get information about size in pixels and bounding box of raster, where all tiles will be joined
         map_region = req_mgr.GetMapRegion()
 
@@ -64,7 +56,11 @@
 
             grass.debug(query_url)
             try: 
-                wms_data = urllib2.urlopen(query_url)
+                request = urllib2.Request(query_url)
+                if self.params['username']:
+                    base64string = base64.encodestring('%s:%s' % (self.params['username'], self.params['password'])).replace('\n', '')
+                    request.add_header("Authorization", "Basic %s" % base64string) 
+                wms_data = urllib2.urlopen(request)
             except (IOError, HTTPException), e:
                 if HTTPError == type(e) and e.code == 401:
                     grass.fatal(_("Authorization failed"))           



More information about the grass-commit mailing list