[Freeswitch-svn] [commit] r7731 - freeswitch/trunk/scripts/socket/freepy

Freeswitch SVN greenlizard at freeswitch.org
Sat Feb 23 17:48:56 EST 2008


Author: greenlizard
Date: Sat Feb 23 17:48:55 2008
New Revision: 7731

Modified:
   freeswitch/trunk/scripts/socket/freepy/__init__.py
   freeswitch/trunk/scripts/socket/freepy/request.py

Log:
chocking on my own dogfood

Modified: freeswitch/trunk/scripts/socket/freepy/__init__.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/__init__.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/__init__.py	Sat Feb 23 17:48:55 2008
@@ -34,6 +34,7 @@
 from time import strftime
 from Queue import Queue
 from freepy import request
+import freepy.globals
 
 """
 freepy library -- connect to freeswitch mod_socket_event via python/twisted
@@ -53,6 +54,7 @@
         self.active_request = None # the current active (de-queued) request
 
     def connectionMade(self):
+        print "Connection made"
         self.conncb(self)
         
     def connectionLost(self, reason):
@@ -69,6 +71,8 @@
         req = request.LoginRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
+        if freepy.globals.DEBUG_ON:
+            print msg
         return req.getDeferred()
 
     def confdialout(self, conf_name, sofia_url, bgapi=True):

Modified: freeswitch/trunk/scripts/socket/freepy/request.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/request.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/request.py	Sat Feb 23 17:48:55 2008
@@ -30,11 +30,13 @@
 from twisted.protocols.basic import LineReceiver
 from twisted.internet.protocol import Protocol, ClientFactory
 from twisted.python import failure
+from twisted.python.failure import Failure
 import time, re
 from time import strftime
 from Queue import Queue
 
 from freepy import models
+import freepy.globals
 
 """
 These are response handlers for different types of requests.
@@ -47,6 +49,7 @@
 
 """
 
+
 class FreepyRequest(object):
 
     def __init__(self):
@@ -80,6 +83,9 @@
 
         otherwise, if the fs response is incomplete, just buffer the data
         """
+        if freepy.globals.DEBUG_ON:
+            print line
+            
         if not line or len(line) == 0:
             self._fsm.BlankLine()
             return self.isRequestFinished()
@@ -126,18 +132,13 @@
         self._fsm.ProcessLine(line)
         return self.isRequestFinished()
 
-
-
-
     def callOrErrback(self):
         matchstr = re.compile("OK", re.I)
         result = matchstr.search(self.response_content)
         if (result != None):
             self.callbackDeferred(self.response_content)
             return
-        
-        self.errbackDeferred(self.response_content)
-
+        self.errbackDeferred(Failure(Exception(self.response_content)))
 
     def doNothing(self):
         # weird smc issue workaround attempt
@@ -170,41 +171,16 @@
         super(LoginRequest, self).__init__()
         import loginrequest_sm
         self._fsm = loginrequest_sm.LoginRequest_sm(self)
-        
-    def processOLD(self, line):
 
-        if not line or len(line) == 0:
-            self._fsm.BlankLine()
-            return self.isRequestFinished()
-        
-        matchstr = re.compile("auth/request", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            self._fsm.AuthRequest()
-            return self.isRequestFinished()
-
-
-        matchstr = re.compile("command/reply", re.I)
-        result = matchstr.search(line)
-        if (result != None):
-            self._fsm.CommandReply()
-            return self.isRequestFinished()
-
-
-        matchstr = re.compile("Reply-Text", re.I)
-        result = matchstr.search(line)
+    def callOrErrback(self):
+        matchstr = re.compile("OK", re.I)
+        result = matchstr.search(self.response_content)
         if (result != None):
-            fields = line.split(":") # eg, ['Reply-Text','+OK Job-UUID', '882']
-            endfields = fields[1:]
-            self.response_content = "".join(endfields)
-            self._fsm.ReplyText()
-            return self.isRequestFinished()
-
-
-        self._fsm.ProcessLine(line)
-        return self.isRequestFinished()
-
-
+            self.callbackDeferred(self.response_content)
+            return
+        msg = "Login failed, most likely a bad password"
+        self.errbackDeferred(Failure(Exception(msg)))
+        
     def getReplyText(self):
         self.response_content
 



More information about the Freeswitch-svn mailing list