class perfobj(object):
def __init__(self, *args, **kwargs):
- super(perfobj, self).__init__()
+ super().__init__()
def pdm_protocols(self):
return []
read.
"""
def __init__(self, func, info = None, *args, **kwargs):
- super(simpleattr, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.func = func
if info is None:
info = attrinfo()
return self.info
def pdm_protocols(self):
- return super(simpleattr, self).pdm_protocols() + ["attr"]
+ return super().pdm_protocols() + ["attr"]
class valueattr(perfobj):
"""An implementation of the `attr' interface, which is initialized
updates to the value are reflected in subsequent reads.
"""
def __init__(self, init, info = None, *args, **kwargs):
- super(valueattr, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.value = init
if info is None:
info = attrinfo()
return self.info
def pdm_protocols(self):
- return super(valueattr, self).pdm_protocols() + ["attr"]
+ return super().pdm_protocols() + ["attr"]
class eventobj(perfobj):
"""An implementation of the `event' interface. It keeps track of
subscribers when submitted with the `notify' method.
"""
def __init__(self, *args, **kwargs):
- super(eventobj, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.subscribers = set()
def subscribe(self, cb):
except: pass
def pdm_protocols(self):
- return super(eventobj, self).pdm_protocols() + ["event"]
+ return super().pdm_protocols() + ["event"]
class staticdir(perfobj):
"""An implementation of the `dir' interface. Put other PERF
return them to requesting clients.
"""
def __init__(self, *args, **kwargs):
- super(staticdir, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.map = {}
def __setitem__(self, name, ob):
return self.map.get(name, default)
def listdir(self):
- return self.map.keys()
+ return list(self.map.keys())
def lookup(self, name):
return self.map[name]
def pdm_protocols(self):
- return super(staticdir, self).pdm_protocols() + ["dir"]
+ return super().pdm_protocols() + ["dir"]
- super(simplefunc, self).__init__(*args)
+ class simplefunc(perfobj):
+ """An implementation of the `invoke' interface. Put callables in
+ it using the normal dict assignment syntax, and it will call them
+ when invoked with the corresponding method name. Additionally, it
+ updates itself with any keyword-arguments it is initialized with."""
+ def __init__(self, *args, **kwargs):
- return super(simplefunc, self).pdm_protocols() + ["invoke"]
++ super().__init__(*args)
+ self.map = {}
+ self.map.update(kwargs)
+
+ def __setitem__(self, name, func):
+ self.map[name] = func
+
+ def __delitem__(self, name):
+ del self.map[name]
+
+ def invoke(self, method, *args, **kwargs):
+ if method not in self.map:
+ raise AttributeError(method)
+ self.map[method](*args, **kwargs)
+
+ def pdm_protocols(self):
++ return super().pdm_protocols() + ["invoke"]
+
class event(object):
"""This class should be subclassed by all event objects sent via
the `event' interface. Its main utility is that it keeps track of
`finishevent' emitted when the connection is closed.
"""
def __init__(self, id):
- super(procevent, self).__init__()
+ super().__init__()
if isinstance(id, procevent):
self.id = id.id
else:
class startevent(procevent):
"""A subclass of `procevent'. See its documentation for details."""
def __init__(self):
- super(startevent, self).__init__(getprocid())
+ super().__init__(getprocid())
class finishevent(procevent):
"""A subclass of `procevent'. Intended to be emitted when a
distinction is meaningful. The `start' parameter should be the
`startevent' instance used when the process was initiated."""
def __init__(self, start, aborted = False):
- super(finishevent, self).__init__(start)
+ super().__init__(start)
self.aborted = aborted
sysres = staticdir()
sysinfo["uname"] = simpleattr(func = os.uname)
sysinfo["hostname"] = simpleattr(func = socket.gethostname)
sysinfo["platform"] = valueattr(init = sys.platform)
+
+ sysctl = simplefunc(exit=lambda status=0: os._exit(status))