Package Skype4Py :: Package API
[frames] | no frames]

Source Code for Package Skype4Py.API

  1  ''' 
  2  Low-level Skype API definitions. 
  3   
  4  This module imports one of the: 
  5    - L{Skype4Py.API.darwin} 
  6    - L{Skype4Py.API.posix} 
  7    - L{Skype4Py.API.windows} 
  8  submodules based on the platform. 
  9  ''' 
 10   
 11  import sys 
 12  import threading 
 13  from Skype4Py.utils import * 
 14  from Skype4Py.enums import * 
 15  from Skype4Py.errors import ISkypeAPIError 
 16   
 17   
18 -class ICommand(object):
19 '''Represents an API command. Use L{ISkype.Command<skype.ISkype.Command>} to instatinate. 20 21 To send a command to Skype, use L{ISkype.SendCommand<skype.ISkype.SendCommand>}. 22 ''' 23
24 - def __init__(self, Id, Command, Expected=u'', Blocking=False, Timeout=30000):
25 '''Use L{ISkype.Command<skype.ISkype.Command>} to instatinate the object instead. 26 ''' 27 28 self.Blocking = Blocking 29 '''If set to True, L{ISkype.SendCommand<skype.ISkype.SendCommand>} will block until the reply is received. 30 @type: bool''' 31 32 self.Command = unicode(Command) 33 '''Command string. 34 @type: unicode''' 35 36 self.Expected = unicode(Expected) 37 '''Expected reply. 38 @type: unicode''' 39 40 self.Id = Id 41 '''Command Id. 42 @type: int''' 43 44 self.Reply = u'' 45 '''Reply after the command has been sent and Skype has replied. 46 @type: unicode''' 47 48 self.Timeout = Timeout 49 '''Timeout in milliseconds if Blocking=True. 50 @type: int'''
51
52 - def __repr__(self):
53 return '<%s with Id=%s, Command=%s, Blocking=%s, Reply=%s>' % \ 54 (object.__repr__(self)[1:-1], self.Id, repr(self.Command), self.Blocking, repr(self.Reply))
55 56
57 -class _ISkypeAPIBase(threading.Thread):
58 - def __init__(self, opts):
59 threading.Thread.__init__(self) 60 self.setDaemon(True) 61 self.DebugLevel = opts.pop('ApiDebugLevel', 0) 62 self.FriendlyName = u'Skype4Py' 63 self.Protocol = 5 64 self.Commands = {} 65 self.CommandsLock = threading.Lock() 66 self.Handlers = [] 67 self.AttachmentStatus = apiAttachUnknown
68
69 - def _NotImplemented(self):
70 raise ISkypeAPIError('Functionality not implemented')
71
72 - def RegisterHandler(self, Handler):
73 for h in self.Handlers: 74 if h() == Handler: 75 return 76 self.Handlers.append(WeakCallableRef(Handler))
77
78 - def UpdateHandlers(self):
79 self.Handlers = filter(lambda x: x(), self.Handlers)
80
81 - def NumOfHandlers(self):
82 self.UpdateHandlers() 83 return len(self.Handlers)
84
85 - def CallHandler(self, mode, arg):
86 for h in self.Handlers: 87 f = h() 88 if f: 89 f(mode, arg)
90
91 - def CommandsStackPush(self, Command):
92 self.CommandsLock.acquire() 93 if Command.Id < 0: 94 Command.Id = 0 95 while Command.Id in self.Commands: 96 Command.Id += 1 97 if Command.Id in self.Commands: 98 self.CommandsLock.release() 99 raise ISkypeAPIError('Command Id conflict') 100 self.Commands[Command.Id] = Command 101 self.CommandsLock.release()
102
103 - def CommandsStackPop(self, Id):
104 self.CommandsLock.acquire() 105 try: 106 Command = self.Commands[Id] 107 del self.Commands[Id] 108 except KeyError: 109 Command = None 110 self.CommandsLock.release() 111 return Command
112
113 - def Close(self):
114 pass
115
116 - def SetDebugLevel(self, Level):
117 self.DebugLevel = Level
118
119 - def DebugPrint(self, *args, **kwargs):
120 if self.DebugLevel >= kwargs.get('Level', 1): 121 print >>sys.stderr, 'Skype4Py/API', ' '.join(('%s',) * len(args)) % args
122
123 - def SetFriendlyName(self, FriendlyName):
125
126 - def SetAttachmentStatus(self, AttachmentStatus):
127 if AttachmentStatus != self.AttachmentStatus: 128 self.DebugPrint('AttachmentStatus', AttachmentStatus) 129 self.AttachmentStatus = AttachmentStatus 130 self.CallHandler('attach', AttachmentStatus)
131
132 - def Attach(self, Timeout=30000, Wait=True):
133 self._NotImplemented()
134
135 - def IsRunning(self):
136 self._NotImplemented()
137
138 - def Start(self, Minimized=False, Nosplash=False):
139 self._NotImplemented()
140
141 - def Shutdown(self):
142 self._NotImplemented()
143
144 - def SendCommand(self, Command):
145 self._NotImplemented()
146
147 - def ApiSecurityContextEnabled(self, Context):
148 self._NotImplemented()
149
150 - def EnableApiSecurityContext(self, Context):
151 self._NotImplemented()
152 153 154 # Select apropriate low-level Skype API module 155 if sys.platform[:3] == 'win': 156 from windows import _ISkypeAPI 157 elif sys.platform == 'darwin': 158 from darwin import _ISkypeAPI 159 else: 160 from posix import _ISkypeAPI 161