Package papyon :: Package event :: Module client

Source Code for Module papyon.event.client

  1  # -*- coding: utf-8 -*- 
  2  # 
  3  # Copyright (C) 2007  Ali Sabil <ali.sabil@gmail.com> 
  4  # Copyright (C) 2007  Ole André Vadla Ravnås <oleavr@gmail.com> 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 19  # 
 20   
 21  """Client event interfaces 
 22   
 23  The interfaces defined in this module allow receiving core notification events 
 24  from the client. 
 25   
 26      @sort: ClientEventInterface 
 27      @group Enums: ClientState, ClientErrorType 
 28      @group Error Enums: NetworkError, AuthenticationError, ProtocolError, 
 29          AddressBookError, OfflineMessagesBoxError""" 
 30   
 31  from papyon.event import BaseEventInterface 
 32   
 33  import papyon.gnet 
 34  import papyon.service.AddressBook.constants 
 35  import papyon.service.OfflineIM.constants 
 36  import papyon.msnp 
 37   
 38  __all__ = [ "ClientState", "ClientErrorType", 
 39          "NetworkError", "AuthenticationError", "ProtocolError", 
 40          "AddressBookError", "OfflineMessagesBoxError", 
 41          "ClientEventInterface" ] 
 42   
43 -class ClientState(object):
44 "L{Client<papyon.Client>} states" 45 CLOSED = 0 46 CONNECTING = 1 47 CONNECTED = 2 48 AUTHENTICATING = 3 49 AUTHENTICATED = 4 50 SYNCHRONIZING = 5 51 SYNCHRONIZED = 6 52 OPEN = 7
53
54 -class ClientErrorType(object):
55 """L{Client<papyon.Client>} error types 56 @see: L{ClientEventInterface.on_client_error}""" 57 58 NETWORK = 0 59 "Network related errors" 60 AUTHENTICATION = 1 61 "Authentication related errors" 62 PROTOCOL = 2 63 "Protocol related errors" 64 ADDRESSBOOK = 3 65 "Address book related errors" 66 OFFLINE_MESSAGES = 4 67 "Offline IM related errors"
68 69 NetworkError = papyon.gnet.IoError 70 "Network related errors" 71
72 -class AuthenticationError(object):
73 "Authentication related errors" 74 UNKNOWN = 0 75 INVALID_USERNAME = 1 76 INVALID_PASSWORD = 2 77 INVALID_USERNAME_OR_PASSWORD = 3
78
79 -class ProtocolError(object):
80 "Protocol related errors" 81 UNKNOWN = 0 82 OTHER_CLIENT = 1 83 SERVER_DOWN = 2
84 85 AddressBookError = papyon.service.AddressBook.constants.AddressBookError 86 OfflineMessagesBoxError = papyon.service.OfflineIM.constants.OfflineMessagesBoxError 87 88
89 -class ClientEventInterface(BaseEventInterface):
90 """Interface allowing the user to get notified about the 91 L{Client<papyon.Client>} events""" 92
93 - def __init__(self, client):
94 """Initializer 95 @param client: the client we want to be notified for its events 96 @type client: L{Client<papyon.Client>}""" 97 BaseEventInterface.__init__(self, client)
98
99 - def on_client_state_changed(self, state):
100 """Called when the state of the L{Client<papyon.Client>} changes. 101 @param state: the new state of the client 102 @type state: L{ClientState}""" 103 pass
104
105 - def on_client_error(self, type, error):
106 """Called when an error occurs in the L{Client<papyon.Client>}. 107 108 @param type: the error type 109 @type type: L{ClientErrorType} 110 111 @param error: the error code 112 @type error: L{NetworkError} or L{AuthenticationError} or 113 L{ProtocolError} or L{AddressBookError} or 114 L{OfflineMessagesBoxError}""" 115 pass
116