Back to index

moin  1.9.0~rc2
__init__.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Parser Package
00004 
00005     See "plain.py" for the most simple parser that also
00006     defines the parser interface.
00007 
00008     @copyright: 2000 Juergen Hermann <jh@web.de>
00009     @license: GNU GPL, see COPYING for details.
00010 """
00011 
00012 from MoinMoin.util import pysupport
00013 from MoinMoin import wikiutil
00014 
00015 modules = pysupport.getPackageModules(__file__)
00016 
00017 
00018 def parse_start_step(request, args):
00019     """
00020     Parses common Colorizer parameters start, step, numbers.
00021     Uses L{wikiutil.parseAttributes} and sanitizes the results.
00022 
00023     Start and step must be a non negative number and default to 1,
00024     numbers might be on, off, or none and defaults to on. On or off
00025     means that numbers are switchable via JavaScript (html formatter),
00026     disabled means that numbers are disabled completely.
00027 
00028     attrdict is returned as last element in the tuple, to enable the
00029     calling parser to extract further arguments.
00030 
00031     @param request: a request instance
00032     @param args: the argument string
00033 
00034     @returns: numbers, start, step, attrdict
00035     """
00036     nums, start, step = 1, 1, 1
00037     attrs, msg = wikiutil.parseAttributes(request, args)
00038     if not msg:
00039         try:
00040             start = int(attrs.get('start', '"1"')[1:-1])
00041         except ValueError:
00042             pass
00043         try:
00044             step = int(attrs.get('step', '"1"')[1:-1])
00045         except ValueError:
00046             pass
00047         if attrs.get('numbers', '"on"')[1:-1].lower() in ('off', 'false', 'no'):
00048             nums = 0
00049         elif attrs.get('numbers', '"on"')[1:-1].lower() in ('none', 'disable'):
00050             nums = -1
00051     return nums, start, step, attrs
00052