Did I find the right examples for you? yes no

All Samples(28)  |  Call(20)  |  Derive(0)  |  Import(8)
function to open urls - wrapper around urllib2.urlopen but with additional checks for OGC service exceptions and url formatting, also handles cookies and simple user password authentication

        def openURL(url_base, data, method='Get', cookies=None, username=None, password=None):
    ''' function to open urls - wrapper around urllib2.urlopen but with additional checks for OGC service exceptions and url formatting, also handles cookies and simple user password authentication'''
    url_base.strip() 
    lastchar = url_base[-1]
    if lastchar not in ['?', '&']:
        if url_base.find('?') == -1:
            url_base = url_base + '?'
        else:
            url_base = url_base + '&'
            
    if username and password:
        # Provide login information in order to use the WMS server
        # Create an OpenerDirector with support for Basic HTTP 
        # Authentication...
        passman = HTTPPasswordMgrWithDefaultRealm()
        passman.add_password(None, url_base, username, password)
        auth_handler = HTTPBasicAuthHandler(passman)
        opener = urllib2.build_opener(auth_handler)
        openit = opener.open
    else:
        # NOTE: optionally set debuglevel>0 to debug HTTP connection
        #opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=0))
        #openit = opener.open
        openit = urlopen
   
    try:
        if method == 'Post':
            req = Request(url_base, data)
            # set appropriate header if posting XML
            try:
                xml = etree.fromstring(data)
                req.add_header('Content-Type', "text/xml")
            except:
                pass
        else:
            req=Request(url_base + data)
        if cookies is not None:
            req.add_header('Cookie', cookies)
        u = openit(req)
    except HTTPError, e: #Some servers may set the http header to 400 if returning an OGC service exception or 401 if unauthorised.
        if e.code in [400, 401]:
            raise ServiceException, e.read()
        else:
            raise e
    # check for service exceptions without the http header set
    if u.info()['Content-Type'] in ['text/xml', 'application/xml']:          
        #just in case 400 headers were not set, going to have to read the xml to see if it's an exception report.
        #wrap the url stram in a extended StringIO object so it's re-readable
        u=RereadableURL(u)      
        se_xml= u.read()
        se_tree = etree.fromstring(se_xml)
        serviceException=se_tree.find('{http://www.opengis.net/ows}Exception')
        if serviceException is None:
            serviceException=se_tree.find('ServiceException')
        if serviceException is not None:
            raise ServiceException, \
            str(serviceException.text).strip()
        u.seek(0) #return cursor to start of u      
    return u
        


src/t/r/TransCloud-HEAD/gisdemo/OWSLib-0.5.0/owslib/wps.py   TransCloud(Download)
                       OWS_NAMESPACE_1_0_0, ServiceIdentification, ServiceProvider, OperationsMetadata
from time import sleep
from util import (testXMLValue, build_get_url, dump, getTypedValue, 
                  getNamespace, xml2string, nspath, openURL, nspath_eval)
from xml.dom.minidom import parseString
            # split URL into base url and query string to use utility function
            spliturl=request_url.split('?')
            u = openURL(spliturl[0], spliturl[1], method='Get', username=username, password=password)
            return etree.fromstring(u.read())
 
        elif method == 'Post':
            u = openURL(url, data, method='Post', username = username, password = password)
                    if '?' in url:
                        spliturl=url.split('?')
                        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
                        # extract output filepath from URL query string
                        if filepath is None:
                            filepath = spliturl[1].split('=')[1]
                    else:
                        u = openURL(url, '', method='Get', username = self.username, password = self.password)

src/t/r/TransCloud-HEAD/gisdemo/OWSLib-0.5.0/owslib/wms.py   TransCloud(Download)
from urllib import urlencode
from etree import etree
from .util import openURL, testXMLValue
from fgdc import Metadata
from iso import MD_Metadata
        data = urlencode(request)
 
        u = openURL(base_url, data, method, username = self.username, password = self.password)
 
        # check for service exceptions, and return
        #now split it up again to use the generic openURL function...
        spliturl=getcaprequest.split('?')
        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
        return etree.fromstring(u.read())
 

src/o/w/OWSLib-HEAD/owslib/wms.py   OWSLib(Download)
import warnings
from etree import etree
from .util import openURL, testXMLValue, extract_xml_list, xmltag_split
from fgdc import Metadata
from iso import MD_Metadata
        data = urlencode(request)
 
        u = openURL(base_url, data, method, username = self.username, password = self.password)
 
        # check for service exceptions, and return
        #now split it up again to use the generic openURL function...
        spliturl=getcaprequest.split('?')
        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
        return etree.fromstring(u.read())
 

src/o/w/OWSLib-HEAD/owslib/wmts.py   OWSLib(Download)
from urllib import urlencode
from etree import etree
from .util import openURL, testXMLValue, xmltag_split
from fgdc import Metadata
from iso import MD_Metadata
            except StopIteration:
                pass
        u = openURL(base_url, data, username = self.username, password = self.password)
 
        # check for service exceptions, and return
        #now split it up again to use the generic openURL function...
        spliturl=getcaprequest.split('?')
        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
        return etree.fromstring(u.read())
 

src/o/w/OWSLib-0.8.6/owslib/wms.py   OWSLib(Download)
import warnings
from etree import etree
from .util import openURL, testXMLValue, extract_xml_list
from fgdc import Metadata
from iso import MD_Metadata
        data = urlencode(request)
 
        u = openURL(base_url, data, method, username = self.username, password = self.password)
 
        # check for service exceptions, and return
        #now split it up again to use the generic openURL function...
        spliturl=getcaprequest.split('?')
        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
        return etree.fromstring(u.read())
 

src/o/w/OWSLib-HEAD/owslib/tms.py   OWSLib(Download)
 
from etree import etree
from .util import openURL, testXMLValue
 
FORCE900913 = False
    def _gettilefromset(self, tilesets, x, y,z, ext):
        for tileset in tilesets:
            if tileset['order'] == z:
                url = tileset['href'] + '/' + str(x) +'/' + str(y) + '.' + ext
                u = openURL(url, '', username = self.username,
    def read(self, url):
        u = openURL(url, '', method='Get', username = self.username, password = self.password)
        self._parse(etree.fromstring(u.read()))
 
    def readString(self, st):
    def read(self, service_url):
        """Get and parse a TMS capabilities document, returning an
        elementtree instance
        """
        u = openURL(service_url, '', method='Get', username = self.username, password = self.password)

src/o/w/OWSLib-0.8.6/owslib/tms.py   OWSLib(Download)
 
from etree import etree
from .util import openURL, testXMLValue
 
FORCE900913 = False
    def _gettilefromset(self, tilesets, x, y,z, ext):
        for tileset in tilesets:
            if tileset['order'] == z:
                url = tileset['href'] + '/' + str(x) +'/' + str(y) + '.' + ext
                u = openURL(url, '', username = self.username,
    def read(self, url):
        u = openURL(url, '', method='Get', username = self.username, password = self.password)
        self._parse(etree.fromstring(u.read()))
 
    def readString(self, st):
    def read(self, service_url):
        """Get and parse a TMS capabilities document, returning an
        elementtree instance
        """
        u = openURL(service_url, '', method='Get', username = self.username, password = self.password)

src/o/w/OWSLib-0.8.6/owslib/wmts.py   OWSLib(Download)
from urllib import urlencode
from etree import etree
from .util import openURL, testXMLValue
from fgdc import Metadata
from iso import MD_Metadata
        if base_url is None:
            base_url = self.getOperationByName('GetTile').methods['Get']['url']
        u = openURL(base_url, data, username = self.username, password = self.password)
 
        # check for service exceptions, and return
        #now split it up again to use the generic openURL function...
        spliturl=getcaprequest.split('?')
        u = openURL(spliturl[0], spliturl[1], method='Get', username = self.username, password = self.password)
        return etree.fromstring(u.read())