Changeset 94bd28f
- Timestamp:
- 2007-08-20T14:26:05Z (17 years ago)
- Branches:
- master
- Children:
- a316c4e
- Parents:
- cb35add
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
skype/skyped.py
rcb35add r94bd28f 23 23 24 24 def utf8_decode(utf8_str): 25 26 27 28 25 if need_conv: 26 return utf8_str.decode('utf-8').encode(local_encoding, 'replace') 27 else: 28 return utf8_str 29 29 30 30 def utf8_encode(local_str): 31 32 33 34 31 if need_conv: 32 return local_str.decode(local_encoding).encode('utf-8') 33 else: 34 return local_str 35 35 36 36 def sig_handler(signum, frame): 37 38 37 print 'Caught signal %d, exiting.' % signum 38 mainloop.quit() 39 39 40 40 def input_handler(fd, io_condition): 41 input = fd.recv(1024) 42 for i in input.split("\n"): 43 if i: 44 fd.send(skype.send(i.strip()) + "\n") 45 return True 41 input = fd.recv(1024) 42 for i in input.split("\n"): 43 if i: 44 fd.send(skype.send(i.strip()) + "\n") 45 return True 46 47 class SkypeApi(dbus.service.Object): 48 def __init__(self): 49 bus = dbus.SessionBus() 50 51 try: 52 self.skype_api = bus.get_object(SKYPE_SERVICE, '/com/Skype') 53 except dbus.exceptions.DBusException: 54 sys.exit("Can't find any Skype instance. Are you sure you have started Skype?") 55 56 reply = self.send('NAME ' + CLIENT_NAME) 57 if reply != 'OK': 58 sys.exit('Could not bind to Skype client') 59 60 reply = self.send('PROTOCOL 5') 61 dbus.service.Object.__init__(self, bus, "/com/Skype/Client", bus_name='com.Skype.API') 46 62 47 63 48 class SkypeApi(dbus.service.Object): 49 def __init__(self): 50 bus = dbus.SessionBus() 64 # skype -> client (async) 65 @dbus.service.method(dbus_interface='com.Skype.API') 66 def Notify(self, msg_text): 67 global conn 68 text = utf8_decode(msg_text) 69 print '<<', text 70 if conn: 71 conn.send(msg_text + "\n") 51 72 52 try: 53 self.skype_api = bus.get_object(SKYPE_SERVICE, '/com/Skype') 54 except dbus.exceptions.DBusException: 55 sys.exit("Can't find any Skype instance. Are you sure you have started Skype?") 56 57 reply = self.send('NAME ' + CLIENT_NAME) 58 if reply != 'OK': 59 sys.exit('Could not bind to Skype client') 60 61 reply = self.send('PROTOCOL 5') 62 dbus.service.Object.__init__(self, bus, "/com/Skype/Client", bus_name='com.Skype.API') 63 64 65 # skype -> client (async) 66 @dbus.service.method(dbus_interface='com.Skype.API') 67 def Notify(self, msg_text): 68 global conn 69 text = utf8_decode(msg_text) 70 print '<<', text 71 if conn: 72 conn.send(msg_text + "\n") 73 74 # client -> skype (sync, 5 sec timeout) 75 def send(self, msg_text): 76 if not len(msg_text): 77 return 78 print '>> ', msg_text 79 try: 80 reply = utf8_decode(self.skype_api.Invoke(utf8_encode(msg_text))) 81 except dbus.exceptions.DBusException, s: 82 reply = str(s) 83 print '<< ', reply 84 return reply 85 73 # client -> skype (sync, 5 sec timeout) 74 def send(self, msg_text): 75 if not len(msg_text): 76 return 77 print '>> ', msg_text 78 try: 79 reply = utf8_decode(self.skype_api.Invoke(utf8_encode(msg_text))) 80 except dbus.exceptions.DBusException, s: 81 reply = str(s) 82 print '<< ', reply 83 return reply 86 84 87 85 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Note: See TracChangeset
for help on using the changeset viewer.