[asterisk-bugs] [JIRA] (ASTERISK-27811) [patch] sip_to_pjsip: Enable python3 compatibility.

Alexander Traud (JIRA) noreply at issues.asterisk.org
Thu Apr 19 03:26:50 CDT 2018


     [ https://issues.asterisk.org/jira/browse/ASTERISK-27811?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Traud updated ASTERISK-27811:
---------------------------------------

    Description: 
In {{contrib/scripts}}, there is the Python script {{sip_to_pjsip}}, which converts an existing configuration file from the old SIP channel driver {{chan_sip}} to the new {{chan_pjsip}}, see the [Wiki...|https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip]

In the year 2013, the last big change to that script happened (ASTERISK-22374). Although then, Python 3 existed already, that script works only with Python 2.7 as of today. Even the Shebang is not in line with the other Python scripts in Asterisk and not the [recommended one|https://stackoverflow.com/a/19305076].

Luckily, the changes for Python 3 are not much: The biggest change is {{print()}} and the import statements. ASTERISK-27333 introduced white-space errors, which Python 3 is picky about. Finally, the analyzer [pyflakes3|https://pypi.org/project/pyflakes/] hinted that the function {{cmp()}} must be replaced to be Python 3 compatible.

With ASTERISK-27348, a new script was added. That imported {{cli_options()}} from the existing script but re-defined just later. pyflakes3 was not happy about that, therefore I removed that import. Furthermore, that script tries to catch an {{Exception,e}} - looks like a typo for me. Finally, I enhanced that script not only to require MySQLdb but allow as alternative also the external library pymysql.

The final script is still compatible with Python 2 and created the same output with a rather complex {{sip.conf}}, both in Python 2.7 and Python 3.6. This change here is part of a series of three changes to get the scripts within Asterisk compatible with Python 3:
1. [Build System...|https://gerrit.asterisk.org/8641]
3. Test Framework, see ASTERISK-27787

  was:
In {{contrib/scripts}}, there is the Python script {{sip_to_pjsip}}, which converts an existing configuration file from the old SIP channel driver {{chan_sip}} to the new {{chan_pjsip}}, see the [Wiki...|https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip]

In the year 2013, the last big change to that script happened (ASTERISK-22374). Although then, Python 3 existed already, that script works only with Python 2.7 as of today. Even the Shebang is not in line with the other Python scripts in Asterisk and not the [recommended one|https://stackoverflow.com/a/19305076].

Luckily, the changes for Python 3 are not much: The biggest change is {{print()}} and the import statements. ASTERISK-27333 introduced white-space errors, which Python 3 is picky about. Finally, the analyzer [pyflakes3|https://pypi.org/project/pyflakes/] hinted that the function {{cmp()}} must be replaced to be Python 3 compatible.

With ASTERISK-27348, a new script was added. That imported {{cli_options()}} from the existing script but re-defined just later. pyflakes3 was not happy about that, therefore I removed that import. Furthermore, that script tries to catch an {{Exception,e}} - looks like a typo for me. Finally, I enhanced that script not only to require MySQLdb but allow as alternative also the external library pymysql.

The final script is still compatible with Python 2 and created the same output with a rather complex {{sip.conf}}, both in Python 2.7 and Python 3.6. This change here is part of a series of three changes to get the scripts within Asterisk compatible with Python 3:
1. [~coreyfarrell] does the change in the [Build System...|https://gerrit.asterisk.org/8641]
3. Somebody to be named must migrate the Test-Framework, see the comments of ASTERISK-27717


> [patch] sip_to_pjsip: Enable python3 compatibility.
> ---------------------------------------------------
>
>                 Key: ASTERISK-27811
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-27811
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: Contrib/General
>    Affects Versions: 13.20.0, 15.3.0
>         Environment: Python 3.6
> Python 2.7
>            Reporter: Alexander Traud
>            Assignee: Alexander Traud
>              Labels: patch, pjsip
>         Attachments: python3.patch
>
>
> In {{contrib/scripts}}, there is the Python script {{sip_to_pjsip}}, which converts an existing configuration file from the old SIP channel driver {{chan_sip}} to the new {{chan_pjsip}}, see the [Wiki...|https://wiki.asterisk.org/wiki/display/AST/Migrating+from+chan_sip+to+res_pjsip]
> In the year 2013, the last big change to that script happened (ASTERISK-22374). Although then, Python 3 existed already, that script works only with Python 2.7 as of today. Even the Shebang is not in line with the other Python scripts in Asterisk and not the [recommended one|https://stackoverflow.com/a/19305076].
> Luckily, the changes for Python 3 are not much: The biggest change is {{print()}} and the import statements. ASTERISK-27333 introduced white-space errors, which Python 3 is picky about. Finally, the analyzer [pyflakes3|https://pypi.org/project/pyflakes/] hinted that the function {{cmp()}} must be replaced to be Python 3 compatible.
> With ASTERISK-27348, a new script was added. That imported {{cli_options()}} from the existing script but re-defined just later. pyflakes3 was not happy about that, therefore I removed that import. Furthermore, that script tries to catch an {{Exception,e}} - looks like a typo for me. Finally, I enhanced that script not only to require MySQLdb but allow as alternative also the external library pymysql.
> The final script is still compatible with Python 2 and created the same output with a rather complex {{sip.conf}}, both in Python 2.7 and Python 3.6. This change here is part of a series of three changes to get the scripts within Asterisk compatible with Python 3:
> 1. [Build System...|https://gerrit.asterisk.org/8641]
> 3. Test Framework, see ASTERISK-27787



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list