[python-bugzilla] [PATCH] Add is_logged_in utility method.

abn at redhat.com abn at redhat.com
Mon Nov 24 23:42:47 UTC 2014


From: Arun Babu Neelicattu <abn at redhat.com>

---
 bugzilla/base.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bugzilla/base.py b/bugzilla/base.py
index e06223f..7aba942 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -697,6 +697,26 @@ class BugzillaBase(object):
         self.password = ''
         self.logged_in = False
 
+    def is_logged_in(self):
+        """
+        Utility method to check if this instance has already been logged in.
+
+        If the instance has its logged_in attribute set to True, this method
+        returns true. Otherwise, to test if this session is authenticated, the
+        method calls the User.get() XMLRPC method with ids set. Logged-out users
+        cannot pass the 'ids' parameter and will result in a 505 error.
+        """
+        try:
+            if self.logged_in:
+                return True
+            self._proxy.User.get({'ids': self._listify([])})
+            return True
+        except Fault:
+            e = sys.exc_info()[1]
+            if e.faultCode == 505:
+                return False
+            raise e
+
 
     #############################################
     # Fetching info about the bugzilla instance #
-- 
1.9.3



More information about the python-bugzilla mailing list