<commit_before># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
##
## Indico 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 3 of the
## License, or (at your option) any later version.
##
## Indico 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 Indico;if not, see <http://www.gnu.org/licenses/>.
import copy
import inspect
import time
import os
import profile as profiler
import pstats
import sys
import random
import StringIO
from datetime import datetime, timedelta
from urlparse import urljoin
from xml.sax.saxutils import escape

import oauth2 as oauth
import transaction
from flask import request, session
from werkzeug.exceptions import BadRequest, MethodNotAllowed, NotFound
from ZEO.Exceptions import ClientDisconnected
from ZODB.POSException import ConflictError, POSKeyError

from MaKaC.accessControl import AccessWrapper

from MaKaC.common import fossilize, security
from MaKaC.common.contextManager import ContextManager
from MaKaC.common.utils import truncate
from MaKaC.errors import (
    AccessError,
    BadRefererError,
    ConferenceClosedError,
    KeyAccessError,
    MaKaCError,
    ModificationError,
    NotLoggedError,
)
from MaKaC.plugins.base import OldObservable
from MaKaC.webinterface.mail import GenericMailer
import MaKaC.webinterface.urlHandlers as urlHandlers
import MaKaC.webinterface.pages.errors as errors
from MaKaC.webinterface.pages.error import WErrorWSGI
from MaKaC.webinterface.pages.conferences import WPConferenceModificationClosed
from indico.core.config import Config
from indico.core.db import DBMgr
from indico.core.logger import Logger
from indico.util import json
from indico.core.db.util import flush_after_commit_queue
from indico.util.decorators import jsonify_error
from indico.util.i18n import _, availableLocales, setLocale
from indico.util.redis import RedisError
from indico.web.flask.util import ResponseUtil


class RequestHandlerBase(OldObservable):

    _uh = None

    def __init__(self, req=None):
        if req is not None:
            raise Exception("Received request object")

    def _checkProtection(self):
        """This method is called after _checkParams and is a good place
        to check if the user is permitted to perform some actions.

        If you only want to run some code for GET or POST requests, you can create
        a method named e.g. _checkProtection_POST which will be executed AFTER this one.
        """
        pass

    def _getAuth(self):
        """
        Returns True if current user is a user or has either a modification key in their session.
        """
        return session.get('modifKeys') or self._getUser()

    def getAW(self):
        """
        Returns the access wrapper related to this session/user
        """
        return self._aw

    accessWrapper = property(getAW)

    def _getUser(self):
        """
        Returns the current user
        """
        return self._aw.getUser()

    def _setUser(self, new_user=None):
        """
        Sets the current user
        """
        self._aw.setUser(new_user)

    def getRequestURL(self, secure=False):
        """
        Reconstructs the request URL
        """
        if secure:
            return urljoin(Config.getInstance().getBaseSecureURL(), request.path)
        else:
            return request.url

    def use_https(self):
        """
        If the RH must be HTTPS and there is a BaseSecurURL, then use it!
        """<commit_msg>Preserve query string when redirecting to https<commit_after># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
##
## Indico 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 3 of the
## License, or (at your option) any later version.
##
## Indico 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 Indico;if not, see <http://www.gnu.org/licenses/>.
import copy
import inspect
import time
import os
import profile as profiler
import pstats
import sys
import random
import StringIO
from datetime import datetime, timedelta
from urlparse import urljoin
from xml.sax.saxutils import escape

import oauth2 as oauth
import transaction
from flask import request, session
from werkzeug.exceptions import BadRequest, MethodNotAllowed, NotFound
from ZEO.Exceptions import ClientDisconnected
from ZODB.POSException import ConflictError, POSKeyError

from MaKaC.accessControl import AccessWrapper

from MaKaC.common import fossilize, security
from MaKaC.common.contextManager import ContextManager
from MaKaC.common.utils import truncate
from MaKaC.errors import (
    AccessError,
    BadRefererError,
    ConferenceClosedError,
    KeyAccessError,
    MaKaCError,
    ModificationError,
    NotLoggedError,
)
from MaKaC.plugins.base import OldObservable
from MaKaC.webinterface.mail import GenericMailer
import MaKaC.webinterface.urlHandlers as urlHandlers
import MaKaC.webinterface.pages.errors as errors
from MaKaC.webinterface.pages.error import WErrorWSGI
from MaKaC.webinterface.pages.conferences import WPConferenceModificationClosed
from indico.core.config import Config
from indico.core.db import DBMgr
from indico.core.logger import Logger
from indico.util import json
from indico.core.db.util import flush_after_commit_queue
from indico.util.decorators import jsonify_error
from indico.util.i18n import _, availableLocales, setLocale
from indico.util.redis import RedisError
from indico.web.flask.util import ResponseUtil


class RequestHandlerBase(OldObservable):

    _uh = None

    def __init__(self, req=None):
        if req is not None:
            raise Exception("Received request object")

    def _checkProtection(self):
        """This method is called after _checkParams and is a good place
        to check if the user is permitted to perform some actions.

        If you only want to run some code for GET or POST requests, you can create
        a method named e.g. _checkProtection_POST which will be executed AFTER this one.
        """
        pass

    def _getAuth(self):
        """
        Returns True if current user is a user or has either a modification key in their session.
        """
        return session.get('modifKeys') or self._getUser()

    def getAW(self):
        """
        Returns the access wrapper related to this session/user
        """
        return self._aw

    accessWrapper = property(getAW)

    def _getUser(self):
        """
        Returns the current user
        """
        return self._aw.getUser()

    def _setUser(self, new_user=None):
        """
        Sets the current user
        """
        self._aw.setUser(new_user)

    def getRequestURL(self, secure=False):
        """
        Reconstructs the request URL
        """
        query_string = ('?' + request.query_string) if request.query_string else ''
        if secure:
            return urljoin(Config.getInstance().getBaseSecureURL(), request.path) + query_string
        else:
            return request.url + query_string

    def use_https(self):
        """
        If the RH must be HTTPS and there is a BaseSecurURL, then use it!
        """
{'fraction_non_alphanumeric': 0.06732698094282849, 'fraction_numerical': 0.003259779338014042, 'mean_word_length': 3.3495092693565978, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6702268', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2117, 'n_words': 841}