Update vendored windows libs

This commit is contained in:
Labrys of Knossos 2022-11-28 05:59:32 -05:00
commit b1cefa94e5
226 changed files with 33472 additions and 11882 deletions

View file

@ -0,0 +1,39 @@
import ctypes
from jaraco.windows import environ
import os
getenv = ctypes.cdll.msvcrt.getenv
getenv.restype = ctypes.c_char_p
putenv = ctypes.cdll.msvcrt._putenv
def do_putenv(*pair):
return putenv("=".join(pair))
def print_environment_variable(key):
for method in (os.environ.get, os.getenv, environ.GetEnvironmentVariable, getenv):
try:
print(repr(method(key)))
except Exception as e:
print(e, end=' ')
print
def do_test():
key = 'TEST_PYTHON_ENVIRONMENT'
print_environment_variable(key)
methods = (
os.environ.__setitem__,
os.putenv,
environ.SetEnvironmentVariable,
do_putenv,
)
for i, method in enumerate(methods):
print('round', i)
method(key, 'value when using method %d' % i)
print_environment_variable(key)
if __name__ == '__main__':
do_test()

View file

@ -0,0 +1,69 @@
import os
def findpath(target, start=os.path.curdir):
r"""
Find a path from start to target where target is relative to start.
>>> orig_wd = os.getcwd()
>>> os.chdir('c:\\windows') # so we know what the working directory is
>>> findpath('d:\\')
'd:\\'
>>> findpath('d:\\', 'c:\\windows')
'd:\\'
>>> findpath('\\bar', 'd:\\')
'd:\\bar'
>>> findpath('\\bar', 'd:\\foo') # fails with '\\bar'
'd:\\bar'
>>> findpath('bar', 'd:\\foo')
'd:\\foo\\bar'
>>> findpath('bar\\baz', 'd:\\foo')
'd:\\foo\\bar\\baz'
>>> findpath('\\baz', 'd:\\foo\\bar') # fails with '\\baz'
'd:\\baz'
Since we're on the C drive, findpath may be allowed to return
relative paths for targets on the same drive. I use abspath to
confirm that the ultimate target is what we expect.
>>> os.path.abspath(findpath('\\bar'))
'c:\\bar'
>>> os.path.abspath(findpath('bar'))
'c:\\windows\\bar'
>>> findpath('..', 'd:\\foo\\bar')
'd:\\foo'
>>> findpath('..\\bar', 'd:\\foo')
'd:\\bar'
The parent of the root directory is the root directory.
>>> findpath('..', 'd:\\')
'd:\\'
restore the original working directory
>>> os.chdir(orig_wd)
"""
return os.path.normpath(os.path.join(start, target))
def main():
import sys
if sys.argv[1:]:
print(findpath(*sys.argv[1:]))
else:
import doctest
doctest.testmod()
if __name__ == '__main__':
main()

View file

@ -0,0 +1,21 @@
from ctypes import CDLL, c_char_p
def get_libc():
libnames = ('msvcrt', 'libc.so.6')
for libname in libnames:
try:
return CDLL(libname)
except WindowsError:
pass
except OSError:
pass
raise RuntimeError("Unable to find a suitable libc (tried %s)" % libnames)
getenv = get_libc().getenv
getenv.restype = c_char_p
# call into your linked module here
print('new value is', getenv('FOO'))

View file

@ -0,0 +1,29 @@
import os
import sys
try:
from jaraco.windows.filesystem import symlink
except ImportError:
# a dirty reimplementation of symlink from jaraco.windows
from ctypes import windll
from ctypes.wintypes import LPWSTR, DWORD, BOOLEAN
CreateSymbolicLink = windll.kernel32.CreateSymbolicLinkW
CreateSymbolicLink.argtypes = (LPWSTR, LPWSTR, DWORD)
CreateSymbolicLink.restype = BOOLEAN
def symlink(link, target, target_is_directory=False):
"""
An implementation of os.symlink for Windows (Vista and greater)
"""
target_is_directory = target_is_directory or os.path.isdir(target)
CreateSymbolicLink(link, target, target_is_directory)
assert sys.platform in ('win32',)
os.makedirs(r'.\foo')
assert os.path.isdir(r'.\foo')
symlink(r'.\foo_sym', r'.\foo')
assert os.path.isdir(r'.\foo_sym')
assert os.path.islink(r'.\foo_sym') # fails

View file

@ -0,0 +1,20 @@
# reported at http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/f43c2faf-3df3-4f11-9f5e-1a9101753f93
from win32wnet import WNetAddConnection2, NETRESOURCE
resource = NETRESOURCE()
resource.lpRemoteName = r'\\aoshi\users'
username = 'jaraco'
res = WNetAddConnection2(resource, UserName=username)
print('first result is', res)
res = WNetAddConnection2(resource, UserName=username)
print('second result is', res)
"""
Output is:
first result is None
Traceback (most recent call last):
File ".\wnetaddconnection2-error-on-64-bit.py", line 7, in <module>
res = WNetAddConnection2(resource, UserName=username)
pywintypes.error: (1219, 'WNetAddConnection2', 'Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.')
"""