Skip to content

Commit b1f049a

Browse files
authored
Migrated % string formating (FreeOpcUa#372)
1 parent 55ba0ba commit b1f049a

12 files changed

Lines changed: 21 additions & 21 deletions

opcua/common/callback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def addSubscriber(self, subscriber):
8585
self.addListener(eventName, getattr(subscriber, params))
8686
elif isinstance(params, list):
8787
if not params:
88-
raise ValueError('Invalid params "%r" for event "%s"' % (params, eventName))
88+
raise ValueError('Invalid params "{0!r}" for event "{1!s}"'.format(params, eventName))
8989
if len(params) <= 2 and isinstance(params[0], str):
9090
priority = params[1] if len(params) > 1 else 0
9191
self.addListener(eventName, getattr(subscriber, params[0]), priority)
@@ -94,6 +94,6 @@ def addSubscriber(self, subscriber):
9494
priority = listener[1] if len(listener) > 1 else 0
9595
self.addListener(eventName, getattr(subscriber, listener[0]), priority)
9696
else:
97-
raise ValueError('Invalid params for event "%s"' % eventName)
97+
raise ValueError('Invalid params for event "{0!s}"'.format(eventName))
9898

9999

opcua/common/copy_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ def _read_and_copy_attrs(node_type, struct, addnode):
7373
else:
7474
setattr(struct, name, results[idx].Value.Value)
7575
else:
76-
print("Instantiate: while copying attributes from node type %s, attribute %s, statuscode is %s" % (node_type, name, results[idx].StatusCode))
76+
print("Instantiate: while copying attributes from node type {0!s}, attribute {1!s}, statuscode is {2!s}".format(node_type, name, results[idx].StatusCode))
7777
addnode.NodeAttributes = struct

opcua/common/ua_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def get_base_data_type(datatype):
230230
if base.nodeid.NamespaceIndex == 0 and isinstance(base.nodeid.Identifier, int) and base.nodeid.Identifier <= 30:
231231
return base
232232
base = get_node_supertype(base)
233-
raise ua.UaError("Datatype must be a subtype of builtin types %s" % datatype)
233+
raise ua.UaError("Datatype must be a subtype of builtin types {0!s}".format(datatype))
234234

235235

236236
def get_nodes_of_namespace(server, namespaces=None):

opcua/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def uacall():
704704
elif ( len( methods ) == 1 ):
705705
method_id = methods[0]
706706
else:
707-
raise ValueError( "Selected node has %d methods but no method given. Provide one of %s" % (methods) )
707+
raise ValueError( "Selected node has {0:d} methods but no method given. Provide one of {1!s}".format(*(methods)) )
708708
else:
709709
for m in methods:
710710
if ( m.nodeid.Identifier == args.method ):
@@ -718,7 +718,7 @@ def uacall():
718718
#print( "method_id=%s\nval=%s" % (method_id,val) )
719719

720720
result_variants = node.call_method( method_id, *val )
721-
print( "resulting result_variants=%s" % result_variants )
721+
print( "resulting result_variants={0!s}".format(result_variants) )
722722
finally:
723723
client.disconnect()
724724
sys.exit(0)

opcua/ua/ua_binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def unpack_uatype(vtype, data):
290290
klass = getattr(uatypes, vtype.name)
291291
return klass.from_binary(data)
292292
else:
293-
raise UaError("can not unpack unknown vtype %s" % vtype)
293+
raise UaError("can not unpack unknown vtype {0!s}".format(vtype))
294294

295295

296296
def unpack_uatype_array(vtype, data):

schemas/generate_address_space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def make_header(self, ):
7575
from opcua import ua
7676
7777
78-
def create_standard_address_space_%s(server):
79-
''' % (self.part))
78+
def create_standard_address_space_{0!s}(server):
79+
'''.format((self.part)))
8080

8181
def make_node_code(self, obj, indent):
8282
self.writecode(indent, 'node = ua.AddNodesItem()')

tests/tests_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ class TestClient(unittest.TestCase, CommonTests, SubscriptionTests):
2222
def setUpClass(cls):
2323
# start our own server
2424
cls.srv = Server()
25-
cls.srv.set_endpoint('opc.tcp://localhost:%d' % port_num1)
25+
cls.srv.set_endpoint('opc.tcp://localhost:{0:d}'.format(port_num1))
2626
add_server_methods(cls.srv)
2727
cls.srv.start()
2828

2929
# start admin client
3030
# long timeout since travis (automated testing) can be really slow
31-
cls.clt = Client('opc.tcp://admin@localhost:%d' % port_num1, timeout=10)
31+
cls.clt = Client('opc.tcp://admin@localhost:{0:d}'.format(port_num1), timeout=10)
3232
cls.clt.connect()
3333
cls.opc = cls.clt
3434

3535
# start anonymous client
36-
cls.ro_clt = Client('opc.tcp://localhost:%d' % port_num1)
36+
cls.ro_clt = Client('opc.tcp://localhost:{0:d}'.format(port_num1))
3737
cls.ro_clt.connect()
3838

3939
@classmethod

tests/tests_cmd_lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestCmdLines(unittest.TestCase):
1515
@classmethod
1616
def setUpClass(cls):
1717
cls.srv = Server()
18-
cls.srv_url = 'opc.tcp://localhost:%d' % port_num
18+
cls.srv_url = 'opc.tcp://localhost:{0:d}'.format(port_num)
1919
cls.srv.set_endpoint(cls.srv_url)
2020
objects = cls.srv.get_objects_node()
2121
obj = objects.add_object(4, "directory")

tests/tests_crypto_connect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestCryptoConnect(unittest.TestCase):
2828
def setUpClass(cls):
2929
# start our own server
3030
cls.srv_crypto = Server()
31-
cls.uri_crypto = 'opc.tcp://localhost:%d' % port_num1
31+
cls.uri_crypto = 'opc.tcp://localhost:{0:d}'.format(port_num1)
3232
cls.srv_crypto.set_endpoint(cls.uri_crypto)
3333
# load server certificate and private key. This enables endpoints
3434
# with signing and encryption.
@@ -38,7 +38,7 @@ def setUpClass(cls):
3838

3939
# start a server without crypto
4040
cls.srv_no_crypto = Server()
41-
cls.uri_no_crypto = 'opc.tcp://localhost:%d' % port_num2
41+
cls.uri_no_crypto = 'opc.tcp://localhost:{0:d}'.format(port_num2)
4242
cls.srv_no_crypto.set_endpoint(cls.uri_no_crypto)
4343
cls.srv_no_crypto.start()
4444

tests/tests_history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class HistoryCommon(object):
2424
@classmethod
2525
def start_server_and_client(cls):
2626
cls.srv = Server()
27-
cls.srv.set_endpoint('opc.tcp://localhost:%d' % port_num1)
27+
cls.srv.set_endpoint('opc.tcp://localhost:{0:d}'.format(port_num1))
2828
cls.srv.start()
2929

30-
cls.clt = Client('opc.tcp://localhost:%d' % port_num1)
30+
cls.clt = Client('opc.tcp://localhost:{0:d}'.format(port_num1))
3131
cls.clt.connect()
3232

3333
@classmethod

0 commit comments

Comments
 (0)