X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Futils%2Futils.py;fp=sima%2Futils%2Futils.py;h=cb672639e2e780d06187f641b9b0ac0c5d84ebe7;hb=1a178217e8efd3b2b523afb93775124baf1be05f;hp=c148892d5276d7a4e684b795a28ac50b1bbbe971;hpb=789124aae8798173ffa1711c4851e83b4b4f976a;p=mpd-sima.git diff --git a/sima/utils/utils.py b/sima/utils/utils.py index c148892..cb67263 100644 --- a/sima/utils/utils.py +++ b/sima/utils/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (c) 2010, 2011, 2013, 2014, 2015, 2020, 2021 kaliko +# Copyright (c) 2010, 2011, 2013, 2014, 2015, 2020, 2021, 2024 kaliko # # This file is part of sima # @@ -214,5 +214,21 @@ class WSHTTPError(WSError): class PluginException(MPDSimaException): pass + +# Wrap Exception decorator +def get_decorator(errors=(OSError, TimeoutError), wrap_into=Exception): + def decorator(func): + def w_func(*args, **kwargs): + try: + return func(*args, **kwargs) + except errors as err: + strerr = str(err) + if hasattr(err, 'strerror'): + if err.strerror: + strerr = err.strerror + raise wrap_into(strerr) from err + return w_func + return decorator + # VIM MODLINE # vim: ai ts=4 sw=4 sts=4 expandtab