Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 161 lines (126 sloc) 4.939 kB
971ccb2 @asabil - Started client implementation
asabil authored
1 #!/usr/bin/env python
2
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
3 import papyon
4 import papyon.event
971ccb2 @asabil - Started client implementation
asabil authored
5
5168659 @jprieur - Added custom emoticons support.
jprieur authored
6
971ccb2 @asabil - Started client implementation
asabil authored
7 import logging
8 import gobject
9
10 logging.basicConfig(level=logging.DEBUG)
11
12 finished = False
72bfb1d @asabil - Merged jprieur's branch
asabil authored
13
971ccb2 @asabil - Started client implementation
asabil authored
14 def get_proxies():
15 import urllib
16 proxies = urllib.getproxies()
17 result = {}
02416ce @asabil - Updated pymsn to the new gio
asabil authored
18 if 'https' not in proxies and \
19 'http' in proxies:
20 url = proxies['http'].replace("http://", "https://")
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
21 result['https'] = papyon.Proxy(url)
971ccb2 @asabil - Started client implementation
asabil authored
22 for type, url in proxies.items():
23 if type == 'no': continue
92b93ce @asabil - Cleaned up the SwitchboardManager a bit
asabil authored
24 if type == 'https' and url.startswith('http://'):
25 url = url.replace('http://', 'https://', 1)
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
26 result[type] = papyon.Proxy(url)
971ccb2 @asabil - Started client implementation
asabil authored
27 return result
28
9e686e1 @asabil - Conversations are usable now
asabil authored
29
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
30 class ClientEvents(papyon.event.ClientEventInterface):
9e686e1 @asabil - Conversations are usable now
asabil authored
31 def on_client_state_changed(self, state):
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
32 if state == papyon.event.ClientState.CLOSED:
9e686e1 @asabil - Conversations are usable now
asabil authored
33 self._client.quit()
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
34 elif state == papyon.event.ClientState.OPEN:
9e686e1 @asabil - Conversations are usable now
asabil authored
35 self._client.profile.display_name = "Kimbix"
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
36 self._client.profile.presence = papyon.Presence.ONLINE
0924e58 @asabil - Merged jprieur's branch
asabil authored
37 self._client.profile.current_media = ("I listen to", "Nothing")
13bdc5e @asabil - Removed the is_messenger attribute for contacts, is_messenger is ba…
asabil authored
38 for contact in self._client.address_book.contacts:
39 print contact
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
40 #self._client.profile.personal_message = "Testing papyon, and freeing the pandas!"
09f5106 use timeout_add_seconds instead of timeout_add where possible
Louis-Francis Ratté-Boulianne authored
41 gobject.timeout_add_seconds(5, self._client.start_conversation)
9e686e1 @asabil - Conversations are usable now
asabil authored
42
43 def on_client_error(self, error_type, error):
44 print "ERROR :", error_type, " ->", error
45
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
46 class AnnoyingConversation(papyon.event.ConversationEventInterface):
9e686e1 @asabil - Conversations are usable now
asabil authored
47 def on_conversation_user_joined(self, contact):
09f5106 use timeout_add_seconds instead of timeout_add where possible
Louis-Francis Ratté-Boulianne authored
48 gobject.timeout_add_seconds(5, self.annoy_user)
9e686e1 @asabil - Conversations are usable now
asabil authored
49
50 def annoy_user(self):
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
51 msg = "Let's free the pandas ! (testing papyon)"
52 formatting = papyon.TextFormat("Comic Sans MS",
53 papyon.TextFormat.UNDERLINE | papyon.TextFormat.BOLD,
5168659 @jprieur - Added custom emoticons support.
jprieur authored
54 'FF0000')
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
55 self._client.send_text_message(papyon.ConversationMessage(msg, formatting))
2e0d45b @jprieur - Fixed typo.
jprieur authored
56 # self._client.send_nudge()
57 # self._client.send_typing_notification()
9e686e1 @asabil - Conversations are usable now
asabil authored
58 return True
59
2e0d45b @jprieur - Fixed typo.
jprieur authored
60 def on_conversation_user_typing(self, contact):
61 pass
62
5168659 @jprieur - Added custom emoticons support.
jprieur authored
63 def on_conversation_message_received(self, sender, message):
64 pass
3c64797 @asabil - Merged Johann's Typing notifications, and text formatting code
asabil authored
65
9e686e1 @asabil - Conversations are usable now
asabil authored
66 def on_conversation_error(self, error_type, error):
67 print "ERROR :", error_type, " ->", error
68
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
69 class Client(papyon.Client):
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
70 def __init__(self, account, quit, http_mode=False):
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
71 server = ('messenger.hotmail.com', 1863)
971ccb2 @asabil - Started client implementation
asabil authored
72 self.quit = quit
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
73 self.account = account
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
74 if http_mode:
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
75 from papyon.transport import HTTPPollConnection
76 papyon.Client.__init__(self, server, get_proxies(), HTTPPollConnection)
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
77 else:
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
78 papyon.Client.__init__(self, server, proxies = get_proxies())
ce39f8b @asabil - EventHandlers are now weak referenced in EventDispatchers
asabil authored
79 self._event_handler = ClientEvents(self)
4e39701 @asabil - Added some callbacks to Client
asabil authored
80 gobject.idle_add(self._connect)
971ccb2 @asabil - Started client implementation
asabil authored
81
4e39701 @asabil - Added some callbacks to Client
asabil authored
82 def _connect(self):
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
83 self.login(*self.account)
971ccb2 @asabil - Started client implementation
asabil authored
84 return False
85
9e686e1 @asabil - Conversations are usable now
asabil authored
86 def start_conversation(self):
0cef59f test.py sends a webcam request to a contact
Youness Alaoui authored
87 global peer
88
6d918f1 Renaming pymsn to papyon
Youness Alaoui authored
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]:
0cef59f test.py sends a webcam request to a contact
Youness Alaoui authored
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
1a22770 Fix webcam support
Youness Alaoui authored
107 self._webcam_handler.invite(contact)
0cef59f test.py sends a webcam request to a contact
Youness Alaoui authored
108
109 return False
110
111 return True
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
112
971ccb2 @asabil - Started client implementation
asabil authored
113 def main():
114 import sys
115 import getpass
116 import signal
b2f4ebb @asabil - Changed the Event notification API.
asabil authored
117
0cef59f test.py sends a webcam request to a contact
Youness Alaoui authored
118 global peer
119
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
120 if "--http" in sys.argv:
121 http_mode = True
122 sys.argv.remove('--http')
123 else:
124 http_mode = False
971ccb2 @asabil - Started client implementation
asabil authored
125
126 if len(sys.argv) < 2:
127 account = raw_input('Account: ')
128 else:
129 account = sys.argv[1]
b2f4ebb @asabil - Changed the Event notification API.
asabil authored
130
971ccb2 @asabil - Started client implementation
asabil authored
131 if len(sys.argv) < 3:
132 passwd = getpass.getpass('Password: ')
133 else:
134 passwd = sys.argv[2]
135
0cef59f test.py sends a webcam request to a contact
Youness Alaoui authored
136 if len(sys.argv) < 4:
137 peer = raw_input('Send webcam to : ')
138 else:
139 peer = sys.argv[3]
140
971ccb2 @asabil - Started client implementation
asabil authored
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
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
151 n = Client((account, passwd), quit, http_mode)
971ccb2 @asabil - Started client implementation
asabil authored
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.