本文整理汇总了Python中pywintypes.error方法的典型用法代码示例。如果您正苦于以下问题:Python pywintypes.error方法的具体用法?Python pywintypes.error怎么用?Python pywintypes.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywintypes
的用法示例。
在下文中一共展示了pywintypes.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _openHandle
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def _openHandle(path, bWriteAccess, bWriteShare,
logfunc = lambda s: None):
TIMEOUT, NUM_RETRIES = 10, 20
for retry_count in range(6):
try:
access_flag = win32con.GENERIC_READ | \
(bWriteAccess and win32con.GENERIC_WRITE or 0)
share_flag = win32con.FILE_SHARE_READ | \
(bWriteShare and win32con.FILE_SHARE_WRITE or 0)
handle = win32file.CreateFile(
path, access_flag, share_flag, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
nth = { 0: 'first', 1:'second', 2:'third'}
logfunc("Opening [%s]: success at the %s iteration" %
(path, nth.get(retry_count, '%sth' % (retry_count+1))))
return handle
except pywintypes.error as e:
logfunc('Exception=>'+str(e))
if NUM_RETRIES/3 < retry_count:
bWriteShare = True
time.sleep(TIMEOUT / float(NUM_RETRIES))
else:
raise RuntimeError("Couldn't open handle for %s." % path)
示例2: lockPhysicalDrive
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def lockPhysicalDrive(handle, logfunc=lambda s: None):
try:
win32file.DeviceIoControl(
handle, winioctlcon.FSCTL_ALLOW_EXTENDED_DASD_IO,
None, 0, None)
except pywintypes.error as e:
logfunc('IO boundary checks diabled.')
for retry in range(20):
try:
win32file.DeviceIoControl(handle, winioctlcon.FSCTL_LOCK_VOLUME,
None, 0, None)
return
except pywintypes.error as e:
logfunc( str(e) )
time.sleep(1)
raise RuntimeError("Couldn't lock the Volume.")
示例3: lin_check_default_route
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def lin_check_default_route(self):
# get default gateway(s)
ps = subprocess.Popen(["route", "-n"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = ps.communicate()
if stderr != "":
common.internal_print("Route error: {0}".format(stderr), -1)
sys.exit(-1)
lines = stdout.split("\n")
default_route_number = 0
for line in lines:
if line[0:7] == "0.0.0.0":
default_route_number += 1
if default_route_number < 1:
common.internal_print("No default route. Please set up your routing before executing the tool", -1)
sys.exit(-1)
if default_route_number > 1:
common.internal_print("More than one default route. This should be reviewed before executing the tool.", -1)
sys.exit(-1)
return
示例4: supported
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def supported(cls, stream=sys.stdout):
"""
A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise.
"""
if not stream.isatty():
return False # auto color only on TTYs
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
except curses.error:
curses.setupterm()
return curses.tigetnum("colors") > 2
except Exception:
# guess false in case of error
return False
示例5: _OpenFileForRead
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def _OpenFileForRead(self, path):
try:
fhandle = self.fhandle = win32file.CreateFile(
path,
win32file.GENERIC_READ,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
self._closer = weakref.ref(
self, lambda x: win32file.CloseHandle(fhandle))
self.write_enabled = False
return fhandle
except pywintypes.error as e:
raise IOError("Unable to open %s: %s" % (path, e))
示例6: __init__
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def __init__(self, base=None, filename=None, **kwargs):
self.as_assert(base == None, 'Must be first Address Space')
super(Win32FileAddressSpace, self).__init__(**kwargs)
path = filename or self.session.GetParameter("filename")
self.as_assert(path, "Filename must be specified in session (e.g. "
"session.SetParameter('filename', 'MyFile.raw').")
self.fname = path
# The file is just a regular file, we open for reading.
fhandle = self._OpenFileForRead(path)
# If we can not get the file size it means this is not a regular file -
# maybe a device.
self.fhandle_as = Win32FileWrapper(fhandle)
try:
file_size = win32file.GetFileSize(fhandle)
self.add_run(0, 0, file_size, self.fhandle_as)
except pywintypes.error:
# This may be a device, we just read the whole space.
self.add_run(0, 0, 2**63, self.fhandle_as)
self.volatile = True
示例7: _OpenFileForWrite
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def _OpenFileForWrite(self, path):
try:
fhandle = self.fhandle = win32file.CreateFile(
path,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
self.write_enabled = True
self._closer = weakref.ref(
self, lambda x: win32file.CloseHandle(fhandle))
return fhandle
except pywintypes.error as e:
raise IOError("Unable to open %s: %s" % (path, e))
示例8: _print_at
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def _print_at(self, text, x, y, width):
"""
Print string at the required location.
:param text: The text string to print.
:param x: The x coordinate
:param y: The Y coordinate
:param width: The width of the character (for dual-width glyphs in CJK languages).
"""
# We can throw temporary errors on resizing, so catch and ignore
# them on the assumption that we'll resize shortly.
try:
# Move the cursor if necessary
if x != self._cur_x or y != self._cur_y:
self._stdout.SetConsoleCursorPosition(
win32console.PyCOORDType(x, y))
# Print the text at the required location and update the current
# position.
self._stdout.WriteConsole(text)
self._cur_x = x + width
self._cur_y = y
except pywintypes.error:
pass
示例9: loadTestsFromName
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def loadTestsFromName(self, name, module=None):
test = unittest.TestLoader.loadTestsFromName(self, name, module)
if isinstance(test, unittest.TestSuite):
pass # hmmm? print "Don't wrap suites yet!", test._tests
elif isinstance(test, unittest.TestCase):
test = self._getTestWrapper(test)
else:
print "XXX - what is", test
return test
# Lots of classes necessary to support one simple feature: we want a 3rd
# test result state - "SKIPPED" - to indicate that the test wasn't able
# to be executed for various reasons. Inspired by bzr's tests, but it
# has other concepts, such as "Expected Failure", which we don't bother
# with.
# win32 error codes that probably mean we need to be elevated (ie, if we
# aren't elevated, we treat these error codes as 'skipped')
示例10: _GetServiceShortName
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def _GetServiceShortName(longName):
# looks up a services name
# from the display name
# Thanks to Andy McKay for this code.
access = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services", 0, access)
num = win32api.RegQueryInfoKey(hkey)[0]
longName = longName.lower()
# loop through number of subkeys
for x in range(0, num):
# find service name, open subkey
svc = win32api.RegEnumKey(hkey, x)
skey = win32api.RegOpenKey(hkey, svc, 0, access)
try:
# find display name
thisName = str(win32api.RegQueryValueEx(skey, "DisplayName")[0])
if thisName.lower() == longName:
return svc
except win32api.error:
# in case there is no key called DisplayName
pass
return None
# Open a service given either it's long or short name.
示例11: RemoveService
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def RemoveService(serviceName):
try:
import perfmon
perfmon.UnloadPerfCounterTextStrings("python.exe "+serviceName)
except (ImportError, win32api.error):
pass
hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
try:
hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
win32service.DeleteService(hs)
win32service.CloseServiceHandle(hs)
finally:
win32service.CloseServiceHandle(hscm)
import win32evtlogutil
try:
win32evtlogutil.RemoveSourceFromRegistry(serviceName)
except win32api.error:
pass
示例12: GetServiceClassString
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def GetServiceClassString(cls, argv = None):
if argv is None:
argv = sys.argv
import pickle
modName = pickle.whichmodule(cls, cls.__name__)
if modName == '__main__':
try:
fname = win32api.GetFullPathName(argv[0])
path = os.path.split(fname)[0]
# Eaaaahhhh - sometimes this will be a short filename, which causes
# problems with 1.5.1 and the silly filename case rule.
# Get the long name
fname = os.path.join(path, win32api.FindFiles(fname)[0][8])
except win32api.error:
raise error("Could not resolve the path name '%s' to a full path" % (argv[0]))
modName = os.path.splitext(fname)[0]
return modName + "." + cls.__name__
示例13: test_impersonate_user
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def test_impersonate_user(self):
auth = self.authorizer_class()
nonexistent_user = self.get_nonexistent_user()
try:
if self.authorizer_class.__name__ == 'UnixAuthorizer':
auth.impersonate_user(self.get_current_user(), '')
self.assertRaises(
AuthorizerError,
auth.impersonate_user, nonexistent_user, 'pwd')
else:
self.assertRaises(
Win32ExtError,
auth.impersonate_user, nonexistent_user, 'pwd')
self.assertRaises(
Win32ExtError,
auth.impersonate_user, self.get_current_user(), '')
finally:
auth.terminate_impersonation('')
示例14: add_anonymous
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def add_anonymous(self, homedir, **kwargs):
"""Add an anonymous user to the virtual users table.
AuthorizerError exception raised on error conditions such as
invalid permissions, missing home directory, or duplicate
anonymous users.
The keyword arguments in kwargs are the same expected by
add_user method: "perm", "msg_login" and "msg_quit".
The optional "perm" keyword argument is a string defaulting to
"elr" referencing "read-only" anonymous user's permissions.
Using write permission values ("adfmwM") results in a
RuntimeWarning.
"""
DummyAuthorizer.add_user(self, 'anonymous', '', homedir, **kwargs)
示例15: __init__
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import error [as 别名]
def __init__(self, retain_dir=None):
EngineBase.__init__(self)
self.natlink = None
try:
import natlink
except ImportError:
self._log.error("%s: failed to import natlink module." % self)
raise EngineError("Requested engine 'natlink' is not available: Natlink is not installed.")
self.natlink = natlink
self._grammar_count = 0
self._recognition_observer_manager = NatlinkRecObsManager(self)
self._timer_manager = NatlinkTimerManager(0.02, self)
self._timer_thread = None
self._retain_dir = None
try:
self.set_retain_directory(retain_dir)
except EngineError as err:
self._retain_dir = None
self._log.error(err)