How to use the pywatchman.compat.PYTHON2 function in pywatchman

To help you get started, we’ve selected a few pywatchman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / watchman / tests / integration / path_utils.py View on Github external
close_handle = ctypes.windll.kernel32.CloseHandle

        h = open_file_win(name)
        try:
            gfpnbh = ctypes.windll.kernel32.GetFinalPathNameByHandleW
            numwchars = 1024
            while True:
                buf = ctypes.create_unicode_buffer(numwchars)
                result = gfpnbh(h, buf, numwchars, 0)
                if result == 0:
                    raise Exception("unknown error while normalizing path")

                # The first four chars are //?/
                if result <= numwchars:
                    path = buf.value[4:].replace("\\", "/")
                    if compat.PYTHON2:
                        path = path.encode("utf8")
                    return path

                # Not big enough; the result is the amount we need
                numwchars = result + 1
        finally:
            close_handle(h)