# Path: lektor/i18n.py
# def get_i18n_block(inifile_or_dict, key):
#     """Extracts an i18n block from an ini file or dictionary for a given
#     key.
#     """
#     rv = {}
#     for k, v in inifile_or_dict.iteritems():
#         if k == key:
#             # English is the internal default language with preferred
#             # treatment.
#             rv['en'] = v
#         elif k.startswith(key + '['):
#             rv[k[len(key) + 1:-1]] = v
#     return rv
# 
# Path: lektor/pluginsystem.py
# class PluginController(object):
#     """Helper management class that is used to control plugins through
#     the environment.
#     """
# 
#     def __init__(self, env):
#         self._env = weakref(env)
# 
#     @property
#     def env(self):
#         rv = self._env()
#         if rv is None:
#             raise RuntimeError('Environment went away')
#         return rv
# 
#     def instanciate_plugin(self, plugin_id, plugin_cls):
#         env = self.env
#         if plugin_id in env.plugins:
#             raise RuntimeError('Plugin "%s" is already registered'
#                                % plugin_id)
#         env.plugins[plugin_id] = plugin_cls(env, plugin_id)
#         env.plugin_ids_by_class[plugin_cls] = plugin_id
# 
#     def iter_plugins(self):
#         # XXX: sort?
#         return self.env.plugins.itervalues()
# 
#     def emit(self, event, **kwargs):
#         rv = {}
#         funcname = 'on_' + event.replace('-', '_')
#         for plugin in self.iter_plugins():
#             handler = getattr(plugin, funcname, None)
#             if handler is not None:
#                 rv[plugin.id] = handler(**kwargs)
#         return rv


import os
import re
import uuid
import copy
import jinja2
from functools import update_wrapper
from babel import dates
from inifile import IniFile
from lektor.utils import tojson_filter, secure_url, format_lat_long, \
     bool_from_string
from lektor.i18n import get_i18n_block
from lektor.context import url_to, get_asset_url, site_proxy, \
     config_proxy, get_ctx, get_locale
from lektor.pluginsystem import PluginController
        from lektor.db import F
        from lektor.types import builtin_types
        from .packages import load_packages
        from .pluginsystem import initialize_plugins
        from lektor.db import Database
            server_info = self.get_server(server, public=public)
            if server_info is None:
                continue
            rv[server] = server_info
        return rv

    def get_default_server(self, public=False):
        """Returns the default server."""
        choices = []
        for server in self.values['SERVERS']:
            server_info = self.get_server(server, public=public)
            if server_info is not None:
                if server_info.default:
                    return server_info
                choices.append(server_info)
        if len(choices) == 1:
            return choices[0]

    def get_server(self, name, public=False):
        """Looks up a server info by name."""
        info = self.values['SERVERS'].get(name)
        if info is None:
            return None
        target = info.get('target')
        if target is None:
            return None
        if public:
            target = secure_url(target)
        return ServerInfo(
            id=name,

# Path: lektor/i18n.py
# def get_i18n_block(inifile_or_dict, key):
#     """Extracts an i18n block from an ini file or dictionary for a given
#     key.
#     """
#     rv = {}
#     for k, v in inifile_or_dict.iteritems():
#         if k == key:
#             # English is the internal default language with preferred
#             # treatment.
#             rv['en'] = v
#         elif k.startswith(key + '['):
#             rv[k[len(key) + 1:-1]] = v
#     return rv
# 
# Path: lektor/pluginsystem.py
# class PluginController(object):
#     """Helper management class that is used to control plugins through
#     the environment.
#     """
# 
#     def __init__(self, env):
#         self._env = weakref(env)
# 
#     @property
#     def env(self):
#         rv = self._env()
#         if rv is None:
#             raise RuntimeError('Environment went away')
#         return rv
# 
#     def instanciate_plugin(self, plugin_id, plugin_cls):
#         env = self.env
#         if plugin_id in env.plugins:
#             raise RuntimeError('Plugin "%s" is already registered'
#                                % plugin_id)
#         env.plugins[plugin_id] = plugin_cls(env, plugin_id)
#         env.plugin_ids_by_class[plugin_cls] = plugin_id
# 
#     def iter_plugins(self):
#         # XXX: sort?
#         return self.env.plugins.itervalues()
# 
#     def emit(self, event, **kwargs):
#         rv = {}
#         funcname = 'on_' + event.replace('-', '_')
#         for plugin in self.iter_plugins():
#             handler = getattr(plugin, funcname, None)
#             if handler is not None:
#                 rv[plugin.id] = handler(**kwargs)
#         return rv


# Path: lektor/environment.py
import os
import re
import uuid
import copy
import jinja2
from functools import update_wrapper
from babel import dates
from inifile import IniFile
from lektor.utils import tojson_filter, secure_url, format_lat_long, \
     bool_from_string
from lektor.i18n import get_i18n_block
from lektor.context import url_to, get_asset_url, site_proxy, \
     config_proxy, get_ctx, get_locale
from lektor.pluginsystem import PluginController
        from lektor.db import F
        from lektor.types import builtin_types
        from .packages import load_packages
        from .pluginsystem import initialize_plugins
        from lektor.db import Database

            server_info = self.get_server(server, public=public)
            if server_info is None:
                continue
            rv[server] = server_info
        return rv

    def get_default_server(self, public=False):
        """Returns the default server."""
        choices = []
        for server in self.values['SERVERS']:
            server_info = self.get_server(server, public=public)
            if server_info is not None:
                if server_info.default:
                    return server_info
                choices.append(server_info)
        if len(choices) == 1:
            return choices[0]

    def get_server(self, name, public=False):
        """Looks up a server info by name."""
        info = self.values['SERVERS'].get(name)
        if info is None:
            return None
        target = info.get('target')
        if target is None:
            return None
        if public:
            target = secure_url(target)
        return ServerInfo(
            id=name,

            name_i18n=get_i18n_block(info, 'name'),