• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zope.configuration / 16248876899

06 Dec 2024 07:34AM UTC coverage: 99.857%. Remained the same
16248876899

push

github

icemac
Back to development: 6.1

350 of 356 branches covered (98.31%)

Branch coverage included in aggregate %.

3850 of 3850 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/zope/configuration/docutils.py
1
##############################################################################
2
#
3
# Copyright (c) 2004 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
"""Helper Utility to wrap a text to a set width of characters
15
"""
16
__docformat__ = 'restructuredtext'
1✔
17

18
import re
1✔
19

20

21
__all__ = [
1✔
22
    'wrap',
23
    'makeDocStructures',
24
]
25

26
para_sep = re.compile('\n{2,}')
1✔
27
whitespace = re.compile('[ \t\n\r]+')
1✔
28

29

30
def wrap(text, width=78, indent=0):
1✔
31
    """
32
    Makes sure that we keep a line length of a certain width.
33

34
    Examples:
35

36
      >>> from zope.configuration.docutils import wrap
37
      >>> print(wrap('foo bar')[:-2])
38
      foo bar
39
      >>> print(wrap('foo bar', indent=2)[:-2])
40
        foo bar
41
      >>> print(wrap('foo bar, more foo bar', 10)[:-2])
42
      foo bar,
43
      more foo
44
      bar
45
      >>> print(wrap('foo bar, more foo bar', 10, 2)[:-2])
46
        foo bar,
47
        more foo
48
        bar
49
    """
50
    paras = para_sep.split(text.strip())
1✔
51

52
    new_paras = []
1✔
53
    for par in paras:
1✔
54
        words = filter(None, whitespace.split(par))
1✔
55

56
        lines = []
1✔
57
        line = []
1✔
58
        length = indent
1✔
59
        for word in words:
1✔
60
            if length + len(word) <= width:
1✔
61
                line.append(word)
1✔
62
                length += len(word) + 1
1✔
63
            else:
64
                lines.append(' ' * indent + ' '.join(line))
1✔
65
                line = [word]
1✔
66
                length = len(word) + 1 + indent
1✔
67

68
        lines.append(' ' * indent + ' '.join(line))
1✔
69

70
        new_paras.append('\n'.join(lines))
1✔
71

72
    return '\n\n'.join(new_paras) + '\n\n'
1✔
73

74

75
def makeDocStructures(context):
1✔
76
    """
77
    makeDocStructures(context) -> namespaces, subdirs
78

79
    Creates two structures that provide a friendly format for
80
    documentation.
81

82
    *namespaces* is a dictionary that maps namespaces to a directives
83
    dictionary with the key being the name of the directive and the
84
    value is a tuple: (schema, handler, info).
85

86
    *subdirs* maps a (namespace, name) pair to a list of subdirectives
87
    that have the form (namespace, name, schema, info).
88
    """
89
    namespaces = {}
1✔
90
    subdirs = {}
1✔
91
    registry = context._docRegistry
1✔
92
    for (namespace, name), schema, usedIn, handler, info, parent in registry:
1✔
93
        if not parent:
1✔
94
            ns_entry = namespaces.setdefault(namespace, {})
1✔
95
            ns_entry[name] = (schema, handler, info)
1✔
96
        else:
97
            sd_entry = subdirs.setdefault((parent.namespace, parent.name), [])
1✔
98
            sd_entry.append((namespace, name, schema, handler, info))
1✔
99
    return namespaces, subdirs
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc