[dts] [next][PATCH V1 3/5] dep: modify dts dep to support python3
xinfengx
xinfengx.zhao at intel.com
Sun Jan 12 23:18:29 CET 2020
Signed-off-by: xinfengx <xinfengx.zhao at intel.com>
---
dep/Dot1BR.py | 1 -
dep/QMP/qmp.py | 10 +++++-----
dep/gtp.py | 4 +---
dep/gtp_v2.py | 2 --
dep/lldp.py | 13 +++++++------
dep/vxlan.py | 3 ++-
6 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/dep/Dot1BR.py b/dep/Dot1BR.py
index 114c19a..cc3c01f 100644
--- a/dep/Dot1BR.py
+++ b/dep/Dot1BR.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
## This file is part of Scapy
## See http://www.secdev.org/projects/scapy for more informations
## Copyright (C) Philippe Biondi <phil at secdev.org>
diff --git a/dep/QMP/qmp.py b/dep/QMP/qmp.py
index 4ade3ce..9e6f4cf 100755
--- a/dep/QMP/qmp.py
+++ b/dep/QMP/qmp.py
@@ -50,7 +50,7 @@ class QEMUMonitorProtocol:
def __negotiate_capabilities(self):
greeting = self.__json_read()
- if greeting is None or not greeting.has_key('QMP'):
+ if greeting is None or 'QMP' not in greeting:
raise QMPConnectError
# Greeting seems ok, negotiate capabilities
resp = self.cmd('qmp_capabilities')
@@ -109,7 +109,7 @@ class QEMUMonitorProtocol:
"""
try:
self.__sock.sendall(json.dumps(qmp_cmd))
- except socket.error, err:
+ except socket.error as err:
if err[0] == errno.EPIPE:
return
raise socket.error(err)
@@ -135,7 +135,7 @@ class QEMUMonitorProtocol:
if not ret:
return
else:
- if ret.has_key('error'):
+ if 'error' in ret:
raise Exception(ret['error']['desc'])
return ret['return']
@@ -148,7 +148,7 @@ class QEMUMonitorProtocol:
self.__sock.setblocking(0)
try:
self.__json_read()
- except socket.error, err:
+ except socket.error as err:
if err[0] == errno.EAGAIN:
# No data available
pass
@@ -168,7 +168,7 @@ class QEMUMonitorProtocol:
self.__sock.setblocking(0)
try:
self.__json_read()
- except socket.error, err:
+ except socket.error as err:
if err[0] == errno.EAGAIN:
# No data available
pass
diff --git a/dep/gtp.py b/dep/gtp.py
index 7d57789..76f5e8e 100644
--- a/dep/gtp.py
+++ b/dep/gtp.py
@@ -1,5 +1,3 @@
-#! /usr/bin/env python
-
# Copyright (C) 2018 Leonardo Monteiro <decastromonteiro at gmail.com>
# 2017 Alexis Sultan <alexis.sultan at sfr.com>
# 2017 Alessio Deiana <adeiana at gmail.com>
@@ -11,7 +9,7 @@
# scapy.contrib.description = GPRS Tunneling Protocol (GTP)
# scapy.contrib.status = loads
-from __future__ import absolute_import
+
import struct
diff --git a/dep/gtp_v2.py b/dep/gtp_v2.py
index af94918..6cffd47 100644
--- a/dep/gtp_v2.py
+++ b/dep/gtp_v2.py
@@ -1,5 +1,3 @@
-#! /usr/bin/env python
-
# Copyright (C) 2017 Alessio Deiana <adeiana at gmail.com>
# 2017 Alexis Sultan <alexis.sultan at sfr.com>
diff --git a/dep/lldp.py b/dep/lldp.py
index d8fabe2..9792e05 100644
--- a/dep/lldp.py
+++ b/dep/lldp.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
## This file is part of Scapy
## See http://www.secdev.org/projects/scapy for more informations
## Copyright (C) Philippe Biondi <phil at secdev.org>
@@ -79,7 +78,7 @@ class LLDPGeneric(Packet):
def post_build(self, p, pay):
if self.length is None:
l = len(p) - 2
- p = chr((self.type << 1) ^ (l >> 8)) + chr(l & 0xff) + p[2:]
+ p = chr((self.type << 1) ^ (l >> 8)) + chr(l & 0xff) + bytes.decode(p[2:], encoding='gbk')
return p+pay
@@ -212,13 +211,15 @@ class LLDPManagementAddress(LLDPGeneric):
# TODO Remove redundant code. LLDPGeneric.post_build()
if self.length is None:
l = len(p) - 2
- p = chr((self.type << 1) ^ (l >> 8)) + chr(l & 0xff) + p[2:]
+ p = chr((self.type << 1) ^ (l >> 8)) + chr(l & 0xff) + p[2:].decode()
if self.addrlen is None:
addrlen = len(p) - 2 - 8 - len(self.oid) + 1
- p = p[:2] + struct.pack("B", addrlen) + p[3:]
-
- return p+pay
+ if isinstance(p, type('abc')):
+ p = p[:2]+ struct.pack("B", addrlen).decode() + p[3:]
+ else:
+ p = p[:2].decode() + struct.pack("B", addrlen).decode() + p[3:].decode()
+ return bytes(p, encoding="utf-8")+pay
_LLDPDot1Subtype = {1: "Port VLAN Id"}
diff --git a/dep/vxlan.py b/dep/vxlan.py
index 0683b42..c2661d6 100644
--- a/dep/vxlan.py
+++ b/dep/vxlan.py
@@ -10,8 +10,9 @@ from scapy.layers.inet6 import IPv6
from scapy.layers.dns import DNS
from scapy.layers.l2 import Ether
-vxlanmagic = "0x8"
+XLAN_PORT=4789
+VXLAN_PORT=4789
_GP_FLAGS = ["R", "R", "R", "A", "R", "R", "D", "R"]
class VXLAN(Packet):
--
2.17.1
More information about the dts
mailing list