本文整理汇总了Python中_winreg.error方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.error方法的具体用法?Python _winreg.error怎么用?Python _winreg.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_winreg
的用法示例。
在下文中一共展示了_winreg.error方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _doregister
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
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,)
示例2: test_struct_uint_bad_value_cp20039
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def test_struct_uint_bad_value_cp20039(self):
class x(object):
def __init__(self, value):
self.value = value
def __and__(self, other):
global andCalled
andCalled = True
return self.value
def __int__(self):
raise Exception('foo')
import _struct
global andCalled
andCalled = False
self.assertRaisesRegexp(_struct.error, "integer out of range for 'L' format code",
_struct.Struct('L').pack, 4294967296)
self.assertRaisesRegexp(_struct.error, "integer out of range for 'L' format code",
_struct.Struct('L').pack, -1)
self.assertRaisesRegexp(Exception, "foo",
_struct.Struct('L').pack, x(0))
self.assertRaisesRegexp(Exception, "foo", _struct.Struct('L').pack, x(-1))
self.assertRaisesRegexp(_struct.error, "integer out of range for 'I' format code",
_struct.Struct('I').pack, 4294967296)
self.assertRaisesRegexp(_struct.error, "integer out of range for 'I' format code",
_struct.Struct('I').pack, -1)
self.assertRaisesRegexp(Exception, "foo",
_struct.Struct('I').pack, x(0))
self.assertRaisesRegexp(Exception, "foo", _struct.Struct('I').pack, x(-1))
# __and__ was called in Python2.6 check that this is no longer True
self.assertTrue(not andCalled)
示例3: test_winreg_error_cp17050
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def test_winreg_error_cp17050(self):
import _winreg
self.assertEqual(_winreg.error, WindowsError)
示例4: __call__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def __call__(self, env, source, ext=None):
if ext is None:
try:
ext = source[0].suffix
except IndexError:
ext = ""
try:
return self[ext]
except KeyError:
# Try to perform Environment substitution on the keys of
# the dictionary before giving up.
s_dict = {}
for (k,v) in self.items():
if k is not None:
s_k = env.subst(k)
if s_k in s_dict:
# We only raise an error when variables point
# to the same suffix. If one suffix is literal
# and a variable suffix contains this literal,
# the literal wins and we don't raise an error.
raise KeyError(s_dict[s_k][0], k, s_k)
s_dict[s_k] = (k,v)
try:
return s_dict[ext][1]
except KeyError:
try:
return self[None]
except KeyError:
return None
示例5: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def __init__(self):
if self.info is not None:
return
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
if sys.version_info[0] >= 3:
import winreg
else:
import _winreg as winreg
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
pnum=0
while True:
try:
proc=winreg.EnumKey(chnd, pnum)
except winreg.error:
break
else:
pnum+=1
info.append({"Processor":proc})
phnd=winreg.OpenKey(chnd, proc)
pidx=0
while True:
try:
name, value, vtpe=winreg.EnumValue(phnd, pidx)
except winreg.error:
break
else:
pidx=pidx+1
info[-1][name]=value
if name=="Identifier":
srch=prgx.search(value)
if srch:
info[-1]["Family"]=int(srch.group("FML"))
info[-1]["Model"]=int(srch.group("MDL"))
info[-1]["Stepping"]=int(srch.group("STP"))
except Exception:
print(sys.exc_info()[1], '(ignoring)')
self.__class__.info = info
示例6: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def __init__(self):
if self.info is not None:
return
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
if sys.version_info[0] >= 3:
import winreg
else:
import _winreg as winreg
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
pnum=0
while True:
try:
proc=winreg.EnumKey(chnd, pnum)
except winreg.error:
break
else:
pnum+=1
info.append({"Processor":proc})
phnd=winreg.OpenKey(chnd, proc)
pidx=0
while True:
try:
name, value, vtpe=winreg.EnumValue(phnd, pidx)
except winreg.error:
break
else:
pidx=pidx+1
info[-1][name]=value
if name=="Identifier":
srch=prgx.search(value)
if srch:
info[-1]["Family"]=int(srch.group("FML"))
info[-1]["Model"]=int(srch.group("MDL"))
info[-1]["Stepping"]=int(srch.group("STP"))
except:
print(sys.exc_info()[1], '(ignoring)')
self.__class__.info = info
示例7: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def __init__(self):
if self.info is not None:
return
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
if sys.version_info[0] >= 3:
import winreg
else:
import _winreg as winreg
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"\
"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
pnum=0
while True:
try:
proc=winreg.EnumKey(chnd, pnum)
except winreg.error:
break
else:
pnum+=1
info.append({"Processor":proc})
phnd=winreg.OpenKey(chnd, proc)
pidx=0
while True:
try:
name, value, vtpe=winreg.EnumValue(phnd, pidx)
except winreg.error:
break
else:
pidx=pidx+1
info[-1][name]=value
if name=="Identifier":
srch=prgx.search(value)
if srch:
info[-1]["Family"]=int(srch.group("FML"))
info[-1]["Model"]=int(srch.group("MDL"))
info[-1]["Stepping"]=int(srch.group("STP"))
except:
print(sys.exc_info()[1], '(ignoring)')
self.__class__.info = info
示例8: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import error [as 别名]
def __init__(self):
try:
import _winreg
except ImportError: # Python 3
import winreg as _winreg
if self.info is not None:
return
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
chnd = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.pkey)
pnum = 0
while 1:
try:
proc = _winreg.EnumKey(chnd, pnum)
except _winreg.error:
break
else:
pnum += 1
info.append({"Processor": proc})
phnd = _winreg.OpenKey(chnd, proc)
pidx = 0
while True:
try:
name, value, vtpe = _winreg.EnumValue(phnd, pidx)
except _winreg.error:
break
else:
pidx = pidx + 1
info[-1][name] = value
if name == "Identifier":
srch = prgx.search(value)
if srch:
info[-1]["Family"] = int(srch.group("FML"))
info[-1]["Model"] = int(srch.group("MDL"))
info[-1]["Stepping"] = int(srch.group("STP"))
except:
print(sys.exc_value, '(ignoring)')
self.__class__.info = info