Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/skype/skyped.py

    r9ec6b36 r1a0b734  
    33#   skyped.py
    44
    5 #   Copyright (c) 2007-2013 by Miklos Vajna <vmiklos@vmiklos.hu>
     5#   Copyright (c) 2007, 2008, 2009, 2010, 2011 by Miklos Vajna <vmiklos@frugalware.org>
    66#
    77#   This program is free software; you can redistribute it and/or modify
     
    276276                sock.close()
    277277
    278 class MockedSkype:
    279         """Mock class for Skype4Py.Skype(), in case the -m option is used."""
    280         def __init__(self, mock):
    281                 sock = open(mock)
    282                 self.lines = sock.readlines()
    283        
    284         def SendCommand(self, c):
    285                 pass
    286 
    287         def Command(self, msg, Block):
    288                 if msg == "PING":
    289                         return ["PONG"]
    290                 line = self.lines[0].strip()
    291                 if not line.startswith(">> "):
    292                         raise Exception("Corrupted mock input")
    293                 line = line[3:]
    294                 if line != msg:
    295                         raise Exception("'%s' != '%s'" % (line, msg))
    296                 self.lines = self.lines[1:] # drop the expected incoming line
    297                 ret = []
    298                 while True:
    299                         # and now send back all the following lines, up to the next expected incoming line
    300                         if len(self.lines) == 0:
    301                                 break
    302                         if self.lines[0].startswith(">> "):
    303                                 break
    304                         if not self.lines[0].startswith("<< "):
    305                                 raise Exception("Corrupted mock input")
    306                         ret.append(self.lines[0][3:].strip())
    307                         self.lines = self.lines[1:]
    308                 return ret
    309 
    310278class SkypeApi:
    311         def __init__(self, mock):
    312                 if not mock:
    313                         self.skype = Skype4Py.Skype()
    314                         self.skype.OnNotify = self.recv
    315                         self.skype.Client.Start()
    316                 else:
    317                         self.skype = MockedSkype(mock)
     279        def __init__(self):
     280                self.skype = Skype4Py.Skype()
     281                self.skype.OnNotify = self.recv
     282                self.skype.Client.Start()
    318283
    319284        def recv(self, msg_text):
     
    370335                        c = self.skype.Command(e, Block=True)
    371336                        self.skype.SendCommand(c)
    372                         if hasattr(c, "Reply"):
    373                                 self.recv(c.Reply) # Skype4Py answer
    374                         else:
    375                                 for i in c: # mock may return multiple iterable answers
    376                                         self.recv(i)
     337                        self.recv(c.Reply)
    377338                except Skype4Py.SkypeError:
    378339                        pass
     
    399360                # this will be read first by the input handler
    400361                self.buf = None
    401                 self.mock = None
    402362
    403363
     
    462422        options = Options()
    463423        try:
    464                 opts, args = getopt.getopt(sys.argv[1:], "c:dhH:l:m:np:v", ["config=", "debug", "help", "host=", "log=", "mock=", "nofork", "port=", "version"])
     424                opts, args = getopt.getopt(sys.argv[1:], "c:dhH:l:np:v", ["config=", "debug", "help", "host=", "log=", "nofork", "port=", "version"])
    465425        except getopt.GetoptError:
    466426                options.usage(1)
     
    476436                elif opt in ("-l", "--log"):
    477437                        options.log = arg
    478                 elif opt in ("-m", "--mock"):
    479                         options.mock = arg
    480438                elif opt in ("-n", "--nofork"):
    481439                        options.daemon = False
     
    528486                server(options.host, options.port)
    529487        try:
    530                 skype = SkypeApi(options.mock)
     488                skype = SkypeApi()
    531489        except Skype4Py.SkypeAPIError, s:
    532490                sys.exit("%s. Are you sure you have started Skype?" % s)
Note: See TracChangeset for help on using the changeset viewer.