# Path: henet/app.py
# def make_app(config_file):
# 
#     fileConfig(config_file)
#     multiprocessing_logging.install_mp_handler()
# 
#     with codecs.open(config_file, 'r', 'utf8') as f:
#         config = konfig.Config(f)
# 
#     bottle.debug(config['henet'].get('debug', DEFAULT_DEBUG))
#     app = bottle.app()
# 
#     # bottle config used by bottle-utils
#     csrf_config = dict([('csrf.%s' % key, val) for key, val in
#                         config.items('csrf')])
#     app.config.update(csrf_config)
# 
#     # setting up languages
#     default_locale = config['henet'].get('default_locale', 'fr_FR')
#     langs = [[p.strip() for p in lang.split(',')] for lang
#              in config['henet'].get('langs', ['fr_FR'])]
# 
#     app = I18NPlugin(app, langs=langs, default_locale=default_locale,
#                      locale_dir=LOCALES_PATH)
# 
#     cats = []
# 
#     config_cats = config['henet']['categories']
#     if not isinstance(config_cats, list):
#         config_cats = [config_cats]
# 
#     for cat in config_cats:
#         values = dict(config[cat].items())
#         # defaults
#         if 'can_create' not in values:
#             values['can_create'] = True
#         cats.append((cat, values))
# 
#     pages = []
# 
#     config_pages = config['henet']['pages']
#     if not isinstance(config_pages, list):
#         config_pages = [config_pages]
# 
#     for page in config_pages:
#         values = dict(config[page].items())
#         # defaults
#         if 'can_create' not in values:
#             values['can_create'] = True
#         pages.append((page, values))
# 
#     use_comments = config['henet'].get('comments', True)
#     use_media = config['henet'].get('media', True)
# 
#     app_stack.vars = app.vars = {'pages': pages,
#                                  'categories': cats,
#                                  'get_alerts': get_alerts,
#                                  'site_url': config['henet']['site_url'],
#                                  'use_comments': use_comments,
#                                  'use_media': use_media,
#                                  'langs': langs}
# 
#     app_stack.view = partial(view, **app.vars)
#     app_stack._config = app._config = config
#     app_stack.workers = app.workers = MemoryWorkers()
#     app_stack.use_comments = app.use_comments = use_comments
#     app_stack.use_media = app.use_media = use_media
#     app_stack.add_alert = app.add_alert = add_alert
# 
#     smtp_config = dict(config.items('smtp'))
# 
#     def _send_email(*args):
#         args = list(args) + [smtp_config]
#         app.workers.apply_async('send-email', send_email, args)
# 
#     app_stack.send_email = app.send_email = _send_email
# 
#     from henet import views  # NOQA
# 
#     def _close_workers(*args):
#         app.workers.close()
#         sys.exit(0)
# 
#     subscribe(ALL_EVENTS, add_alert)
#     signal.signal(signal.SIGINT, _close_workers)
# 
#     return app


import os
import unittest
import tempfile
import shutil
from konfig import Config
from webtest import TestApp
from henet.app import make_app



HERE = os.path.dirname(__file__)
content = os.path.join(HERE, 'content')


class TestView(unittest.TestCase):

    def setUp(self):
        self.config = os.path.join(HERE, 'config.ini')
        hdl, self.config_file = tempfile.mkstemp()
        with open(self.config) as f:
            os.write(hdl, f.read() % {'testdir': HERE})
        os.close(hdl)
        environ = {'HTTP_X_FORWARDED_FOR': '168.0.0.1',
                   'REMOTE_ADDR': '127.0.0.1'}
        self.app = TestApp(make_app(self.config_file),
                           extra_environ=environ)
        self.config = Config(unicode(self.config_file))
        self.tmp_content = tempfile.mkdtemp()
        self.save_content = os.path.join(self.tmp_content, 'content')
        shutil.copytree(content, self.save_content)


# Path: henet/app.py
# def make_app(config_file):
# 
#     fileConfig(config_file)
#     multiprocessing_logging.install_mp_handler()
# 
#     with codecs.open(config_file, 'r', 'utf8') as f:
#         config = konfig.Config(f)
# 
#     bottle.debug(config['henet'].get('debug', DEFAULT_DEBUG))
#     app = bottle.app()
# 
#     # bottle config used by bottle-utils
#     csrf_config = dict([('csrf.%s' % key, val) for key, val in
#                         config.items('csrf')])
#     app.config.update(csrf_config)
# 
#     # setting up languages
#     default_locale = config['henet'].get('default_locale', 'fr_FR')
#     langs = [[p.strip() for p in lang.split(',')] for lang
#              in config['henet'].get('langs', ['fr_FR'])]
# 
#     app = I18NPlugin(app, langs=langs, default_locale=default_locale,
#                      locale_dir=LOCALES_PATH)
# 
#     cats = []
# 
#     config_cats = config['henet']['categories']
#     if not isinstance(config_cats, list):
#         config_cats = [config_cats]
# 
#     for cat in config_cats:
#         values = dict(config[cat].items())
#         # defaults
#         if 'can_create' not in values:
#             values['can_create'] = True
#         cats.append((cat, values))
# 
#     pages = []
# 
#     config_pages = config['henet']['pages']
#     if not isinstance(config_pages, list):
#         config_pages = [config_pages]
# 
#     for page in config_pages:
#         values = dict(config[page].items())
#         # defaults
#         if 'can_create' not in values:
#             values['can_create'] = True
#         pages.append((page, values))
# 
#     use_comments = config['henet'].get('comments', True)
#     use_media = config['henet'].get('media', True)
# 
#     app_stack.vars = app.vars = {'pages': pages,
#                                  'categories': cats,
#                                  'get_alerts': get_alerts,
#                                  'site_url': config['henet']['site_url'],
#                                  'use_comments': use_comments,
#                                  'use_media': use_media,
#                                  'langs': langs}
# 
#     app_stack.view = partial(view, **app.vars)
#     app_stack._config = app._config = config
#     app_stack.workers = app.workers = MemoryWorkers()
#     app_stack.use_comments = app.use_comments = use_comments
#     app_stack.use_media = app.use_media = use_media
#     app_stack.add_alert = app.add_alert = add_alert
# 
#     smtp_config = dict(config.items('smtp'))
# 
#     def _send_email(*args):
#         args = list(args) + [smtp_config]
#         app.workers.apply_async('send-email', send_email, args)
# 
#     app_stack.send_email = app.send_email = _send_email
# 
#     from henet import views  # NOQA
# 
#     def _close_workers(*args):
#         app.workers.close()
#         sys.exit(0)
# 
#     subscribe(ALL_EVENTS, add_alert)
#     signal.signal(signal.SIGINT, _close_workers)
# 
#     return app


# Path: henet/tests/support.py
import os
import unittest
import tempfile
import shutil
from konfig import Config
from webtest import TestApp
from henet.app import make_app




HERE = os.path.dirname(__file__)
content = os.path.join(HERE, 'content')


class TestView(unittest.TestCase):

    def setUp(self):
        self.config = os.path.join(HERE, 'config.ini')
        hdl, self.config_file = tempfile.mkstemp()
        with open(self.config) as f:
            os.write(hdl, f.read() % {'testdir': HERE})
        os.close(hdl)
        environ = {'HTTP_X_FORWARDED_FOR': '168.0.0.1',
                   'REMOTE_ADDR': '127.0.0.1'}
        self.app = TestApp(make_app(self.config_file),
                           extra_environ=environ)
        self.config = Config(unicode(self.config_file))
        self.tmp_content = tempfile.mkdtemp()
        self.save_content = os.path.join(self.tmp_content, 'content')
        shutil.copytree(content, self.save_content)


    def tearDown(self):