Files
James Gross a7b5f8deef Py3 cutover (try number: who knows?) (#328)
Massive cutover to python3 (baseline is 3.9.1, but is also tested/working on 3.7.x). This merge is a breaking change for any downstream consumers, as the python 2->3 strings/bytes change is central. Most APIs should still work roughly as intended, as I didn't majorly re-organize the codebase, so most APIs live where they lived before. But a changelog/migration guide will be included in the next PR for this.

This PR will constitute most if not all of the v1.0.0 release that is forthcoming soon.
2021-02-03 14:37:09 -05:00

35 lines
930 B
Python

class VSConstResolver:
def __init__(self):
self.rev_lookup = {}
self.const_lookup = {}
def clearAll(self):
self.rev_lookup = {}
self.const_lookup = {}
def addModule(self, mod):
for name in dir(mod):
val = getattr(mod, name)
if type(val) is not int:
continue
# First lets add the "reverse" lookup
revs = self.rev_lookup.get(val)
if revs is None:
revs = []
self.rev_lookup[val] = revs
revs.append(name)
# Now the forward....
self.const_lookup[name] = val
def constLookup(self, name):
return self.const_lookup.get(name)
def revLookup(self, const):
'''
Lookup the possible names of a constant based on
modules added with constAddModule()
'''
return self.rev_lookup.get(const)