summary refs log tree commit diff stats
path: root/abdl/exceptions.py
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2020-02-25 22:54:47 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-02-25 22:54:47 -0300
commit34551d96ce021d2264094a4941ef15a64224d195 (patch)
tree0429b51a212c85a0790eac764bac54e403328a17 /abdl/exceptions.py
parentb4971f08758a4428fe90d0a56f58257cdbd728eb (diff)
Refactor
* Cleaned up many pylint messages
* Cleaned up parser
* Other minor changes
Diffstat (limited to 'abdl/exceptions.py')
-rw-r--r--abdl/exceptions.py53
1 files changed, 24 insertions, 29 deletions
diff --git a/abdl/exceptions.py b/abdl/exceptions.py
index 961acff..83ca2ca 100644
--- a/abdl/exceptions.py
+++ b/abdl/exceptions.py
@@ -14,23 +14,40 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+"""ABDL Exceptions.
+
+The exceptions for pattern and validation errors are defined here.
+"""
+
+import warnings
+
 class DeprecationError(Exception):
     """Raised for deprecated features, if they are disabled.
 
-    This class controls warning/error behaviour of deprecated features."""
-    #enable_key_match_compat = False
-    #warn_key_match_compat = False
+    This class controls warning/error behaviour of deprecated features.
+
+    Note: This class is deprecated. Use ``abdl.feature`` instead.
+    """
+    # enable_key_match_compat = False
+    # warn_key_match_compat = False
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        warnings.warn("DeprecationError is deprecated. "
+                      "Use ``abdl.feature`` instead.", DeprecationWarning)
 
     @classmethod
     def warn_all(cls):
         """Enables all deprecation warnings."""
-        pass
+        warnings.warn("DeprecationError is deprecated. "
+                      "Use ``abdl.feature`` instead.", DeprecationWarning)
 
 class PatternError(Exception):
     """Raised for invalid input or output expressions."""
     # TODO implement formatting
 
-    def __init__(self, msg, pattern, defs, pos, toks):
+    def __init__(self, msg, pattern=None, defs=None, pos=None, toks=None):
+        super().__init__(msg, pattern, defs, pos, toks)
         self.msg = msg
         self.pattern = pattern
         self.defs = defs
@@ -41,33 +58,11 @@ class PatternError(Exception):
         if pattern is not None:
             if self.pattern is not None:
                 raise ValueError("Attempt to normalize normalized pattern")
-            else:
-                self.pattern = pattern
+            self.pattern = pattern
         if defs is not None:
             if self.defs is not None:
                 raise ValueError("Attempt to normalize normalized defs")
-            else:
-                self.defs = defs
-
-    @classmethod
-    def _str_escape(cls, s, pos, toks):
-        raise cls("Error in string escape", None, None, pos, toks)
-
-    @classmethod
-    def _str_end(cls, s, pos, toks):
-        raise cls("Unfinished string", None, None, pos, toks)
-
-    @classmethod
-    def _re_escape(cls, s, pos, toks):
-        raise cls("Error in regex escape", None, None, pos, toks)
-
-    @classmethod
-    def _re_end(cls, s, pos, toks):
-        raise cls("Unfinished regex", None, None, pos, toks)
-
-    @classmethod
-    def _unexpected_tok(cls, s, pos, toks):
-        raise cls("Unexpected token", None, None, pos, toks)
+            self.defs = defs
 
 class ValidationError(Exception):
     """Raised when the object tree doesn't validate against the given pattern."""