Skip to content

Commit 2e7c292

Browse files
committed
Make Status int-compatible
See spatialaudio#8.
1 parent 93ad5f0 commit 2e7c292

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

‎jack.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,28 @@ def clear(self):
18771877
self._portlist[0].unregister()
18781878

18791879

1880-
class Status(object):
1880+
def _make_statusbase():
1881+
"""Create base class for Status."""
1882+
import numbers
1883+
1884+
def redirect(name):
1885+
1886+
def redirected(self, *args):
1887+
return getattr(self._code, name)(*args)
1888+
1889+
return redirected
1890+
1891+
names = set(['__gt__', '__ge__'])
1892+
names.update(numbers.Integral.__abstractmethods__)
1893+
methods = dict((name, redirect(name)) for name in names)
1894+
methods.update({'__eq__': lambda self, other: int(self) == other})
1895+
return type("_StatusBase", (), methods)
1896+
1897+
_StatusBase = _make_statusbase()
1898+
del _make_statusbase
1899+
1900+
1901+
class Status(_StatusBase):
18811902

18821903
"""Representation of the JACK status bits."""
18831904

@@ -1889,7 +1910,7 @@ def __repr__(self):
18891910
if not name.startswith('_') and getattr(self, name))
18901911
if not flags:
18911912
flags = "no flags set"
1892-
return "<jack.Status 0x{0:x}: {1}>".format(self._code, flags)
1913+
return "<jack.Status 0x{0:X}: {1}>".format(int(self), flags)
18931914

18941915
@property
18951916
def failure(self):
@@ -1972,7 +1993,7 @@ def client_zombie(self):
19721993

19731994
def _hasflag(self, flag):
19741995
"""Helper function for Status properties."""
1975-
return bool(self._code & flag)
1996+
return bool(self & flag)
19761997

19771998

19781999
class JackError(Exception):

0 commit comments

Comments
 (0)