Skip to content

Commit

Permalink
Fix (most) deprecation and syntax warnings (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
saegel authored Nov 12, 2020
1 parent d08e2ed commit 83d0738
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion conpot/core/databus.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def notify_observers(self, key):
def observe_value(self, key, callback):
assert hasattr(callback, "__call__")
assert len(
inspect.getargspec(callback)[0]
inspect.getfullargspec(callback)[0]
) # depreciated in py3.5, un-depreciated in py3.6
if key not in self._observer_map:
self._observer_map[key] = []
Expand Down
4 changes: 2 additions & 2 deletions conpot/core/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def chown(
}
}
if self.isdir(path) and recursive:
if self.norm_path(path) is not "/":
if self.norm_path(path) != "/":
self.setinfo(path, chown_cache)
sub_dir = self.opendir(path)
for _path, _ in sub_dir.walk.info():
Expand Down Expand Up @@ -866,7 +866,7 @@ def chmod(self, path: str, mode: oct, recursive: bool = False) -> None:
mode = int(mode, 8)
chmod_cache_info = {"access": {"permissions": Permissions.create(mode)}}
if self.isdir(path) and recursive:
if path is not "/":
if path != "/":
self.setinfo(path, chmod_cache_info)
# create a walker
sub_dir = self.opendir(path)
Expand Down
2 changes: 1 addition & 1 deletion conpot/emulators/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def handle(self, sock, address):
except _socket.error as socket_err:
data = []
socket_close_reason = str(socket_err)
if len(data) is 0:
if len(data) == 0:
self._close([proxy_socket, sock])
if s is proxy_socket:
logging.warning(
Expand Down
2 changes: 1 addition & 1 deletion conpot/protocols/ftp/ftp_base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def start_data_channel(self, send_recv="send"):
# waait till that process finishes.
self._data_channel_send.wait()
self._data_channel_recv.wait()
if send_recv is "send":
if send_recv == "send":
# we just want to do send and not receive
self._data_channel_send.clear()
self._data_channel_recv.set()
Expand Down
2 changes: 1 addition & 1 deletion conpot/protocols/kamstrup/management_protocol/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def parse_ip(ip_string):
else:
octets = [int(ip_string[i : i + 3]) for i in range(0, len(ip_string), 3)]

if len(octets) is not 4:
if len(octets) != 4:
return default
for octet in octets:
if int(octet) < 0 or int(octet) > 255:
Expand Down
6 changes: 2 additions & 4 deletions conpot/protocols/kamstrup/meter_protocol/decoder_382.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import logging
from conpot.helpers import chr_py3
import crc16
from crc16.crc16pure import crc16xmodem
from . import kamstrup_constants


Expand Down Expand Up @@ -214,9 +214,7 @@ def _decode_cmd_login(self):
@classmethod
def valid_crc(cls, message):
supplied_crc = message[-2] * 256 + message[-1]
calculated_crc = crc16.crc16xmodem(
b"".join([chr_py3(item) for item in message[:-2]])
)
calculated_crc = crc16xmodem(b"".join([chr_py3(item) for item in message[:-2]]))
return supplied_crc == calculated_crc

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions conpot/protocols/kamstrup/meter_protocol/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
import binascii
from conpot.helpers import chr_py3
import crc16
from crc16.crc16pure import crc16xmodem
from . import kamstrup_constants
import conpot.core as conpot_core

Expand Down Expand Up @@ -103,7 +103,7 @@ def serialize(self, message):
final_message.append(c)

# generate and append checksum
crc = crc16.crc16xmodem(b"".join([chr_py3(item) for item in final_message[1:]]))
crc = crc16xmodem(b"".join([chr_py3(item) for item in final_message[1:]]))
final_message.append(crc >> 8)
final_message.append(crc & 0xFF)

Expand Down
6 changes: 2 additions & 4 deletions conpot/protocols/kamstrup/meter_protocol/request_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import logging
from conpot.helpers import chr_py3
import crc16
from crc16.crc16pure import crc16xmodem

from . import kamstrup_constants
from .messages import KamstrupRequestGetRegisters, KamstrupRequestUnknown
Expand Down Expand Up @@ -94,7 +94,5 @@ def get_request(self):
@classmethod
def valid_crc(cls, message):
supplied_crc = message[-2] * 256 + message[-1]
calculated_crc = crc16.crc16xmodem(
b"".join([chr_py3(item) for item in message[:-2]])
)
calculated_crc = crc16xmodem(b"".join([chr_py3(item) for item in message[:-2]]))
return supplied_crc == calculated_crc
8 changes: 4 additions & 4 deletions conpot/protocols/snmp/conpot_cmdrsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def handleMgmtOperation(self, snmpEngine, stateReference, contextName, PDU, acIn
self.log(snmp_version, "Get", addr, varBinds, rspVarBinds, sock)

# apply tarpit delay
if self.tarpit is not 0:
if self.tarpit != 0:
self.do_tarpit(self.tarpit)

# send response
Expand Down Expand Up @@ -204,7 +204,7 @@ def handleMgmtOperation(self, snmpEngine, stateReference, contextName, PDU, acIn
rspVarBinds = rspModBinds

# apply tarpit delay
if self.tarpit is not 0:
if self.tarpit != 0:
self.do_tarpit(self.tarpit)

# send response
Expand Down Expand Up @@ -281,7 +281,7 @@ def handleMgmtOperation(self, snmpEngine, stateReference, contextName, PDU, acIn
self.log(snmp_version, "Bulk", addr, varBinds, rspVarBinds, sock)

# apply tarpit delay
if self.tarpit is not 0:
if self.tarpit != 0:
self.do_tarpit(self.tarpit)

# send response
Expand Down Expand Up @@ -321,7 +321,7 @@ def handleMgmtOperation(self, snmpEngine, stateReference, contextName, PDU, acIn
rspVarBinds = None

# apply tarpit delay
if self.tarpit is not 0:
if self.tarpit != 0:
self.do_tarpit(self.tarpit)

try:
Expand Down
4 changes: 2 additions & 2 deletions conpot/tests/test_tftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_tftp_upload(self):
i for i in _data_fs.listdir("./") if "2018-07-15 17:51:17-test-txt" in i
]
self.assertEqual(
_data_fs.gettext(_file),
_data_fs.readtext(_file),
"This is just a test file for Conpot's TFTP server\n",
)
_data_fs.remove(_file)
Expand All @@ -50,7 +50,7 @@ def test_mkdir_upload(self):
i for i in _data_fs.listdir("./") if "2018-07-15 17:51:17-test-txt" in i
]
self.assertEqual(
_data_fs.gettext(_file),
_data_fs.readtext(_file),
"This is just a test file for Conpot's TFTP server\n",
)
_data_fs.remove(_file)
Expand Down
10 changes: 5 additions & 5 deletions conpot/tests/test_vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ def test_openbin_file(self):
with self.test_vfs.openbin("new_file", mode="wb") as _file:
_file.write(b"This is just a test")
self.assertIn("new_file", self.test_vfs.listdir("/"))
_test = self.test_vfs.gettext("/new_file")
_test = self.test_vfs.readtext("/new_file")
self.test_vfs.getinfo("new_file", namespaces=["basic"])
self.assertEqual(_test, "This is just a test")

def test_open_file(self):
with self.test_vfs.open("new_file", mode="w+") as _file:
_file.write("This is just a test")
self.assertIn("new_file", self.test_vfs.listdir("/"))
_test = self.test_vfs.gettext("/new_file")
_test = self.test_vfs.readtext("/new_file")
self.test_vfs.getinfo("new_file", namespaces=["basic"])
self.assertEqual(_test, "This is just a test")

Expand Down Expand Up @@ -306,7 +306,7 @@ def test_copyfile(self):
self.test_vfs.copy(
src_path="test_fs.txt", dst_path="test_fs_copy.txt", overwrite=True
)
_text = self.test_vfs.gettext("test_fs_copy.txt")
_text = self.test_vfs.readtext("test_fs_copy.txt")
self.assertEqual(_text, "This is just a test file checking copyfile")
self.assertTrue(self.test_vfs.getbasic("test_fs_copy.txt"))

Expand All @@ -317,7 +317,7 @@ def test_movefile(self):
_file.write("This is just a test file checking copyfile")
_uid = self.test_vfs.getinfo("test_fs.txt", namespaces=["access"]).uid
self.test_vfs.move("test_fs.txt", "test_fs_copy.txt", overwrite=True)
_text = self.test_vfs.gettext("test_fs_copy.txt")
_text = self.test_vfs.readtext("test_fs_copy.txt")
self.assertEqual(
self.test_vfs.getinfo("test_fs_copy.txt", namespaces=["access"]).uid, _uid
)
Expand Down Expand Up @@ -402,7 +402,7 @@ def test_open_file(self):
self.test_vfs.settimes(
"/new_file", accessed=datetime.now(), modified=datetime.now()
)
_test = self.test_vfs.gettext("/new_file")
_test = self.test_vfs.readtext("/new_file")
self.assertEqual(_test, "This is just a test")
self.assertEqual(
self.test_vfs.getinfo("new_file", namespaces=["details"]).modified.ctime(),
Expand Down

0 comments on commit 83d0738

Please sign in to comment.