<commit_before># coding: utf8

from urlparse import urlparse
import logging
import re
import unicodedata
import urllib

from flask import request, session
from flask_login import current_user

from labonneboite.conf import settings
from labonneboite.conf.common.contact_mode import CONTACT_MODE_DEFAULT
from labonneboite.common.load_data import load_contact_modes

logger = logging.getLogger('main')


def get_search_url(base_url, request_args, naf=None):
    query_string = {}
    if naf:
        query_string['naf'] = naf

    if request_args.get('q'):
        query_string['q'] = request_args.get('q').encode('utf8')
    if request_args.get('r'):
        query_string['r'] = request_args.get('r')
    if request_args.get('l'):
        query_string['l'] = request_args.get('l').encode('utf8')
    if request_args.get('d'):
        query_string['d'] = request_args.get('d')
    if request_args.get('lon'):
        query_string['lon'] = request_args.get('lon')
    if request_args.get('lat'):
        query_string['lat'] = request_args.get('lat')
    if request_args.get('j'):
        query_string['j'] = request_args.get('j').encode('utf8')
    if request_args.get('mode'):
        query_string['mode'] = request_args.get('mode')

    return "%s?%s" % (base_url, urllib.urlencode(query_string))


def get_user_ip():
    logger.debug("request.remote_addr = %s", request.remote_addr)
    logger.debug('request.headers.getlist("X-Forwarded-For") = %s', request.headers.getlist("X-Forwarded-For"))
    logger.debug("request.access_route = %s", request.access_route)
    # If a forwarded header exists, get its first ip (it's the client one),
    # otherwise, fallback to remote_addr.
    # http://werkzeug.pocoo.org/docs/0.10/wrappers/#werkzeug.wrappers.BaseRequest.access_route
    return request.access_route[0] if request.access_route else request.remote_addr


def user_is_pro():
    """
    The website has a special version called "Version PRO"
    which is only visible to "PRO users"

    PRO users are
    - Conseillers PE identified by their specific IP
    - Institutionals identified by their specific PEAM emails

    The "Version PRO" is the same as the regular "Version publique",
    plus some exclusive indicators, filters and data:
    - Flags : Junior, Senior, Handicap...
    - Office data : statistics about recruitments...
    """

    # Check user IP (no need to be authenticated)
    user_ip = get_user_ip()
    if user_ip in settings.VERSION_PRO_ALLOWED_IPS:
        return True

    # Check user e-mail by plain_value, suffix or regex (@see local_settings.py)
    if current_user.is_authenticated:
        current_user_email = current_user.email.lower()
<<<<<<< HEAD

        return (current_user_email in settings.VERSION_PRO_ALLOWED_EMAILS
            or any(current_user_email.endswith(suffix) for suffix in settings.VERSION_PRO_ALLOWED_EMAIL_SUFFIXES)
            or any(re.match(
                regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))

    return False

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
        return result

    return False

def pro_mode_activated():
    return session.get("pro_mode", False)
=======
=======
>>>>>>> Remove switch, no more action= in the URL et pro_version everywhere
def pro_version_enabled():
    return session.get("pro_version", False)
>>>>>>> Change wording, texte (pro_mode => pro_version), redirect by url in request and more !
=======
=======

        return (current_user_email in settings.VERSION_PRO_ALLOWED_EMAILS
            or any(current_user_email.endswith(suffix) for suffix in settings.VERSION_PRO_ALLOWED_EMAIL_SUFFIXES)
<<<<<<< HEAD
<<<<<<< HEAD
            or any(re.match(regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS)
            )
>>>>>>> Add the pro mode (session based)

<<<<<<< HEAD
def pro_version_enabled():
    return session.get('pro_version', False)
>>>>>>> Test that the Pro Version is correctly enabled/desabled
=======
        return result

=======
            or any(re.match(regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))
        
>>>>>>> Change wording, texte (pro_mode => pro_version), redirect by url in request and more !
=======
            or any(re.match(
                regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))

>>>>>>> Ensure that the `allowed_hosts` parameter is optional.
    return False
>>>>>>> quick bugfix - feel free to improve it @Alexandre

def pro_version_enabled():
    return session.get("pro_version", False)


def get_doorbell_tags(tag):
    if tag not in ['faq', 'help', 'press', 'results']:<commit_msg>Test that the Pro Version is correctly enabled/desabled<commit_after># coding: utf8

from urlparse import urlparse
import logging
import re
import unicodedata
import urllib

from flask import request, session
from flask_login import current_user

from labonneboite.conf import settings
from labonneboite.conf.common.contact_mode import CONTACT_MODE_DEFAULT
from labonneboite.common.load_data import load_contact_modes

logger = logging.getLogger('main')


def get_search_url(base_url, request_args, naf=None):
    query_string = {}
    if naf:
        query_string['naf'] = naf

    if request_args.get('q'):
        query_string['q'] = request_args.get('q').encode('utf8')
    if request_args.get('r'):
        query_string['r'] = request_args.get('r')
    if request_args.get('l'):
        query_string['l'] = request_args.get('l').encode('utf8')
    if request_args.get('d'):
        query_string['d'] = request_args.get('d')
    if request_args.get('lon'):
        query_string['lon'] = request_args.get('lon')
    if request_args.get('lat'):
        query_string['lat'] = request_args.get('lat')
    if request_args.get('j'):
        query_string['j'] = request_args.get('j').encode('utf8')
    if request_args.get('mode'):
        query_string['mode'] = request_args.get('mode')

    return "%s?%s" % (base_url, urllib.urlencode(query_string))


def get_user_ip():
    logger.debug("request.remote_addr = %s", request.remote_addr)
    logger.debug('request.headers.getlist("X-Forwarded-For") = %s', request.headers.getlist("X-Forwarded-For"))
    logger.debug("request.access_route = %s", request.access_route)
    # If a forwarded header exists, get its first ip (it's the client one),
    # otherwise, fallback to remote_addr.
    # http://werkzeug.pocoo.org/docs/0.10/wrappers/#werkzeug.wrappers.BaseRequest.access_route
    return request.access_route[0] if request.access_route else request.remote_addr


def user_is_pro():
    """
    The website has a special version called "Version PRO"
    which is only visible to "PRO users"

    PRO users are
    - Conseillers PE identified by their specific IP
    - Institutionals identified by their specific PEAM emails

    The "Version PRO" is the same as the regular "Version publique",
    plus some exclusive indicators, filters and data:
    - Flags : Junior, Senior, Handicap...
    - Office data : statistics about recruitments...
    """

    # Check user IP (no need to be authenticated)
    user_ip = get_user_ip()
    if user_ip in settings.VERSION_PRO_ALLOWED_IPS:
        return True

    # Check user e-mail by plain_value, suffix or regex (@see local_settings.py)
    if current_user.is_authenticated:
        current_user_email = current_user.email.lower()
<<<<<<< HEAD

        return (current_user_email in settings.VERSION_PRO_ALLOWED_EMAILS
            or any(current_user_email.endswith(suffix) for suffix in settings.VERSION_PRO_ALLOWED_EMAIL_SUFFIXES)
            or any(re.match(
                regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))

    return False

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
        return result

    return False

def pro_mode_activated():
    return session.get("pro_mode", False)
=======
=======
>>>>>>> Remove switch, no more action= in the URL et pro_version everywhere
def pro_version_enabled():
    return session.get("pro_version", False)
>>>>>>> Change wording, texte (pro_mode => pro_version), redirect by url in request and more !
=======
=======

        return (current_user_email in settings.VERSION_PRO_ALLOWED_EMAILS
            or any(current_user_email.endswith(suffix) for suffix in settings.VERSION_PRO_ALLOWED_EMAIL_SUFFIXES)
<<<<<<< HEAD
<<<<<<< HEAD
            or any(re.match(regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS)
            )
>>>>>>> Add the pro mode (session based)

<<<<<<< HEAD
def pro_version_enabled():
    return session.get('pro_version', False)
>>>>>>> Test that the Pro Version is correctly enabled/desabled
=======
        return result

=======
            or any(re.match(regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))
        
>>>>>>> Change wording, texte (pro_mode => pro_version), redirect by url in request and more !
=======
            or any(re.match(
                regexp, current_user_email) is not None for regexp in settings.VERSION_PRO_ALLOWED_EMAIL_REGEXPS))

>>>>>>> Ensure that the `allowed_hosts` parameter is optional.
    return False
>>>>>>> quick bugfix - feel free to improve it @Alexandre
=======
>>>>>>> Test that the Pro Version is correctly enabled/desabled

def pro_version_enabled():
    return session.get('pro_version', False)



def get_doorbell_tags(tag):
    if tag not in ['faq', 'help', 'press', 'results']:
{'fraction_non_alphanumeric': 0.12559833506763787, 'fraction_numerical': 0.0016649323621227888, 'mean_word_length': 3.8663291139240505, 'pattern_counts': {'":': 0, '<': 108, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '212808', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2946, 'n_words': 781}