Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Private Member Functions | Private Attributes
asyncipp._IPPAuthOperation Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def error_handler
def auth_handler
def submit_task

Private Member Functions

def _destroy
def _on_auth_dialog_response
def _reconnect_reply
def _reconnect_error
def _on_retry_server_error_response
def _error

Private Attributes

 _auth_called
 _dialog_shown
 _use_password
 _cancel
 _reconnect
 _reconnected
 _user
 _conn
 _try_as_root
 _client_fn
 _client_args
 _client_kwds
 _client_reply_handler
 _client_error_handler
 _dialog

Detailed Description

Definition at line 309 of file asyncipp.py.


Constructor & Destructor Documentation

def asyncipp._IPPAuthOperation.__init__ (   self,
  reply_handler,
  error_handler,
  conn,
  user = None,
  fn = None,
  args = None,
  kwds = None 
)

Definition at line 311 of file asyncipp.py.

00311 
00312                   user=None, fn=None, args=None, kwds=None):
00313         self._auth_called = False
00314         self._dialog_shown = False
00315         self._use_password = ''
00316         self._cancel = False
00317         self._reconnect = False
00318         self._reconnected = False
00319         self._user = user
00320         self._conn = conn
00321         self._try_as_root = self._conn.try_as_root
00322         self._client_fn = fn
00323         self._client_args = args
00324         self._client_kwds = kwds
00325         self._client_reply_handler = reply_handler
00326         self._client_error_handler = error_handler
00327 
00328         debugprint ("+%s" % self)

Definition at line 329 of file asyncipp.py.

00329 
00330     def __del__ (self):
00331         debug.debugprint ("-%s" % self)


Member Function Documentation

def asyncipp._IPPAuthOperation._destroy (   self) [private]

Definition at line 332 of file asyncipp.py.

00332 
00333     def _destroy (self):
00334         del self._conn
00335         del self._client_fn
00336         del self._client_args
00337         del self._client_kwds
00338         del self._client_reply_handler
00339         del self._client_error_handler

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation._error (   self,
  exc 
) [private]

Definition at line 577 of file asyncipp.py.

00577 
00578     def _error (self, exc):
00579         if self._client_error_handler:
00580             self._client_error_handler (self._conn, exc)
00581             self._destroy ()

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation._on_auth_dialog_response (   self,
  dialog,
  response 
) [private]

Definition at line 490 of file asyncipp.py.

00490 
00491     def _on_auth_dialog_response (self, dialog, response):
00492         (user, password) = dialog.get_auth_info ()
00493         if user == '':
00494             user = self._user;
00495         authconn.global_authinfocache.cache_auth_info ((user,
00496                                                         password),
00497                                                        host=self._conn.thread.host,
00498                                                        port=self._conn.thread.port)
00499         self._dialog = dialog
00500         dialog.hide ()
00501 
00502         if (response == gtk.RESPONSE_CANCEL or
00503             response == gtk.RESPONSE_DELETE_EVENT):
00504             self._cancel = True
00505             self._conn.set_auth_info ('')
00506             authconn.global_authinfocache.remove_auth_info (host=self._conn.thread.host,
00507                                                             port=self._conn.thread.port)
00508             debugprint ("Auth canceled")
00509             return
00510 
00511         if user == self._user:
00512             self._use_password = password
00513             self._conn.set_auth_info (password)
00514             debugprint ("Password supplied.")
00515             return
00516 
00517         self._user = user
00518         self._use_password = password
00519         self._reconnect = True
00520         self._conn.set_auth_info ('')
00521         debugprint ("Will try as %s" % self._user)

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation._on_retry_server_error_response (   self,
  dialog,
  response 
) [private]

Definition at line 568 of file asyncipp.py.

00568 
00569     def _on_retry_server_error_response (self, dialog, response):
00570         dialog.destroy ()
00571         if response == gtk.RESPONSE_OK:
00572             self._conn.reconnect (self._conn.thread.user,
00573                                   reply_handler=self._reconnect_reply,
00574                                   error_handler=self._reconnect_error)
00575         else:
00576             self._error (cups.IPPError (0, _("Operation canceled")))

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation._reconnect_error (   self,
  conn,
  exc 
) [private]

Definition at line 530 of file asyncipp.py.

00530 
00531     def _reconnect_error (self, conn, exc):
00532         debugprint ("Failed to connect as %s" % self._user)
00533         if not self._conn.prompt_allowed:
00534             self._error (exc)
00535             return
00536 
00537         op = None
00538         if conn.semantic:
00539             op = conn.semantic.current_operation ()
00540 
00541         if op == None:
00542             msg = _("CUPS server error")
00543         else:
00544             msg = _("CUPS server error (%s)") % op
00545 
00546         d = gtk.MessageDialog (self._conn.parent,
00547                                gtk.DIALOG_MODAL |
00548                                gtk.DIALOG_DESTROY_WITH_PARENT,
00549                                gtk.MESSAGE_ERROR,
00550                                gtk.BUTTONS_NONE,
00551                                msg)
00552 
00553         if self._client_fn == None and type (exc) == RuntimeError:
00554             # This was a connection failure.
00555             message = 'service-error-service-unavailable'
00556         elif type (exc) == cups.IPPError:
00557             message = exc.args[1]
00558         else:
00559             message = repr (exc)
00560 
00561         d.format_secondary_text (_("There was an error during the "
00562                                    "CUPS operation: '%s'." % message))
00563         d.add_buttons (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
00564                        _("Retry"), gtk.RESPONSE_OK)
00565         d.set_default_response (gtk.RESPONSE_OK)
00566         d.connect ("response", self._on_retry_server_error_response)
00567         d.show ()

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation._reconnect_reply (   self,
  conn,
  result 
) [private]

Definition at line 522 of file asyncipp.py.

00522 
00523     def _reconnect_reply (self, conn, result):
00524         # A different username was given in the authentication dialog,
00525         # so we've reconnected as that user.  Alternatively, the
00526         # connection has failed and we're retrying.
00527         debugprint ("Connected as %s" % self._user)
00528         if self._client_fn != None:
00529             self.submit_task ()

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation.auth_handler (   self,
  prompt,
  conn,
  method = None,
  resource = None 
)

Definition at line 414 of file asyncipp.py.

00414 
00415     def auth_handler (self, prompt, conn, method=None, resource=None):
00416         if self._auth_called == False:
00417             if self._user == None:
00418                 self._user = cups.getUser()
00419             if self._user:
00420                 host = conn.thread.host
00421                 port = conn.thread.port
00422                 creds = authconn.global_authinfocache.lookup_auth_info (host=host,
00423                                                                         port=port)
00424                 if creds:
00425                     if creds[0] == self._user:
00426                         self._use_password = creds[1]
00427                         self._reconnected = True
00428                     del creds
00429         else:
00430             host = conn.thread.host
00431             port = conn.thread.port
00432             authconn.global_authinfocache.remove_auth_info (host=host,
00433                                                             port=port)
00434             self._use_password = ''
00435 
00436         self._auth_called = True
00437         if self._reconnected:
00438             debugprint ("Supplying password after reconnection")
00439             self._reconnected = False
00440             conn.set_auth_info (self._use_password)
00441             return
00442 
00443         self._reconnected = False
00444         if not conn.prompt_allowed:
00445             conn.set_auth_info (self._use_password)
00446             return
00447 
00448         # If we've previously prompted, explain why we're prompting again.
00449         if self._dialog_shown:
00450             d = gtk.MessageDialog (self._conn.parent,
00451                                    gtk.DIALOG_MODAL |
00452                                    gtk.DIALOG_DESTROY_WITH_PARENT,
00453                                    gtk.MESSAGE_ERROR,
00454                                    gtk.BUTTONS_CLOSE,
00455                                    _("Not authorized"))
00456             d.format_secondary_text (_("The password may be incorrect."))
00457             d.run ()
00458             d.destroy ()
00459 
00460         op = None
00461         if conn.semantic:
00462             op = conn.semantic.current_operation ()
00463 
00464         if op == None:
00465             d = authconn.AuthDialog (parent=conn.parent)
00466         else:
00467             title = _("Authentication (%s)") % op
00468             d = authconn.AuthDialog (title=title,
00469                                      parent=conn.parent)
00470 
00471         d.set_prompt (prompt)
00472         if self._user == None:
00473             self._user = cups.getUser()
00474         d.set_auth_info ([self._user, ''])
00475         d.field_grab_focus ('password')
00476         d.set_keep_above (True)
00477         d.show_all ()
00478         d.connect ("response", self._on_auth_dialog_response)
00479         self._dialog_shown = True

Here is the call graph for this function:

Here is the caller graph for this function:

def asyncipp._IPPAuthOperation.error_handler (   self,
  conn,
  exc 
)

Definition at line 340 of file asyncipp.py.

00340 
00341     def error_handler (self, conn, exc):
00342         if self._client_fn == None:
00343             # This is the initial "connection" operation, or a
00344             # subsequent reconnection attempt.
00345             debugprint ("Connection/reconnection failed")
00346             return self._reconnect_error (conn, exc)
00347 
00348         if self._cancel:
00349             return self._error (exc)
00350 
00351         if self._reconnect:
00352             self._reconnect = False
00353             self._reconnected = True
00354             conn.reconnect (self._user,
00355                             reply_handler=self._reconnect_reply,
00356                             error_handler=self._reconnect_error)
00357             return
00358 
00359         forbidden = False
00360         if type (exc) == cups.IPPError:
00361             (e, m) = exc.args
00362             if (e == cups.IPP_NOT_AUTHORIZED or
00363                 e == cups.IPP_FORBIDDEN or
00364                 e == cups.IPP_AUTHENTICATION_CANCELED):
00365                 forbidden = (e == cups.IPP_FORBIDDEN)
00366             elif e == cups.IPP_SERVICE_UNAVAILABLE:
00367                 return self._reconnect_error (conn, exc)
00368             else:
00369                 return self._error (exc)
00370         elif type (exc) == cups.HTTPError:
00371             (s,) = exc.args
00372             if (s == cups.HTTP_UNAUTHORIZED or
00373                 s == cups.HTTP_FORBIDDEN):
00374                 forbidden = (s == cups.HTTP_FORBIDDEN)
00375             else:
00376                 return self._error (exc)
00377         else:
00378             return self._error (exc)
00379 
00380         # Not authorized.
00381 
00382         if (self._try_as_root and
00383             self._user != 'root' and
00384             (self._conn.thread.host[0] == '/' or forbidden)):
00385             # This is a UNIX domain socket connection so we should
00386             # not have needed a password (or it is not a UDS but
00387             # we got an HTTP_FORBIDDEN response), and so the
00388             # operation must not be something that the current
00389             # user is authorised to do.  They need to try as root,
00390             # and supply the password.  However, to get the right
00391             # prompt, we need to try as root but with no password
00392             # first.
00393             debugprint ("Authentication: Try as root")
00394             self._user = "root"
00395             conn.reconnect (self._user,
00396                             reply_handler=self._reconnect_reply,
00397                             error_handler=self._reconnect_error)
00398             # Don't submit the task until we've connected.
00399             return
00400 
00401         if not self._auth_called:
00402             # We aren't even getting a chance to supply credentials.
00403             return self._error (exc)
00404 
00405         # Now reconnect and retry.
00406         host = conn.thread.host
00407         port = conn.thread.port
00408         authconn.global_authinfocache.remove_auth_info (host=host,
00409                                                         port=port)
00410         self._use_password = ''
00411         conn.reconnect (self._user,
00412                         reply_handler=self._reconnect_reply,
00413                         error_handler=self._reconnect_error)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 480 of file asyncipp.py.

00480 
00481     def submit_task (self):
00482         self._auth_called = False
00483         self._conn.queue.put ((self._client_fn, self._client_args,
00484                                self._client_kwds,
00485                                self._client_reply_handler,
00486                                
00487                                # Use our own error and auth handlers.
00488                                self.error_handler,
00489                                self.auth_handler))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 312 of file asyncipp.py.

Definition at line 315 of file asyncipp.py.

Definition at line 322 of file asyncipp.py.

Definition at line 325 of file asyncipp.py.

Definition at line 321 of file asyncipp.py.

Definition at line 323 of file asyncipp.py.

Definition at line 324 of file asyncipp.py.

Definition at line 319 of file asyncipp.py.

Definition at line 498 of file asyncipp.py.

Definition at line 313 of file asyncipp.py.

Definition at line 316 of file asyncipp.py.

Definition at line 317 of file asyncipp.py.

Definition at line 320 of file asyncipp.py.

Definition at line 314 of file asyncipp.py.

Definition at line 318 of file asyncipp.py.


The documentation for this class was generated from the following file: