<p>Michael Bradeen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/starpy/+/18244">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Changes required for Python 3 compatibility<br><br>manager: Replace 'async' reference with 'nowait'. This change breaks backwards<br>compatibility with previous versions of the testsuite, requiring a matching<br>change there.<br><br>manager and fastagi: twisted in general uses bytes for passing data back and<br>forth while internally we generally want to deal with strings. This requires<br>converting between the two as we interact with the twisted library.<br><br>ASTERISK-26826<br><br>Change-Id: I2fab42abb5318a5db2af3bcd291fc2db95b87e15<br>---<br>M starpy/fastagi.py<br>M starpy/manager.py<br>2 files changed, 21 insertions(+), 19 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/starpy refs/changes/44/18244/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/starpy/fastagi.py b/starpy/fastagi.py</span><br><span>index 85de054..4e888ee 100644</span><br><span>--- a/starpy/fastagi.py</span><br><span>+++ b/starpy/fastagi.py</span><br><span>@@ -81,7 +81,7 @@</span><br><span> """</span><br><span> readingVariables = False</span><br><span> lostConnectionDeferred = None</span><br><span style="color: hsl(0, 100%, 40%);">- delimiter = '\n'</span><br><span style="color: hsl(120, 100%, 40%);">+ delimiter = b'\n'</span><br><span> </span><br><span> def __init__(self, *args, **named):</span><br><span> """Initialise the AMIProtocol, arguments are ignored"""</span><br><span>@@ -117,17 +117,18 @@</span><br><span> </span><br><span> def lineReceived(self, line):</span><br><span> """(Internal) Handle Twisted's report of an incoming line from AMI"""</span><br><span style="color: hsl(0, 100%, 40%);">- log.debug('Line In: %r', line)</span><br><span style="color: hsl(120, 100%, 40%);">+ linestring = line.decode("utf-8")</span><br><span style="color: hsl(120, 100%, 40%);">+ log.debug('Line In: %r', linestring)</span><br><span> if self.readingVariables:</span><br><span style="color: hsl(0, 100%, 40%);">- if not line.strip():</span><br><span style="color: hsl(120, 100%, 40%);">+ if not linestring.strip():</span><br><span> self.readingVariables = False</span><br><span> self.factory.mainFunction(self)</span><br><span> else:</span><br><span> try:</span><br><span style="color: hsl(0, 100%, 40%);">- key, value = line.split(':', 1)</span><br><span style="color: hsl(120, 100%, 40%);">+ key, value = linestring.split(':', 1)</span><br><span> value = value[1:].rstrip('\n').rstrip('\r')</span><br><span> except ValueError as err:</span><br><span style="color: hsl(0, 100%, 40%);">- log.error("""Invalid variable line: %r""", line)</span><br><span style="color: hsl(120, 100%, 40%);">+ log.error("""Invalid variable line: %r""", linestring)</span><br><span> else:</span><br><span> self.variables[key.lower()] = value</span><br><span> log.debug("""%s = %r""", key, value)</span><br><span>@@ -135,21 +136,21 @@</span><br><span> try:</span><br><span> df = self.pendingMessages.pop(0)</span><br><span> except IndexError as err:</span><br><span style="color: hsl(0, 100%, 40%);">- log.warn("Line received without pending deferred: %r", line)</span><br><span style="color: hsl(120, 100%, 40%);">+ log.warn("Line received without pending deferred: %r", linestring)</span><br><span> else:</span><br><span style="color: hsl(0, 100%, 40%);">- if line.startswith('200'):</span><br><span style="color: hsl(0, 100%, 40%);">- line = line[4:]</span><br><span style="color: hsl(0, 100%, 40%);">- if line.lower().startswith('result='):</span><br><span style="color: hsl(0, 100%, 40%);">- line = line[7:]</span><br><span style="color: hsl(0, 100%, 40%);">- df.callback(line)</span><br><span style="color: hsl(120, 100%, 40%);">+ if linestring.startswith('200'):</span><br><span style="color: hsl(120, 100%, 40%);">+ linestring = linestring[4:]</span><br><span style="color: hsl(120, 100%, 40%);">+ if linestring.lower().startswith('result='):</span><br><span style="color: hsl(120, 100%, 40%);">+ linestring = linestring[7:]</span><br><span style="color: hsl(120, 100%, 40%);">+ df.callback(linestring)</span><br><span> else:</span><br><span> # XXX parse out the error code</span><br><span> try:</span><br><span style="color: hsl(0, 100%, 40%);">- errCode, line = line.split(' ', 1)</span><br><span style="color: hsl(120, 100%, 40%);">+ errCode, linestring = linestring.split(' ', 1)</span><br><span> errCode = int(errCode)</span><br><span> except ValueError as err:</span><br><span> errCode = 500</span><br><span style="color: hsl(0, 100%, 40%);">- df.errback(error.AGICommandFailure(errCode, line))</span><br><span style="color: hsl(120, 100%, 40%);">+ df.errback(error.AGICommandFailure(errCode, linestring))</span><br><span> </span><br><span> def sendCommand(self, commandString):</span><br><span> """(Internal) Send the given command to the other side"""</span><br><span>@@ -157,7 +158,7 @@</span><br><span> commandString = commandString.rstrip('\n').rstrip('\r')</span><br><span> df = defer.Deferred()</span><br><span> self.pendingMessages.append(df)</span><br><span style="color: hsl(0, 100%, 40%);">- self.sendLine(commandString)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.sendLine(bytes(commandString,"utf-8"))</span><br><span> return df</span><br><span> </span><br><span> def checkFailure(self, result, failure='-1'):</span><br><span>diff --git a/starpy/manager.py b/starpy/manager.py</span><br><span>index 70c93b3..72d94ea 100644</span><br><span>--- a/starpy/manager.py</span><br><span>+++ b/starpy/manager.py</span><br><span>@@ -168,8 +168,9 @@</span><br><span> </span><br><span> def lineReceived(self, line):</span><br><span> """Handle Twisted's report of an incoming line from the manager"""</span><br><span style="color: hsl(0, 100%, 40%);">- log.debug('Line In: %r', line)</span><br><span style="color: hsl(0, 100%, 40%);">- self.messageCache.append(line)</span><br><span style="color: hsl(120, 100%, 40%);">+ linestring = line.decode("utf-8")</span><br><span style="color: hsl(120, 100%, 40%);">+ log.debug('Line In: %r', linestring)</span><br><span style="color: hsl(120, 100%, 40%);">+ self.messageCache.append(linestring)</span><br><span> if not line.strip():</span><br><span> self.dispatchIncoming() # does dispatch and clears cache</span><br><span> </span><br><span>@@ -716,7 +717,7 @@</span><br><span> def originate(</span><br><span> self, channel, context=None, exten=None, priority=None,</span><br><span> timeout=None, callerid=None, account=None, application=None,</span><br><span style="color: hsl(0, 100%, 40%);">- data=None, variable={}, async=False, channelid=None,</span><br><span style="color: hsl(120, 100%, 40%);">+ data=None, variable={}, nowait=False, channelid=None,</span><br><span> otherchannelid=None, codecs=None):</span><br><span> """Originate call to connect channel to given context/exten/priority</span><br><span> </span><br><span>@@ -730,7 +731,7 @@</span><br><span> application -- alternate application to Dial to use for outbound dial</span><br><span> data -- data to pass to application</span><br><span> variable -- variables associated to the call</span><br><span style="color: hsl(0, 100%, 40%);">- async -- make the origination asynchronous</span><br><span style="color: hsl(120, 100%, 40%);">+ nowait -- make the origination asynchronous</span><br><span> """</span><br><span> message = [(k, v) for (k, v) in (</span><br><span> ('action', 'originate'),</span><br><span>@@ -742,7 +743,7 @@</span><br><span> ('account', account),</span><br><span> ('application', application),</span><br><span> ('data', data),</span><br><span style="color: hsl(0, 100%, 40%);">- ('async', str(async)),</span><br><span style="color: hsl(120, 100%, 40%);">+ ('async', str(nowait)),</span><br><span> ('channelid', channelid),</span><br><span> ('otherchannelid', otherchannelid),</span><br><span> ('codecs', codecs),</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/starpy/+/18244">change 18244</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/starpy/+/18244"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: starpy </div>
<div style="display:none"> Gerrit-Branch: 1.1 </div>
<div style="display:none"> Gerrit-Change-Id: I2fab42abb5318a5db2af3bcd291fc2db95b87e15 </div>
<div style="display:none"> Gerrit-Change-Number: 18244 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>