[Pywps-commits] r1184 - in trunk: pywps/Parser tests
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Aug 8 12:46:35 CEST 2011
Author: jesus
Date: 2011-08-08 12:46:34 +0200 (Mon, 08 Aug 2011)
New Revision: 1184
Modified:
trunk/pywps/Parser/Execute.py
trunk/pywps/Parser/Get.py
trunk/tests/parser.py
trunk/tests/perform_requests.py
Log:
FEATURE: There wasn't a way to input "@" as incoded "%40". Path by Andrea Francia (andrea__AT__andreafrancia.it)
Modified: trunk/pywps/Parser/Execute.py
===================================================================
--- trunk/pywps/Parser/Execute.py 2011-08-08 10:05:49 UTC (rev 1183)
+++ trunk/pywps/Parser/Execute.py 2011-08-08 10:46:34 UTC (rev 1184)
@@ -28,7 +28,7 @@
from pywps.Parser.Post import Post as PostParser
from pywps.Parser.Get import Get as GetParser
-import string,re
+import string,re,urllib
class Post(PostParser):
""" HTTP POST XML request encoding parser. """
@@ -59,6 +59,7 @@
identifiers = []
identifierNode = None
dataInputs = []
+
#
# Mandatory options
@@ -310,7 +311,6 @@
attributes["type"] = "ComplexValue"
attributes["asReference"] = True
-
return attributes
def parseHeaderDataInput(self,headerNode):
@@ -365,7 +365,6 @@
attributes["encoding"] = complexDataNode.getAttribute("encoding")
attributes["schema"] = complexDataNode.getAttribute("schema")
attributes["value"] = None
-
for complexDataChildNode in complexDataNode.childNodes:
# CDATA or text and the input value is empty and the Text or
# CDATA is not empty
@@ -474,8 +473,7 @@
# ResponseDocument
try:
self.inputs["responseform"]["responsedocument"] = \
- {"outputs": self.parseDataInputs(
- self.unparsedInputs["responsedocument"])}
+ {"outputs": self.parseDataInputs(self.unparsedInputs["responsedocument"])}
except KeyError:
self.inputs["responseform"]["responsedocument"] = {}
@@ -518,7 +516,6 @@
len(self.inputs["responseform"]["responsedocument"])>0:
raise pywps.InvalidParameterValue(
"Either responseDocument or rawDataOutput should be specified, but not both")
-
return self.inputs
def _parseRawDataOutput(self, dataInput):
@@ -553,39 +550,45 @@
for dataInput in dataInputs.split(";"):
try:
# key is separated by "=" from value
- key,value = string.split(dataInput,"=",maxsplit=1)
+ key,valueAndAttrs = string.split(dataInput,"=",maxsplit=1)
except ValueError,e:
key = dataInput
- value = ""
+ valueAndAttrs = ""
- if not key and not value:
+ if not key and not valueAndAttrs:
continue
-
+
# initial value
- parsedDataInputs.append({"identifier":key, "value":None})
-
+ parsed={"identifier":key, "value":None}
# additional input attributes are separated by "@"
attributes = []
- if value.find("@") > 0:
- parsedDataInputs[-1]["value"]=value.split("@")[0]
- attributes=value.split("@")[1:]
- elif value.find("@") == 0:
- parsedDataInputs[-1]["value"]=None
- attributes=value.split("@")[1:]
+ if valueAndAttrs.find("@") > 0:
+
+ encodedValue=valueAndAttrs.split("@")[0]
+ parsed["value"]=urllib.unquote(encodedValue)
+ attributes=valueAndAttrs.split("@")[1:]
+
+ elif valueAndAttrs.find("@") == 0:
+ parsed["value"]=None
+ attributes=valueAndAttrs.split("@")[1:]
else:
- parsedDataInputs[-1]["value"]=self._trueOrFalse(value)
+ #needs to be checked for trueOrFalse
+ encodedValue=valueAndAttrs
+ parsed["value"]=self._trueOrFalse(urllib.unquote(valueAndAttrs))
attributes = []
-
+
# additional attribute key is separated by "=" from it's value
for attribute in attributes:
attributeKey, attributeValue = attribute.split("=")
- parsedDataInputs[-1][attributeKey.lower()] =self._trueOrFalse(attributeValue)
+
+ parsed[attributeKey.lower()]=self._trueOrFalse(urllib.unquote(attributeValue))
+
+ parsedDataInputs.append(parsed)
return parsedDataInputs
-
- # Moved to Parser class
+
+ #Moved to Parser class
#def _trueOrFalse(self,str):
# """Return True or False, if input is "true" or "false" """
- #
# if str.lower() == "false":
# return False
# elif str.lower() == "true":
Modified: trunk/pywps/Parser/Get.py
===================================================================
--- trunk/pywps/Parser/Get.py 2011-08-08 10:05:49 UTC (rev 1183)
+++ trunk/pywps/Parser/Get.py 2011-08-08 10:46:34 UTC (rev 1184)
@@ -41,8 +41,8 @@
import pywps.config
from pywps.Parser import Parser
from pywps.Process.Lang import Lang
-import urllib
+
class Get(Parser):
""" Main Class for parsing HTTP GET request types """
unparsedInputs = None # temporary store for later validation
@@ -83,7 +83,6 @@
else:
try:
key,value = split(feature,"=",maxsplit=1)
- value = urllib.unquote(value)
except:
raise NoApplicableCode(\
'Invalid Key-Value-Pair: "' + \
@@ -105,7 +104,7 @@
# parse the request
self.inputs = self.requestParser.parse(self.unparsedInputs, self.inputs)
-
+
if not self.inputs:
raise MissingParameterValue("service")
return self.inputs
Modified: trunk/tests/parser.py
===================================================================
--- trunk/tests/parser.py 2011-08-08 10:05:49 UTC (rev 1183)
+++ trunk/tests/parser.py 2011-08-08 10:46:34 UTC (rev 1184)
@@ -2,7 +2,8 @@
import sys
pywpsPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0],".."))
-sys.path.append(pywpsPath)
+sys.path.insert(0,pywpsPath)
+#sys.path.append(pywpsPath)
import pywps
import pywps.Process
@@ -80,11 +81,14 @@
self.assertEquals(getinputs, postinputs,"Get and Post inputs are not same:\n%s\n%s" % (getinputs,postinputs))
def testParseExecuteLiteralInput(self):
- """Test if Execute request is parsed, literal data inputs"""
+ """Test if Execute request is parsed, literal data inputs, including '@' in GET """
+
+ #NOTE: Unittest changed after SVN: 1146 to check for the parsing of "@"
+
getpywps = pywps.Pywps(pywps.METHOD_GET)
postpywps = pywps.Pywps(pywps.METHOD_POST)
executeRequestFile = open(os.path.join(pywpsPath,"tests","requests","wps_execute_request-literalinput.xml"))
- getinputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=literalprocess&datainputs=[int=1;string=spam;float=1.1]")
+ getinputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=literalprocess&datainputs=[int=1;string=spam%40foo.com at mimetype=text/plain at xlink:href=http%3A//www.w3.org/TR/xmlschema-2/%23string;float=1.1]")
postinputs = postpywps.parseRequest(executeRequestFile)
self.assertEquals(getinputs["request"], "execute")
@@ -98,7 +102,7 @@
self.assertEquals(getinputs["datainputs"][1]["value"],postinputs["datainputs"][1]["value"])
self.assertEquals(getinputs["datainputs"][2]["value"],postinputs["datainputs"][2]["value"])
self.assertTrue(getinputs["datainputs"][0]["value"],1)
- self.assertTrue(getinputs["datainputs"][1]["value"],"spam")
+ self.assertTrue(getinputs["datainputs"][1]["value"],"spam%40foo.com")
self.assertTrue(getinputs["datainputs"][2]["value"],"1.1")
def testParseExecuteComplexInputAsReference(self):
Modified: trunk/tests/perform_requests.py
===================================================================
--- trunk/tests/perform_requests.py 2011-08-08 10:05:49 UTC (rev 1183)
+++ trunk/tests/perform_requests.py 2011-08-08 10:46:34 UTC (rev 1184)
@@ -168,7 +168,7 @@
getpywps = pywps.Pywps(pywps.METHOD_GET)
postpywps = pywps.Pywps(pywps.METHOD_POST)
- getinputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=literalprocess&datainputs=[int=1;string=spam;float=1.1;zeroset=0.0;bool=False]")
+ getinputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=literalprocess&datainputs=[int=1;string=spam%40foo.com;float=1.1;zeroset=0.0;bool=False]")
executeRequestFile = open(os.path.join(pywpsPath,"tests","requests","wps_execute_request-literalinput.xml"))
postinputs = postpywps.parseRequest(executeRequestFile)
@@ -194,7 +194,7 @@
self.assertEquals(getliteraldata[0].firstChild.nodeValue, "1")
self.assertEquals(getliteraldata[1].firstChild.nodeValue, "1.1")
self.assertEquals(getliteraldata[2].firstChild.nodeValue, "False")
- self.assertEquals(getliteraldata[3].firstChild.nodeValue, "spam")
+ self.assertEquals(getliteraldata[3].firstChild.nodeValue, "spam at foo.com")
More information about the Pywps-commits
mailing list