Mercurial > hg > pyloader
view README.txt @ 25:8aabb54129a7
make factory.py executable
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 06 Jun 2011 09:55:14 -0700 |
parents | ff634cc2e62b |
children | db095765807d |
line wrap: on
line source
pyloader =========== Load python attributes from strings JSON Format ----------- pyloader uses a JSON-serializable format for the canonical (serializable) form of python objects:: {'foo': # (arbitrary) object name, {'args': ['positional', 'arguments'], 'kwargs': {'keyword': 'arguments}, 'path': 'dotted.or.file.path:ObjectName'}, 'bar': ... } # etc Objects are instantiated like:: ObjectName(*args, **kwargs) In the case that the object is not to be instantiated (e.g. a standalone function, ``args`` and ``kwargs`` will either not be present or will be None (``null`` in JSON). INI Format ---------- pyloader also features an INI format which is translated to the JSON Format but adds a few convenience features. A simple object is expressed as:: [foo:dotted.or.file.path:ObjectName] . = positional, arguments keyword = arguments ``.`` expresses positional arguments which is a comma-separated list. The remaining (key, value) pairs become keyword arguments. The section name contains the object name (e.g. ``foo``) followed by a ``:`` followed by a loading path. Like JSON, a dotted path or a file path may be used. In addition, other (pluggable) loading paths are available: - override loader: you can use a section name like ``[foo:bar]`` to override variables from the ``bar`` object with variables from ``foo``:: [foo:bar] . = cats, dogs type = count [bar:%(here)s/some/path.py:MyObject] . = elephants type = concatenate The above results in a JSON blob for foo like:: {'foo': {'args': ['elephants', 'cats', 'dogs'], 'kwargs': {'type': 'concatenate'}, 'path': '/location/of/ini/file/some/path.py:MyObject'}} ``args`` is extended. ``kwargs`` will be overridden. - wrappers: in addition to the override pattern, you can also wrap an object:: [foo:bar:baz] In addition, .ini files may include other .ini files. This allows for encapsulation of intent of specific .ini files:: [include:%(here)s/some/file.ini] INI files have a few convenience variables: - %(here)s : the location of the directory the .ini file lives in - %(app)s : used for wrappers Additional variables may be provided by the consumer. ---- Jeff Hammel http://k0s.org/