Merge pull request #49434 from dwoz/cleanup_exception_handling

Clean up exception handling on py3
This commit is contained in:
Nicole Thomas 2018-08-30 08:56:23 -04:00 committed by GitHub
commit 03d97507f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 11 deletions

View File

@ -303,7 +303,7 @@ def shutdown(message=None, timeout=5, force_close=True, reboot=False, # pylint:
force_close, reboot)
return True
except pywintypes.error as exc:
(number, context, message) = exc
(number, context, message) = exc.args
log.error('Failed to shutdown the system')
log.error('nbr: {0}'.format(number))
log.error('ctx: {0}'.format(context))
@ -346,7 +346,7 @@ def shutdown_abort():
win32api.AbortSystemShutdown('127.0.0.1')
return True
except pywintypes.error as exc:
(number, context, message) = exc
(number, context, message) = exc.args
log.error('Failed to abort system shutdown')
log.error('nbr: {0}'.format(number))
log.error('ctx: {0}'.format(context))
@ -485,7 +485,7 @@ def set_computer_desc(desc=None):
try:
win32net.NetServerSetInfo(None, 101, system_info)
except win32net.error as exc:
(number, context, message) = exc
(number, context, message) = exc.args
log.error('Failed to update system')
log.error('nbr: {0}'.format(number))
log.error('ctx: {0}'.format(context))
@ -1016,7 +1016,7 @@ def set_system_date_time(years=None,
try:
date_time = win32api.GetLocalTime()
except win32api.error as exc:
(number, context, message) = exc
(number, context, message) = exc.args
log.error('Failed to get local time')
log.error('nbr: {0}'.format(number))
log.error('ctx: {0}'.format(context))

View File

@ -164,7 +164,6 @@ def add(name,
try:
win32net.NetUserAdd(None, 1, user_info)
except win32net.error as exc:
(number, context, message) = exc
log.error('Failed to create user {0}'.format(name))
log.error('nbr: {0}'.format(exc.winerror))
log.error('ctx: {0}'.format(exc.funcname))
@ -266,7 +265,6 @@ def update(name,
try:
user_info = win32net.NetUserGetInfo(None, name, 4)
except win32net.error as exc:
(number, context, message) = exc
log.error('Failed to update user {0}'.format(name))
log.error('nbr: {0}'.format(exc.winerror))
log.error('ctx: {0}'.format(exc.funcname))
@ -326,7 +324,6 @@ def update(name,
try:
win32net.NetUserSetInfo(None, name, 4, user_info)
except win32net.error as exc:
(number, context, message) = exc
log.error('Failed to update user {0}'.format(name))
log.error('nbr: {0}'.format(exc.winerror))
log.error('ctx: {0}'.format(exc.funcname))
@ -415,7 +412,7 @@ def delete(name,
sid = getUserSid(name)
win32profile.DeleteProfile(sid)
except pywintypes.error as exc:
(number, context, message) = exc
(number, context, message) = exc.args
if number == 2: # Profile Folder Not Found
pass
else:
@ -429,7 +426,6 @@ def delete(name,
try:
win32net.NetUserDel(None, name)
except win32net.error as exc:
(number, context, message) = exc
log.error('Failed to delete user {0}'.format(name))
log.error('nbr: {0}'.format(exc.winerror))
log.error('ctx: {0}'.format(exc.funcname))

View File

@ -268,8 +268,8 @@ class UseraddModuleTestWindows(ModuleCase):
self._add_group()
self.run_function('user.addgroup', [self.user_name, self.group_name])
self.assertIn(self.group_name, self.run_function('user.list_groups', [self.user_name]))
self.run_function('user.removegroup', [self.group_name])
self.assertIn(self.group_name, self.run_function('user.list_groups', [self.user_name]))
self.run_function('user.removegroup', [self.user_name, self.group_name])
self.assertNotIn(self.group_name, self.run_function('user.list_groups', [self.user_name]))
def test_user_rename(self):
'''