# -*- coding: utf-8 -*- """The small Python 2 / Python 3 bridge. We do not choose the interpreter -- pyRevit does, from the engine configured for the host. This extension was written on Revit 2025 with IronPython 2.7, but the same folder may be dropped on a machine whose pyRevit is set to IronPython 3 or CPython 3, where `unicode` and `basestring` are a NameError. A NameError at module scope takes the whole button down with a traceback the user cannot act on, so the two names are resolved once, here. Everything else in this extension is already written in the intersection of the two languages: no f-strings, no print statement, no implicit integer division, no pathlib. Keep it that way and the engine stops mattering. """ try: # Python 2 (IronPython 2.7) text_type = unicode # noqa: F821 string_types = (str, unicode) # noqa: F821 except NameError: # Python 3 (IronPython 3, CPython 3) text_type = str string_types = (str,) def as_text(value, encoding='utf-8'): """Return value as the interpreter's unicode text type.""" if isinstance(value, text_type): return value if isinstance(value, bytes): return value.decode(encoding) return text_type(value)