Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 160 lines (126 sloc) 4.939 kb
971ccb20 » asabil
2007-01-15 - Started client implementation
1 #!/usr/bin/env python
2
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
3 import papyon
4 import papyon.event
971ccb20 » asabil
2007-01-15 - Started client implementation
5
51686598 » Johann Prieur
2007-09-18 - Added custom emoticons support.
6
971ccb20 » asabil
2007-01-15 - Started client implementation
7 import logging
8 import gobject
9
10 logging.basicConfig(level=logging.DEBUG)
11
12 finished = False
72bfb1dd » asabil
2007-08-06 - Merged jprieur's branch
13
971ccb20 » asabil
2007-01-15 - Started client implementation
14 def get_proxies():
15 import urllib
16 proxies = urllib.getproxies()
17 result = {}
02416ce2 » asabil
2007-03-20 - Updated pymsn to the new gio
18 if 'https' not in proxies and \
19 'http' in proxies:
20 url = proxies['http'].replace("http://", "https://")
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
21 result['https'] = papyon.Proxy(url)
971ccb20 » asabil
2007-01-15 - Started client implementation
22 for type, url in proxies.items():
23 if type == 'no': continue
92b93ce5 » asabil
2007-06-11 - Cleaned up the SwitchboardManager a bit
24 if type == 'https' and url.startswith('http://'):
25 url = url.replace('http://', 'https://', 1)
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
26 result[type] = papyon.Proxy(url)
971ccb20 » asabil
2007-01-15 - Started client implementation
27 return result
28
9e686e19 » asabil
2007-05-31 - Conversations are usable now
29
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
30 class ClientEvents(papyon.event.ClientEventInterface):
9e686e19 » asabil
2007-05-31 - Conversations are usable now
31 def on_client_state_changed(self, state):
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
32 if state == papyon.event.ClientState.CLOSED:
9e686e19 » asabil
2007-05-31 - Conversations are usable now
33 self._client.quit()
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
34 elif state == papyon.event.ClientState.OPEN:
9e686e19 » asabil
2007-05-31 - Conversations are usable now
35 self._client.profile.display_name = "Kimbix"
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
36 self._client.profile.presence = papyon.Presence.ONLINE
0924e580 » asabil
2007-08-09 - Merged jprieur's branch
37 self._client.profile.current_media = ("I listen to", "Nothing")
13bdc5e2 » asabil
2008-01-01 - Removed the is_messenger attribute for contacts, is_messenger is ba…
38 for contact in self._client.address_book.contacts:
39 print contact
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
40 #self._client.profile.personal_message = "Testing papyon, and freeing the pandas!"
09f5106d » Louis-Francis Ratté-Boulianne
2010-08-12 use timeout_add_seconds instead of timeout_add where possible
41 gobject.timeout_add_seconds(5, self._client.start_conversation)
9e686e19 » asabil
2007-05-31 - Conversations are usable now
42
43 def on_client_error(self, error_type, error):
44 print "ERROR :", error_type, " ->", error
45
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
46 class AnnoyingConversation(papyon.event.ConversationEventInterface):
9e686e19 » asabil
2007-05-31 - Conversations are usable now
47 def on_conversation_user_joined(self, contact):
09f5106d » Louis-Francis Ratté-Boulianne
2010-08-12 use timeout_add_seconds instead of timeout_add where possible
48 gobject.timeout_add_seconds(5, self.annoy_user)
9e686e19 » asabil
2007-05-31 - Conversations are usable now
49
50 def annoy_user(self):
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
51 msg = "Let's free the pandas ! (testing papyon)"
52 formatting = papyon.TextFormat("Comic Sans MS",
53 papyon.TextFormat.UNDERLINE | papyon.TextFormat.BOLD,
51686598 » Johann Prieur
2007-09-18 - Added custom emoticons support.
54 'FF0000')
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
55 self._client.send_text_message(papyon.ConversationMessage(msg, formatting))
2e0d45ba » Johann Prieur
2007-09-08 - Fixed typo.
56 # self._client.send_nudge()
57 # self._client.send_typing_notification()
9e686e19 » asabil
2007-05-31 - Conversations are usable now
58 return True
59
2e0d45ba » Johann Prieur
2007-09-08 - Fixed typo.
60 def on_conversation_user_typing(self, contact):
61 pass
62
51686598 » Johann Prieur
2007-09-18 - Added custom emoticons support.
63 def on_conversation_message_received(self, sender, message):
64 pass
3c64797a » asabil
2007-07-04 - Merged Johann's Typing notifications, and text formatting code
65
9e686e19 » asabil
2007-05-31 - Conversations are usable now
66 def on_conversation_error(self, error_type, error):
67 print "ERROR :", error_type, " ->", error
68
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
69 class Client(papyon.Client):
41a2c90f » asabil
2007-03-06 - Fixed GNet protocol/HTTP.py http proxy authentication support
70 def __init__(self, account, quit, http_mode=False):
ebc2c89b » asabil
2007-05-08 - Added initial switchboard protocol implementation
71 server = ('messenger.hotmail.com', 1863)
971ccb20 » asabil
2007-01-15 - Started client implementation
72 self.quit = quit
ebc2c89b » asabil
2007-05-08 - Added initial switchboard protocol implementation
73 self.account = account
41a2c90f » asabil
2007-03-06 - Fixed GNet protocol/HTTP.py http proxy authentication support
74 if http_mode:
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
75 from papyon.transport import HTTPPollConnection
76 papyon.Client.__init__(self, server, get_proxies(), HTTPPollConnection)
41a2c90f » asabil
2007-03-06 - Fixed GNet protocol/HTTP.py http proxy authentication support
77 else:
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
78 papyon.Client.__init__(self, server, proxies = get_proxies())
ce39f8b5 » asabil
2007-12-09 - EventHandlers are now weak referenced in EventDispatchers
79 self._event_handler = ClientEvents(self)
4e39701b » asabil
2007-03-27 - Added some callbacks to Client
80 gobject.idle_add(self._connect)
971ccb20 » asabil
2007-01-15 - Started client implementation
81
4e39701b » asabil
2007-03-27 - Added some callbacks to Client
82 def _connect(self):
ebc2c89b » asabil
2007-05-08 - Added initial switchboard protocol implementation
83 self.login(*self.account)
971ccb20 » asabil
2007-01-15 - Started client implementation
84 return False
85
9e686e19 » asabil
2007-05-31 - Conversations are usable now
86 def start_conversation(self):
0cef59fd » Youness Alaoui
2009-03-12 test.py sends a webcam request to a contact
87 global peer
88
6d918f1c » Youness Alaoui
2009-05-05 Renaming pymsn to papyon
89 for state in [papyon.Presence.ONLINE, \
90 papyon.Presence.BUSY, \
91 papyon.Presence.IDLE, \
92 papyon.Presence.AWAY, \
93 papyon.Presence.BE_RIGHT_BACK, \
94 papyon.Presence.ON_THE_PHONE, \
95 papyon.Presence.OUT_TO_LUNCH]:
0cef59fd » Youness Alaoui
2009-03-12 test.py sends a webcam request to a contact
96 print "Trying %s" % state
97 contacts = self.address_book.contacts.\
98 search_by_presence(state)
99
100 if len(contacts) == 0:
101 print "No %s contacts" % state
102 else:
103 for contact in contacts:
104 print "%s is %s" % (contact.display_name, state)
105 if contact.account == peer:
106 print "Inviting %s for a webcam" % contact.display_name
1a22770f » Youness Alaoui
2009-05-25 Fix webcam support
107 self._webcam_handler.invite(contact)
0cef59fd » Youness Alaoui
2009-03-12 test.py sends a webcam request to a contact
108
109 return False
110
111 return True
ebc2c89b » asabil
2007-05-08 - Added initial switchboard protocol implementation
112
971ccb20 » asabil
2007-01-15 - Started client implementation
113 def main():
114 import sys
115 import getpass
116 import signal
b2f4ebb9 » asabil
2007-05-17 - Changed the Event notification API.
117
0cef59fd » Youness Alaoui
2009-03-12 test.py sends a webcam request to a contact
118 global peer
119
41a2c90f » asabil
2007-03-06 - Fixed GNet protocol/HTTP.py http proxy authentication support
120 if "--http" in sys.argv:
121 http_mode = True
122 sys.argv.remove('--http')
123 else:
124 http_mode = False
971ccb20 » asabil
2007-01-15 - Started client implementation
125
126 if len(sys.argv) < 2:
127 account = raw_input('Account: ')
128 else:
129 account = sys.argv[1]
b2f4ebb9 » asabil
2007-05-17 - Changed the Event notification API.
130
971ccb20 » asabil
2007-01-15 - Started client implementation
131 if len(sys.argv) < 3:
132 passwd = getpass.getpass('Password: ')
133 else:
134 passwd = sys.argv[2]
135
0cef59fd » Youness Alaoui
2009-03-12 test.py sends a webcam request to a contact
136 if len(sys.argv) < 4:
137 peer = raw_input('Send webcam to : ')
138 else:
139 peer = sys.argv[3]
140
971ccb20 » asabil
2007-01-15 - Started client implementation
141 mainloop = gobject.MainLoop(is_running=True)
142
143 def quit():
144 mainloop.quit()
145
146 def sigterm_cb():
147 gobject.idle_add(quit)
148
149 signal.signal(signal.SIGTERM, sigterm_cb)
150
41a2c90f » asabil
2007-03-06 - Fixed GNet protocol/HTTP.py http proxy authentication support
151 n = Client((account, passwd), quit, http_mode)
971ccb20 » asabil
2007-01-15 - Started client implementation
152
153 while mainloop.is_running():
154 try:
155 mainloop.run()
156 except KeyboardInterrupt:
157 quit()
158
159 if __name__ == '__main__':
160 main()
Something went wrong with that request. Please try again.