--- contrib/scripts/sip_to_pjsip/astconfigparser.py (Asterisk 15.3) +++ contrib/scripts/sip_to_pjsip/astconfigparser.py (working copy) @@ -52 +52 @@ - return cmp(self.id, other.id) + return (self.id > other.id) - (self.id < other.id) @@ -448 +448 @@ - print "Could not open file ", filename, " for reading" + print("Could not open file " + filename + " for reading") @@ -493 +493 @@ - print "Could not open file ", config_file, " for writing" + print("Could not open file " + config_file + " for writing") --- contrib/scripts/sip_to_pjsip/astdicts.py (Asterisk 15.3) +++ contrib/scripts/sip_to_pjsip/astdicts.py (working copy) @@ -5,6 +5,8 @@ try: - from thread import get_ident as _get_ident + from threading import get_ident as _get_ident except ImportError: - from dummy_thread import get_ident as _get_ident - + try: + from thread import get_ident as _get_ident + except ImportError: + from dummy_thread import get_ident as _get_ident try: @@ -269,3 +271,3 @@ if key not in self: -# print "__setitem__ key = ", key, " val = ", val +# print("__setitem__ key = " + key + " val = " + val) OrderedDict.__setitem__( @@ -273,3 +275,3 @@ return -# print "inserting key = ", key, " val = ", val +# print("inserting key = " + key + " val = " + val) vals = self[key] --- contrib/scripts/sip_to_pjsip/sip_to_pjsip.py (Asterisk 15.3) +++ contrib/scripts/sip_to_pjsip/sip_to_pjsip.py (working copy) @@ -1,8 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/env python import optparse import socket -import urlparse # Python 2.7 required for Literal IPv6 Addresses - +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse # Python 2.7 required for Literal IPv6 Addresses import astdicts import astconfigparser @@ -91,30 +93,30 @@ if key == 'allow': - try: - disallow = sip.get(section, 'disallow')[0] - if disallow == 'all': - #don't inherit - for i in sip.get(section, 'allow'): - set_value(key, i, section, pjsip, nmapped, type) - else: - merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) - except LookupError: - print "lookup error" - merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) - return + try: + disallow = sip.get(section, 'disallow')[0] + if disallow == 'all': + #don't inherit + for i in sip.get(section, 'allow'): + set_value(key, i, section, pjsip, nmapped, type) + else: + merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) + except LookupError: + print("lookup error") + merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) + return elif key == 'disallow': - try: - allow = sip.get(section, 'allow')[0] - if allow == 'all': - #don't inherit - for i in sip.get(section, 'disallow'): - set_value(key, i, section, pjsip, nmapped, type) - else: - merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) - except LookupError: - merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) - return + try: + allow = sip.get(section, 'allow')[0] + if allow == 'all': + #don't inherit + for i in sip.get(section, 'disallow'): + set_value(key, i, section, pjsip, nmapped, type) + else: + merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) + except LookupError: + merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) + return else: - merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) + merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to) @@ -165,5 +167,5 @@ val = sip.get('general', 't38pt_udptl')[0] except LookupError: - return + return ec = 'none' @@ -292,5 +294,5 @@ # Literal IPv6 (like [::]), IPv4, or hostname # does not work for IPv6 without brackets; case catched above - url = urlparse.urlparse('sip://' + host) + url = urlparse('sip://' + host) if port_key: @@ -436,6 +438,5 @@ # options in pjsip.conf on an endpoint that have no sip.conf equivalent: -# type, 100rel, trust_id_outbound, aggregate_mwi, -# connected_line_method +# type, 100rel, trust_id_outbound, aggregate_mwi, connected_line_method # known sip.conf peer keys that can be mapped to a pjsip.conf section/key @@ -592,5 +593,5 @@ # Literal IPv6 (like [::]), IPv4, or hostname # does not work for IPv6 without brackets; case catched above - url = urlparse.urlparse('sip://' + addr) + url = urlparse('sip://' + addr) # TODO Does not compress IPv6, for example 0:0:0:0:0:0:0:0 should get [::] return (url.hostname, url.port) @@ -840,9 +841,9 @@ 'sslclientmethod'])[0] if section != 'transport-' + protocol + '6': # print only once - print 'In chan_sip, you specified the TLS version. With chan_sip,' \ + print('In chan_sip, you specified the TLS version. With chan_sip,' \ ' this was just for outbound client connections. In' \ ' chan_pjsip, this value is for client and server. Instead,' \ ' consider not to specify \'tlsclientmethod\' for chan_sip' \ - ' and \'method = sslv23\' for chan_pjsip.' + ' and \'method = sslv23\' for chan_pjsip.') except LookupError: """ @@ -1247,5 +1248,5 @@ except IOError: - print "Could not open file ", filename, " for writing" + print("Could not open file " + filename + " for writing") ############################################################################### @@ -1278,10 +1279,10 @@ # configuration parser for sip.conf sip = astconfigparser.MultiOrderedConfigParser() - print 'Please, report any issue at:' - print ' https://issues.asterisk.org/' - print 'Reading', sip_filename + print('Please, report any issue at:') + print(' https://issues.asterisk.org/') + print('Reading ' + sip_filename) sip.read(sip_filename) - print 'Converting to PJSIP...' + print('Converting to PJSIP...') pjsip, non_mappings = convert(sip, pjsip_filename, dict(), False) - print 'Writing', pjsip_filename + print('Writing ' + pjsip_filename) write_pjsip(pjsip_filename, pjsip, non_mappings) --- contrib/scripts/sip_to_pjsip/sip_to_pjsql.py (Asterisk 15.3) +++ contrib/scripts/sip_to_pjsip/sip_to_pjsql.py (working copy) @@ -1,4 +1,3 @@ -#!/usr/bin/python +#!/usr/bin/env python -from sip_to_pjsip import cli_options from sip_to_pjsip import convert @@ -20,3 +19,3 @@ except IOError: - print "Could not open file ", filename, " for writing" + print("Could not open file " + filename + " for writing") @@ -72,9 +71,9 @@ sip.connect(user,password,host,port,database) - print 'Please, report any issue at:' - print ' https://issues.asterisk.org/' - print 'Reading', sip_filename + print('Please, report any issue at:') + print(' https://issues.asterisk.org/') + print('Reading ' + sip_filename) sip.read(sip_filename) - print 'Converting to PJSIP realtime sql...' + print('Converting to PJSIP realtime sql...') pjsip, non_mappings = convert(sip, pjsip_filename, dict(), False) - print 'Writing', pjsip_filename + print('Writing ' + pjsip_filename) write_pjsip(pjsip_filename, pjsip, non_mappings) --- contrib/scripts/sip_to_pjsip/sqlconfigparser.py (Asterisk 15.3) +++ contrib/scripts/sip_to_pjsip/sqlconfigparser.py (working copy) @@ -1,5 +1,10 @@ from astconfigparser import MultiOrderedConfigParser -import MySQLdb +try: + import pymysql as MySQLdb + MySQLdb.install_as_MySQLdb() +except ImportError: + import MySQLdb + import traceback @@ -62,8 +67,5 @@ try: self.write_dicts(config_file, self._sections) - except Exception,e: - print "Could not open file ", config_file, " for writing" + except: + print("Could not open file " + config_file + " for writing") traceback.print_exc() - - -