ctables: string/bytes confusion. genutil:funcs for idioms I keep replacing

Change-Id: Ic1bce8efd82be80b9911b62d0b932eba0a08ed08
(cherry picked from commit adb6a4f9032feef846f6e81660424963c18cf7da)
This commit is contained in:
Mark Charney
2017-06-11 13:22:21 -04:00
parent fa988755e2
commit 9983af67b9
2 changed files with 10 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ class constant_table_t(object):
def dump(self):
print("%s(%s)::" % (self.name, self.operand))
for (v,p) in self.value_string_pairs:
if isinstance(p, bytes):
if genutil.is_stringish(p):
print("%s '%s'" % (hex(v),p))
else:
print("%s error" %(hex(v)))
@@ -78,7 +78,7 @@ class constant_table_t(object):
lines.append('static const char* %s[] = {' % (self.string_table_name))
for (v,p) in self.value_string_pairs:
if isinstance(p, bytes):
if genutil.is_stringish(p):
lines.append( '/*%s*/ "%s",' % (hex(v),p))
else:
lines.append( '/*%s*/ 0, /* error */' % (hex(v)))

View File

@@ -425,3 +425,11 @@ def uniqueify(values):
k.sort()
return k
def is_stringish(x):
return isinstance(x,bytes) or isinstance(x,str)
def make_list_of_str(lst):
return [ str(x) for x in lst]
def open_readlines(fn):
return open(f,'r').readlines()