[Asterisk-code-review] syncami: wrap utf-8 string before parsing (testsuite[15])

Jenkins2 asteriskteam at digium.com
Tue Sep 11 04:23:37 CDT 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/10068 )

Change subject: syncami: wrap utf-8 string before parsing
......................................................................

syncami: wrap utf-8 string before parsing

For some reason in some older versions of Python directly passing a utf-8 string
to HeaderParser's parsestr method would not parse the data correctly. However,
wrapping it in a StringIO object first works for all versions.

Change-Id: I24af2df707983accc9298da095c018b1aaf963e3
---
M lib/python/asterisk/syncami.py
1 file changed, 5 insertions(+), 3 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/lib/python/asterisk/syncami.py b/lib/python/asterisk/syncami.py
index 5482400..917e9e4 100644
--- a/lib/python/asterisk/syncami.py
+++ b/lib/python/asterisk/syncami.py
@@ -15,6 +15,7 @@
     # python 3 import
     from urllib.parse import urlencode
 
+from StringIO import StringIO
 from email.parser import HeaderParser
 try:
     from httplib import *
@@ -93,7 +94,8 @@
         if res.status != 200:
             raise InvalidAMIResponse(res)
         self.cookie = res.getheader('set-cookie', None)
-        data = res.read().decode('utf-8')
-        parser = HeaderParser()
 
-        return parser.parsestr(data)
+        data = StringIO(res.read().decode('utf-8', 'ignore'))
+        res = HeaderParser().parse(data)
+        data.close()
+        return res

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

Gerrit-Project: testsuite
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I24af2df707983accc9298da095c018b1aaf963e3
Gerrit-Change-Number: 10068
Gerrit-PatchSet: 2
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180911/46f3e322/attachment.html>


More information about the asterisk-code-review mailing list