pep 8 lines too long
[tiramisu.git] / tiramisu / option.py
index 23cbd27..bedb43a 100644 (file)
@@ -68,7 +68,8 @@ class BaseInformation(object):
             self._impl_informations[key] = value
         except AttributeError:
             raise AttributeError(_('{0} has no attribute '
-                                   'impl_set_information').format(self.__class__.__name__))
+                                   'impl_set_information').format(
+                                   self.__class__.__name__))
 
     def impl_get_information(self, key, default=None):
         """retrieves one information's item
@@ -81,10 +82,12 @@ class BaseInformation(object):
             elif default is not None:
                 return default
             else:
-                raise ValueError(_("Information's item not found: {0}").format(key))
+                raise ValueError(_("Information's item"
+                                   "not found: {0}").format(key))
         except AttributeError:
             raise AttributeError(_('{0} has no attribute '
-                                   'impl_get_information').format(self.__class__.__name__))
+                                   'impl_get_information').format(
+                                   self.__class__.__name__))
 
 
 class Option(BaseInformation):
@@ -93,8 +96,10 @@ class Option(BaseInformation):
 
     Reminder: an Option object is **not** a container for the value
     """
-    __slots__ = ('_name', '_requires', '_multi', '_validator', '_default_multi',
-                 '_default', '_properties', '_callback', '_multitype',
+    __slots__ = ('_name', '_requires', '_multi', '_validator',
+                 '_default_multi',
+                 '_default',
+                 '_properties', '_callback', '_multitype',
                  '_master_slaves', '_consistencies', '_empty')
     _empty = ''
 
@@ -145,13 +150,16 @@ class Option(BaseInformation):
                 self._validate(default_multi)
             except ValueError, err:
                 raise ValueError(_("invalid default_multi value {0} "
-                                   "for option {1}: {2}").format(str(default_multi), name, err))
-        if callback is not None and (default is not None or default_multi is not None):
+                                   "for option {1}: {2}").format(
+                                   str(default_multi), name, err))
+        if callback is not None and (default is not None or
+                                     default_multi is not None):
             raise ValueError(_("default value not allowed if option: {0} "
                              "is calculated").format(name))
         if callback is None and callback_params is not None:
             raise ValueError(_("params defined for a callback function but "
-                             "no callback defined yet for option {0}").format(name))
+                             "no callback defined"
+                             " yet for option {0}").format(name))
         if callback is not None:
             if type(callback) != FunctionType:
                 raise ValueError('callback must be a function')
@@ -172,14 +180,18 @@ class Option(BaseInformation):
             properties = tuple()
         if not isinstance(properties, tuple):
             raise TypeError(_('invalid properties type {0} for {1},'
-                            ' must be a tuple').format(type(properties), self._name))
+                            ' must be a tuple').format(
+                                                type(properties),
+                                                self._name))
         self._properties = properties  # 'hidden', 'disabled'...
 
     def __eq__(self, other):
         "Option comparison"
         if not isinstance(other, Option):
             return False
-        slots = list(self.__slots__ + Option.__slots__ + BaseInformation.__slots__)
+        slots = list(self.__slots__ +
+                     Option.__slots__ +
+                     BaseInformation.__slots__)
         for var in slots:
             try:
                 val1 = getattr(self, var)
@@ -270,8 +282,11 @@ class Option(BaseInformation):
             if _value is None:
                 return True
             if not val_validator(_value):
-                raise ValueError(_("invalid value {0} for option {1} for object {2}"
-                                   "").format(_value, self._name, self.__class__.__name__))
+                raise ValueError(_("invalid value {0} "
+                                   "for option {1} for object {2}"
+                                   ).format(_value,
+                                            self._name,
+                                            self.__class__.__name__))
             try:
                 self._validate(_value)
             except ValueError, err:
@@ -314,7 +329,8 @@ class Option(BaseInformation):
     def impl_is_empty_by_default(self):
         "no default value has been set yet"
         if ((not self.impl_is_multi() and self._default is None) or
-                (self.impl_is_multi() and (self._default == [] or None in self._default))):
+                (self.impl_is_multi() and (self._default == []
+                                      or None in self._default))):
             return True
         return False
 
@@ -343,9 +359,13 @@ class Option(BaseInformation):
         if self is opt:
             raise ValueError('cannot add consistency with itself')
         if self.impl_is_multi() != opt.impl_is_multi():
-            raise ValueError('options in consistency should be multi in two sides')
+            raise ValueError('options in consistency'
+                             ' should be multi in two sides')
         func = '_cons_{0}'.format(func)
-        self._launch_consistency(func, self, self.impl_getdefault(), None, None, opt)
+        self._launch_consistency(func,
+                                 self,
+                                 self.impl_getdefault(),
+                                 None, None, opt)
         self._consistencies.append((func, opt))
         self.impl_validate(self.impl_getdefault())
 
@@ -397,7 +417,8 @@ class ChoiceOption(Option):
 
     def _validate(self, value):
         if not self._open_values and not value in self._values:
-            raise ValueError(_('value {0} is not permitted, only {1} is allowed'
+            raise ValueError(_('value {0} is not permitted, '
+                               'only {1} is allowed'
                                '').format(value, self._values))
 
 
@@ -461,7 +482,8 @@ class SymLinkOption(object):
         self._name = name
         if not isinstance(opt, Option):
             raise ValueError(_('malformed symlinkoption '
-                               'must be an option for symlink {0}').format(name))
+                               'must be an option '
+                               'for symlink {0}').format(name))
         self._opt = opt
 
     def __getattr__(self, name):
@@ -525,7 +547,10 @@ class PortOption(Option):
         ports_min = [0, 1, 1024, 49152]
         ports_max = [0, 1023, 49151, 65535]
         is_finally = False
-        for index, allowed in enumerate([allow_zero, allow_wellknown, allow_registred, allow_private]):
+        for index, allowed in enumerate([allow_zero,
+                                         allow_wellknown,
+                                         allow_registred,
+                                         allow_private]):
             if self._min_value is None:
                 if allowed:
                     self._min_value = ports_min[index]
@@ -555,7 +580,8 @@ class PortOption(Option):
             if len(value) != 2:
                 raise ValueError('range must have two values only')
             if not value[0] < value[1]:
-                raise ValueError('first port in range must be smaller than the second one')
+                raise ValueError('first port in range must be'
+                                 ' smaller than the second one')
         else:
             value = [value]
 
@@ -605,7 +631,8 @@ class NetmaskOption(Option):
                         make_net=not make_net)
                 except ValueError:
                     if not make_net:
-                        msg = _("invalid network {0} ({1}) with netmask {2} ({3}),"
+                        msg = _("invalid network {0} ({1}) "
+                                "with netmask {2} ({3}),"
                                 " this network is an IP")
                 else:
                     if make_net:
@@ -671,7 +698,8 @@ class DomainnameOption(Option):
                 raise ValueError(_("invalid value for {0}, must have dot"
                                    "").format(self._name))
         if len(value) > length:
-            raise ValueError(_("invalid domainname's length for {0} (max {1})").format(self._name, length))
+            raise ValueError(_("invalid domainname's length for "
+                               " {0} (max {1})").format(self._name, length))
         if len(value) == 1:
             raise ValueError(_("invalid domainname's length for {0} (min 2)"
                                "").format(self._name))
@@ -693,7 +721,8 @@ class OptionDescription(BaseInformation):
 
         """
         if not valid_name(name):
-            raise ValueError(_("invalid name: {0} for optiondescription").format(name))
+            raise ValueError(_("invalid name: "
+                               " {0} for optiondescription").format(name))
         self._name = name
         self._impl_informations = {}
         self.impl_set_information('doc', doc)
@@ -716,7 +745,8 @@ class OptionDescription(BaseInformation):
             properties = tuple()
         if not isinstance(properties, tuple):
             raise TypeError(_('invalid properties type {0} for {1},'
-                              ' must be a tuple').format(type(properties), self._name))
+                              ' must be a tuple').format(type(properties),
+                                                         self._name))
         self._properties = properties  # 'hidden', 'disabled'...
         # the group_type is useful for filtering OptionDescriptions in a config
         self._group_type = groups.default
@@ -728,8 +758,9 @@ class OptionDescription(BaseInformation):
         try:
             return self._children[1][self._children[0].index(name)]
         except ValueError:
-            raise AttributeError(_('unknown Option {0} in OptionDescription {1}'
-                                 '').format(name, self._name))
+            raise AttributeError(_('unknown Option {0} '
+                                   'in OptionDescription {1}'
+                                   '').format(name, self._name))
 
     def impl_getkey(self, config):
         return tuple([child.impl_getkey(getattr(config, child._name))
@@ -756,7 +787,11 @@ class OptionDescription(BaseInformation):
     def impl_getchildren(self):
         return self._children[1]
 
-    def impl_build_cache(self, cache_path=None, cache_option=None, _currpath=None, _consistencies=None):
+    def impl_build_cache(self,
+                         cache_path=None,
+                         cache_option=None,
+                         _currpath=None,
+                         _consistencies=None):
         if _currpath is None and self._cache_paths is not None:
             return
         if _currpath is None:
@@ -779,11 +814,16 @@ class OptionDescription(BaseInformation):
                     for consistency in option._consistencies:
                         func, opt = consistency
                         opts = (option, opt)
-                        _consistencies.setdefault(opt, []).append((func, opts))
-                        _consistencies.setdefault(option, []).append((func, opts))
+                        _consistencies.setdefault(opt,
+                                                  []).append((func, opts))
+                        _consistencies.setdefault(option,
+                                                  []).append((func, opts))
             else:
                 _currpath.append(attr)
-                option.impl_build_cache(cache_path, cache_option, _currpath, _consistencies)
+                option.impl_build_cache(cache_path,
+                                        cache_option,
+                                        _currpath,
+                                        _consistencies)
                 _currpath.pop()
         if save:
             #valid no duplicated option
@@ -819,7 +859,8 @@ class OptionDescription(BaseInformation):
         """
         if self._group_type != groups.default:
             raise TypeError(_('cannot change group_type if already set '
-                            '(old {0}, new {1})').format(self._group_type, group_type))
+                            '(old {0}, new {1})').format(self._group_type,
+                                                         group_type))
         if isinstance(group_type, groups.GroupType):
             self._group_type = group_type
             if isinstance(group_type, groups.MasterGroupType):
@@ -836,7 +877,8 @@ class OptionDescription(BaseInformation):
                         raise ValueError(_("master group {0} shall not have "
                                          "a symlinkoption").format(self._name))
                     if not child.impl_is_multi():
-                        raise ValueError(_("not allowed option {0} in group {1}"
+                        raise ValueError(_("not allowed option {0} "
+                                         "in group {1}"
                                          ": this option is not a multi"
                                          "").format(child._name, self._name))
                     if child._name == self._name:
@@ -846,18 +888,20 @@ class OptionDescription(BaseInformation):
                     else:
                         slaves.append(child)
                 if master is None:
-                    raise ValueError(_('master group with wrong master name for {0}'
-                                     '').format(self._name))
+                    raise ValueError(_('master group with wrong'
+                                       ' master name for {0}'
+                                       ).format(self._name))
                 master._master_slaves = tuple(slaves)
                 for child in self.impl_getchildren():
                     if child != master:
                         child._master_slaves = master
                         child._multitype = multitypes.slave
                 if not identical_master_child_name:
-                    raise ValueError(_("no child has same nom has master group "
-                                       "for: {0}").format(self._name))
+                    raise ValueError(_("no child has same nom has master group"
+                                       " for: {0}").format(self._name))
         else:
-            raise ValueError(_('not allowed group_type : {0}').format(group_type))
+            raise ValueError(_('group_type : {0}'
+                               ' not allowed').format(group_type))
 
     def impl_get_group_type(self):
         return self._group_type
@@ -867,8 +911,12 @@ class OptionDescription(BaseInformation):
         if consistencies is not None:
             for consistency in consistencies:
                 opt_ = consistency[1]
-                ret = opt_[0]._launch_consistency(consistency[0], opt, value, context,
-                                                  index, opt_[1])
+                ret = opt_[0]._launch_consistency(consistency[0],
+                                                  opt,
+                                                  value,
+                                                  context,
+                                                  index,
+                                                  opt_[1])
                 if ret is False:
                     return False
         return True
@@ -930,10 +978,12 @@ def validate_requires_arg(requires, name):
                 option._validate(expected)
             except ValueError, err:
                 raise ValueError(_('malformed requirements second argument '
-                                   'must be valid for option {0}: {1}').format(name, err))
+                                   'must be valid for option {0}'
+                                   ': {1}').format(name, err))
         if action in config_action:
             if inverse != config_action[action]:
-                raise ValueError(_("inconsistency in action types for option: {0}"
+                raise ValueError(_("inconsistency in action types"
+                                   " for option: {0}"
                                    " action: {1}").format(name, action))
         else:
             config_action[action] = inverse
@@ -949,7 +999,11 @@ def validate_requires_arg(requires, name):
     for opt_requires in ret_requires.values():
         ret_action = []
         for require in opt_requires.values():
-            req = (require[0], tuple(require[1]), require[2], require[3], require[4], require[5])
+            req = (require[0], tuple(require[1]),
+                                     require[2],
+                                     require[3],
+                                     require[4],
+                                     require[5])
             ret_action.append(req)
         ret.append(tuple(ret_action))
     return tuple(ret)