1 Star 0 Fork 0

src-NestOS/WALinuxAgent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0002-handle-py3.9-check-in-future.py.patch 3.62 KB
一键复制 编辑 原始数据 按行查看 历史
duyiwei 提交于 2021-07-07 15:26 . init
From 66f600ed3d9f22c2aa6790002507d0c821a7fd0c Mon Sep 17 00:00:00 2001
From: Paula Gombar <[email protected]>
Date: Tue, 8 Dec 2020 18:38:33 -0800
Subject: [PATCH 2/3] handle py3.9 check in future.py
---
azurelinuxagent/common/future.py | 13 ++++++++++++-
azurelinuxagent/common/osutil/bigip.py | 8 +++-----
azurelinuxagent/common/osutil/default.py | 9 ++-------
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/azurelinuxagent/common/future.py b/azurelinuxagent/common/future.py
index 577fb12e186e..0f76aceba786 100644
--- a/azurelinuxagent/common/future.py
+++ b/azurelinuxagent/common/future.py
@@ -103,4 +103,15 @@ def get_openwrt_platform():
elif product_matches:
if product_matches.group(1) == "OpenWrt":
result[0] = "openwrt"
- return result
\ No newline at end of file
+ return result
+
+
+def array_to_string_or_bytes(buffer):
+ # Python 3.9 removed the tostring() method on arrays, the new alias is tobytes()
+ if sys.version_info[0] == 2:
+ return buffer.tostring()
+
+ if sys.version_info[0] == 3 and sys.version_info[1] <= 8:
+ return buffer.tostring()
+
+ return buffer.tobytes()
diff --git a/azurelinuxagent/common/osutil/bigip.py b/azurelinuxagent/common/osutil/bigip.py
index ceadf8ca2066..cc1b64143c12 100644
--- a/azurelinuxagent/common/osutil/bigip.py
+++ b/azurelinuxagent/common/osutil/bigip.py
@@ -24,6 +24,8 @@ import socket
import struct
import time
+from azurelinuxagent.common.future import array_to_string_or_bytes
+
try:
# WAAgent > 2.1.3
import azurelinuxagent.common.logger as logger
@@ -280,12 +282,8 @@ class BigIpOSUtil(DefaultOSUtil):
if retsize == (expected * struct_size):
logger.warn(('SIOCGIFCONF returned more than {0} up '
'network interfaces.'), expected)
- try:
- # Python 3.9 removed the tostring() method on arrays, tobytes() is the new alias
- sock = buff.tostring()
- except AttributeError:
- sock = buff.tobytes()
+ sock = array_to_string_or_bytes(buff)
for i in range(0, struct_size * expected, struct_size):
iface = self._format_single_interface_name(sock, i)
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
index 6179061756e3..c1ca15cf64ef 100644
--- a/azurelinuxagent/common/osutil/default.py
+++ b/azurelinuxagent/common/osutil/default.py
@@ -41,7 +41,7 @@ import azurelinuxagent.common.utils.fileutil as fileutil
import azurelinuxagent.common.utils.shellutil as shellutil
import azurelinuxagent.common.utils.textutil as textutil
from azurelinuxagent.common.exception import OSUtilError
-from azurelinuxagent.common.future import ustr
+from azurelinuxagent.common.future import ustr, array_to_string_or_bytes
from azurelinuxagent.common.utils.cryptutil import CryptUtil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.utils.networkutil import RouteEntry, NetworkInterfaceCard
@@ -758,12 +758,7 @@ class DefaultOSUtil(object):
logger.warn(('SIOCGIFCONF returned more than {0} up '
'network interfaces.'), expected)
- try:
- # Python 3.9 removed the tostring() method on arrays, tobytes() is the new alias
- ifconf_buff = buff.tostring()
- except AttributeError:
- ifconf_buff = buff.tobytes()
-
+ ifconf_buff = array_to_string_or_bytes(buff)
ifaces = {}
for i in range(0, array_size, struct_size):
iface = ifconf_buff[i:i+IFNAMSIZ].split(b'\0', 1)[0]
--
2.26.2
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-nest-os/walinux-agent.git
[email protected]:src-nest-os/walinux-agent.git
src-nest-os
walinux-agent
WALinuxAgent
master

搜索帮助