Back to index

moin  1.9.0~rc2
Public Member Functions | Private Attributes
MoinMoin.wikiutil.UnitArgument Class Reference
Inheritance diagram for MoinMoin.wikiutil.UnitArgument:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.wikiutil.UnitArgument:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def parse_argument
def get_default

Private Attributes

 _units
 _type
 _defaultunit
 _default

Detailed Description

Argument class for invoke_extension_function that forces
having any of the specified units given for a value.

Note that the default unit is "mm".

Use, for example, "UnitArgument('7mm', float, ['%', 'mm'])".

If the defaultunit parameter is given, any argument that
can be converted into the given argtype is assumed to have
the default unit. NOTE: This doesn't work with a choice
(tuple or list) argtype.

Definition at line 1690 of file wikiutil.py.


Constructor & Destructor Documentation

def MoinMoin.wikiutil.UnitArgument.__init__ (   self,
  default,
  argtype,
  units = ['mm'],
  defaultunit = None 
)
Initialise a UnitArgument giving the default,
argument type and the permitted units.

Definition at line 1704 of file wikiutil.py.

01704 
01705     def __init__(self, default, argtype, units=['mm'], defaultunit=None):
01706         """
01707         Initialise a UnitArgument giving the default,
01708         argument type and the permitted units.
01709         """
01710         IEFArgument.__init__(self)
01711         self._units = list(units)
01712         self._units.sort(lambda x, y: len(y) - len(x))
01713         self._type = argtype
01714         self._defaultunit = defaultunit
01715         assert defaultunit is None or defaultunit in units
01716         if default is not None:
01717             self._default = self.parse_argument(default)
01718         else:
01719             self._default = None


Member Function Documentation

Return the default for this argument.

Reimplemented from MoinMoin.wikiutil.IEFArgument.

Definition at line 1734 of file wikiutil.py.

01734 
01735     def get_default(self):
01736         return self._default
01737 

Parse the argument given in s (a string) and return
the argument for the extension function.

Reimplemented from MoinMoin.wikiutil.IEFArgument.

Definition at line 1720 of file wikiutil.py.

01720 
01721     def parse_argument(self, s):
01722         for unit in self._units:
01723             if s.endswith(unit):
01724                 ret = (self._type(s[:len(s) - len(unit)]), unit)
01725                 return ret
01726         if self._defaultunit is not None:
01727             try:
01728                 return (self._type(s), self._defaultunit)
01729             except ValueError:
01730                 pass
01731         units = ', '.join(self._units)
01732         ## XXX: how can we translate this?
01733         raise ValueError("Invalid unit in value %s (allowed units: %s)" % (s, units))


Member Data Documentation

Definition at line 1716 of file wikiutil.py.

Definition at line 1713 of file wikiutil.py.

Definition at line 1712 of file wikiutil.py.

Definition at line 1710 of file wikiutil.py.


The documentation for this class was generated from the following file: