Skip to content

Commit e5ed1b6

Browse files
committed
Remove code repetition from Status class
1 parent af92bb3 commit e5ed1b6

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

jack.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,12 +1816,12 @@ def __repr__(self):
18161816
@property
18171817
def failure(self):
18181818
"""Overall operation failed."""
1819-
return bool(self._code & _lib.JackFailure)
1819+
return self._hasflag(_lib.JackFailure)
18201820

18211821
@property
18221822
def invalid_option(self):
18231823
"""The operation contained an invalid or unsupported option."""
1824-
return bool(self._code & _lib.JackInvalidOption)
1824+
return self._hasflag(_lib.JackInvalidOption)
18251825

18261826
@property
18271827
def name_not_unique(self):
@@ -1836,7 +1836,7 @@ def name_not_unique(self):
18361836
long, the open fails instead.
18371837
18381838
"""
1839-
return bool(self._code & _lib.JackNameNotUnique)
1839+
return self._hasflag(_lib.JackNameNotUnique)
18401840

18411841
@property
18421842
def server_started(self):
@@ -1845,52 +1845,56 @@ def server_started(self):
18451845
Otherwise, it was running already.
18461846
18471847
"""
1848-
return bool(self._code & _lib.JackServerStarted)
1848+
return self._hasflag(_lib.JackServerStarted)
18491849

18501850
@property
18511851
def server_failed(self):
18521852
"""Unable to connect to the JACK server."""
1853-
return bool(self._code & _lib.JackServerFailed)
1853+
return self._hasflag(_lib.JackServerFailed)
18541854

18551855
@property
18561856
def server_error(self):
18571857
"""Communication error with the JACK server."""
1858-
return bool(self._code & _lib.JackServerError)
1858+
return self._hasflag(_lib.JackServerError)
18591859

18601860
@property
18611861
def no_such_client(self):
18621862
"""Requested client does not exist."""
1863-
return bool(self._code & _lib.JackNoSuchClient)
1863+
return self._hasflag(_lib.JackNoSuchClient)
18641864

18651865
@property
18661866
def load_failure(self):
18671867
"""Unable to load internal client."""
1868-
return bool(self._code & _lib.JackLoadFailure)
1868+
return self._hasflag(_lib.JackLoadFailure)
18691869

18701870
@property
18711871
def init_failure(self):
18721872
"""Unable to initialize client."""
1873-
return bool(self._code & _lib.JackInitFailure)
1873+
return self._hasflag(_lib.JackInitFailure)
18741874

18751875
@property
18761876
def shm_failure(self):
18771877
"""Unable to access shared memory."""
1878-
return bool(self._code & _lib.JackShmFailure)
1878+
return self._hasflag(_lib.JackShmFailure)
18791879

18801880
@property
18811881
def version_error(self):
18821882
"""Client's protocol version does not match."""
1883-
return bool(self._code & _lib.JackVersionError)
1883+
return self._hasflag(_lib.JackVersionError)
18841884

18851885
@property
18861886
def backend_error(self):
18871887
"""Backend error."""
1888-
return bool(self._code & _lib.JackBackendError)
1888+
return self._hasflag(_lib.JackBackendError)
18891889

18901890
@property
18911891
def client_zombie(self):
18921892
"""Client zombified failure."""
1893-
return bool(self._code & _lib.JackClientZombie)
1893+
return self._hasflag(_lib.JackClientZombie)
1894+
1895+
def _hasflag(self, flag):
1896+
"""Helper function for Status properties."""
1897+
return bool(self._code & flag)
18941898

18951899

18961900
class JackError(Exception):

0 commit comments

Comments
 (0)