<commit_before># -*- coding: utf-8 -*-
import proxy
import urllib
import requests
from django.conf import settings
from django.http import HttpResponse
#import xml.etree.ElementTree as ET
from lxml import etree as ET
from django.contrib.auth.models import User
from geoprisma.utils import isAuthorized
from geoprisma.models import Datastore
from django.db.models import Q


class WMSProxyFactory(object):
    """
    Un proxy factory pour le WMS qui retourne le bon proxy WMS selon l'operation demande.

    """
    WMS_OP_GETCAPABILITIES = 1
    WMS_OP_GETMAP = 2
    WMS_OP_GETLEGENDGRAPHIC = 3
    WMS_OP_GETFEATUREINFO = 4


    def getWMSProxy(self, pobjService, prequest):
        """
        Recupere le proxy selon l'operation

        Args:
            pobjService: Object service
            prequest: La requete
        Returns:
            Un proxy WMS
        """
        iOPType = self.getOperationFromGET(prequest)

        objWMSProxy = None
        if iOPType == self.WMS_OP_GETCAPABILITIES:
            objWMSProxy = WMSGetCapabilityProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETMAP:
            objWMSProxy = WMSProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETLEGENDGRAPHIC:
            objWMSProxy = WMSProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETFEATUREINFO:
            objWMSProxy = WMSProxy(pobjService, prequest)

        if objWMSProxy is None:
            raise Exception("Proxy method not handled.")

        return objWMSProxy

    def getOperationFromGET(self, prequest):
        """
        Recupere l'operation dans l'url

        Args:
            prequest: La requete contenant l'url
        Returns:
            l'operation
        """
        strRequest = ''
        for (strKey, strValue) in prequest.GET.iteritems():
            if strKey.upper() == 'REQUEST':
                strRequest = strValue
                break
        if strRequest == 'GetCapabilities':
            return self.WMS_OP_GETCAPABILITIES
        elif strRequest == 'GetMap':
            return self.WMS_OP_GETMAP
        elif strRequest == 'GetLegendGraphic':
            return self.WMS_OP_GETLEGENDGRAPHIC
        elif strRequest == 'GetFeatureInfo':
            return self.WMS_OP_GETFEATUREINFO
        return None

class WMSProxy(proxy.Proxy):
    """
    Class WMSProxy qui herite de la class proxy de base

    """

    def getAction(self):
        return self.CRUD_READ

    def setResources(self, pobjArrayResources):
        """
        Defini la resource du proxy

        Args:
            pobjArrayResources: Object resource
        """
        self.m_objResource = pobjArrayResources

    def process(self):
        """
        Traite l'information a retourner

        Returns:
            HttpResponce
        """
        excluded_headers = ('connection','keep-alive','proxy-authenticate','proxy-authorization','te','trailers','transfer-encoding','content-encoding','upgrade')

        if self.m_objRequest.method == "POST":
            strServiceURL = self.m_objService.source
            strParams = self.getRequestParams()
            requestUrl = requests.post(strServiceURL, data=strParams)
<commit_msg>Update wmsproxy.py<commit_after># -*- coding: utf-8 -*-
import proxy
import urllib
import requests
from django.conf import settings
from django.http import HttpResponse
#import xml.etree.ElementTree as ET
from lxml import etree as ET
from django.contrib.auth.models import User
from geoprisma.utils import isAuthorized
from geoprisma.models import Datastore
from django.db.models import Q


class WMSProxyFactory(object):
    """
    Un proxy factory pour le WMS qui retourne le bon proxy WMS selon l'operation demande.

    """
    WMS_OP_GETCAPABILITIES = 1
    WMS_OP_GETMAP = 2
    WMS_OP_GETLEGENDGRAPHIC = 3
    WMS_OP_GETFEATUREINFO = 4


    def getWMSProxy(self, pobjService, prequest):
        """
        Recupere le proxy selon l'operation

        Args:
            pobjService: Object service
            prequest: La requete
        Returns:
            Un proxy WMS
        """
        iOPType = self.getOperationFromGET(prequest)

        objWMSProxy = None
        if iOPType == self.WMS_OP_GETCAPABILITIES:
            objWMSProxy = WMSGetCapabilityProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETMAP:
            objWMSProxy = WMSProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETLEGENDGRAPHIC:
            objWMSProxy = WMSProxy(pobjService, prequest)
        elif iOPType == self.WMS_OP_GETFEATUREINFO:
            objWMSProxy = WMSProxy(pobjService, prequest)

        if objWMSProxy is None:
            raise Exception("Proxy method not handled.")

        return objWMSProxy

    def getOperationFromGET(self, prequest):
        """
        Recupere l'operation dans l'url

        Args:
            prequest: La requete contenant l'url
        Returns:
            l'operation
        """
        strRequest = ''
        for (strKey, strValue) in prequest.GET.iteritems():
            if strKey.upper() == 'REQUEST':
                strRequest = strValue
                break
        if strRequest == 'GetCapabilities':
            return self.WMS_OP_GETCAPABILITIES
        elif strRequest == 'GetMap':
            return self.WMS_OP_GETMAP
        elif strRequest == 'GetLegendGraphic':
            return self.WMS_OP_GETLEGENDGRAPHIC
        elif strRequest == 'GetFeatureInfo':
            return self.WMS_OP_GETFEATUREINFO
        return None

class WMSProxy(proxy.Proxy):
    """
    Class WMSProxy qui herite de la class proxy de base

    """

    def getAction(self):
        return self.CRUD_READ

    def setResources(self, pobjArrayResources):
        """
        Defini la resource du proxy

        Args:
            pobjArrayResources: Object resource
        """
        self.m_objResource = pobjArrayResources

    def process(self):
        """
        Traite l'information a retourner

        Returns:
            HttpResponce
        """
        excluded_headers = ('connection','keep-alive','proxy-authenticate','proxy-authorization','te','trailers','transfer-encoding','content-encoding','content-length','upgrade')

        if self.m_objRequest.method == "POST":
            strServiceURL = self.m_objService.source
            strParams = self.getRequestParams()
            requestUrl = requests.post(strServiceURL, data=strParams)

{'fraction_non_alphanumeric': 0.07920946156240274, 'fraction_numerical': 0.001556178026766262, 'mean_word_length': 2.3439125910509886, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1864343', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1849, 'n_words': 453}