From b9447e9a8e495dda9ef1b65a224529ffef1905ff Mon Sep 17 00:00:00 2001 From: "victor.silva" Date: Fri, 14 Jun 2019 18:37:24 +0000 Subject: [PATCH 1/4] Ignoring pycharm ide files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5f98a29..939bf62 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist starpy.egg-info .tox *.pyc +.idea \ No newline at end of file From 2a8a0b0ac58d32353e68d5363f919f3e8fee93e8 Mon Sep 17 00:00:00 2001 From: "victor.silva" Date: Fri, 14 Jun 2019 18:37:50 +0000 Subject: [PATCH 2/4] Fixed TypeError on python 3. --- starpy/fastagi.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/starpy/fastagi.py b/starpy/fastagi.py index 85de054..e59649e 100644 --- a/starpy/fastagi.py +++ b/starpy/fastagi.py @@ -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""" @@ -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: @@ -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 @@ -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) From d33971c1f8799ee08c04b7c9761ae8c3ab80c42a Mon Sep 17 00:00:00 2001 From: "victor.silva" Date: Wed, 19 Jun 2019 17:57:26 +0000 Subject: [PATCH 3/4] Refactored async parameter to is_async. - The async is now a reserved keyword in Python 3. --- starpy/manager.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/starpy/manager.py b/starpy/manager.py index 7adac62..39819e8 100644 --- a/starpy/manager.py +++ b/starpy/manager.py @@ -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 @@ -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'), @@ -742,7 +742,7 @@ def originate( ('account', account), ('application', application), ('data', data), - ('async', str(async)), + ('async', str(is_async)), ('channelid', channelid), ('otherchannelid', otherchannelid), ) if v is not None] From 5d2be649deef17282bc3d11fda0ac29457cb453a Mon Sep 17 00:00:00 2001 From: "victor.silva" Date: Tue, 19 Nov 2019 17:56:15 -0300 Subject: [PATCH 4/4] Using list casting to prevent error when iterate a dictionary using items method on python 3. --- starpy/manager.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/starpy/manager.py b/starpy/manager.py index 39819e8..d41f2cf 100644 --- a/starpy/manager.py +++ b/starpy/manager.py @@ -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")) @@ -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')) @@ -748,7 +748,7 @@ def originate( ) 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) @@ -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) @@ -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)