<commit_before>"""
Get
---

.. moduleauthor: <NAME>
"""
# Author:	<NAME>
#        	http://les-ejk.cz
# Lince:
#
# Web Processing Service implementation
# Copyright (C) 2006 <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# references used in the comments of this source code:
# OWS_1-1-0:
#      OGC Web Services Common Specification
#      version 1.1.0 with Corrigendum 1
#      ref.num.: OGC 06-121r3
# WPS_1-0-0:
#      OpenGIS(R) Web Processing Service
#      version 1.0.0
#      ref.num.: OGC 05-007r7

import urllib
import types
from string import split
import pywps
from pywps.Exceptions import *
import pywps.config
from pywps.Parser import Parser
from pywps.Process.Lang import Lang


class Get(Parser):
    """ Main Class for parsing HTTP GET request types """
    unparsedInputs =  None    # temporary store for later validation
    requestParser = None

    GET_CAPABILITIES = "getcapabilities"
    DESCRIBE_PROCESS = "describeprocess"
    EXECUTE = "execute"

    def __init__(self,wps):
        Parser.__init__(self,wps)
        self.unparsedInputs = {}

    def parse(self,queryString):
        """Parse given string with parameters given in KVP encoding

        :param queryString: string of parameters taken from URL in KVP encoding
        :returns: parsed inputs object
        """

        key = None
        value = None
        keys = []
        maxInputLength = int(pywps.config.getConfigValue("server","maxinputparamlength"))
        unquotedQueryString = urllib.unquote(queryString)
        serverEncoding = pywps.config.getConfigValue("wps", "encoding")
        decodedQueryString = unquotedQueryString.decode(serverEncoding)
        # parse query string
        # arguments are separated by "&" character
        # everything is stored into unparsedInputs structure, for latter
        # validation
        for feature in decodedQueryString.split("&"):
            feature = feature.strip()
            # omit empty KVPs, e.g. due to optional ampersand after the last
            # KVP in request string (OWS_1-1-0, p.75, sect. 11.2):
            if not feature == '':
                if feature.lower() == "wsdl":
                    self.inputs["wsdl"] = True
                    break
                else:
                    try:
                        key,value = split(feature,"=",maxsplit=1)
                    except:
                        raise NoApplicableCode(\
                                                    'Invalid Key-Value-Pair: "' + \
                                                    str(feature) + '"')
                    if value.find("[") == 0:  # if value in brackets:
                        value = value[1:-1]   #    delete brackets
                    if len(value)>maxInputLength:
                            raise FileSizeExceeded(key)
                keys.append(key)
                self.unparsedInputs[key.lower()] = value[:maxInputLength]


        if not self.inputs.has_key("wsdl"):
            # check service name
            service = self.checkService()

            # check request type
            self.checkRequestType()
<commit_msg>@jorgejesus temporary fix to GET parser<commit_after>"""
Get
---

.. moduleauthor: <NAME>
"""
# Author:	<NAME>
#        	http://les-ejk.cz
# Lince:
#
# Web Processing Service implementation
# Copyright (C) 2006 <NAME>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# references used in the comments of this source code:
# OWS_1-1-0:
#      OGC Web Services Common Specification
#      version 1.1.0 with Corrigendum 1
#      ref.num.: OGC 06-121r3
# WPS_1-0-0:
#      OpenGIS(R) Web Processing Service
#      version 1.0.0
#      ref.num.: OGC 05-007r7

import urllib
import types
from string import split
import pywps
from pywps.Exceptions import *
import pywps.config
from pywps.Parser import Parser
from pywps.Process.Lang import Lang


class Get(Parser):
    """ Main Class for parsing HTTP GET request types """
    unparsedInputs =  None    # temporary store for later validation
    requestParser = None

    GET_CAPABILITIES = "getcapabilities"
    DESCRIBE_PROCESS = "describeprocess"
    EXECUTE = "execute"

    def __init__(self,wps):
        Parser.__init__(self,wps)
        self.unparsedInputs = {}

    def parse(self,queryString):
        """Parse given string with parameters given in KVP encoding

        :param queryString: string of parameters taken from URL in KVP encoding
        :returns: parsed inputs object
        """

        key = None
        value = None
        keys = []
        maxInputLength = int(pywps.config.getConfigValue("server","maxinputparamlength"))
        serverEncoding = pywps.config.getConfigValue("wps", "encoding")
        decodedQueryString = queryString.decode(serverEncoding)
        
        # parse query string
        # arguments are separated by "&" character
        # everything is stored into unparsedInputs structure, for latter
        # validation
        for feature in decodedQueryString.split("&"):
            feature= urllib.unquote(feature)
        #for feature in decodedQueryString.split("&"):
            feature = feature.strip()
            # omit empty KVPs, e.g. due to optional ampersand after the last
            # KVP in request string (OWS_1-1-0, p.75, sect. 11.2):
            if not feature == '':
                if feature.lower() == "wsdl":
                    self.inputs["wsdl"] = True
                    break
                else:
                    try:
                        key,value = split(feature,"=",maxsplit=1)
                    except:
                        raise NoApplicableCode(\
                                                    'Invalid Key-Value-Pair: "' + \
                                                    str(feature) + '"')
                    if value.find("[") == 0:  # if value in brackets:
                        value = value[1:-1]   #    delete brackets
                    if len(value)>maxInputLength:
                            raise FileSizeExceeded(key)
                keys.append(key)
                self.unparsedInputs[key.lower()] = value[:maxInputLength]


        if not self.inputs.has_key("wsdl"):
            # check service name
            service = self.checkService()

            # check request type
            self.checkRequestType()

{'fraction_non_alphanumeric': 0.08563864990072799, 'fraction_numerical': 0.014030443414956982, 'mean_word_length': 2.075295075295075, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5131614', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1980, 'n_words': 685}