1 """client class dealing with all Exceptions
8 # Wrap Exception decorator
10 """Decorator to wrap errors in musicpd.MPDError"""
11 errors=(OSError, TimeoutError)
12 into = musicpd.MPDError
13 def w_func(*args, **kwargs):
15 return func(*args, **kwargs)
18 if hasattr(err, 'strerror'):
21 raise into(strerr) from err
25 class MyClient(musicpd.MPDClient):
26 """Plain client inheriting from MPDClient"""
29 # Set logging to debug level
30 logging.basicConfig(level=logging.DEBUG,
31 format='%(levelname)-8s %(module)-10s %(message)s')
32 self.log = logging.getLogger(__name__)
36 def __getattr__(self, cmd):
37 """Wrapper around MPDClient calls for abstract overriding"""
38 self.log.debug('cmd: %s', cmd)
39 return super().__getattr__(cmd)
42 if __name__ == '__main__':
44 # You can overrides host here or in init
45 #cli.host = 'example.org'
51 except musicpd.MPDError as error:
54 cli.log.info('Disconnecting')
56 # Tries to close the socket anyway