tiramisu/tiramisu/option/syndynoptiondescription.py

75 lines
2.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Copyright (C) 2017 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# The original `Config` design model is unproudly borrowed from
# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from ..i18n import _
from ..setting import undefined
class SynDynOptionDescription(object):
__slots__ = ('_opt',
'_name',
'_suffix')
def __init__(self,
opt,
name,
suffix):
self._opt = opt
self._name = name
self._suffix = suffix
def __getattr__(self, name):
return getattr(self._opt, name)
def impl_getchild(self,
name,
setting_properties,
context):
if name.endswith(self._suffix):
oname = name[:-len(self._suffix)]
child = self._children[1][self._children[0].index(oname)]
return self._impl_get_dynchild(child,
self._suffix)
raise AttributeError(_('unknown Option {0} '
'in SynDynOptionDescription {1}'
'').format(name, self.impl_getname()))
def impl_getname(self):
return self._name
def impl_getchildren(self,
setting_properties,
dyn=True,
context=undefined):
children = []
for child in self._opt.impl_getchildren(setting_properties):
yield(self._opt._impl_get_dynchild(child,
self._suffix))
def impl_getpath(self, context):
path = self.impl_getopt().impl_getpath(context).split('.')
path[-1] += self._suffix
path.append(self._name)
return '.'.join(path)
def impl_getopt(self):
return self._opt