Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility for WebIDL.py #5799

Merged
merged 4 commits into from
Nov 20, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions third_party/WebIDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ def parseInt(literal):
return value * sign

# Magic for creating enums
def M_add_class_attribs(attribs, start):
def foo(name, bases, dict_):
for v, k in enumerate(attribs):
dict_[k] = start + v
assert 'length' not in dict_
dict_['length'] = start + len(attribs)
return type(name, bases, dict_)
return foo
def M_add_class_attribs(name, base, attribs, start):
dict_ = dict()
for v, k in enumerate(attribs):
dict_[k] = start + v
assert 'length' not in dict_
dict_['length'] = start + len(attribs)
return type(name, (base,), dict_)

def enum(*names, **kw):
if len(kw) == 1:
Expand All @@ -57,10 +56,10 @@ def enum(*names, **kw):
assert len(kw) == 0
base = object
start = 0
class Foo(base):
__metaclass__ = M_add_class_attribs(names, start)
def __setattr__(self, name, value): # this makes it read-only
raise NotImplementedError
Foo = M_add_class_attribs("Foo", base, names, start)
def __setattr__(self, name, value): # this makes it read-only
raise NotImplementedError
Foo.__setattr__ = __setattr__
return Foo()

class WebIDLError(Exception):
Expand Down Expand Up @@ -644,7 +643,6 @@ def finish(self, scope):
# self.members. Sort our consequential interfaces by name
# just so we have a consistent order.
for iface in sorted(self.getConsequentialInterfaces(),
cmp=cmp,
key=lambda x: x.identifier.name):
# Flag the interface as being someone's consequential interface
iface.setIsConsequentialInterfaceOf(self)
Expand Down Expand Up @@ -1155,7 +1153,7 @@ def finish(self, scope):
assert member.type.isComplete()

# Members of a dictionary are sorted in lexicographic order
self.members.sort(cmp=cmp, key=lambda x: x.identifier.name)
self.members.sort(key=lambda x: x.identifier.name)

inheritedMembers = []
ancestor = self.parent
Expand Down Expand Up @@ -3754,7 +3752,7 @@ def p_Interface(self, p):
[location, p[0].location])
p[0].setNonPartial(location, parent, members)
return
except Exception, ex:
except Exception as ex:
if isinstance(ex, WebIDLError):
raise ex
pass
Expand All @@ -3778,7 +3776,7 @@ def p_InterfaceForwardDecl(self, p):
"%s and %s" % (identifier.name, p[0]),
[location, p[0].location])
return
except Exception, ex:
except Exception as ex:
if isinstance(ex, WebIDLError):
raise ex
pass
Expand All @@ -3805,7 +3803,7 @@ def p_PartialInterface(self, p):
# automatically.
p[0].members.extend(members)
return
except Exception, ex:
except Exception as ex:
if isinstance(ex, WebIDLError):
raise ex
pass
Expand Down Expand Up @@ -4930,8 +4928,8 @@ def __init__(self, outputdir='', lexer=None):
def _installBuiltins(self, scope):
assert isinstance(scope, IDLScope)

# xrange omits the last value.
for x in xrange(IDLBuiltinType.Types.ArrayBuffer, IDLBuiltinType.Types.Float64Array + 1):
# range omits the last value.
for x in range(IDLBuiltinType.Types.ArrayBuffer, IDLBuiltinType.Types.Float64Array + 1):
builtin = BuiltinTypes[x]
name = builtin.name

Expand Down Expand Up @@ -5020,14 +5018,14 @@ def main():
f = open(fullPath, 'rb')
lines = f.readlines()
f.close()
print fullPath
print(fullPath)
parser.parse(''.join(lines), fullPath)
parser.finish()
except WebIDLError, e:
except WebIDLError as e:
if options.verbose_errors:
traceback.print_exc()
else:
print e
print(e)

if __name__ == '__main__':
main()
Expand Down