Package pyxmpp2 :: Module settings :: Class XMPPSettings
[hide private]

Class XMPPSettings


Container for various parameters used all over PyXMPP.

It can be used like a regular dictionary, but will provide reasonable defaults for PyXMPP for parameters which are not explicitely set.

All known PyXMPP settings are included in the settings list.

Nested Classes [hide private]

Inherited from _abcoll.Sized: __metaclass__

Instance Methods [hide private]
 
__init__(self, data=None)
Create settings, optionally initialized with data.
 
__len__(self)
Number of parameters set.
 
__iter__(self)
Iterate over the parameter names.
 
__contains__(self, key)
Check if a parameter is set.
 
__getitem__(self, key)
Get a parameter value.
 
__setitem__(self, key, value)
Set a parameter value.
 
__delitem__(self, key)
Unset a parameter value.
 
get(self, key, local_default=None, required=False)
Get a parameter value.
  • list of unicode
keys(self)
Return names of parameters set.
  • list of tuples
items(self)
Return names and values of parameters set.
 
load_arguments(self, args)
Load settings from ArgumentParser output.

Inherited from _abcoll.MutableMapping: clear, pop, popitem, setdefault, update

Inherited from _abcoll.Mapping: __eq__, __ne__, iteritems, iterkeys, itervalues, values

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

Class Methods [hide private]
 
add_setting(cls, name, type=<type 'unicode'>, default=None, factory=None, cache=False, default_d=None, doc=None, cmdline_help=None, validator=None, basic=False)
Add a new setting definition.
 
list_all(cls, basic=None)
List known settings.
argparse.ArgumentParser
get_arg_parser(cls, settings=None, option_prefix=u'--', add_help=False)
Make a command-line option parser.

Inherited from _abcoll.Sized: __subclasshook__

Static Methods [hide private]
 
validate_string_list(value)
Validator for string lists to be used with add_setting.
 
validate_positive_int(value)
Positive integer validator to be used with add_setting.
 
validate_positive_float(value)
Positive float validator to be used with add_setting.
 
get_int_range_validator(start, stop)
Return an integer range validator to be used with add_setting.
Class Variables [hide private]
  _defs = {}
  __abstractmethods__ = frozenset([])
  _abc_cache = <_weakrefset.WeakSet object at 0x86b5a4c>
  _abc_negative_cache = <_weakrefset.WeakSet object at 0x86b5a8c>
  _abc_registry = <_weakrefset.WeakSet object at 0x86b5a0c>
  _defaults
defaults for registered parameters.
  _defaults_factories
factory functions providing default values which cannot be hard-coded.

Inherited from _abcoll.Mapping: __hash__

Inherited from _abcoll.Mapping (private): _abc_negative_cache_version

Instance Variables [hide private]
  _settings
current values of the parameters explicitely set.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data=None)
(Constructor)

 
Create settings, optionally initialized with data.
Parameters:
Overrides: object.__init__

__len__(self)
(Length operator)

 
Number of parameters set.
Overrides: _abcoll.Sized.__len__

__iter__(self)

 
Iterate over the parameter names.
Overrides: _abcoll.Iterable.__iter__

__contains__(self, key)
(In operator)

 
Check if a parameter is set.
Parameters:
  • key (unicode) - the parameter name
Overrides: _abcoll.Container.__contains__

__getitem__(self, key)
(Indexing operator)

 
Get a parameter value. Return the default if no value is set and the default is provided by PyXMPP.
Parameters:
  • key (unicode) - the parameter name
Overrides: _abcoll.Mapping.__getitem__

__setitem__(self, key, value)
(Index assignment operator)

 
Set a parameter value.
Parameters:
  • key (unicode) - the parameter name
  • value - the new value
Overrides: _abcoll.MutableMapping.__setitem__

__delitem__(self, key)
(Index deletion operator)

 
Unset a parameter value.
Parameters:
  • key (unicode) - the parameter name
Overrides: _abcoll.MutableMapping.__delitem__

get(self, key, local_default=None, required=False)

 

Get a parameter value.

If parameter is not set, return local_default if it is not None or the PyXMPP global default otherwise.

Returns:
parameter value
Raises:
  • KeyError - if parameter has no value and no global default
Overrides: _abcoll.Mapping.get

keys(self)

 
Return names of parameters set.
Returns:
  • list of unicode

Overrides: _abcoll.Mapping.keys

items(self)

 
Return names and values of parameters set.
Returns:
  • list of tuples

Overrides: _abcoll.Mapping.items

load_arguments(self, args)

 
Load settings from ArgumentParser output.
Parameters:
  • args - output of argument parsed based on the one returned by get_arg_parser()

add_setting(cls, name, type=<type 'unicode'>, default=None, factory=None, cache=False, default_d=None, doc=None, cmdline_help=None, validator=None, basic=False)
Class Method

 
Add a new setting definition.
Parameters:
  • name (unicode) - setting name
  • type (type or unicode) - setting type object or type description
  • default - default value
  • factory (a callable) - default value factory
  • cache (bool) - if True the factory will be called only once and its value stored as a constant default.
  • default_d (unicode) - description of the default value
  • doc (unicode) - setting documentation
  • cmdline_help (unicode) - command line argument description. When not provided then the setting won't be available as a command-line option
  • basic (bool) - when True the option is considered a basic option - one of those which should usually stay configurable in an application.
  • validator (a callable) - function validating command-line option value string and returning proper value for the settings objects. Defaults to type.

get_int_range_validator(start, stop)
Static Method

 
Return an integer range validator to be used with add_setting.
Parameters:
  • start (int) - minimum value for the integer
  • stop (int) - the upper bound (maximum value + 1)
Returns:
a validator function

list_all(cls, basic=None)
Class Method

 
List known settings.
Parameters:
  • basic - When True then limit output to the basic settings, when False list only the extra settings.

get_arg_parser(cls, settings=None, option_prefix=u'--', add_help=False)
Class Method

 

Make a command-line option parser.

The returned parser may be used as a parent parser for application argument parser.

Parameters:
  • settings (list of unicode) - list of PyXMPP2 settings to consider. By default all 'basic' settings are provided.
  • option_prefix (str) - custom prefix for PyXMPP2 options. E.g. '--xmpp' to differentiate them from not xmpp-related application options.
  • add_help () - when True a '--help' option will be included (probably already added in the application parser object)
Returns: argparse.ArgumentParser
an argument parser object.