chocking on my own dogfood

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7731 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Traun Leyden 2008-02-23 22:48:55 +00:00
parent 8b1cc5879b
commit d275a8dd3d
2 changed files with 20 additions and 40 deletions

View File

@ -34,6 +34,7 @@ import time, re
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 @@ class FreepyDispatcher(LineReceiver):
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 @@ class FreepyDispatcher(LineReceiver):
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):

View File

@ -30,11 +30,13 @@ from twisted.internet import reactor, defer
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 @@ LoginRequest - Response handler for a login request
"""
class FreepyRequest(object):
def __init__(self):
@ -80,6 +83,9 @@ class FreepyRequest(object):
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 @@ class FreepyRequest(object):
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 @@ class LoginRequest(FreepyRequest):
super(LoginRequest, self).__init__()
import loginrequest_sm
self._fsm = loginrequest_sm.LoginRequest_sm(self)
def callOrErrback(self):
matchstr = re.compile("OK", re.I)
result = matchstr.search(self.response_content)
if (result != None):
self.callbackDeferred(self.response_content)
return
msg = "Login failed, most likely a bad password"
self.errbackDeferred(Failure(Exception(msg)))
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)
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()
def getReplyText(self):
self.response_content