2 # -------------------------------------------------------------------------
3 # Copyright (c) 2015-2017 AT&T Intellectual Property
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # -------------------------------------------------------------------------
22 from conductor.i18n import _LE # pylint: disable=W0212
26 """Returns a class given a fully qualified class name"""
27 parts = kls.split('.')
28 module = ".".join(parts[:-1])
29 mod = __import__(module)
30 for comp in parts[1:]:
31 mod = getattr(mod, comp)
35 class abstractclassmethod(classmethod): # pylint: disable=C0103,R0903
36 """Abstract Class Method Decorator from Python 3.3's abc module"""
38 __isabstractmethod__ = True
40 def __init__(self, callable): # pylint: disable=W0622
41 callable.__isabstractmethod__ = True
42 super(abstractclassmethod, self).__init__(callable)
45 class ClassPropertyDescriptor(object): # pylint: disable=R0903
46 """Supports the notion of a class property"""
48 def __init__(self, fget, fset=None):
53 def __get__(self, obj, klass=None):
57 return self.fget.__get__(obj, klass)()
59 def __set__(self, obj, value):
62 raise AttributeError(_LE("Can't set attribute"))
64 return self.fset.__get__(obj, type_)(value)
66 def setter(self, func):
68 if not isinstance(func, (classmethod, staticmethod)):
69 func = classmethod(func)
74 def classproperty(func):
75 """Class Property decorator"""
76 if not isinstance(func, (classmethod, staticmethod)):
77 func = classmethod(func)
79 return ClassPropertyDescriptor(func)