[bug] Python pjsua: Error should derive from Exception

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I would like to report a bug in the Python-interface:
class Error should derive from Exception.

I've attached a patch, which solves this issue and additionally
makes the Error-class more pythonic.


thanks,
Roland

--- pjsip-apps/src/python/pjsua.py	2014-04-07 08:56:06.000000000 +0200
+++ pjsip-apps/src/python/pjsua.py	2016-12-18 01:22:14.075998739 +0100
@@ -62,7 +62,7 @@
 import weakref
 import time
 
-class Error:
+class Error(Exception):
     """Error exception class.
     
     Member documentation:
@@ -70,29 +70,29 @@
     op_name  -- name of the operation that generated this error.
     obj      -- the object that generated this error.
     err_code -- the error code.
+    message  -- the error-message.
 
     """
-    op_name = ""
-    obj = None
-    err_code = -1
-    _err_msg = ""
-
     def __init__(self, op_name, obj, err_code, err_msg=""):
         self.op_name = op_name
         self.obj = obj
         self.err_code = err_code
-        self._err_msg = err_msg
+
+        if err_msg:
+            self.message = error
+        else:
+            self.message = Lib.strerror(self.err_code)
 
     def err_msg(self):
-        "Retrieve the description of the error."
-        if self._err_msg != "":
-            return self._err_msg
-        self._err_msg = Lib.strerror(self.err_code)
-        return self._err_msg
+        """Retrieve the description of the error.
+
+        For backwards-compatibility; you may use the message-member instead.
+        """
+        return self.message
 
     def __str__(self):
         return "Object: " + str(self.obj) + ", operation=" + self.op_name + \
-               ", error=" + self.err_msg()
+               ", error=" + self.message
 
 # 
 # Constants
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux