/usr/share/pyshared/zope/configuration/docutils.py is in python-zope.configuration 3.7.4-2fakesync1.
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 | ##############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Helper Utility to wrap a text to a set width of characters
"""
__docformat__ = 'restructuredtext'
import re
para_sep = re.compile('\n{2,}')
whitespace=re.compile('[ \t\n\r]+')
def wrap(text, width=78, indent=0):
"""Makes sure that we keep a line length of a certain width.
Examples:
>>> print wrap('foo bar')[:-2]
foo bar
>>> print wrap('foo bar', indent=2)[:-2]
foo bar
>>> print wrap('foo bar, more foo bar', 10)[:-2]
foo bar,
more foo
bar
>>> print wrap('foo bar, more foo bar', 10, 2)[:-2]
foo bar,
more foo
bar
"""
paras = para_sep.split(text.strip())
new_paras = []
for par in paras:
words= filter(None, whitespace.split(par))
lines = []
line = []
length = indent
for word in words:
if length + len(word) <= width:
line.append(word)
length += len(word) + 1
else:
lines.append(' '*indent + ' '.join(line))
line = [word]
length = len(word) + 1 + indent
lines.append(' '*indent + ' '.join(line))
new_paras.append('\n'.join(lines))
return '\n\n'.join(new_paras) + '\n\n'
def makeDocStructures(context):
"""Creates two structures that provide a friendly format for
documentation.
'namespaces' is a dictionary that maps namespaces to a directives
dictionary with the key being the name of the directive and the value is a
tuple: (schema, handler, info).
'subdirs' maps a (namespace, name) pair to a list of subdirectives that
have the form (namespace, name, schema, info).
"""
namespaces = {}
subdirs = {}
registry = context._docRegistry
for (namespace, name), schema, usedIn, handler, info, parent in registry:
if not parent:
ns_entry = namespaces.setdefault(namespace, {})
ns_entry[name] = (schema, handler, info)
else:
sd_entry = subdirs.setdefault((parent.namespace, parent.name), [])
sd_entry.append((namespace, name, schema, handler, info))
return namespaces, subdirs
|