annotate README.txt @ 98:d59f0425d705 default tip

version bump
author Jeff Hammel <k0scist@gmail.com>
date Mon, 27 May 2024 16:20:52 -0700
parents c852ff04c940
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 pyloader
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 ===========
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
7
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
4 Load python attributes from strings
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
5
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
6 JSON Format
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
7 -----------
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
8
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
9 pyloader uses a JSON-serializable format for the canonical
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
10 (serializable) form of python objects::
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
11
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
12 {'foo': # (arbitrary) object name,
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
13 {'args': ['positional', 'arguments'],
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
14 'kwargs': {'keyword': 'arguments},
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
15 'path': 'dotted.or.file.path:ObjectName'},
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
16 'bar': ... } # etc
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
17
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
18 Objects are instantiated like::
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
19
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
20 ObjectName(*args, **kwargs)
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
21
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
22 In the case that the object is not to be instantiated (e.g. a
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
23 standalone function, ``args`` and ``kwargs`` will either not be
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
24 present or will be None (``null`` in JSON).
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
25
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
26
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
27 INI Format
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
28 ----------
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
29
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
30 pyloader also features an INI format which is translated to the JSON
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
31 Format but adds a few convenience features. A simple object is
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
32 expressed as::
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
33
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
34 [foo:dotted.or.file.path:ObjectName]
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
35 . = positional, arguments
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
36 keyword = arguments
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
37
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
38 ``.`` expresses positional arguments which is a comma-separated
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
39 list. The remaining (key, value) pairs become keyword arguments. The
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
40 section name contains the object name (e.g. ``foo``) followed by a
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
41 ``:`` followed by a loading path. Like JSON, a dotted path or a file
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
42 path may be used. In addition, other (pluggable) loading paths are
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
43 available:
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
44
8
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
45 - override loader: you can use a section name like ``[foo:bar]`` to
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
46 override variables from the ``bar`` object with variables from
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
47 ``foo``::
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
48
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
49 [foo:bar]
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
50 . = cats, dogs
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
51 type = count
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
52
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
53 [bar:%(here)s/some/path.py:MyObject]
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
54 . = elephants
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
55 type = concatenate
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
56
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
57 The above results in a JSON blob for foo like::
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
58
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
59 {'foo': {'args': ['elephants', 'cats', 'dogs'],
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
60 'kwargs': {'type': 'concatenate'},
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
61 'path': '/location/of/ini/file/some/path.py:MyObject'}}
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
62
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
63 ``args`` is extended. ``kwargs`` will be overridden.
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
64
9
ff634cc2e62b unfinished sketch of an abstract factory
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
65 - wrappers: in addition to the override pattern, you can also wrap an
ff634cc2e62b unfinished sketch of an abstract factory
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
66 object::
ff634cc2e62b unfinished sketch of an abstract factory
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
67
ff634cc2e62b unfinished sketch of an abstract factory
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
68 [foo:bar:baz]
7
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
69
39
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
70 This will create an object, ``foo`` which wraps the object ``baz`` in
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
71 by the pattern given by ``bar``. In this case, ``bar`` is provided
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
72 a special variable, `%(app)s`.
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
73
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
74 You can also do::
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
75
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
76 [foo:bar:hi,hello,x=1,y=2:%(here)/objects.py:MyClass]
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
77
db095765807d update decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
78
7
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
79 In addition, .ini files may include other .ini files. This allows for
8
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
80 encapsulation of intent of specific .ini files::
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
81
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
82 [include:%(here)s/some/file.ini]
7
79676a48f6d8 begin porting and modernizing instructions from wsgiblob to pyloader
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
83
8
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
84 INI files have a few convenience variables:
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
85
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
86 - %(here)s : the location of the directory the .ini file lives in
40
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
87 - %(object)s : used for wrappers
8
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
88
4d3ea44fd813 further spec out
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
89 Additional variables may be provided by the consumer.
0
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90
40
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
91 Summary of .ini decorator syntax
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
92 --------------------------------
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
93
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
94 1. ``[foo:%(here)s/objects.py:MyClass]``: create object ``foo`` of type
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
95 ``MyClass`` using arguments given from the section
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
96
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
97 2. ``[foo:bar]``: create object ``foo`` using the pattern from section
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
98 ``bar`` but overriding any arguments in the ``bar`` section with
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
99 those from this section
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
100
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
101 3. ``[foo:bar:%(here)s/objects.py:MyClass]``: create object ``foo``
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
102 which is an instance of ``MyClass`` wrapped in the object created by
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
103 the ``bar`` pattern. ``bar`` is passed a special argument,
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
104 ``%(object)s`` which is the instance of the wrapped object (the
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
105 ``MyClass`` instance). Internally, the wrapped object is known by
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
106 the whole section name (``foo:bar:%(here)s/objects.py:MyClass``). The
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
107 arguments in this section apply to ``MyClass(...)``
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
108
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
109 4. ``[foo:bar:app=%(object)s,value=1:%(here)s/objects.py:MyClass]``:
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
110 the same as 3. but override the values in the ``bar`` section with
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
111 ``app=%(object)s`` and ``value=1``
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
112
80
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
113 Section Name Syntax
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
114 -------------------
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
115
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
116 - *[name:resource]* : create an object named *name* , where resource
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
117 is either a section name or a *path* as described in `JSON Format`_ .
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
118 In the case where *resouce* is another section name, the options
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
119 will overide the options given in the *resource* section and a new
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
120 object named *name* will be created. In the case where *section* is
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
121 a path, an object will be created as given by the *path* with the
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
122 given options.
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
123 - *[name:decorator:resource]* : create an object named *name* where
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
124 the object given by *resource* is passed to *decorator*. Overrides
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
125 and loading is as described for *[name:reource]* . An anonymous
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
126 object is created of the whole section name for the wrapped
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
127 object. So this form results in two sections for the `JSON Format`_ .
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
128 *decorator* is a section in the same namespace as *name*.
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
129 - *[name:decorator:overrides:resource]* : similar to
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
130 *[name:decorator:resource]* , but apply *overides* to the
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
131 *decorator* section. *overrides* is a string of the format
c852ff04c940 note formal syntax of section names
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
132 ``foo,bar,fleem=5``.
40
0b2019d0af98 finalize (hopefully) decorator syntax
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
133
0
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
134 ----
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
135
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
136 Jeff Hammel
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
137 http://k0s.org/
6fa6d987b3af initial commit of pyloader
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
138