nat/vty: Fix construct not working with python 2.6

Use the simpler approach and just call encode('hex') on the str and
then convert it to lower case to keep the tests working.

reproduce:

Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = '\0\0'
>>> d
'\x00\x00'
>>> "".join("{:02x}".format(ord(c)) for c in d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <genexpr>
ValueError: zero length field name in format

fixes:

======================================================================
ERROR: testBSCreload (__main__.TestVTYNAT)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./vty_test_runner.py", line 658, in testBSCreload
    b0 = nat_bsc_sock_test(0, "lol")
  File "./vty_test_runner.py", line 1150, in nat_bsc_sock_test
    ipa_handle_small(bsc, verbose)
  File "./vty_test_runner.py", line 1116, in ipa_handle_small
    s = data2str(x.recv(4))
  File "./vty_test_runner.py", line 1100, in data2str
    return "".join("{:02x}".format(ord(c)) for c in d)
  File "./vty_test_runner.py", line 1100, in <genexpr>
    return "".join("{:02x}".format(ord(c)) for c in d)
ValueError: zero length field name in format

----------------------------------------------------------------------
This commit is contained in:
Holger Hans Peter Freyther 2016-04-14 21:40:04 -04:00
parent 5044597d52
commit 7db1ff602b
1 changed files with 1 additions and 1 deletions

View File

@ -1097,7 +1097,7 @@ def nat_msc_ip(x, ip, port):
x.vty.command("end")
def data2str(d):
return "".join("{:02x}".format(ord(c)) for c in d)
return d.encode('hex').lower()
def nat_msc_test(x, ip, port, verbose = False):
msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)