Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit cf36dd0

Browse files
committed
Python 3 support -- supporting scripts
Application of python-modernize to scripts in src/lib/support
1 parent 8942ff6 commit cf36dd0

File tree

3 files changed

+125
-118
lines changed

3 files changed

+125
-118
lines changed

src/lib/support/gen-oid-table.py

Lines changed: 108 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# TLV encodings (notably the Weave Certificate object).
2525
#
2626

27+
from __future__ import absolute_import
28+
from __future__ import print_function
2729
import sys
2830

2931
def identity(n):
@@ -221,126 +223,126 @@ def encodeOID(oid):
221223

222224
return encodedOID
223225

224-
print "/*"
225-
print " *"
226-
print " * Copyright (c) 2019 Google LLC."
227-
print " * Copyright (c) 2013-2017 Nest Labs, Inc."
228-
print " * All rights reserved."
229-
print " *"
230-
print " * Licensed under the Apache License, Version 2.0 (the \"License\");"
231-
print " * you may not use this file except in compliance with the License."
232-
print " * You may obtain a copy of the License at"
233-
print " *"
234-
print " * http://www.apache.org/licenses/LICENSE-2.0"
235-
print " *"
236-
print " * Unless required by applicable law or agreed to in writing, software"
237-
print " * distributed under the License is distributed on an \"AS IS\" BASIS,"
238-
print " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."
239-
print " * See the License for the specific language governing permissions and"
240-
print " * limitations under the License."
241-
print " *"
242-
print " */"
243-
print ""
244-
print "/**"
245-
print " * @file"
246-
print " * ASN.1 Object ID Definitions"
247-
print " *"
248-
print " * !!! WARNING !!! WARNING !!! WARNING !!!"
249-
print " *"
250-
print " * DO NOT EDIT THIS FILE! This file is generated by the"
251-
print " * gen-oid-table.py script."
252-
print " *"
253-
print " * To make changes, edit the script and re-run it to generate"
254-
print " * this file."
255-
print " *"
256-
print " */"
257-
print ""
258-
print "#ifndef ASN1OID_H_"
259-
print "#define ASN1OID_H_"
260-
print ""
261-
print "enum OIDCategory"
262-
print "{"
226+
print("/*")
227+
print(" *")
228+
print(" * Copyright (c) 2019 Google LLC.")
229+
print(" * Copyright (c) 2013-2017 Nest Labs, Inc.")
230+
print(" * All rights reserved.")
231+
print(" *")
232+
print(" * Licensed under the Apache License, Version 2.0 (the \"License\");")
233+
print(" * you may not use this file except in compliance with the License.")
234+
print(" * You may obtain a copy of the License at")
235+
print(" *")
236+
print(" * http://www.apache.org/licenses/LICENSE-2.0")
237+
print(" *")
238+
print(" * Unless required by applicable law or agreed to in writing, software")
239+
print(" * distributed under the License is distributed on an \"AS IS\" BASIS,")
240+
print(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.")
241+
print(" * See the License for the specific language governing permissions and")
242+
print(" * limitations under the License.")
243+
print(" *")
244+
print(" */")
245+
print("")
246+
print("/**")
247+
print(" * @file")
248+
print(" * ASN.1 Object ID Definitions")
249+
print(" *")
250+
print(" * !!! WARNING !!! WARNING !!! WARNING !!!")
251+
print(" *")
252+
print(" * DO NOT EDIT THIS FILE! This file is generated by the")
253+
print(" * gen-oid-table.py script.")
254+
print(" *")
255+
print(" * To make changes, edit the script and re-run it to generate")
256+
print(" * this file.")
257+
print(" *")
258+
print(" */")
259+
print("")
260+
print("#ifndef ASN1OID_H_")
261+
print("#define ASN1OID_H_")
262+
print("")
263+
print("enum OIDCategory")
264+
print("{")
263265
for (catName, catEnum) in oidCategories:
264-
print " kOIDCategory_%s = 0x%04X," % (catName, catEnum)
265-
print ""
266-
print " kOIDCategory_NotSpecified = 0,"
267-
print " kOIDCategory_Unknown = 0x0F00,"
268-
print " kOIDCategory_Mask = 0x0F00"
269-
print "};"
270-
print ""
271-
272-
print "typedef uint16_t OID;"
273-
print ""
274-
275-
print "enum"
276-
print "{"
266+
print(" kOIDCategory_%s = 0x%04X," % (catName, catEnum))
267+
print("")
268+
print(" kOIDCategory_NotSpecified = 0,")
269+
print(" kOIDCategory_Unknown = 0x0F00,")
270+
print(" kOIDCategory_Mask = 0x0F00")
271+
print("};")
272+
print("")
273+
274+
print("typedef uint16_t OID;")
275+
print("")
276+
277+
print("enum")
278+
print("{")
277279
for (catName, catEnum) in oidCategories:
278280
for (oidCatName, oidName, oidEnum, oid) in oids:
279281
if (oidCatName == catName):
280-
print " kOID_%s_%s = 0x%04X," % (catName, oidName, catEnum + oidEnum)
281-
print ""
282-
print " kOID_NotSpecified = 0,"
283-
print " kOID_Unknown = 0xFFFF,"
284-
print " kOID_Mask = 0x00FF"
285-
print "};"
286-
print ""
287-
288-
print "struct OIDTableEntry"
289-
print "{"
290-
print " OID EnumVal;"
291-
print " const uint8_t *EncodedOID;"
292-
print " uint16_t EncodedOIDLen;"
293-
print "};"
294-
print ""
295-
296-
print "struct OIDNameTableEntry"
297-
print "{"
298-
print " OID EnumVal;"
299-
print " const char *Name;"
300-
print "};"
301-
print ""
302-
303-
print "extern const OIDTableEntry sOIDTable[];"
304-
print "extern const OIDNameTableEntry sOIDNameTable[];"
305-
print "extern const size_t sOIDTableSize;"
306-
print ""
307-
308-
print "#ifdef ASN1_DEFINE_OID_TABLE"
309-
print ""
282+
print(" kOID_%s_%s = 0x%04X," % (catName, oidName, catEnum + oidEnum))
283+
print("")
284+
print(" kOID_NotSpecified = 0,")
285+
print(" kOID_Unknown = 0xFFFF,")
286+
print(" kOID_Mask = 0x00FF")
287+
print("};")
288+
print("")
289+
290+
print("struct OIDTableEntry")
291+
print("{")
292+
print(" OID EnumVal;")
293+
print(" const uint8_t *EncodedOID;")
294+
print(" uint16_t EncodedOIDLen;")
295+
print("};")
296+
print("")
297+
298+
print("struct OIDNameTableEntry")
299+
print("{")
300+
print(" OID EnumVal;")
301+
print(" const char *Name;")
302+
print("};")
303+
print("")
304+
305+
print("extern const OIDTableEntry sOIDTable[];")
306+
print("extern const OIDNameTableEntry sOIDNameTable[];")
307+
print("extern const size_t sOIDTableSize;")
308+
print("")
309+
310+
print("#ifdef ASN1_DEFINE_OID_TABLE")
311+
print("")
310312

311313
for (catName, oidName, oidEnum, oid) in oids:
312-
print "static const uint8_t sOID_%s_%s[] = { %s };" % (catName, oidName, ", ".join([ "0x%02X" % (x) for x in encodeOID(oid) ]))
313-
print ""
314+
print("static const uint8_t sOID_%s_%s[] = { %s };" % (catName, oidName, ", ".join([ "0x%02X" % (x) for x in encodeOID(oid) ])))
315+
print("")
314316

315-
print "const OIDTableEntry sOIDTable[] ="
316-
print "{"
317+
print("const OIDTableEntry sOIDTable[] =")
318+
print("{")
317319
oidTableSize = 0
318320
for (catName, oidName, oidEnum, oid) in oids:
319-
print " { kOID_%s_%s, sOID_%s_%s, sizeof(sOID_%s_%s) }," % (catName, oidName, catName, oidName, catName, oidName)
321+
print(" { kOID_%s_%s, sOID_%s_%s, sizeof(sOID_%s_%s) }," % (catName, oidName, catName, oidName, catName, oidName))
320322
oidTableSize += 1
321-
print " { kOID_NotSpecified, NULL, 0 }"
322-
print "};"
323-
print ""
323+
print(" { kOID_NotSpecified, NULL, 0 }")
324+
print("};")
325+
print("")
324326

325-
print "const size_t sOIDTableSize = %d;" % (oidTableSize)
326-
print ""
327+
print("const size_t sOIDTableSize = %d;" % (oidTableSize))
328+
print("")
327329

328-
print "#endif // ASN1_DEFINE_OID_TABLE"
329-
print ""
330+
print("#endif // ASN1_DEFINE_OID_TABLE")
331+
print("")
330332

331-
print "#ifdef ASN1_DEFINE_OID_NAME_TABLE"
332-
print ""
333+
print("#ifdef ASN1_DEFINE_OID_NAME_TABLE")
334+
print("")
333335

334-
print "const OIDNameTableEntry sOIDNameTable[] ="
335-
print "{"
336+
print("const OIDNameTableEntry sOIDNameTable[] =")
337+
print("{")
336338
for (catName, oidName, oidEnum, oid) in oids:
337-
print " { kOID_%s_%s, \"%s\" }," % (catName, oidName, oidName)
338-
print " { kOID_NotSpecified, NULL }"
339-
print "};"
340-
print ""
339+
print(" { kOID_%s_%s, \"%s\" }," % (catName, oidName, oidName))
340+
print(" { kOID_NotSpecified, NULL }")
341+
print("};")
342+
print("")
341343

342-
print "#endif // ASN1_DEFINE_OID_NAME_TABLE"
343-
print ""
344+
print("#endif // ASN1_DEFINE_OID_NAME_TABLE")
345+
print("")
344346

345-
print ""
346-
print "#endif // ASN1OID_H_"
347+
print("")
348+
print("#endif // ASN1OID_H_")

src/lib/support/ula/make-ula-global-id.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"""Tool for making unique pseudo-random global identifiers (Global IDs) for IPv6 unique local addresses (ULAs) according to Section 3.2.2 of RFC 4193.
2828
"""
2929

30+
from __future__ import absolute_import
31+
from __future__ import print_function
3032
import sys
3133
import os
3234
import re
@@ -97,11 +99,11 @@ def MakeULAGlobalId(macAddr, timeStamp=datetime.utcnow()):
9799
"""
98100

99101
if len(sys.argv) < 2:
100-
print usage
102+
print(usage)
101103
sys.exit(-1)
102104

103105
if len(sys.argv) > 4:
104-
print "Unexpected argument: %s" % (sys.argv[3])
106+
print("Unexpected argument: %s" % (sys.argv[3]))
105107
sys.exit(-1)
106108

107109
macAddr = sys.argv[1]
@@ -117,4 +119,4 @@ def MakeULAGlobalId(macAddr, timeStamp=datetime.utcnow()):
117119
else:
118120
timeStamp = datetime.utcnow()
119121

120-
print ("%s::/48") % MakeULAGlobalId(macAddr, timeStamp)
122+
print(("%s::/48") % MakeULAGlobalId(macAddr, timeStamp))

src/lib/support/verhoeff/Verhoeff.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
# a given base.
2626
#
2727

28+
from __future__ import absolute_import
29+
from __future__ import print_function
2830
import sys
31+
from six.moves import range
2932

3033
__all__ = [ 'ComputeCheckChar', 'VerifyCheckChar',
3134
'ComputeCheckChar16', 'VerifyCheckChar16',
@@ -123,30 +126,30 @@ def VerifyCheckChar36(str, charSet=CharSet_Base36):
123126
""" % (sys.argv[0])
124127

125128
if (len(sys.argv) < 2):
126-
print usage
129+
print(usage)
127130
elif (sys.argv[1] == "generate"):
128131
if (len(sys.argv) < 3):
129-
print usage
132+
print(usage)
130133
sys.exit(-1)
131134
ch = ComputeCheckChar(sys.argv[2])
132-
print "%s%c" % (sys.argv[2], ch)
135+
print("%s%c" % (sys.argv[2], ch))
133136
elif (sys.argv[1] == "verify"):
134137
if (len(sys.argv) < 3):
135-
print usage
138+
print(usage)
136139
sys.exit(-1)
137140
if (VerifyCheckChar(sys.argv[2])):
138-
print "%s is VALID" % (sys.argv[2])
141+
print("%s is VALID" % (sys.argv[2]))
139142
sys.exit(0)
140143
else:
141-
print "%s is INVALID" % (sys.argv[2])
144+
print("%s is INVALID" % (sys.argv[2]))
142145
sys.exit(-1)
143146
elif (sys.argv[1] == "gen-multiply-table"):
144147
if (len(sys.argv) < 3):
145-
print usage
148+
print(usage)
146149
sys.exit(-1)
147150
base = int(sys.argv[2])
148151
if (base % 2 != 0):
149-
print "Base must be even"
152+
print("Base must be even")
150153
sys.exit(-1);
151154
n = base / 2
152155
for x in range(0, base):
@@ -156,7 +159,7 @@ def VerifyCheckChar36(str, charSet=CharSet_Base36):
156159
sys.stdout.write("%2d, " % o)
157160
sys.stdout.write("\n")
158161
else:
159-
print usage
162+
print(usage)
160163
sys.exit(-1)
161164
sys.exit(0)
162165

0 commit comments

Comments
 (0)