def build(self):
if (any(platform.win32_ver())):
stroutput = self.remove_accents(self.output)
else:
stroutput = self.output
cmd = {'sender': self.sender,
'receiver': self.receiver,
'output': stroutput,
'cmd': self.cmd,
'jobid': self.jobid}
return base64.b64encode(json.dumps(cmd))
#------------------------------------------------------------------------------
# Class ChromePasswords
#------------------------------------------------------------------------------
python类win32_ver()的实例源码
def __convert_csv_to_coocur_dict(self, res_folder):
import csv, win32api
import platform
cooccurrence_counts = defaultdict(float)
new_words = []
res_folder_gen = [label_folder for label_folder in os.listdir(res_folder) if label_folder[:2] != SUCCESS_HEADER]
for label_folder in res_folder_gen:
csv_gen = [csv_fname for csv_fname in os.listdir(os.path.join(res_folder, label_folder)) if csv_fname[-3:] == 'csv']
for csv_fname in csv_gen:
if any(platform.win32_ver()):
csv_file = win32api.GetShortPathName(os.path.join(win32api.GetShortPathName(res_folder), label_folder, csv_fname))
else:
csv_file = os.path.join(res_folder, label_folder, csv_fname)
reader = csv.DictReader(open(csv_file), fieldnames=['tgt_word', 'ctx_word', 'coor_val'])
for row in reader:
target_word = row['tgt_word']
context_word = row['ctx_word']
print(row['tgt_word'])
if (self.__embeddings is None or target_word not in self.__embeddings.keys()) and target_word not in new_words:
new_words.append(target_word)
if (self.__embeddings is None or context_word not in self.__embeddings.keys()) and context_word not in new_words:
new_words.append(context_word)
cooccurrence_counts[(target_word, context_word)] = row['coor_val']
self.__new_words = new_words
return cooccurrence_counts
def system_info():
import constructor, sys, platform
import conda.exports, conda.config
out = {'constructor': constructor.__version__,
'conda': conda.__version__,
'platform': sys.platform,
'python': sys.version,
'python_version': tuple(sys.version_info),
'machine': platform.machine(),
'platform_full': platform.version()}
if sys.platform == 'darwin':
out['extra'] = platform.mac_ver()
elif sys.platform.startswith('linux'):
out['extra'] = platform.dist()
elif sys.platform.startswith('win'):
out['extra'] = platform.win32_ver()
prefix = os.environ.get('CONDA_PREFIX', conda.config.default_prefix)
prefix_records = conda.exports.linked_data(prefix).values()
nsis_prefix_rec = next(
(rec for rec in prefix_records if rec.name == 'nsis'), None)
if nsis_prefix_rec:
out['nsis'] = nsis_prefix_rec.version
return out
def run(self):
'''Begin processing events, scheduled functions and window updates.
This method returns when `has_exit` is set to True.
Developers are discouraged from overriding this method, as the
implementation is platform-specific.
'''
self.has_exit = False
self._legacy_setup()
platform_event_loop = app.platform_event_loop
platform_event_loop.start()
self.dispatch_event('on_enter')
self.is_running = True
if compat_platform == 'win32' and int(platform.win32_ver()[0]) <= 5:
self._run_estimated()
else:
self._run()
self.is_running = False
self.dispatch_event('on_exit')
platform_event_loop.stop()
def run(self):
'''Begin processing events, scheduled functions and window updates.
This method returns when `has_exit` is set to True.
Developers are discouraged from overriding this method, as the
implementation is platform-specific.
'''
self.has_exit = False
self._legacy_setup()
platform_event_loop = app.platform_event_loop
platform_event_loop.start()
self.dispatch_event('on_enter')
self.is_running = True
if compat_platform == 'win32' and int(platform.win32_ver()[0]) <= 5:
self._run_estimated()
else:
self._run()
self.is_running = False
self.dispatch_event('on_exit')
platform_event_loop.stop()
def __register_font(self):
'''
????????,?????????????
:return:
'''
if platform.system() == 'Windows':
if platform.win32_ver()[0] == '8':
__platform = 'Win8'
else:
__platform = 'Win7orLower'
elif platform.system() == 'Linux':
__platform = 'Linux'
else:
__platform = 'MacOS'
if __platform != 'Win7orLower':
if __platform == 'Win8':
pdfmetrics.registerFont(TTFont('chsFont','msyh.TTC'))
elif __platform == 'MacOS':
pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
elif __platform == 'Linux': #???linux??????????????????
pdfmetrics.registerFont(TTFont('chsFont','STHeiti Light.ttc'))
else:
pdfmetrics.registerFont(TTFont('chsFont','msyh.TTF'))
def sys_info():
result = {
'platform': '{} [{}]'.format(platform.platform(), platform.version()),
'python': '{} {}'.format(
platform.python_implementation(),
sys.version.replace('\n', '')
),
'os': 'Unknown'
}
linux_ver = platform.linux_distribution()
mac_ver = platform.mac_ver()
win_ver = platform.win32_ver()
if linux_ver[0]:
result['os'] = 'Linux - {}'.format(' '.join(linux_ver))
elif mac_ver[0]:
result['os'] = 'OS X - {}'.format(' '.join(mac_ver[::2]))
elif win_ver[0]:
result['os'] = 'Windows - {}'.format(' '.join(win_ver[:2]))
return result
def get_user_agent(self):
# type: () -> str
vendor = ''
vendor_version = ''
try:
vendor = platform.system()
vendor_version = platform.release()
except IOError:
# If the calling process is handling SIGCHLD, platform.system() can
# fail with an IOError. See http://bugs.python.org/issue9127
pass
if vendor == "Linux":
vendor, vendor_version, dummy = platform.linux_distribution()
elif vendor == "Windows":
vendor_version = platform.win32_ver()[1]
elif vendor == "Darwin":
vendor_version = platform.mac_ver()[0]
return "{client_name} ({vendor}; {vendor_version})".format(
client_name=self.client_name,
vendor=vendor,
vendor_version=vendor_version,
)
def os_id_index():
"""Get the index of the machine OS in the `OS_ID` tuple.
The `OS_ID` tuple contains the major and minor version of all
affected Windows versions. These are matched against
the major and minor version of `sys.getwindowsversion()`.
For Windows 8.1 and above `sys.getwindowsversion()` doesn't
report the correct value, these systems are handled specially.
Windows 8 and Server 2012 are special cased because the have the
same version numbers but require different KBs.
:return: The index of the operating system in `OS_ID`.
:rtype: int
"""
winver = sys.getwindowsversion()
# sys.getwindowsversion is not enough by itself as the underlying
# API has been deprecated. Only applications which have been
# developed specifically for Windows 8.1 and above, and write that
# into their manifest file get the correct Windows version on those
# systems. Other applications (Python doesn't have the manifest)
# get a version that pretends to be Windows 8 (major=6, minor=2).
# See:
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms724834.aspx
major, minor = winver.major, winver.minor
if (major, minor) == (6, 2):
# Determine if this system is a newer version than Windows 8 by
# parsing the version string in `platform.win32_ver()[1]`:
major, minor = tuple(map(int, platform.win32_ver()[1].split('.')[:2]))
for i, os_id in enumerate(OS_ID):
if os_id[:2] == (major, minor):
if len(os_id) == 2:
return i
# else evaluate the third item if present which is a lambda:
if os_id[2]():
return i
# otherwise continue with the next item
def patch_platform_win32_ver(mocker):
mocker.patch.object(arg_parsing.platform, 'win32_ver')
return arg_parsing.platform.win32_ver
def test_f_comment_ignoring_argument_parser_convert_filename():
# Actually checks against the current local system
parser = arg_parsing.CommentIgnoringArgumentParser()
if any(platform.win32_ver()):
assert not parser._CommentIgnoringArgumentParser__is_posix
expected_transform = NON_POSIX_FILEPATH
else:
assert parser._CommentIgnoringArgumentParser__is_posix
expected_transform = POSIX_FILEPATH
parsed_line = [arg for arg in parser.convert_arg_line_to_args(expected_transform[0])]
assert expected_transform[1] == parsed_line
def is_windows():
return any(platform.win32_ver())
def is_windows():
return any(platform.win32_ver())
def __init__(self, *args, **kwargs):
"""Sets up the dummy argument registry."""
# The type profile for this it really complex and we don't do anything to it, so
# I would rather not duplicate the typeshed's effort keeping it up to date.
# https://github.com/python/typeshed/blob/master/stdlib/2and3/argparse.pyi#L27-L39
self.__dummy_arguments = []
self.__is_posix = not any(platform.win32_ver())
super(CommentIgnoringArgumentParser, self).__init__(*args, **kwargs)
def getCurrentDef(normname):
bname, wver, stuff, whichkern = platform.win32_ver()
wvertup = wver.split('.')
arch = envi.getCurrentArch()
if isSysWow64():
arch = 'wow64'
modname = 'vstruct.defs.windows.win_%s_%s_%s.%s' % (wvertup[0], wvertup[1], arch, normname)
try:
mod = __import__(modname, {}, {}, 1)
except ImportError, e:
mod = None
return mod
def test_main(verbose=False):
if support.verbose:
plats = {
'Linux': platform.linux_distribution,
'Mac': platform.mac_ver,
'Windows': platform.win32_ver,
}
for name, func in plats.items():
plat = func()
if plat and plat[0]:
plat = '%s %r' % (name, plat)
break
else:
plat = repr(platform.platform())
print("test_ssl: testing with %r %r" %
(ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO))
print(" under %s" % plat)
print(" HAS_SNI = %r" % ssl.HAS_SNI)
for filename in [
CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE,
ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY,
BADCERT, BADKEY, EMPTYCERT]:
if not os.path.exists(filename):
raise support.TestFailed("Can't read certificate file %r" % filename)
tests = [ContextTests, BasicSocketTests]
if support.is_resource_enabled('network'):
tests.append(NetworkedTests)
if _have_threads:
thread_info = support.threading_setup()
if thread_info and support.is_resource_enabled('network'):
tests.append(ThreadedTests)
try:
support.run_unittest(*tests)
finally:
if _have_threads:
support.threading_cleanup(*thread_info)
def test_win32_ver(self):
res = platform.win32_ver()
def is_windows():
return any(platform.win32_ver())
def test_win32_ver(self):
res = platform.win32_ver()
def genwincodec(codepage):
import platform
map = genwinmap(codepage)
encodingname = 'cp%d' % codepage
code = codegen("", map, encodingname)
# Replace first lines with our own docstring
code = '''\
"""Python Character Mapping Codec %s generated on Windows:
%s with the command:
python Tools/unicode/genwincodec.py %s
"""#"
''' % (encodingname, ' '.join(platform.win32_ver()), codepage
) + code.split('"""#"', 1)[1]
print code
def test_win32_ver(self):
res = platform.win32_ver()
def genwincodec(codepage):
import platform
map = genwinmap(codepage)
encodingname = 'cp%d' % codepage
code = codegen("", map, encodingname)
# Replace first lines with our own docstring
code = '''\
"""Python Character Mapping Codec %s generated on Windows:
%s with the command:
python Tools/unicode/genwincodec.py %s
"""#"
''' % (encodingname, ' '.join(platform.win32_ver()), codepage
) + code.split('"""#"', 1)[1]
print code
def getCurrentDef(normname):
bname, wver, stuff, whichkern = platform.win32_ver()
wvertup = wver.split('.')
arch = envi.getCurrentArch()
if isSysWow64():
arch = 'wow64'
modname = 'vstruct.defs.windows.win_%s_%s_%s.%s' % (wvertup[0], wvertup[1], arch, normname)
try:
mod = __import__(modname, {}, {}, 1)
except ImportError as e:
mod = None
return mod
def test_main(verbose=False):
if support.verbose:
plats = {
'Linux': platform.linux_distribution,
'Mac': platform.mac_ver,
'Windows': platform.win32_ver,
}
for name, func in plats.items():
plat = func()
if plat and plat[0]:
plat = '%s %r' % (name, plat)
break
else:
plat = repr(platform.platform())
print("test_ssl: testing with %r %r" %
(ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO))
print(" under %s" % plat)
print(" HAS_SNI = %r" % ssl.HAS_SNI)
for filename in [
CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE,
ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY,
BADCERT, BADKEY, EMPTYCERT]:
if not os.path.exists(filename):
raise support.TestFailed("Can't read certificate file %r" % filename)
tests = [ContextTests, BasicSocketTests, SSLErrorTests]
if support.is_resource_enabled('network'):
tests.append(NetworkedTests)
if _have_threads:
thread_info = support.threading_setup()
if thread_info:
tests.append(ThreadedTests)
try:
support.run_unittest(*tests)
finally:
if _have_threads:
support.threading_cleanup(*thread_info)
def test_win32_ver(self):
res = platform.win32_ver()
def getCurrentDef(normname):
bname, wver, stuff, whichkern = platform.win32_ver()
wvertup = wver.split('.')
arch = envi.getCurrentArch()
if isSysWow64():
arch = 'wow64'
modname = 'vstruct.defs.windows.win_%s_%s_%s.%s' % (wvertup[0], wvertup[1], arch, normname)
try:
mod = __import__(modname, {}, {}, 1)
except ImportError, e:
mod = None
return mod
def getCurrentDef(normname):
bname, wver, stuff, whichkern = platform.win32_ver()
wvertup = wver.split('.')
arch = envi.getCurrentArch()
if isSysWow64():
arch = 'wow64'
modname = 'vstruct.defs.windows.win_%s_%s_%s.%s' % (wvertup[0], wvertup[1], arch, normname)
try:
mod = __import__(modname, {}, {}, 1)
except ImportError, e:
mod = None
return mod
def get_system_type(cls):
'''???????????'''
if platform.system() == 'Windows':
if platform.win32_ver()[0] == '8':
return 'Win8'
else:
return 'Win7orLower'
elif platform.system() == 'Linux':
return 'Linux'
else:
return 'MacOS'
def test_win32_ver(self):
res = platform.win32_ver()
def test_win32_ver(self):
res = platform.win32_ver()