Skip to content

Commit

Permalink
Python3 compatibility: unicode to str
Browse files Browse the repository at this point in the history
When transitioning from python2 to python3 the following type class
changes occured:

python2 -> python3
unicode -> str
str -> bytes

That means we have to check the python version and do the right type
check python3 will throw an error when it tries to use the unicode
type because it doesn't exist.

Signed-off-by: Jason Wessel <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
jwessel authored and blp committed Jul 6, 2017
1 parent 3fa5aa4 commit 7430959
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ovsdb/ovsdb-doc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ def columnGroupToNroff(table, groupXml, documented_columns):
if node.hasAttribute('type'):
type_string = node.attributes['type'].nodeValue
type_json = ovs.json.from_string(str(type_string))
if type(type_json) in (str, unicode):
raise error.Error("%s %s:%s has invalid 'type': %s"
% (table.name, name, key, type_json))
# py2 -> py3 means str -> bytes and unicode -> str
try:
if type(type_json) in (str, unicode):
raise error.Error("%s %s:%s has invalid 'type': %s"
% (table.name, name, key, type_json))
except:
if type(type_json) in (bytes, str):
raise error.Error("%s %s:%s has invalid 'type': %s"
% (table.name, name, key, type_json))
type_ = ovs.db.types.BaseType.from_json(type_json)
else:
type_ = column.type.value
Expand Down

0 comments on commit 7430959

Please sign in to comment.