From anonymous, 1 Month ago, written in Python.
This paste is a reply to Untitled from anonymous
- view diff
Embed
  1. class DeserializationError(Exception):
  2.     pass
  3.  
  4.  
  5. @contextlib.contextmanager
  6. def _map_exceptions():
  7.     """Handle exception API differences in adblock 0.5.0."""
  8.     adblock_deserialization_error = getattr(
  9.         adblock, "DeserializationError", ValueError)
  10.  
  11.     try:
  12.         yield
  13.     except adblock_deserialization_error as e:
  14.         if isinstance(e, ValueError) and str(e) != "DeserializationError":
  15.             # All Rust exceptions get turned into a ValueError by
  16.             # python-adblock
  17.             raise
  18.         raise DeserializationError(str(e))