本文整理匯總了Python中winreg.error方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.error方法的具體用法?Python winreg.error怎麽用?Python winreg.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.error方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __call__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import error [as 別名]
def __call__(self, env, source, ext=None):
if ext is None:
try:
ext = source[0].get_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
示例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.assertRaisesRegex(_struct.error, "integer out of range for 'L' format code" if is_cli else "argument out of range",
_struct.Struct('L').pack, 4294967296)
self.assertRaisesRegex(_struct.error, "integer out of range for 'L' format code" if is_cli else "argument out of range",
_struct.Struct('L').pack, -1)
self.assertRaisesRegex(Exception, "foo" if is_cli else "required argument is not an integer", _struct.Struct('L').pack, x(0))
self.assertRaisesRegex(Exception, "foo" if is_cli else "required argument is not an integer", _struct.Struct('L').pack, x(-1))
self.assertRaisesRegex(_struct.error, "integer out of range for 'I' format code" if is_cli else "argument out of range",
_struct.Struct('I').pack, 4294967296)
self.assertRaisesRegex(_struct.error, "integer out of range for 'I' format code" if is_cli else "argument out of range",
_struct.Struct('I').pack, -1)
self.assertRaisesRegex(Exception, "foo" if is_cli else "required argument is not an integer", _struct.Struct('I').pack, x(0))
self.assertRaisesRegex(Exception, "foo" if is_cli else "required argument is not an integer", _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