Clean up printf((...) and some imports

This commit is contained in:
Björn Freise 2019-04-23 11:37:18 +02:00
parent db4c8ec5ed
commit 5da871355a
15 changed files with 25 additions and 33 deletions

View file

@ -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")

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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):

View file

@ -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'

View file

@ -1,4 +1,4 @@
import logging.config
import logging
import random
import socket
import struct

View file

@ -73,7 +73,6 @@ class Option(object):
else:
if value is not None:
value = bytes(value, "utf-8")
self._value = value
@property

View file

@ -1,4 +1,4 @@
import logging.config
import logging
import random
import socket
import struct

View file

@ -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:

View file

@ -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'

View file

@ -1138,7 +1138,7 @@ class Tests(unittest.TestCase):
expected.token = None
expected.payload = "<value>0</value>"
print((expected.pretty_print()))
print(expected.pretty_print())
exchange7 = (req, expected)
self.current_mid += 1

View file

@ -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: