@@ -0,0 +1,2 @@
|
||||
class ExecutionContext:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class Sheerka:
|
||||
pass
|
||||
@@ -0,0 +1,31 @@
|
||||
class CustomType:
|
||||
"""
|
||||
Base class for custom types used in Sheerka
|
||||
A custom type is a type that has only one instance across the application and have a semantic meaning
|
||||
For example the type 'None' is a singleton which have a semantic meaning.
|
||||
We need to define others in Sheerka
|
||||
"""
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return self.value
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, CustomType) and self.value == other.value
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.value)
|
||||
|
||||
|
||||
class NotFoundType(CustomType):
|
||||
"""
|
||||
Using when an entry in not found in Cache or in sdp
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(NotFoundType, self).__init__("**NotFound**")
|
||||
|
||||
|
||||
NotFound = NotFoundType()
|
||||
@@ -0,0 +1,32 @@
|
||||
def get_class(qname):
|
||||
"""
|
||||
Loads a class from its full qualified name
|
||||
:param qname:
|
||||
:return:
|
||||
"""
|
||||
parts = qname.split('.')
|
||||
module = ".".join(parts[:-1])
|
||||
m = __import__(module)
|
||||
for comp in parts[1:]:
|
||||
m = getattr(m, comp)
|
||||
return m
|
||||
|
||||
|
||||
def get_full_qualified_name(obj):
|
||||
"""
|
||||
Returns the full qualified name of a class (including its module name )
|
||||
:param obj:
|
||||
:return:
|
||||
"""
|
||||
if obj.__class__ == type:
|
||||
module = obj.__module__
|
||||
if module is None or module == str.__class__.__module__:
|
||||
return obj.__name__ # Avoid reporting __builtin__
|
||||
else:
|
||||
return module + '.' + obj.__name__
|
||||
else:
|
||||
module = obj.__class__.__module__
|
||||
if module is None or module == str.__class__.__module__:
|
||||
return obj.__class__.__name__ # Avoid reporting __builtin__
|
||||
else:
|
||||
return module + '.' + obj.__class__.__name__
|
||||
Reference in New Issue
Block a user