This file is indexed.

/usr/share/pyshared/ZConfig/schemaless.txt is in python-zconfig 2.9.3-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
=================================
Using ZConfig data without schema
=================================

Sometimes it's useful to use ZConfig configuration data without a
schema.  This is most interesting when assembling a configuration from
fragments, as some buildout recipes do.  This is not recommended for
general application use.

The ``ZConfig.schemaless`` module provides some support for working
without schema.  Something things are not (currently) supported,
including the %define and %include directives.  The %import directive
is supported.

This module provides basic support for loading configuration,
inspecting and modifying it, and re-serializing the result.

  >>> from ZConfig import schemaless

There is a single function which loads configuration data from a file
open for reading.  Let's take a look at this, and what it returns::

  >>> config_text = '''
  ...
  ... some-key some-value
  ...
  ... some-key another-value
  ...
  ... <section>
  ...   key1 value1.1
  ...   key1 value1.2
  ...   key2 value2
  ...
  ...   <deeper>
  ...     another key
  ...     another value
  ...   </deeper>
  ... </section>
  ...
  ... another-key  whee!
  ...
  ...
  ... <another named>
  ...   nothing here
  ... </another>
  ...
  ... '''

  >>> import StringIO

  >>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))

The `config` object is a mapping from top-level keys to lists of
values::

  >>> config["some-key"]
  ['some-value', 'another-value']

  >>> config["another-key"]
  ['whee!']

  >>> config["no-such-key-in-the-config"]
  Traceback (most recent call last):
  KeyError: 'no-such-key-in-the-config'

  >>> lst = list(config)
  >>> lst.sort()
  >>> lst
  ['another-key', 'some-key']

There is also a ``sections`` attribute that lists child sections::

  >>> len(config.sections)
  2

Let's take a look at one of the sections.  Like the top-level
configuration, the section maps keys

  >>> section = config.sections[0]

  >>> section["key1"]
  ['value1.1', 'value1.2']

  >>> section["key2"]
  ['value2']

  >>> section["no-such-key-in-the-config"]
  Traceback (most recent call last):
  KeyError: 'no-such-key-in-the-config'

  >>> lst = list(section)
  >>> lst.sort()
  >>> lst
  ['key1', 'key2']

Child sections are again available via the ``sections`` attribute::

  >>> len(section.sections)
  1

In addition, the section has ``type`` and ``name`` attributes that
record the type and name of the section as ZConfig understands them::

  >>> section.type
  'section'

  >>> print section.name
  None

Let's look at the named section from our example, so we can see the
name::

  >>> section = config.sections[1]
  >>> section.type
  'another'
  >>> section.name
  'named'

We can also mutate the configuration, adding new keys and values as
desired::

  >>> config["new-key"] = ["new-value-1", "new-value-2"]
  >>> config["some-key"].append("third-value")

New sections can also be added::

  >>> section = schemaless.Section("sectiontype", "my-name")
  >>> section["key"] = ["value"]
  >>> config.sections.insert(1, section)

The configuration can be re-serialized using ``str()``::

  >>> print str(config)
  another-key whee!
  new-key new-value-1
  new-key new-value-2
  some-key some-value
  some-key another-value
  some-key third-value
  <BLANKLINE>
  <section>
    key1 value1.1
    key1 value1.2
    key2 value2
  <BLANKLINE>
    <deeper>
      another key
      another value
    </deeper>
  </section>
  <BLANKLINE>
  <sectiontype my-name>
    key value
  </sectiontype>
  <BLANKLINE>
  <another named>
    nothing here
  </another>
  <BLANKLINE>

Note that some adjustments have been made:

- key/value pairs come before child sections

- keys are sorted at each level

- blank lines are removed, with new blank lines inserted to preserve
  some semblance of readability

These are all presentation changes, but not essential changes to the
configuration data.  The ordering of sections is not modified in
rendering, nor are the values for a single key re-ordered within a
section or top-level configuration.


Support for %import
-------------------

Imports are supported, and are re-ordered in much the same way that
other elements of a configuration are::

  >>> config_text = '''
  ...
  ... %import some.package
  ...
  ... <section>
  ...
  ...   %import another.package
  ...
  ...   <another>
  ...     some value
  ...   </another>
  ...
  ... </section>
  ...
  ... some-key some-value
  ...
  ... '''

  >>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))

  >>> print config
  %import some.package
  %import another.package
  <BLANKLINE>
  some-key some-value
  <BLANKLINE>
  <section>
    <another>
      some value
    </another>
  </section>
  <BLANKLINE>

The imports are also available as the ``imports`` attribute of the
configuration object::

  >>> config.imports
  ('some.package', 'another.package')

Multiple imports of the same name are removed::

  >>> config_text = '''
  ...
  ... %import some.package
  ... %import another.package
  ... %import some.package
  ...
  ... '''

  >>> config = schemaless.loadConfigFile(StringIO.StringIO(config_text))

  >>> print config
  %import some.package
  %import another.package
  <BLANKLINE>

  >>> config.imports
  ('some.package', 'another.package')


Limitations
-----------

There are some limitations of handling ZConfig-based configurations
using the ``ZConfig.schemaless`` module.  Some of these are
implementation issues, and may be corrected in the future:

- %define is not supported.

- %include is not supported.

Others are a function of not processing the schema, and can't easily
be avoided:

- normalization of keys based on keytypes specified in the <schema> or
  <sectiontype> elements of the schema if not performed.

  If the transformation of a key might affect the behavior controlled
  by the resulting configuration, the generated configuration may not
  be equivalent.  Examples of this are unusual, but exist.

Limitations related to the non-processing of the schema cannot be
detected by the ``ZConfig.schemaless``, so no errors are reported in
these situations.

For the strictly syntactic limitations, we do get errors when the
input data requires they be supported.  Let's look at both the %define
and %include handling.

When %define is used in the input configuration, an exception is
raised when loading the configuration::

  >>> config_text = '''
  ...
  ... %define  somename  somevalue
  ...
  ... '''

  >>> schemaless.loadConfigFile(StringIO.StringIO(config_text))
  Traceback (most recent call last):
  NotImplementedError: defines are not supported

A similar exception is raised for %include::

  >>> config_text = '''
  ...
  ... %include  some/other/file.conf
  ...
  ... '''

  >>> schemaless.loadConfigFile(StringIO.StringIO(config_text))
  Traceback (most recent call last):
  NotImplementedError: includes are not supported