[Asterisk-code-review] Add support for Python 3 (starpy[1.1])

Michael Bradeen asteriskteam at digium.com
Wed Jun 22 12:43:24 CDT 2022


Michael Bradeen has submitted this change. ( https://gerrit.asterisk.org/c/starpy/+/18244 )

Change subject: Add support for Python 3
......................................................................

Add support for Python 3

manager: Replace 'async' reference with 'nowait'.  This change breaks
backwards compatibility with previous versions of the testsuite,
requiring a matching change there. 'async' is now a reserved word
in python and can not be used.

manager and fastagi: twisted in general uses bytes for passing data back
and forth while internally we generally want to deal with strings.  This
requires converting between the two as we interact with the twisted
library.

ASTERISK-26826

Change-Id: I2fab42abb5318a5db2af3bcd291fc2db95b87e15
---
M starpy/fastagi.py
M starpy/manager.py
2 files changed, 7 insertions(+), 5 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  Michael Bradeen: Looks good to me, approved; Approved for Submit



diff --git a/starpy/fastagi.py b/starpy/fastagi.py
index 85de054..7a39f43 100644
--- a/starpy/fastagi.py
+++ b/starpy/fastagi.py
@@ -81,7 +81,7 @@
     """
     readingVariables = False
     lostConnectionDeferred = None
-    delimiter = '\n'
+    delimiter = b'\n'
 
     def __init__(self, *args, **named):
         """Initialise the AMIProtocol, arguments are ignored"""
@@ -117,6 +117,7 @@
 
     def lineReceived(self, line):
         """(Internal) Handle Twisted's report of an incoming line from AMI"""
+        line = line.decode("utf-8")
         log.debug('Line In: %r', line)
         if self.readingVariables:
             if not line.strip():
@@ -157,7 +158,7 @@
         commandString = commandString.rstrip('\n').rstrip('\r')
         df = defer.Deferred()
         self.pendingMessages.append(df)
-        self.sendLine(commandString)
+        self.sendLine(bytes(commandString,"utf-8"))
         return df
 
     def checkFailure(self, result, failure='-1'):
diff --git a/starpy/manager.py b/starpy/manager.py
index 70c93b3..077b39a 100644
--- a/starpy/manager.py
+++ b/starpy/manager.py
@@ -168,6 +168,7 @@
 
     def lineReceived(self, line):
         """Handle Twisted's report of an incoming line from the manager"""
+        line = line.decode("utf-8")
         log.debug('Line In: %r', line)
         self.messageCache.append(line)
         if not line.strip():
@@ -716,7 +717,7 @@
     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={}, nowait=False, channelid=None,
             otherchannelid=None, codecs=None):
         """Originate call to connect channel to given context/exten/priority
 
@@ -730,7 +731,7 @@
         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
+        nowait -- make the origination asynchronous
         """
         message = [(k, v) for (k, v) in (
             ('action', 'originate'),
@@ -742,7 +743,7 @@
             ('account', account),
             ('application', application),
             ('data', data),
-            ('async', str(async)),
+            ('async', str(nowait)),
             ('channelid', channelid),
             ('otherchannelid', otherchannelid),
             ('codecs', codecs),

-- 
To view, visit https://gerrit.asterisk.org/c/starpy/+/18244
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: starpy
Gerrit-Branch: 1.1
Gerrit-Change-Id: I2fab42abb5318a5db2af3bcd291fc2db95b87e15
Gerrit-Change-Number: 18244
Gerrit-PatchSet: 5
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220622/f8c69842/attachment.html>


More information about the asterisk-code-review mailing list