ยปCore Development>Code coverage>Lib/tkinter/_fix.py

Python code coverage for Lib/tkinter/_fix.py

#countcontent
1n/aimport sys, os
2n/a
3n/a# Delay import _tkinter until we have set TCL_LIBRARY,
4n/a# so that Tcl_FindExecutable has a chance to locate its
5n/a# encoding directory.
6n/a
7n/a# Unfortunately, we cannot know the TCL_LIBRARY directory
8n/a# if we don't know the tcl version, which we cannot find out
9n/a# without import Tcl. Fortunately, Tcl will itself look in
10n/a# <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
11n/a# the real Tcl library will do.
12n/a
13n/a# Expand symbolic links on Vista
14n/atry:
15n/a import ctypes
16n/a ctypes.windll.kernel32.GetFinalPathNameByHandleW
17n/aexcept (ImportError, AttributeError):
18n/a def convert_path(s):
19n/a return s
20n/aelse:
21n/a def convert_path(s):
22n/a if isinstance(s, bytes):
23n/a s = s.decode("mbcs")
24n/a hdir = ctypes.windll.kernel32.\
25n/a CreateFileW(s, 0x80, # FILE_READ_ATTRIBUTES
26n/a 1, # FILE_SHARE_READ
27n/a None, 3, # OPEN_EXISTING
28n/a 0x02000000, # FILE_FLAG_BACKUP_SEMANTICS
29n/a None)
30n/a if hdir == -1:
31n/a # Cannot open directory, give up
32n/a return s
33n/a buf = ctypes.create_unicode_buffer("", 32768)
34n/a res = ctypes.windll.kernel32.\
35n/a GetFinalPathNameByHandleW(hdir, buf, len(buf),
36n/a 0) # VOLUME_NAME_DOS
37n/a ctypes.windll.kernel32.CloseHandle(hdir)
38n/a if res == 0:
39n/a # Conversion failed (e.g. network location)
40n/a return s
41n/a s = buf[:res]
42n/a # Ignore leading \\?\
43n/a if s.startswith("\\\\?\\"):
44n/a s = s[4:]
45n/a if s.startswith("UNC"):
46n/a s = "\\" + s[3:]
47n/a return s
48n/a
49n/aprefix = os.path.join(sys.base_prefix,"tcl")
50n/aif not os.path.exists(prefix):
51n/a # devdir/../tcltk/lib
52n/a prefix = os.path.join(sys.base_prefix, os.path.pardir, "tcltk", "lib")
53n/a prefix = os.path.abspath(prefix)
54n/a# if this does not exist, no further search is needed
55n/aif os.path.exists(prefix):
56n/a prefix = convert_path(prefix)
57n/a if "TCL_LIBRARY" not in os.environ:
58n/a for name in os.listdir(prefix):
59n/a if name.startswith("tcl"):
60n/a tcldir = os.path.join(prefix,name)
61n/a if os.path.isdir(tcldir):
62n/a os.environ["TCL_LIBRARY"] = tcldir
63n/a # Compute TK_LIBRARY, knowing that it has the same version
64n/a # as Tcl
65n/a import _tkinter
66n/a ver = str(_tkinter.TCL_VERSION)
67n/a if "TK_LIBRARY" not in os.environ:
68n/a v = os.path.join(prefix, 'tk'+ver)
69n/a if os.path.exists(os.path.join(v, "tclIndex")):
70n/a os.environ['TK_LIBRARY'] = v
71n/a # We don't know the Tix version, so we must search the entire
72n/a # directory
73n/a if "TIX_LIBRARY" not in os.environ:
74n/a for name in os.listdir(prefix):
75n/a if name.startswith("tix"):
76n/a tixdir = os.path.join(prefix,name)
77n/a if os.path.isdir(tixdir):
78n/a os.environ["TIX_LIBRARY"] = tixdir