# Path: core/modules/ini.py
# _CONFIG_ = None
#         _CONFIG_ = configparser.ConfigParser()
# def init(filename):
# def getenv(env_var, default=None):
# def config(section, option, env_var=None, default=None, boolean=False):
# def test():


import re
import json
from core.modules import ini
from core.modules import logger
from core.modules import request
#-------------------------------------------------------------------------------
# is_empty
#   Tests if a field is empty
#-------------------------------------------------------------------------------
def is_empty(field):
    return len(str(field).strip()) == 0
#-------------------------------------------------------------------------------
# check_captcha 
#   Google ReCaptcha validation process
#-------------------------------------------------------------------------------
def check_captcha(request):
    payload = {
        'secret': ini.config('RECAPTCHA','recaptcha_secret_key'),
        'response': request.form['g-recaptcha-response'],
        'remoteip': request.remote_addr
    }
    resp = request.post('https://www.google.com/recaptcha/api/siteverify', params=payload)
    data = json.loads(resp.text)
    if not data['success']:
        modlgr.error("from validator: {0} might be a bot !".format(request.remote_addr))
    return data['success']
#-------------------------------------------------------------------------------
# normalize_filter
#   Treat filter content to create a valid SQL filter string
#-------------------------------------------------------------------------------
def normalize_filter(search_filter):
    if search_filter is not None:
        # remove forbidden characters
        search_filter = re.sub('[^*a-zA-Z0-9]', '', search_filter)
        # replace special characters

# Path: core/modules/ini.py
# _CONFIG_ = None
#         _CONFIG_ = configparser.ConfigParser()
# def init(filename):
# def getenv(env_var, default=None):
# def config(section, option, env_var=None, default=None, boolean=False):
# def test():


# Path: core/modules/validator.py
import re
import json
from core.modules import ini
from core.modules import logger
from core.modules import request

#-------------------------------------------------------------------------------
# is_empty
#   Tests if a field is empty
#-------------------------------------------------------------------------------
def is_empty(field):
    return len(str(field).strip()) == 0
#-------------------------------------------------------------------------------
# check_captcha 
#   Google ReCaptcha validation process
#-------------------------------------------------------------------------------
def check_captcha(request):
    payload = {
        'secret': ini.config('RECAPTCHA','recaptcha_secret_key'),
        'response': request.form['g-recaptcha-response'],
        'remoteip': request.remote_addr
    }
    resp = request.post('https://www.google.com/recaptcha/api/siteverify', params=payload)
    data = json.loads(resp.text)
    if not data['success']:
        modlgr.error("from validator: {0} might be a bot !".format(request.remote_addr))
    return data['success']
#-------------------------------------------------------------------------------
# normalize_filter
#   Treat filter content to create a valid SQL filter string
#-------------------------------------------------------------------------------
def normalize_filter(search_filter):
    if search_filter is not None:
        # remove forbidden characters
        search_filter = re.sub('[^*a-zA-Z0-9]', '', search_filter)
        # replace special characters

        search_filter = search_filter.replace('*', '%')