Package jazzparser :: Package utils :: Module options :: Class ModuleOption
[hide private]
[frames] | no frames]

Class ModuleOption

source code

object --+
         |
        ModuleOption

An option that can be specified on the command line and that is specific to a certain modular component (e.g. parser, tagger).

Example use of a ModuleOption:

ModuleOption('test',
             lambda x: int(x), 
             help_text="A test option", 
             default=2,
             usage="test=X, where X is an int")

This will accept integer values for the option called "test". If no value is given, it will default to 2.

A filter function may be given which will be applied to the value during option processing. If the filter raises an exception, the value will be reported as invalid.

You may also specify multiple filters as a tuple of functions. Each will be applied in order and the first value successfully returned will be used.

Instance Methods [hide private]
 
__init__(self, name, filter=None, help_text='No help text available', default=None, usage=None, required=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_get_usage(self) source code
 
get_value(self, options)
Pulls the appropriate value out of a dictionary of options and return it.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
process_option_string(optstr)
Takes an option string in the format in which options should be specified on the command line and returns a dictionary ready to pass to the options themselves.
source code
 
process_option_dict(optdict, available_opts)
Takes a dictionary of options, which may be from command-line strings (via process_option_string) or internal, and a list of allowed options and returns a dictionary of all the option values.
source code
Properties [hide private]
  usage

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, filter=None, help_text='No help text available', default=None, usage=None, required=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

process_option_string(optstr)
Static Method

source code 

Takes an option string in the format in which options should be specified on the command line and returns a dictionary ready to pass to the options themselves.

Module options must be in the format opt1=val1:opt2=val2:etc. Later options override earlier ones.

optstr may also be a list of strings. In this case, the options in each string will be concatenated. This allows you to take options from multiple CL options using optparse's append action.

If the optstr is None, or an empty list, returns an empty dict. This allows you to pass in a value directly from an optparse parser.


Property Details [hide private]

usage

Get Method:
_get_usage(self)