~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/parser/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
"""
11
11
 
12
12
from MoinMoin.util import pysupport
13
 
from MoinMoin import wikiutil
14
13
 
15
14
modules = pysupport.getPackageModules(__file__)
16
15
 
17
 
 
18
 
def parse_start_step(request, args):
19
 
    """
20
 
    Parses common Colorizer parameters start, step, numbers.
21
 
    Uses L{wikiutil.parseAttributes} and sanitizes the results.
22
 
 
23
 
    Start and step must be a non negative number and default to 1,
24
 
    numbers might be on, off, or none and defaults to on. On or off
25
 
    means that numbers are switchable via JavaScript (html formatter),
26
 
    disabled means that numbers are disabled completely.
27
 
 
28
 
    attrdict is returned as last element in the tuple, to enable the
29
 
    calling parser to extract further arguments.
30
 
 
31
 
    @param request: a request instance
32
 
    @param args: the argument string
33
 
 
34
 
    @returns: numbers, start, step, attrdict
35
 
    """
36
 
    nums, start, step = 1, 1, 1
37
 
    attrs, msg = wikiutil.parseAttributes(request, args)
38
 
    if not msg:
39
 
        try:
40
 
            start = int(attrs.get('start', '"1"')[1:-1])
41
 
        except ValueError:
42
 
            pass
43
 
        try:
44
 
            step = int(attrs.get('step', '"1"')[1:-1])
45
 
        except ValueError:
46
 
            pass
47
 
        if attrs.get('numbers', '"on"')[1:-1].lower() in ('off', 'false', 'no'):
48
 
            nums = 0
49
 
        elif attrs.get('numbers', '"on"')[1:-1].lower() in ('none', 'disable'):
50
 
            nums = -1
51
 
    return nums, start, step, attrs
52