# Path: modules/bottle_gettext.py
# class GettextPlugin(object):
#     def __init__(self, domain, localedir, allowed_languages, keyword='lang'):
#     def get_language(self):
#     def apply(self, callback, route):
#         def wrapper(*args, **kwargs):
# 
# Path: api/app.py
# class OsmoseAPIBottle(bottle.Bottle):
#     def default_error_handler(self, res):


import bottle
import os.path
import functools
import os
import modules.osmose_bottle
from modules import utils
from modules import bottle_gettext
from web_api import app as web_app
from control import app as control_app
from api import app as api_app

app = bottle.default_app()

####### Monkey patch bootle 0.12 - To be removed on 0.13
# https://github.com/bottlepy/bottle/issues/602#issuecomment-591434275
def pathinfo_adjust_wrapper(func):
    # A wrapper for _handle() method
    @functools.wraps(func)
    def _(environ):
        environ["PATH_INFO"] = environ["PATH_INFO"].encode("utf8").decode("latin1")
        return func(environ)
    return _
app._handle = pathinfo_adjust_wrapper(app._handle)
#######

app.install(bottle_gettext.Plugin('osmose-frontend', os.path.join("web", "po", "mo"), utils.allowed_languages))

for l in utils.allowed_languages:
  app.mount('/' + l, web_app.app)

@app.route('/')
@app.route('/map')
@app.route('/map/')
def index(lang):
    # Route to force a redirect, for missing langue in URL
    pass

app.mount('/control/', control_app.app)

web_app.app.mount('api/0.2/', api_app.app_0_2)

# Path: modules/bottle_gettext.py
# class GettextPlugin(object):
#     def __init__(self, domain, localedir, allowed_languages, keyword='lang'):
#     def get_language(self):
#     def apply(self, callback, route):
#         def wrapper(*args, **kwargs):
# 
# Path: api/app.py
# class OsmoseAPIBottle(bottle.Bottle):
#     def default_error_handler(self, res):


# Path: osmose.py
import bottle
import os.path
import functools
import os
import modules.osmose_bottle
from modules import utils
from modules import bottle_gettext
from web_api import app as web_app
from control import app as control_app
from api import app as api_app


app = bottle.default_app()

####### Monkey patch bootle 0.12 - To be removed on 0.13
# https://github.com/bottlepy/bottle/issues/602#issuecomment-591434275
def pathinfo_adjust_wrapper(func):
    # A wrapper for _handle() method
    @functools.wraps(func)
    def _(environ):
        environ["PATH_INFO"] = environ["PATH_INFO"].encode("utf8").decode("latin1")
        return func(environ)
    return _
app._handle = pathinfo_adjust_wrapper(app._handle)
#######

app.install(bottle_gettext.Plugin('osmose-frontend', os.path.join("web", "po", "mo"), utils.allowed_languages))

for l in utils.allowed_languages:
  app.mount('/' + l, web_app.app)

@app.route('/')
@app.route('/map')
@app.route('/map/')
def index(lang):
    # Route to force a redirect, for missing langue in URL
    pass

app.mount('/control/', control_app.app)

web_app.app.mount('api/0.2/', api_app.app_0_2)

app.mount('/api/0.3/', api_app.app_0_3)