<commit_before>"""Module for designed for printing any kind of response. CGI,
mod_python, Java Servlet and possibly others, which will come in the
future

.. data:: EMPTYPARAMREGEX

    Regular expression for empty parameter identificaion

"""

import types
from sys import stdout as STDOUT
from sys import stderr as STDERR
import re
from pywps import Exceptions
from os import name as OSNAME
from pywps import Soap 

EMPTYPARAMREGEX = re.compile('( \w+="")|( \w+="None")')

def response(response,targets,soapVersion=None,isSoap=False,contentType="application/xml"):
    """
    Print response to files given as input parameter.

    :param targets: file object or list of file objects. File name,
        mod_python request or java servlet response
    :type targets: string or list, 
    :param isSoap: print the response in SOAP envelope
    :type isSoap: bool
    :param response: the response object 
    :type response: file or string
    """


    # convert single file to array
    if type(targets) != type([]):
        targets = [targets]

    if isSoap:
        soap = Soap.SOAP()
        response = soap.getResponse(response,soapVersion)

    if isinstance(response,Exceptions.WPSException):
        response = response.__str__()


    if type(response) != types.FileType:
        response = re.sub(EMPTYPARAMREGEX,"",response)

    # for each file in file descriptor
    for f in targets:

        # consider, if this CGI, mod_python or Java requested output
        # mod_python here
        if repr(type(f)) == "<type 'mp_request'>":
            _printResponseModPython(f,response,contentType)

        # file object (output, or sys.stdout)
        elif types.FileType == type(f):
            _printResponseFile(f,response,contentType)

        # java servlet response
        elif OSNAME == "java" :
            _printResponseJava(f,response,contentType)

        # close and open again, if it is a file
        if type(response) == types.FileType:
            response.close()
            response = open(response.name,"rb")
<commit_msg>New parameters in getResponse: soapVersion and isSoapExecute<commit_after>"""Module for designed for printing any kind of response. CGI,
mod_python, Java Servlet and possibly others, which will come in the
future

.. data:: EMPTYPARAMREGEX

    Regular expression for empty parameter identificaion

"""

import types
from sys import stdout as STDOUT
from sys import stderr as STDERR
import re
from pywps import Exceptions
from os import name as OSNAME
from pywps import Soap 

EMPTYPARAMREGEX = re.compile('( \w+="")|( \w+="None")')

def response(response,targets,soapVersion=None,isSoap=False,isSoapExecute=False,contentType="application/xml"):
    """
    Print response to files given as input parameter.

    :param targets: file object or list of file objects. File name,
        mod_python request or java servlet response
    :type targets: string or list, 
    :param isSoap: print the response in SOAP envelope
    :type isSoap: bool
    :param response: the response object 
    :type response: file or string
    """


    # convert single file to array
    if type(targets) != type([]):
        targets = [targets]

    if isSoap:
        soap = Soap.SOAP()
        
        response = soap.getResponse(response,soapVersion,isSoapExecute)

    if isinstance(response,Exceptions.WPSException):
        response = response.__str__()


    if type(response) != types.FileType:
        response = re.sub(EMPTYPARAMREGEX,"",response)

    # for each file in file descriptor
    for f in targets:

        # consider, if this CGI, mod_python or Java requested output
        # mod_python here
        if repr(type(f)) == "<type 'mp_request'>":
            _printResponseModPython(f,response,contentType)

        # file object (output, or sys.stdout)
        elif types.FileType == type(f):
            _printResponseFile(f,response,contentType)

        # java servlet response
        elif OSNAME == "java" :
            _printResponseJava(f,response,contentType)

        # close and open again, if it is a file
        if type(response) == types.FileType:
            response.close()
            response = open(response.name,"rb")

{'fraction_non_alphanumeric': 0.08913250714966635, 'fraction_numerical': 0.0, 'mean_word_length': 3.0278310940499042, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462353', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1154, 'n_words': 404}