[owslib] 01/05: Imported Upstream version 0.11.1
Sebastiaan Couwenberg
sebastic at moszumanska.debian.org
Thu May 12 17:55:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository owslib.
commit c0b96870bb0c8369197a9ec367970bbe7ef1675d
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Thu May 12 19:46:04 2016 +0200
Imported Upstream version 0.11.1
---
VERSION.txt | 2 +-
owslib/__init__.py | 2 +-
owslib/util.py | 16 +++----
owslib/wms.py | 21 ++++-----
owslib/wmts.py | 5 ++-
owslib/wps.py | 13 +++---
tests/doctests/wfs_MapServerWFSCapabilities.txt | 4 +-
tests/doctests/wps_request10.txt | 51 ++++++++++++++++++++++
tests/resources/wps_USGSExecuteRequest2.xml | 2 +-
...uteRequest2.xml => wps_USGSExecuteRequest4.xml} | 2 +-
10 files changed, 84 insertions(+), 34 deletions(-)
diff --git a/VERSION.txt b/VERSION.txt
index d9df1bb..af88ba8 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1 +1 @@
-0.11.0
+0.11.1
diff --git a/owslib/__init__.py b/owslib/__init__.py
index 145435f..744f304 100644
--- a/owslib/__init__.py
+++ b/owslib/__init__.py
@@ -1,3 +1,3 @@
from __future__ import (absolute_import, division, print_function)
-__version__ = '0.11.0'
+__version__ = '0.11.1'
diff --git a/owslib/util.py b/owslib/util.py
index 21e821b..b40ac2a 100644
--- a/owslib/util.py
+++ b/owslib/util.py
@@ -129,24 +129,21 @@ class ResponseWrapper(object):
return self._response.headers
def read(self):
- if not self._response.encoding:
- return self._response.content # bytes
-
- return self._response.text.encode('utf-8') # str
+ return self._response.content
def geturl(self):
return self._response.url
# @TODO: __getattribute__ for poking at response
-def openURL(url_base, data=None, method='Get', cookies=None, username=None, password=None, timeout=30):
+def openURL(url_base, data=None, method='Get', cookies=None, username=None, password=None, timeout=30, headers=None):
"""
Function to open URLs.
Uses requests library but with additional checks for OGC service exceptions and url formatting.
Also handles cookies and simple user password authentication.
"""
- headers = None
+ headers = headers if headers is not None else {}
rkwargs = {}
rkwargs['timeout'] = timeout
@@ -164,7 +161,7 @@ def openURL(url_base, data=None, method='Get', cookies=None, username=None, pass
if method.lower() == 'post':
try:
xml = etree.fromstring(data)
- headers = {'Content-Type': 'text/xml'}
+ headers['Content-Type'] = 'text/xml'
except (ParseError, UnicodeEncodeError):
pass
@@ -378,10 +375,7 @@ def http_post(url=None, request=None, lang='en-US', timeout=10, username=None, p
rkwargs['auth'] = (username, password)
up = requests.post(url, request, headers=headers, **rkwargs)
- if not up.encoding:
- return up.content # bytes
-
- return up.text.encode('utf-8') # str
+ return up.content
def element_to_string(element, encoding=None, xml_declaration=False):
"""
diff --git a/owslib/wms.py b/owslib/wms.py
index 56ab50b..e7ab2b4 100644
--- a/owslib/wms.py
+++ b/owslib/wms.py
@@ -67,17 +67,18 @@ class WebMapService(object):
raise KeyError("No content named %s" % name)
- def __init__(self, url, version='1.1.1', xml=None, username=None, password=None, parse_remote_metadata=False, timeout=30):
+ def __init__(self, url, version='1.1.1', xml=None, username=None, password=None, parse_remote_metadata=False, timeout=30, headers=None):
"""Initialize."""
self.url = url
self.username = username
self.password = password
self.version = version
self.timeout = timeout
+ self.headers = headers
self._capabilities = None
# Authentication handled by Reader
- reader = WMSCapabilitiesReader(self.version, url=self.url, un=self.username, pw=self.password)
+ reader = WMSCapabilitiesReader(self.version, url=self.url, un=self.username, pw=self.password, headers=self.headers)
if xml: # read from stored xml
self._capabilities = reader.readString(xml)
else: # read from server
@@ -95,7 +96,7 @@ class WebMapService(object):
def _getcapproperty(self):
if not self._capabilities:
reader = WMSCapabilitiesReader(
- self.version, url=self.url, un=self.username, pw=self.password
+ self.version, url=self.url, un=self.username, pw=self.password, headers=self.headers
)
self._capabilities = ServiceMetadata(reader.read(self.url))
return self._capabilities
@@ -152,7 +153,7 @@ class WebMapService(object):
NOTE: this is effectively redundant now"""
reader = WMSCapabilitiesReader(
- self.version, url=self.url, un=self.username, pw=self.password
+ self.version, url=self.url, un=self.username, pw=self.password, headers=self.headers
)
u = self._open(reader.capabilities_url(self.url))
# check for service exceptions, and return
@@ -195,7 +196,6 @@ class WebMapService(object):
if kwargs:
for kw in kwargs:
request[kw]=kwargs[kw]
-
return request
def getmap(self, layers=None, styles=None, srs=None, bbox=None,
@@ -254,11 +254,11 @@ class WebMapService(object):
request = self.__build_getmap_request(layers=layers, styles=styles, srs=srs, bbox=bbox,
format=format, size=size, time=time, transparent=transparent,
- bgcolor=bgcolor, exceptions=exceptions, kwargs=kwargs)
+ bgcolor=bgcolor, exceptions=exceptions, **kwargs)
data = urlencode(request)
- u = openURL(base_url, data, method, username=self.username, password=self.password, timeout=timeout or self.timeout)
+ u = openURL(base_url, data, method, username=self.username, password=self.password, timeout=timeout or self.timeout, headers=self.headers)
# check for service exceptions, and return
if u.info()['Content-Type'] == 'application/vnd.ogc.se_xml':
@@ -304,7 +304,7 @@ class WebMapService(object):
data = urlencode(request)
- u = openURL(base_url, data, method, username=self.username, password=self.password, timeout=timeout or self.timeout)
+ u = openURL(base_url, data, method, username=self.username, password=self.password, timeout=timeout or self.timeout, headers=self.headers)
# check for service exceptions, and return
if u.info()['Content-Type'] == 'application/vnd.ogc.se_xml':
@@ -647,13 +647,14 @@ class WMSCapabilitiesReader:
"""Read and parse capabilities document into a lxml.etree infoset
"""
- def __init__(self, version='1.1.1', url=None, un=None, pw=None):
+ def __init__(self, version='1.1.1', url=None, un=None, pw=None, headers=None):
"""Initialize"""
self.version = version
self._infoset = None
self.url = url
self.username = un
self.password = pw
+ self.headers = headers
#if self.username and self.password:
## Provide login information in order to use the WMS server
@@ -695,7 +696,7 @@ class WMSCapabilitiesReader:
#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, timeout=timeout)
+ u = openURL(spliturl[0], spliturl[1], method='Get', username=self.username, password=self.password, timeout=timeout, headers=self.headers)
return etree.fromstring(u.read())
def readString(self, st):
diff --git a/owslib/wmts.py b/owslib/wmts.py
index 07142e8..2235137 100644
--- a/owslib/wmts.py
+++ b/owslib/wmts.py
@@ -88,7 +88,8 @@ _TILE_MATRIX_LIMITS_TAG = _WMTS_NS + 'TileMatrixLimits'
_TILE_MATRIX_TAG = _WMTS_NS + 'TileMatrix'
_TILE_WIDTH_TAG = _WMTS_NS + 'TileWidth'
_TOP_LEFT_CORNER_TAG = _WMTS_NS + 'TopLeftCorner'
-
+_KEYWORDS_TAG = _OWS_NS + 'Keywords'
+_KEYWORD_TAG = _OWS_NS + 'Keyword'
_HREF_TAG = _XLINK_NS + 'href'
@@ -736,6 +737,8 @@ class ContentMetadata:
self.formats = [f.text for f in elem.findall(_FORMAT_TAG)]
+ self.keywords = [f.text for f in elem.findall(
+ _KEYWORDS_TAG+'/'+_KEYWORD_TAG)]
self.infoformats = [f.text for f in elem.findall(_INFO_FORMAT_TAG)]
self.layers = []
diff --git a/owslib/wps.py b/owslib/wps.py
index 5b74691..3b94234 100644
--- a/owslib/wps.py
+++ b/owslib/wps.py
@@ -111,6 +111,7 @@ DRAW_NAMESPACE = n.get_namespace("draw")
GML_SCHEMA_LOCATION = "http://schemas.opengis.net/gml/3.1.1/base/feature.xsd"
DRAW_SCHEMA_LOCATION = 'http://cida.usgs.gov/climate/derivative/xsd/draw.xsd'
+WFS_SCHEMA_LOCATION = 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd'
WPS_DEFAULT_SCHEMA_LOCATION = 'http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd'
WPS_DEFAULT_VERSION = '1.0.0'
@@ -1115,7 +1116,7 @@ class Output(InputOutput):
# <LiteralOutput>
self._parseLiteralData(outputElement, 'LiteralOutput')
-
+
# <ComplexData> or <ComplexOutput>
self._parseComplexData(outputElement, 'ComplexOutput')
@@ -1397,8 +1398,7 @@ class WFSFeatureCollection(FeatureCollection):
FeatureCollection specified by a WFS query.
All subclasses must implement the getQuery() method to provide the specific query portion of the XML.
'''
-
- def __init__(self, wfsUrl, wfsQuery):
+ def __init__(self, wfsUrl, wfsQuery, wfsMethod=None):
'''
wfsUrl: the WFS service URL
example: wfsUrl = "http://igsarm-cida-gdp2.er.usgs.gov:8082/geoserver/wfs"
@@ -1406,7 +1406,7 @@ class WFSFeatureCollection(FeatureCollection):
'''
self.url = wfsUrl
self.query = wfsQuery
-
+ self.method = wfsMethod
# <wps:Reference xlink:href="http://igsarm-cida-gdp2.er.usgs.gov:8082/geoserver/wfs">
# <wps:Body>
# <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" service="WFS" version="1.1.0" outputFormat="text/xml; subtype=gml/3.1.1" xsi:schemaLocation="http://www.opengis.net/wfs ../wfs/1.1.0/WFS.xsd">
@@ -1415,9 +1415,10 @@ class WFSFeatureCollection(FeatureCollection):
# </wps:Body>
# </wps:Reference>
def getXml(self):
-
root = etree.Element(nspath_eval('wps:Reference', namespaces),
attrib={nspath_eval("xlink:href", namespaces): self.url})
+ if self.method:
+ root.attrib['method'] = self.method
bodyElement = etree.SubElement(
root, nspath_eval('wps:Body', namespaces))
getFeatureElement = etree.SubElement(
@@ -1425,7 +1426,7 @@ class WFSFeatureCollection(FeatureCollection):
attrib={"service": "WFS",
"version": "1.1.0",
"outputFormat": "text/xml; subtype=gml/3.1.1",
- nspath_eval("xsi:schemaLocation", namespaces): "%s %s" % (namespaces['wfs'], '../wfs/1.1.0/WFS.xsd')})
+ nspath_eval("xsi:schemaLocation", namespaces): "%s %s" % (namespaces['wfs'], WFS_SCHEMA_LOCATION)})
# <wfs:Query typeName="sample:CONUS_States">
# <wfs:PropertyName>the_geom</wfs:PropertyName>
diff --git a/tests/doctests/wfs_MapServerWFSCapabilities.txt b/tests/doctests/wfs_MapServerWFSCapabilities.txt
index 6e3d656..e74050d 100644
--- a/tests/doctests/wfs_MapServerWFSCapabilities.txt
+++ b/tests/doctests/wfs_MapServerWFSCapabilities.txt
@@ -101,6 +101,6 @@ Test exceptions
Lastly, test the getcapabilities method
>>> wfs = WebFeatureService('http://nsidc.org/cgi-bin/atlas_south?', version='1.0')
- >>> xml = wfs.getcapabilities().read().decode('utf-8')
- >>> xml.find('<WFS_Capabilities') > 0
+ >>> xml = wfs.getcapabilities().read()
+ >>> xml.find(b'<WFS_Capabilities') > 0
True
diff --git a/tests/doctests/wps_request10.txt b/tests/doctests/wps_request10.txt
new file mode 100644
index 0000000..a604d1c
--- /dev/null
+++ b/tests/doctests/wps_request10.txt
@@ -0,0 +1,51 @@
+Python doctest file to test generation of a WPS request from input arguments.
+The specific request involves a FeatureWeightedGridStatisticsAlgorithm process over a WFS feature.
+
+Imports
+
+ >>> from __future__ import (absolute_import, division, print_function)
+ >>> from tests.utils import resource_file, compare_xml
+ >>> from owslib.wps import WPSExecution, WFSFeatureCollection, WFSQuery
+ >>> from owslib.etree import etree
+
+Supply process input arguments
+
+ >>> wfsUrl = "http://igsarm-cida-gdp2.er.usgs.gov:8082/geoserver/wfs"
+ >>> query = WFSQuery("sample:CONUS_States", propertyNames=['the_geom',"STATE"], filters=["CONUS_States.508","CONUS_States.469"])
+ >>> method = 'POST'
+ >>> featureCollection = WFSFeatureCollection(wfsUrl, query, wfsMethod=method)
+ >>> processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
+ >>> inputs = [ ("FEATURE_ATTRIBUTE_NAME","STATE"),
+ ... ("DATASET_URI", "dods://igsarm-cida-thredds1.er.usgs.gov:8080/thredds/dodsC/dcp/conus_grid.w_meta.ncml"),
+ ... ("DATASET_ID", "ccsm3_a1b_tmax"),
+ ... ("DATASET_ID", "ccsm3_a1b_pr"),
+ ... ("DATASET_ID", "ccsm3_a1fi_tmax"),
+ ... ("TIME_START","1960-01-01T00:00:00.000Z"),
+ ... ("TIME_END","1960-12-31T00:00:00.000Z"),
+ ... ("REQUIRE_FULL_COVERAGE","true"),
+ ... ("DELIMITER","COMMA"),
+ ... ("STATISTICS","MEAN"),
+ ... ("STATISTICS","MINIMUM"),
+ ... ("STATISTICS","MAXIMUM"),
+ ... ("STATISTICS","WEIGHT_SUM"),
+ ... ("STATISTICS","VARIANCE"),
+ ... ("STATISTICS","STD_DEV"),
+ ... ("STATISTICS","COUNT"),
+ ... ("GROUP_BY","STATISTIC"),
+ ... ("SUMMARIZE_TIMESTEP","true"),
+ ... ("SUMMARIZE_FEATURE_ATTRIBUTE","true"),
+ ... ("FEATURE_COLLECTION", featureCollection)
+ ... ]
+ >>> output = "OUTPUT"
+
+ # build XML request for WPS process execution
+ >>> execution = WPSExecution()
+ >>> requestElement = execution.buildRequest(processid, inputs, output=output)
+ >>> request = etree.tostring( requestElement )
+
+Compare to cached XML request
+
+ >>> _request = open(resource_file('wps_USGSExecuteRequest4.xml'), 'rb').read()
+ >>> compare_xml(request, _request)
+ True
+
diff --git a/tests/resources/wps_USGSExecuteRequest2.xml b/tests/resources/wps_USGSExecuteRequest2.xml
index 35acdb1..77b9bf6 100644
--- a/tests/resources/wps_USGSExecuteRequest2.xml
+++ b/tests/resources/wps_USGSExecuteRequest2.xml
@@ -1 +1 @@
-<wps:Execute xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns="http://www.opengis.net/wps/1.0.0" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_reque [...]
\ No newline at end of file
+<wps:Execute xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns="http://www.opengis.net/wps/1.0.0" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_reque [...]
\ No newline at end of file
diff --git a/tests/resources/wps_USGSExecuteRequest2.xml b/tests/resources/wps_USGSExecuteRequest4.xml
similarity index 80%
copy from tests/resources/wps_USGSExecuteRequest2.xml
copy to tests/resources/wps_USGSExecuteRequest4.xml
index 35acdb1..ff68d66 100644
--- a/tests/resources/wps_USGSExecuteRequest2.xml
+++ b/tests/resources/wps_USGSExecuteRequest4.xml
@@ -1 +1 @@
-<wps:Execute xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns="http://www.opengis.net/wps/1.0.0" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_reque [...]
\ No newline at end of file
+<wps:Execute xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns="http://www.opengis.net/wps/1.0.0" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_reque [...]
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/owslib.git
More information about the Pkg-grass-devel
mailing list