# Path: core/modules/validator.py
# _VALIDATORS_ = {
#     'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
#     'alphanum': re.compile('^\w+$'),
#     'int': re.compile('^\d+$'),
#     'double': re.compile('^\d+(\.\d+)?$'),
#     'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
#     'year': re.compile('^\d{4}$'),
#     'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
# }
# def validate(field, vtype=None):
# def is_empty(field):
# def check_captcha(request):
# def normalize_filter(search_filter):
# def test():
# 
# 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/wrappers.py
# def internal_error_handler(err_code):
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             try:
#                 return f(*args, **kwargs)
#             except Exception as e:
#                 timestamp = time.strftime('%d%m%H%M%S')
#                 desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
#                     f.__name__, timestamp
#                 )
#                 modlgr.exception(desc)
#                 code = '{0}.{1}'.format(err_code, timestamp)
#                 resp = Response(has_error=True, code=code, content='')
#                 return json_response(resp.json(), status_code=500)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_connected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if not session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas connecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_disconnected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas déconnecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


import os
import uuid
import locale
import hashlib
import binascii
import datetime
from flask                          import Flask
from flask                          import request
from flask                          import session
from flask                          import redirect
from flask                          import abort
from flask                          import render_template
from flask                          import flash
from flask                          import escape
from flask_responses                import json_response
from flask_responses                import xml_response
from flask_responses                import auto_response
from flask_cors                     import CORS
from core.modules                   import db
from core.modules                   import validator
from core.modules                   import ini
from core.modules                   import logger
from core.modules                   import emails
from core.modules.wrappers          import internal_error_handler
from core.modules.wrappers          import require_connected
from core.modules.wrappers          import require_disconnected
from core.classes.response          import Response
from core.classes.slack_log_handler import SlackLogHandler
# license:
#    MapIF - Where are INSA de Lyon IF students right now ?
#    Copyright (C) 2017  Loic Touzard
#
#    This program 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.
#
#    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
#===============================================================================
# GLOBALS
#===============================================================================
# initialize logger
logger.init()
modlgr = logger.get('mapif.api')
# print current root for debugging
modlgr.debug("Running from {0}".format(os.getcwd()))
# load config file and exit on error
modlgr.debug("Loading configuration file...")

# Path: core/modules/validator.py
# _VALIDATORS_ = {
#     'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
#     'alphanum': re.compile('^\w+$'),
#     'int': re.compile('^\d+$'),
#     'double': re.compile('^\d+(\.\d+)?$'),
#     'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
#     'year': re.compile('^\d{4}$'),
#     'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
# }
# def validate(field, vtype=None):
# def is_empty(field):
# def check_captcha(request):
# def normalize_filter(search_filter):
# def test():
# 
# 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/wrappers.py
# def internal_error_handler(err_code):
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             try:
#                 return f(*args, **kwargs)
#             except Exception as e:
#                 timestamp = time.strftime('%d%m%H%M%S')
#                 desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
#                     f.__name__, timestamp
#                 )
#                 modlgr.exception(desc)
#                 code = '{0}.{1}'.format(err_code, timestamp)
#                 resp = Response(has_error=True, code=code, content='')
#                 return json_response(resp.json(), status_code=500)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_connected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if not session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas connecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_disconnected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas déconnecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


# Path: core/mapif.py
import os
import uuid
import locale
import hashlib
import binascii
import datetime
from flask                          import Flask
from flask                          import request
from flask                          import session
from flask                          import redirect
from flask                          import abort
from flask                          import render_template
from flask                          import flash
from flask                          import escape
from flask_responses                import json_response
from flask_responses                import xml_response
from flask_responses                import auto_response
from flask_cors                     import CORS
from core.modules                   import db
from core.modules                   import validator
from core.modules                   import ini
from core.modules                   import logger
from core.modules                   import emails
from core.modules.wrappers          import internal_error_handler
from core.modules.wrappers          import require_connected
from core.modules.wrappers          import require_disconnected
from core.classes.response          import Response
from core.classes.slack_log_handler import SlackLogHandler

# license:
#    MapIF - Where are INSA de Lyon IF students right now ?
#    Copyright (C) 2017  Loic Touzard
#
#    This program 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.
#
#    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#===============================================================================
# IMPORTS
#===============================================================================
#===============================================================================
# GLOBALS
#===============================================================================
# initialize logger
logger.init()
modlgr = logger.get('mapif.api')
# print current root for debugging
modlgr.debug("Running from {0}".format(os.getcwd()))
# load config file and exit on error
modlgr.debug("Loading configuration file...")

if not ini.init('mapif.ini'):