diff --git a/coapclient.py b/coapclient.py index e4d4d9a..bffe958 100644 --- a/coapclient.py +++ b/coapclient.py @@ -59,7 +59,7 @@ def main(): # pragma: no cover "payload_file="]) except getopt.GetoptError as err: # print help information and exit: - print((str(err))) # will print something like "option -a not recognized" + print(str(err)) # will print something like "option -a not recognized" usage() sys.exit(2) for o, a in opts: @@ -107,7 +107,7 @@ def main(): # pragma: no cover usage() sys.exit(2) response = client.get(path) - print((response.pretty_print())) + print(response.pretty_print()) client.stop() elif op == "OBSERVE": if path is None: @@ -122,7 +122,7 @@ def main(): # pragma: no cover usage() sys.exit(2) response = client.delete(path) - print((response.pretty_print())) + print(response.pretty_print()) client.stop() elif op == "POST": if path is None: @@ -134,7 +134,7 @@ def main(): # pragma: no cover usage() sys.exit(2) response = client.post(path, payload) - print((response.pretty_print())) + print(response.pretty_print()) client.stop() elif op == "PUT": if path is None: @@ -146,11 +146,11 @@ def main(): # pragma: no cover usage() sys.exit(2) response = client.put(path, payload) - print((response.pretty_print())) + print(response.pretty_print()) client.stop() elif op == "DISCOVER": response = client.discover() - print((response.pretty_print())) + print(response.pretty_print()) client.stop() else: print("Operation not recognized") diff --git a/coapforwardproxy.py b/coapforwardproxy.py index 9a6e1d5..36eec0a 100644 --- a/coapforwardproxy.py +++ b/coapforwardproxy.py @@ -11,7 +11,7 @@ class CoAPForwardProxy(CoAP): def __init__(self, host, port, multicast=False, cache=False): CoAP.__init__(self, (host, port), multicast=multicast, cache=cache) - print(("CoAP Proxy start on " + host + ":" + str(port))) + print("CoAP Proxy start on " + host + ":" + str(port)) def usage(): # pragma: no cover diff --git a/coapping.py b/coapping.py index 8ba6787..945dd38 100644 --- a/coapping.py +++ b/coapping.py @@ -51,7 +51,7 @@ if __name__ == '__main__': ping_cnt = 0 # global ping cnt print('COAP ping script') - print(('COAP ping to: %s:%s...' % (host, port))) + print('COAP ping to: %s:%s...' % (host, port)) try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -69,8 +69,8 @@ if __name__ == '__main__': msg += struct.pack("B", ping_no) try : - print(('[0x%08X] Send ping:' % (ping_cnt), [hex(ord(c)) for c in msg])) - #Set the whole string + print('[0x%08X] Send ping:' % (ping_cnt), [hex(ord(c)) for c in msg]) + # Set the whole string s.sendto(msg, (host, port)) s.settimeout(2 + sleep_sec) @@ -81,11 +81,10 @@ if __name__ == '__main__': # We need to check if ping peyload counter is the same in reply status = bytes(msg)[3] == bytes(reply)[3] - print(('[0x%08X] Recv ping:' % (ping_cnt), [hex(ord(c)) for c in reply], 'ok' if status else 'fail')) + print('[0x%08X] Recv ping:' % (ping_cnt), [hex(ord(c)) for c in reply], 'ok' if status else 'fail') except socket.error as e: - print(('Error: socket.error: ', str(e))) - #print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1] + print('Error: socket.error: ', str(e)) sleep(3) # Waiting to recover ;) except socket.timeout: print("Error: closing socket") diff --git a/coapreverseproxy.py b/coapreverseproxy.py index b93fb44..943e5dc 100644 --- a/coapreverseproxy.py +++ b/coapreverseproxy.py @@ -12,7 +12,7 @@ class CoAPReverseProxy(CoAP): CoAP.__init__(self, (host, port), xml_file=xml_file, multicast=multicast, starting_mid=starting_mid, cache=cache) - print(("CoAP Proxy start on " + host + ":" + str(port))) + print("CoAP Proxy start on " + host + ":" + str(port)) def usage(): # pragma: no cover diff --git a/coapserver.py b/coapserver.py index aef8b9c..a5ebf57 100644 --- a/coapserver.py +++ b/coapserver.py @@ -26,8 +26,8 @@ class CoAPServer(CoAP): self.add_resource('advanced/', AdvancedResource()) self.add_resource('advancedSeparate/', AdvancedResourceSeparate()) - print(("CoAP Server start on " + host + ":" + str(port))) - print((self.root.dump())) + print("CoAP Server start on " + host + ":" + str(port)) + print(self.root.dump()) def usage(): # pragma: no cover diff --git a/coapthon/caching/coaplrucache.py b/coapthon/caching/coaplrucache.py index 3a536ef..545e8f2 100644 --- a/coapthon/caching/coaplrucache.py +++ b/coapthon/caching/coaplrucache.py @@ -23,8 +23,7 @@ class CoapLRUCache(CoapCache): :param element: :return: """ - logger.debug("updating cache, key: %s, element: %s", \ - key.hashkey, element) + logger.debug("updating cache, key: %s, element: %s", key.hashkey, element) self.cache.update([(key.hashkey, element)]) def get(self, key): diff --git a/coapthon/client/coap.py b/coapthon/client/coap.py index d2bed4c..5cfa41c 100644 --- a/coapthon/client/coap.py +++ b/coapthon/client/coap.py @@ -1,9 +1,9 @@ -import logging.config -import os +import logging import random import socket import threading import time +import collections from coapthon import defines from coapthon.layers.blocklayer import BlockLayer @@ -14,7 +14,6 @@ from coapthon.messages.message import Message from coapthon.messages.request import Request from coapthon.messages.response import Response from coapthon.serializer import Serializer -import collections __author__ = 'Giacomo Tanganelli' diff --git a/coapthon/forward_proxy/coap.py b/coapthon/forward_proxy/coap.py index b448cca..654a165 100644 --- a/coapthon/forward_proxy/coap.py +++ b/coapthon/forward_proxy/coap.py @@ -1,4 +1,4 @@ -import logging.config +import logging import random import socket import struct diff --git a/coapthon/layers/resourcelayer.py b/coapthon/layers/resourcelayer.py index 5e1f659..41b5b81 100644 --- a/coapthon/layers/resourcelayer.py +++ b/coapthon/layers/resourcelayer.py @@ -229,7 +229,7 @@ class ResourceLayer(object): lp = path parent_resource = self._parent.root[imax] if parent_resource.allow_children: - return self.add_resource(transaction, parent_resource, lp) + return self.add_resource(transaction, parent_resource, lp) else: transaction.response.code = defines.Codes.METHOD_NOT_ALLOWED.number return transaction diff --git a/coapthon/messages/option.py b/coapthon/messages/option.py index 9906576..8e7104f 100644 --- a/coapthon/messages/option.py +++ b/coapthon/messages/option.py @@ -73,7 +73,6 @@ class Option(object): else: if value is not None: value = bytes(value, "utf-8") - self._value = value @property diff --git a/coapthon/reverse_proxy/coap.py b/coapthon/reverse_proxy/coap.py index 61ba364..32bbce5 100644 --- a/coapthon/reverse_proxy/coap.py +++ b/coapthon/reverse_proxy/coap.py @@ -1,4 +1,4 @@ -import logging.config +import logging import random import socket import struct diff --git a/coapthon/serializer.py b/coapthon/serializer.py index f938eeb..bd5593f 100644 --- a/coapthon/serializer.py +++ b/coapthon/serializer.py @@ -200,7 +200,6 @@ class Serializer(object): elif opt_type == defines.STRING: fmt += str(len(bytes(option.value, "utf-8"))) + "s" values.append(bytes(option.value, "utf-8")) - else: # OPAQUE for b in option.value: fmt += "B" @@ -225,9 +224,6 @@ class Serializer(object): else: fmt += str(len(bytes(payload, "utf-8"))) + "s" values.append(bytes(payload, "utf-8")) - # for b in str(payload): - # fmt += "c" - # values.append(bytes(b, "utf-8")) datagram = None if values[1] is None: diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index 3b14f5b..dfc25a1 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -4,6 +4,7 @@ import random import socket import struct import threading +import collections from coapthon import defines from coapthon.layers.blocklayer import BlockLayer @@ -17,7 +18,6 @@ from coapthon.messages.response import Response from coapthon.resources.resource import Resource from coapthon.serializer import Serializer from coapthon.utils import Tree, create_logging -import collections __author__ = 'Giacomo Tanganelli' diff --git a/coverage_test.py b/coverage_test.py index 3fb397b..2546c8c 100644 --- a/coverage_test.py +++ b/coverage_test.py @@ -1138,7 +1138,7 @@ class Tests(unittest.TestCase): expected.token = None expected.payload = "0" - print((expected.pretty_print())) + print(expected.pretty_print()) exchange7 = (req, expected) self.current_mid += 1 diff --git a/coverage_test_proxy.py b/coverage_test_proxy.py index cf27a66..153a8ae 100644 --- a/coverage_test_proxy.py +++ b/coverage_test_proxy.py @@ -105,8 +105,8 @@ class Tests(unittest.TestCase): if expected is not None: datagram, source = sock.recvfrom(4096) received_message = serializer.deserialize(datagram, source) - print((received_message.pretty_print())) - print((expected.pretty_print())) + print(received_message.pretty_print()) + print(expected.pretty_print()) if expected.type is not None: self.assertEqual(received_message.type, expected.type) if expected.mid is not None: