Python fapws.config.load_dict() Examples

The following are 17 code examples of fapws.config.load_dict(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fapws.config , or try the search function .
Example #1
Source File: bottle.py    From EasY_HaCk with Apache License 2.0 6 votes vote down vote up
def load_dict(self, source, namespace=''):
        """ Load values from a dictionary structure. Nesting can be used to
            represent namespaces.

            >>> c = ConfigDict()
            >>> c.load_dict({'some': {'namespace': {'key': 'value'} } })
            {'some.namespace.key': 'value'}
        """
        for key, value in source.items():
            if isinstance(key, basestring):
                nskey = (namespace + '.' + key).strip('.')
                if isinstance(value, dict):
                    self.load_dict(value, namespace=nskey)
                else:
                    self[nskey] = value
            else:
                raise TypeError('Key has type %r (not a string)' % type(key))
        return self 
Example #2
Source File: bottle.py    From silvia-pi with MIT License 6 votes vote down vote up
def load_dict(self, source, namespace=''):
        """ Load values from a dictionary structure. Nesting can be used to
            represent namespaces.

            >>> c = ConfigDict()
            >>> c.load_dict({'some': {'namespace': {'key': 'value'} } })
            {'some.namespace.key': 'value'}
        """
        for key, value in source.items():
            if isinstance(key, basestring):
                nskey = (namespace + '.' + key).strip('.')
                if isinstance(value, dict):
                    self.load_dict(value, namespace=nskey)
                else:
                    self[nskey] = value
            else:
                raise TypeError('Key has type %r (not a string)' % type(key))
        return self 
Example #3
Source File: bottle.py    From warriorframework with Apache License 2.0 6 votes vote down vote up
def __init__(self, app, rule, method, callback,
                 name=None,
                 plugins=None,
                 skiplist=None, **config):
        #: The application this route is installed to.
        self.app = app
        #: The path-rule string (e.g. ``/wiki/<page>``).
        self.rule = rule
        #: The HTTP method as a string (e.g. ``GET``).
        self.method = method
        #: The original callback with no plugins applied. Useful for introspection.
        self.callback = callback
        #: The name of the route (if specified) or ``None``.
        self.name = name or None
        #: A list of route-specific plugins (see :meth:`Bottle.route`).
        self.plugins = plugins or []
        #: A list of plugins to not apply to this route (see :meth:`Bottle.route`).
        self.skiplist = skiplist or []
        #: Additional keyword arguments passed to the :meth:`Bottle.route`
        #: decorator are stored in this dictionary. Used for route-specific
        #: plugin configuration and meta-data.
        self.config = ConfigDict().load_dict(config) 
Example #4
Source File: bottle.py    From EasY_HaCk with Apache License 2.0 6 votes vote down vote up
def __init__(self, app, rule, method, callback,
                 name=None,
                 plugins=None,
                 skiplist=None, **config):
        #: The application this route is installed to.
        self.app = app
        #: The path-rule string (e.g. ``/wiki/<page>``).
        self.rule = rule
        #: The HTTP method as a string (e.g. ``GET``).
        self.method = method
        #: The original callback with no plugins applied. Useful for introspection.
        self.callback = callback
        #: The name of the route (if specified) or ``None``.
        self.name = name or None
        #: A list of route-specific plugins (see :meth:`Bottle.route`).
        self.plugins = plugins or []
        #: A list of plugins to not apply to this route (see :meth:`Bottle.route`).
        self.skiplist = skiplist or []
        #: Additional keyword arguments passed to the :meth:`Bottle.route`
        #: decorator are stored in this dictionary. Used for route-specific
        #: plugin configuration and meta-data.
        self.config = ConfigDict().load_dict(config) 
Example #5
Source File: bottle.py    From warriorframework with Apache License 2.0 6 votes vote down vote up
def load_dict(self, source, namespace=''):
        """ Load values from a dictionary structure. Nesting can be used to
            represent namespaces.

            >>> c = ConfigDict()
            >>> c.load_dict({'some': {'namespace': {'key': 'value'} } })
            {'some.namespace.key': 'value'}
        """
        for key, value in source.items():
            if isinstance(key, basestring):
                nskey = (namespace + '.' + key).strip('.')
                if isinstance(value, dict):
                    self.load_dict(value, namespace=nskey)
                else:
                    self[nskey] = value
            else:
                raise TypeError('Key has type %r (not a string)' % type(key))
        return self 
Example #6
Source File: bottle.py    From slack-machine with MIT License 6 votes vote down vote up
def __init__(self, app, rule, method, callback,
                 name=None,
                 plugins=None,
                 skiplist=None, **config):
        #: The application this route is installed to.
        self.app = app
        #: The path-rule string (e.g. ``/wiki/<page>``).
        self.rule = rule
        #: The HTTP method as a string (e.g. ``GET``).
        self.method = method
        #: The original callback with no plugins applied. Useful for introspection.
        self.callback = callback
        #: The name of the route (if specified) or ``None``.
        self.name = name or None
        #: A list of route-specific plugins (see :meth:`Bottle.route`).
        self.plugins = plugins or []
        #: A list of plugins to not apply to this route (see :meth:`Bottle.route`).
        self.skiplist = skiplist or []
        #: Additional keyword arguments passed to the :meth:`Bottle.route`
        #: decorator are stored in this dictionary. Used for route-specific
        #: plugin configuration and meta-data.
        self.config = app.config._make_overlay()
        self.config.load_dict(config) 
Example #7
Source File: bottle.py    From silvia-pi with MIT License 6 votes vote down vote up
def __init__(self, app, rule, method, callback,
                 name=None,
                 plugins=None,
                 skiplist=None, **config):
        #: The application this route is installed to.
        self.app = app
        #: The path-rule string (e.g. ``/wiki/<page>``).
        self.rule = rule
        #: The HTTP method as a string (e.g. ``GET``).
        self.method = method
        #: The original callback with no plugins applied. Useful for introspection.
        self.callback = callback
        #: The name of the route (if specified) or ``None``.
        self.name = name or None
        #: A list of route-specific plugins (see :meth:`Bottle.route`).
        self.plugins = plugins or []
        #: A list of plugins to not apply to this route (see :meth:`Bottle.route`).
        self.skiplist = skiplist or []
        #: Additional keyword arguments passed to the :meth:`Bottle.route`
        #: decorator are stored in this dictionary. Used for route-specific
        #: plugin configuration and meta-data.
        self.config = app.config._make_overlay()
        self.config.load_dict(config) 
Example #8
Source File: bottle.py    From slack-machine with MIT License 6 votes vote down vote up
def load_dict(self, source, namespace=''):
        """ Load values from a dictionary structure. Nesting can be used to
            represent namespaces.

            >>> c = ConfigDict()
            >>> c.load_dict({'some': {'namespace': {'key': 'value'} } })
            {'some.namespace.key': 'value'}
        """
        for key, value in source.items():
            if isinstance(key, basestring):
                nskey = (namespace + '.' + key).strip('.')
                if isinstance(value, dict):
                    self.load_dict(value, namespace=nskey)
                else:
                    self[nskey] = value
            else:
                raise TypeError('Key has type %r (not a string)' % type(key))
        return self 
Example #9
Source File: bottle.py    From POC-EXP with GNU General Public License v3.0 6 votes vote down vote up
def load_dict(self, source, namespace=''):
        """ Load values from a dictionary structure. Nesting can be used to
            represent namespaces.

            >>> c = ConfigDict()
            >>> c.load_dict({'some': {'namespace': {'key': 'value'} } })
            {'some.namespace.key': 'value'}
        """
        for key, value in source.items():
            if isinstance(key, basestring):
                nskey = (namespace + '.' + key).strip('.')
                if isinstance(value, dict):
                    self.load_dict(value, namespace=nskey)
                else:
                    self[nskey] = value
            else:
                raise TypeError('Key has type %r (not a string)' % type(key))
        return self 
Example #10
Source File: bottle.py    From POC-EXP with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, app, rule, method, callback,
                 name=None,
                 plugins=None,
                 skiplist=None, **config):
        #: The application this route is installed to.
        self.app = app
        #: The path-rule string (e.g. ``/wiki/<page>``).
        self.rule = rule
        #: The HTTP method as a string (e.g. ``GET``).
        self.method = method
        #: The original callback with no plugins applied. Useful for introspection.
        self.callback = callback
        #: The name of the route (if specified) or ``None``.
        self.name = name or None
        #: A list of route-specific plugins (see :meth:`Bottle.route`).
        self.plugins = plugins or []
        #: A list of plugins to not apply to this route (see :meth:`Bottle.route`).
        self.skiplist = skiplist or []
        #: Additional keyword arguments passed to the :meth:`Bottle.route`
        #: decorator are stored in this dictionary. Used for route-specific
        #: plugin configuration and meta-data.
        self.config = ConfigDict().load_dict(config) 
Example #11
Source File: bottle.py    From slack-machine with MIT License 5 votes vote down vote up
def load_module(self, path, squash=True):
        """Load values from a Python module.

           Example modue ``config.py``::

                DEBUG = True
                SQLITE = {
                    "db": ":memory:"
                }


           >>> c = ConfigDict()
           >>> c.load_module('config')
           {DEBUG: True, 'SQLITE.DB': 'memory'}
           >>> c.load_module("config", False)
           {'DEBUG': True, 'SQLITE': {'DB': 'memory'}}

           :param squash: If true (default), dictionary values are assumed to
                          represent namespaces (see :meth:`load_dict`).
        """
        config_obj = load(path)
        obj = {key: getattr(config_obj, key) for key in dir(config_obj)
               if key.isupper()}

        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #12
Source File: bottle.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #13
Source File: bottle.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #14
Source File: bottle.py    From warriorframework with Apache License 2.0 5 votes vote down vote up
def load_module(self, path, squash):
        """ Load values from a Python module.
            :param squash: Squash nested dicts into namespaces by using
                           load_dict(), otherwise use update()
            Example: load_config('my.app.settings', True)
            Example: load_config('my.app.settings', False)
        """
        config_obj = __import__(path)
        obj = dict([(key, getattr(config_obj, key))
                for key in dir(config_obj) if key.isupper()])
        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #15
Source File: bottle.py    From silvia-pi with MIT License 5 votes vote down vote up
def load_module(self, path, squash=True):
        """Load values from a Python module.

           Example modue ``config.py``::

                DEBUG = True
                SQLITE = {
                    "db": ":memory:"
                }


           >>> c = ConfigDict()
           >>> c.load_module('config')
           {DEBUG: True, 'SQLITE.DB': 'memory'}
           >>> c.load_module("config", False)
           {'DEBUG': True, 'SQLITE': {'DB': 'memory'}}

           :param squash: If true (default), dictionary values are assumed to
                          represent namespaces (see :meth:`load_dict`).
        """
        config_obj = load(path)
        obj = {key: getattr(config_obj, key) for key in dir(config_obj)
               if key.isupper()}

        if squash:
            self.load_dict(obj)
        else:
            self.update(obj)
        return self 
Example #16
Source File: bottle.py    From slack-machine with MIT License 4 votes vote down vote up
def _main(argv):  # pragma: no coverage
    args, parser = _cli_parse(argv)

    def _cli_error(cli_msg):
        parser.print_help()
        _stderr('\nError: %s\n' % cli_msg)
        sys.exit(1)

    if args.version:
        _stdout('Bottle %s\n' % __version__)
        sys.exit(0)
    if not args.app:
        _cli_error("No application entry point specified.")

    sys.path.insert(0, '.')
    sys.modules.setdefault('bottle', sys.modules['__main__'])

    host, port = (args.bind or 'localhost'), 8080
    if ':' in host and host.rfind(']') < host.rfind(':'):
        host, port = host.rsplit(':', 1)
    host = host.strip('[]')

    config = ConfigDict()

    for cfile in args.conf or []:
        try:
            if cfile.endswith('.json'):
                with open(cfile, 'rb') as fp:
                    config.load_dict(json_loads(fp.read()))
            else:
                config.load_config(cfile)
        except configparser.Error as parse_error:
            _cli_error(parse_error)
        except IOError:
            _cli_error("Unable to read config file %r" % cfile)
        except (UnicodeError, TypeError, ValueError) as error:
            _cli_error("Unable to parse config file %r: %s" % (cfile, error))

    for cval in args.param or []:
        if '=' in cval:
            config.update((cval.split('=', 1),))
        else:
            config[cval] = True

    run(args.app,
        host=host,
        port=int(port),
        server=args.server,
        reloader=args.reload,
        plugins=args.plugin,
        debug=args.debug,
        config=config) 
Example #17
Source File: bottle.py    From silvia-pi with MIT License 4 votes vote down vote up
def _main(argv):  # pragma: no coverage
    args, parser = _cli_parse(argv)

    def _cli_error(cli_msg):
        parser.print_help()
        _stderr('\nError: %s\n' % cli_msg)
        sys.exit(1)

    if args.version:
        _stdout('Bottle %s\n' % __version__)
        sys.exit(0)
    if not args.app:
        _cli_error("No application entry point specified.")

    sys.path.insert(0, '.')
    sys.modules.setdefault('bottle', sys.modules['__main__'])

    host, port = (args.bind or 'localhost'), 8080
    if ':' in host and host.rfind(']') < host.rfind(':'):
        host, port = host.rsplit(':', 1)
    host = host.strip('[]')

    config = ConfigDict()

    for cfile in args.conf or []:
        try:
            if cfile.endswith('.json'):
                with open(cfile, 'rb') as fp:
                    config.load_dict(json_loads(fp.read()))
            else:
                config.load_config(cfile)
        except configparser.Error as parse_error:
            _cli_error(parse_error)
        except IOError:
            _cli_error("Unable to read config file %r" % cfile)
        except (UnicodeError, TypeError, ValueError) as error:
            _cli_error("Unable to parse config file %r: %s" % (cfile, error))

    for cval in args.param or []:
        if '=' in cval:
            config.update((cval.split('=', 1),))
        else:
            config[cval] = True

    run(args.app,
        host=host,
        port=int(port),
        server=args.server,
        reloader=args.reload,
        plugins=args.plugin,
        debug=args.debug,
        config=config)