Python sys.winver() Examples
The following are 20
code examples of sys.winver().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: dbgpyapp.py From ironpython2 with Apache License 2.0 | 6 votes |
def InitInstance(self): # Use a registry path of "Python\Pythonwin Debugger win32ui.SetAppName(win32ui.LoadString(win32ui.IDR_DEBUGGER)) win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # We _need_ the Scintilla color editor. # (and we _always_ get it now :-) numMRU = win32ui.GetProfileVal("Settings","Recent File List Size", 10) win32ui.LoadStdProfileSettings(numMRU) self.LoadMainFrame() # Display the interactive window if the user wants it. from pywin.framework import interact interact.CreateInteractiveWindowUserPreference() # Load the modules we use internally. self.LoadSystemModules() # Load additional module the user may want. self.LoadUserModules() # win32ui.CreateDebuggerThread() win32ui.EnableControlContainer()
Example #2
Source File: regutil.py From ironpython2 with Apache License 2.0 | 6 votes |
def RegisterCoreDLL(coredllName = None): """Registers the core DLL in the registry. If no params are passed, the name of the Python DLL used in the current process is used and registered. """ if coredllName is None: coredllName = win32api.GetModuleFileName(sys.dllhandle) # must exist! else: try: os.stat(coredllName) except os.error: print "Warning: Registering non-existant core DLL %s" % coredllName hKey = win32api.RegCreateKey(GetRootKey() , BuildDefaultPythonKey()) try: win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName) finally: win32api.RegCloseKey(hKey) # Lastly, setup the current version to point to me. win32api.RegSetValue(GetRootKey(), "Software\\Python\\PythonCore\\CurrentVersion", win32con.REG_SZ, sys.winver)
Example #3
Source File: dllsite.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_bad_stuff(): ''' Cases where IP should not load an assembly for one reason or another. ''' #ensure that users cannot override IP native modules import sys Assert(sys.winver != "HIJACKED") import re Assert(re.compile != "HIJACKED") #ensure corrupted DLLs cannot be loaded try: import fooCORRUPT raise Exception("Corrupted DLL was loaded") except ImportError, e: pass #nothing to do for unmanaged DLLs...if the interpreter has made it #this far, all is well:) #ensure *.exe's cannot take precedence over *.dlls
Example #4
Source File: ImportManager.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.path = "WindowsRegistry" self.map = {} try: import win32api ## import win32con except ImportError: pass else: HKEY_CURRENT_USER = -2147483647 HKEY_LOCAL_MACHINE = -2147483646 KEY_ALL_ACCESS = 983103 subkey = r"Software\Python\PythonCore\%s\Modules" % sys.winver for root in (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE): try: hkey = win32api.RegOpenKeyEx(root, subkey, 0, KEY_ALL_ACCESS) except: pass else: numsubkeys, numvalues, lastmodified = win32api.RegQueryInfoKey(hkey) for i in range(numsubkeys): subkeyname = win32api.RegEnumKey(hkey, i) hskey = win32api.RegOpenKeyEx(hkey, subkeyname, 0, KEY_ALL_ACCESS) val = win32api.RegQueryValueEx(hskey, '') desc = getDescr(val[0]) self.map[subkeyname] = (val[0], desc) hskey.Close() hkey.Close() break
Example #5
Source File: impdirector.py From ConTroll_Remote_Access_Trojan with Apache License 2.0 | 5 votes |
def __init__(self): self.path = "WindowsRegistry" self.map = {} try: import win32api import win32con except ImportError: return subkey = r"Software\Python\PythonCore\%s\Modules" % sys.winver for root in (win32con.HKEY_CURRENT_USER, win32con.HKEY_LOCAL_MACHINE): try: hkey = win32api.RegOpenKeyEx(root, subkey, 0, win32con.KEY_READ) except Exception, e: logger.debug('RegistryImportDirector: %s' % e) continue numsubkeys, numvalues, lastmodified = win32api.RegQueryInfoKey(hkey) for i in range(numsubkeys): subkeyname = win32api.RegEnumKey(hkey, i) hskey = win32api.RegOpenKeyEx(hkey, subkeyname, 0, win32con.KEY_READ) val = win32api.RegQueryValueEx(hskey, '') desc = getDescr(val[0]) #print " RegistryImportDirector got %s %s" % (val[0], desc) #XXX self.map[subkeyname] = (val[0], desc) hskey.Close() hkey.Close() break
Example #6
Source File: test_sys.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_winver(self): import re #E.g., "2.5" self.assertTrue(re.match("^\d\.\d$", sys.winver) != None)
Example #7
Source File: modulediff.py From ironpython3 with Apache License 2.0 | 5 votes |
def gen_bug_report(mod_name, diffs, outdir): needs_to_be_implemented = collect_diffs(diffs, '-') needs_to_be_removed = collect_diffs(diffs, '+') if not needs_to_be_implemented and not needs_to_be_removed: return bug_report_name = outdir + "\\%s.log" % mod_name bug_report = open(bug_report_name, "w") bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver))) #--unfiltered list of attributes to be added if len(needs_to_be_implemented)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes IronPython is still missing implementations for: """) for x in needs_to_be_implemented: bug_report.write(" " + x + '\n') bug_report.write("\n\n\n") #--unfiltered list of attributes to be removed if len(needs_to_be_removed)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes that should be removed from IronPython: """) for x in needs_to_be_removed: bug_report.write(" " + x + '\n') bug_report.close() return bug_report_name
Example #8
Source File: python_parser.py From lark with MIT License | 5 votes |
def _get_lib_path(): if os.name == 'nt': if 'PyPy' in sys.version: return os.path.join(sys.prefix, 'lib-python', sys.winver) else: return os.path.join(sys.prefix, 'Lib') else: return [x for x in sys.path if x.endswith('%s.%s' % sys.version_info[:2])][0]
Example #9
Source File: modulediff.py From ironpython2 with Apache License 2.0 | 5 votes |
def gen_bug_report(mod_name, diffs, outdir): needs_to_be_implemented = collect_diffs(diffs, '-') needs_to_be_removed = collect_diffs(diffs, '+') if not needs_to_be_implemented and not needs_to_be_removed: return bug_report_name = outdir + "\\%s.log" % mod_name bug_report = open(bug_report_name, "w") bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver))) #--unfiltered list of attributes to be added if len(needs_to_be_implemented)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes IronPython is still missing implementations for: """) for x in needs_to_be_implemented: bug_report.write(" " + x + '\n') bug_report.write("\n\n\n") #--unfiltered list of attributes to be removed if len(needs_to_be_removed)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes that should be removed from IronPython: """) for x in needs_to_be_removed: bug_report.write(" " + x + '\n') bug_report.close() return bug_report_name
Example #10
Source File: register.py From ironpython2 with Apache License 2.0 | 5 votes |
def _find_localserver_exe(mustfind): if not sys.platform.startswith("win32"): return sys.executable if pythoncom.__file__.find("_d") < 0: exeBaseName = "pythonw.exe" else: exeBaseName = "pythonw_d.exe" # First see if in the same directory as this .EXE exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName ) if not os.path.exists(exeName): # See if in our sys.prefix directory exeName = os.path.join( sys.prefix, exeBaseName ) if not os.path.exists(exeName): # See if in our sys.prefix/pcbuild directory (for developers) if "64 bit" in sys.version: exeName = os.path.join( sys.prefix, "PCbuild", "amd64", exeBaseName ) else: exeName = os.path.join( sys.prefix, "PCbuild", exeBaseName ) if not os.path.exists(exeName): # See if the registry has some info. try: key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key ) exeName = os.path.join( path, exeBaseName ) except (AttributeError,win32api.error): pass if not os.path.exists(exeName): if mustfind: raise RuntimeError("Can not locate the program '%s'" % exeBaseName) return None return exeName
Example #11
Source File: setup_d.py From ironpython2 with Apache License 2.0 | 5 votes |
def _doregister(mod_name, dll_name): assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!" try: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name)) except _winreg.error: try: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name)) except _winreg.error: print "Could not find the existing '%s' module registered in the registry" % (mod_name,) usage_and_die(4) # Create the debug key. sub_key = _winreg.CreateKey(key, "Debug") _winreg.SetValue(sub_key, None, _winreg.REG_SZ, dll_name) print "Registered '%s' in the registry" % (dll_name,)
Example #12
Source File: cerapi.py From ironpython2 with Apache License 2.0 | 5 votes |
def DumpPythonRegistry(): try: h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\PythonPath" % sys.winver) except win32api.error: print "The remote device does not appear to have Python installed" return 0 path, typ = wincerapi.CeRegQueryValueEx(h, None) print "The remote PythonPath is '%s'" % (str(path), ) h.Close() return 1
Example #13
Source File: intpyapp.py From ironpython2 with Apache License 2.0 | 5 votes |
def InitInstance(self): # Allow "/nodde" and "/newinstance to optimize this! if "/nodde" not in sys.argv and "/newinstance" not in sys.argv: if self.InitDDE(): return 1 # A remote DDE client is doing it for us! else: self.ddeServer = None win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on! app.CApp.InitInstance(self) # Create the taskbar icon win32ui.CreateDebuggerThread() # Allow Pythonwin to host OCX controls. win32ui.EnableControlContainer() # Display the interactive window if the user wants it. import interact interact.CreateInteractiveWindowUserPreference() # Load the modules we use internally. self.LoadSystemModules() # Load additional module the user may want. self.LoadUserModules() # Load the ToolBar state near the end of the init process, as # there may be Toolbar IDs created by the user or other modules. # By now all these modules should be loaded, so all the toolbar IDs loaded. try: self.frame.LoadBarState("ToolbarDefault") except win32ui.error: # MFC sucks. It does essentially "GetDlgItem(x)->Something", so if the # toolbar with ID x does not exist, MFC crashes! Pythonwin has a trap for this # but I need to investigate more how to prevent it (AFAIK, ensuring all the # toolbars are created by now _should_ stop it!) pass # Finally process the command line arguments. self.ProcessArgs(sys.argv)
Example #14
Source File: scriptutils.py From ironpython2 with Apache License 2.0 | 5 votes |
def FindTabNanny(): try: return __import__("tabnanny") except ImportError: pass # OK - not in the standard library - go looking. filename = "tabnanny.py" try: path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver)) except win32api.error: print "WARNING - The Python registry does not have an 'InstallPath' setting" print " The file '%s' can not be located" % (filename) return None fname = os.path.join(path, "Tools\\Scripts\\%s" % filename) try: os.stat(fname) except os.error: print "WARNING - The file '%s' can not be located in path '%s'" % (filename, path) return None tabnannyhome, tabnannybase = os.path.split(fname) tabnannybase = os.path.splitext(tabnannybase)[0] # Put tab nanny at the top of the path. sys.path.insert(0, tabnannyhome) try: return __import__(tabnannybase) finally: # remove the tab-nanny from the path del sys.path[0]
Example #15
Source File: cmodule.py From ironpython2 with Apache License 2.0 | 4 votes |
def gen_bug_report(mod_name, needs_to_be_implemented, needs_to_be_removed): bug_report_name = "bug_reports\\%s.log" % mod_name bug_report = open(bug_report_name, "w") bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver))) bug_report.write("-------------------------------------------------------\n") bug_report.write("""After filtering out Python special method names, IronPython is still MISSING implementations for the following module attributes: """) for x in needs_to_be_implemented: if re.search(REGEX_FILTER, x)==None: bug_report.write(" " + x) bug_report.write("\n\n") bug_report.write("-------------------------------------------------------\n") bug_report.write("""After filtering out Python special method names, IronPython is still PROVIDING implementations for the following module attributes which should NOT exist: """) for x in needs_to_be_removed: if re.search(REGEX_FILTER, x)==None: bug_report.write(" " + x) bug_report.write("\n\n") #--unfiltered list of attributes to be added if len(needs_to_be_implemented)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes IronPython is still missing implementations for: """) for x in needs_to_be_implemented: bug_report.write(" " + x) bug_report.write("\n\n\n") #--unfiltered list of attributes to be removed if len(needs_to_be_removed)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes that should be removed from IronPython: """) for x in needs_to_be_removed: bug_report.write(" " + x) bug_report.close() return bug_report_name #--MAIN------------------------------------------------------------------------
Example #16
Source File: __init__.py From ironpython2 with Apache License 2.0 | 4 votes |
def SetupEnvironment(): HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these... KEY_QUERY_VALUE = 0x1 # Open the root key once, as this is quite slow on NT. try: keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE) except (win32api.error, AttributeError): key = None try: found = 0 if key is not None: try: __path__.append( win32api.RegQueryValue(key, "Extensions" )) found = 1 except win32api.error: # Nothing registered pass if not found: try: __path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") ) except win32api.error: # Give up in disgust! pass # For the sake of developers, we also look up a "BuildPath" key # If extension modules add support, we can load their .pyd's from a completely # different directory (see the comments below) try: if key is not None: global __build_path__ __build_path__ = win32api.RegQueryValue(key, "BuildPath") __path__.append(__build_path__) except win32api.error: # __build_path__ neednt be defined. pass global __gen_path__ if key is not None: try: __gen_path__ = win32api.RegQueryValue(key, "GenPath") except win32api.error: pass finally: if key is not None: key.Close() # A Helper for developers. A sub-package's __init__ can call this help function, # which allows the .pyd files for the extension to live in a special "Build" directory # (which the win32com developers do!)
Example #17
Source File: cmodule.py From ironpython3 with Apache License 2.0 | 4 votes |
def gen_bug_report(mod_name, needs_to_be_implemented, needs_to_be_removed): bug_report_name = "bug_reports\\%s.log" % mod_name bug_report = open(bug_report_name, "w") bug_report.write(BUG_REPORT_PRE % (mod_name, str(sys.winver))) bug_report.write("-------------------------------------------------------\n") bug_report.write("""After filtering out Python special method names, IronPython is still MISSING implementations for the following module attributes: """) for x in needs_to_be_implemented: if re.search(REGEX_FILTER, x)==None: bug_report.write(" " + x) bug_report.write("\n\n") bug_report.write("-------------------------------------------------------\n") bug_report.write("""After filtering out Python special method names, IronPython is still PROVIDING implementations for the following module attributes which should NOT exist: """) for x in needs_to_be_removed: if re.search(REGEX_FILTER, x)==None: bug_report.write(" " + x) bug_report.write("\n\n") #--unfiltered list of attributes to be added if len(needs_to_be_implemented)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes IronPython is still missing implementations for: """) for x in needs_to_be_implemented: bug_report.write(" " + x) bug_report.write("\n\n\n") #--unfiltered list of attributes to be removed if len(needs_to_be_removed)>0: bug_report.write("-------------------------------------------------------\n") bug_report.write("""Complete list of module attributes that should be removed from IronPython: """) for x in needs_to_be_removed: bug_report.write(" " + x) bug_report.close() return bug_report_name #--MAIN------------------------------------------------------------------------
Example #18
Source File: dllsite.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_bad_stuff(): ''' Cases where IP should not load an assembly for one reason or another. ''' #ensure that users cannot override IP native modules import sys Assert(sys.winver != "HIJACKED") import re Assert(re.compile != "HIJACKED") #ensure corrupted DLLs cannot be loaded try: import fooCORRUPT raise Exception("Corrupted DLL was loaded") except ImportError as e: pass #nothing to do for unmanaged DLLs...if the interpreter has made it #this far, all is well:) #ensure *.exe's cannot take precedence over *.dlls import fooDLLEXE AreEqual(fooDLLEXE.Foo().BAR, 1) #ensure *.exe's are not autoloaded at all! try: import fooEXEONLY raise Exception("*.exe's should not be autoloaded!") except ImportError as e: pass except SystemError as e: print("Work Item #189503") #ensure *.txt's are not autoloaded at all try: import fooTXTDLL raise Exception("*.txt's should not be autoloaded!") except ImportError as e: pass
Example #19
Source File: test_importpkg.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_relative_imports(self): try: mod_backup = dict(sys.modules) _f_dir = os.path.join(self.test_dir, 'the_dir') _f_init = os.path.join(_f_dir, '__init__.py') _f_pkg_y = os.path.join(_f_dir, 'abc.py') _f_pkg_x = os.path.join(_f_dir, 'x.py') _f_subdir = os.path.join(_f_dir, 'subdir') _f_subinit = os.path.join(_f_subdir, '__init__.py') _f_subpkg_y = os.path.join(_f_subdir, 'abc.py') _f_subpkg_x = os.path.join(_f_subdir, 'x.py') _f_subpkg_z = os.path.join(_f_subdir, 'z.py') _f_subpkg_a = os.path.join(_f_subdir, 'a.py') _f_subpkg_b = os.path.join(_f_subdir, 'b.py') # write the files self.ensure_directory_present(_f_dir) self.ensure_directory_present(_f_subdir) self.write_to_file(_f_init, '') self.write_to_file(_f_subinit, '') self.write_to_file(_f_pkg_y, 'import sys\nsys.foo = "pkgy"') self.write_to_file(_f_subpkg_y,'import sys\nsys.foo = "subpkgy"') self.write_to_file(_f_pkg_x, 'from . import abc\nreload(abc)') self.write_to_file(_f_subpkg_x, 'from .. import abc\nreload(abc)') self.write_to_file(_f_subpkg_z, 'from . import abc\nreload(abc)') self.write_to_file(_f_subpkg_a, 'from __future__ import absolute_import\ntry:\n import abc\nexcept ImportError:\n import sys\n sys.foo="error"') self.write_to_file(_f_subpkg_b, 'import abc\nreload(abc)') import the_dir.subdir.a if sys.winver=="2.5": self.assertEqual(sys.foo, 'error') else: self.assertTrue(not hasattr(sys, "foo")) import the_dir.x self.assertEqual(sys.foo, 'pkgy') import the_dir.subdir.x self.assertEqual(sys.foo, 'pkgy') import the_dir.subdir.z self.assertEqual(sys.foo, 'subpkgy') import the_dir.subdir.b self.assertEqual(sys.foo, 'subpkgy') del sys.foo finally: sys.modules = mod_backup os.unlink(_f_init) os.unlink(_f_pkg_x) os.unlink(_f_pkg_y) os.unlink(_f_subinit) os.unlink(_f_subpkg_x) os.unlink(_f_subpkg_y) os.unlink(_f_subpkg_z) os.unlink(_f_subpkg_a) os.unlink(_f_subpkg_b) self.clean_directory(_f_subdir) self.clean_directory(_f_dir)
Example #20
Source File: injection.py From PythonForWindows with BSD 3-Clause "New" or "Revised" License | 4 votes |
def find_python_dll_to_inject(target_bitness): pydll_name = get_dll_name_from_python_version() if windows.current_process.bitness == target_bitness: # We can inject our own DLL pymodules = [m for m in windows.current_process.peb.modules if m.name == pydll_name] assert len(pymodules) == 1 return pymodules[0].fullname # Okay, so we need to find the DLL to inject. # Problem is, for py3 the DLL is not un system32, so we need for search for it # Simpler solution is the registry # Add a check using %PATH% ? assert windows.system.bitness == 64, "How can we have process of different bitness on 32b system ?" if sys.version_info.major == 2: # Python2 DLL are located in system32/syswow64 # We know that we are looking to DLL of the other bitness if windows.current_process.bitness == 32: # We need to check that the real system32\pythonXX.dll exists systempath = "sysnative" else: # We need to check that the wow64 system32\pythonXX.dll exists systempath = "syswow64" if not os.path.exists(os.path.join(os.environ["windir"], systempath, pydll_name)): raise IOError("Could not find Python DLL to inject") # In any way (32b ou 64b) the target process will load system32\pydll # If the target is 32b the wow64 layer will translate it return os.path.join(os.environ["windir"], "system32", pydll_name) # Python 3 dll must be located using the registry for base_key in "HKEY_LOCAL_MACHINE", "HKEY_CURRENT_USER": # Open the registry in 64b view regardless of current process bitness regbase = windows.system.registry(base_key, gdef.KEY_WOW64_64KEY | gdef.KEY_READ) # we cannot use sys.winver as we are looking for the OTHER version # But from Python <PCbuild/python.props> it looks like format is # {Major}.{Minor}{-32}(for 32b build) # This code do not handle -test version winver_base = sys.winver[:3] # major-minor if target_bitness == 64: pyinstallkey = regbase("SOFTWARE\Python\PythonCore")(winver_base) else: pyinstallkey = regbase("SOFTWARE\WOW6432Node\Python\PythonCore")(winver_base + "-32") try: pyinstallpath = pyinstallkey("InstallPath")[""].value final_path = os.path.join(pyinstallpath, pydll_name) assert os.path.exists(final_path), "Could not find <{0}> pydll referenced from registry".format(final_path) return final_path except WindowsError as e: if e.winerror != gdef.ERROR_FILE_NOT_FOUND: raise # Not found continue # Could not find a valid installation raise ValueError("Could not find a path for python-dll <{0}>({1}bits)".format(sys.winver, target_bitness))