Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError on Python3.6.x in FastAGI. #44 #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
starpy.egg-info
.tox
*.pyc
.idea
14 changes: 8 additions & 6 deletions starpy/fastagi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class FastAGIProtocol(basic.LineOnlyReceiver):
"""
readingVariables = False
lostConnectionDeferred = None
delimiter = '\n'
delimiter = b'\n'

def __init__(self, *args, **named):
"""Initialise the AMIProtocol, arguments are ignored"""
Expand Down Expand Up @@ -124,8 +124,8 @@ def lineReceived(self, line):
self.factory.mainFunction(self)
else:
try:
key, value = line.split(':', 1)
value = value[1:].rstrip('\n').rstrip('\r')
key, value = line.split(b':', 1)
value = value[1:].rstrip(b'\n').rstrip(b'\r')
except ValueError as err:
log.error("""Invalid variable line: %r""", line)
else:
Expand All @@ -137,15 +137,15 @@ def lineReceived(self, line):
except IndexError as err:
log.warn("Line received without pending deferred: %r", line)
else:
if line.startswith('200'):
if line.startswith(b'200'):
line = line[4:]
if line.lower().startswith('result='):
if line.lower().startswith(b'result='):
line = line[7:]
df.callback(line)
else:
# XXX parse out the error code
try:
errCode, line = line.split(' ', 1)
errCode, line = line.split(b' ', 1)
errCode = int(errCode)
except ValueError as err:
errCode = 500
Expand All @@ -155,6 +155,8 @@ def sendCommand(self, commandString):
"""(Internal) Send the given command to the other side"""
log.info("Send Command: %r", commandString)
commandString = commandString.rstrip('\n').rstrip('\r')
if type(commandString) == str:
commandString = commandString.encode('utf-8')
df = defer.Deferred()
self.pendingMessages.append(df)
self.sendLine(commandString)
Expand Down
16 changes: 8 additions & 8 deletions starpy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def onFailure(reason):

def connectionLost(self, reason):
"""Connection lost, clean up callbacks"""
for key, callable in self.actionIDCallbacks.items():
for key, callable in list(self.actionIDCallbacks.items()):
try:
callable(tw_error.ConnectionDone(
"FastAGI connection terminated"))
Expand Down Expand Up @@ -359,7 +359,7 @@ def sendMessage(self, message, responseCallback=None):
if responseCallback:
self.actionIDCallbacks[message['actionid']] = responseCallback
log.debug("""MSG OUT: %s""", message)
for key, value in message.items():
for key, value in list(message.items()):
line = ('%s: %s' % (str(key.lower()), str(value)))
self.sendLine(line.encode('utf-8'))
self.sendLine(''.encode('utf-8'))
Expand Down Expand Up @@ -716,7 +716,7 @@ def monitor(self, channel, file, format, mix):
def originate(
self, channel, context=None, exten=None, priority=None,
timeout=None, callerid=None, account=None, application=None,
data=None, variable={}, async=False, channelid=None,
data=None, variable={}, is_async=False, channelid=None,
otherchannelid=None):
"""Originate call to connect channel to given context/exten/priority

Expand All @@ -730,7 +730,7 @@ def originate(
application -- alternate application to Dial to use for outbound dial
data -- data to pass to application
variable -- variables associated to the call
async -- make the origination asynchronous
is_async -- make the origination asynchronous
"""
message = [(k, v) for (k, v) in (
('action', 'originate'),
Expand All @@ -742,13 +742,13 @@ def originate(
('account', account),
('application', application),
('data', data),
('async', str(async)),
('async', str(is_async)),
('channelid', channelid),
('otherchannelid', otherchannelid),
) if v is not None]
if timeout is not None:
message.append(('timeout', timeout*1000))
for var_name, var_value in variable.items():
for var_name, var_value in list(variable.items()):
message.append(('variable', '%s=%s' % (var_name, var_value)))
return self.sendDeferred(message).addCallback(self.errorUnlessResponse)

Expand Down Expand Up @@ -1017,7 +1017,7 @@ def updateConfig(self, srcfile, dstfile, reload, headers={}):
'dstfilename': dstfile,
'reload': reload
}
for k, v in headers.items():
for k, v in list(headers.items()):
message[k] = v
return self.sendDeferred(message).addCallback(self.errorUnlessResponse)

Expand All @@ -1027,7 +1027,7 @@ def userEvent(self, event, **headers):
'Action': 'UserEvent',
'userevent': event
}
for i, j in headers.items():
for i, j in list(headers.items()):
message[i] = j
return self.sendMessage(message)

Expand Down