本文整理汇总了Python中sys.exc_info方法的典型用法代码示例。如果您正苦于以下问题:Python sys.exc_info方法的具体用法?Python sys.exc_info怎么用?Python sys.exc_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.exc_info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_settings
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def get_settings(self):
"""Return the DynamoDB aws-auto-remediate-settings table in a Python dict format
Returns:
dict -- aws-auto-remediate-settings table
"""
settings = {}
try:
for record in boto3.client("dynamodb").scan(
TableName=os.environ["SETTINGSTABLE"]
)["Items"]:
record_json = dynamodb_json.loads(record, True)
settings[record_json["key"]] = record_json["value"]
except:
self.logging.error(
f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'."
)
self.logging.error(sys.exc_info()[1])
return settings
示例2: start
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def start(self):
"""Start all services."""
atexit.register(self._clean_exit)
self.state = states.STARTING
self.log('Bus STARTING')
try:
self.publish('start')
self.state = states.STARTED
self.log('Bus STARTED')
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
self.log('Shutting down due to error in start listener:',
level=40, traceback=True)
e_info = sys.exc_info()[1]
try:
self.exit()
except Exception:
# Any stop/exit errors will be logged inside publish().
pass
# Re-raise the original error
raise e_info
示例3: _start_http_thread
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def _start_http_thread(self):
"""HTTP servers MUST be running in new threads, so that the
main thread persists to receive KeyboardInterrupt's. If an
exception is raised in the httpserver's thread then it's
trapped here, and the bus (and therefore our httpserver)
are shut down.
"""
try:
self.httpserver.start()
except KeyboardInterrupt:
self.bus.log('<Ctrl-C> hit: shutting down HTTP server')
self.interrupt = sys.exc_info()[1]
self.bus.exit()
except SystemExit:
self.bus.log('SystemExit raised: shutting down HTTP server')
self.interrupt = sys.exc_info()[1]
self.bus.exit()
raise
except Exception:
self.interrupt = sys.exc_info()[1]
self.bus.log('Error in HTTP server: shutting down',
traceback=True, level=40)
self.bus.exit()
raise
示例4: as_dict
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def as_dict(self, raw=False, vars=None):
"""Convert an INI file to a dictionary"""
# Load INI file into a dict
result = {}
for section in self.sections():
if section not in result:
result[section] = {}
for option in self.options(section):
value = self.get(section, option, raw=raw, vars=vars)
try:
value = unrepr(value)
except Exception:
x = sys.exc_info()[1]
msg = ('Config error in section: %r, option: %r, '
'value: %r. Config values must be valid Python.' %
(section, option, value))
raise ValueError(msg, x.__class__.__name__, x.args)
result[section][option] = value
return result
示例5: respond
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def respond(self, path_info):
"""Generate a response for the resource at self.path_info. (Core)"""
try:
try:
try:
self._do_respond(path_info)
except (cherrypy.HTTPRedirect, cherrypy.HTTPError):
inst = sys.exc_info()[1]
inst.set_response()
self.stage = 'before_finalize (HTTPError)'
self.hooks.run('before_finalize')
cherrypy.serving.response.finalize()
finally:
self.stage = 'on_end_resource'
self.hooks.run('on_end_resource')
except self.throws:
raise
except Exception:
if self.throw_errors:
raise
self.handle_error()
示例6: test_http_over_https
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def test_http_over_https(self):
if self.scheme != 'https':
return self.skip('skipped (not running HTTPS)... ')
# Try connecting without SSL.
conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
conn.putrequest('GET', '/', skip_host=True)
conn.putheader('Host', self.HOST)
conn.endheaders()
response = conn.response_class(conn.sock, method='GET')
try:
response.begin()
self.assertEqual(response.status, 400)
self.body = response.read()
self.assertBody('The client sent a plain HTTP request, but this '
'server only speaks HTTPS on this port.')
except socket.error:
e = sys.exc_info()[1]
# "Connection reset by peer" is also acceptable.
if e.errno != errno.ECONNRESET:
raise
示例7: test_garbage_in
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def test_garbage_in(self):
# Connect without SSL regardless of server.scheme
c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
c._output(b'gjkgjklsgjklsgjkljklsg')
c._send_output()
response = c.response_class(c.sock, method='GET')
try:
response.begin()
self.assertEqual(response.status, 400)
self.assertEqual(response.fp.read(22),
b'Malformed Request-Line')
c.close()
except socket.error:
e = sys.exc_info()[1]
# "Connection reset by peer" is also acceptable.
if e.errno != errno.ECONNRESET:
raise
示例8: mfa_enabled_for_iam_console_access
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def mfa_enabled_for_iam_console_access(self, resource_id):
"""Deletes login profile for user with console access that doesn't have MFA enabled
Arguments:
resource_id {string} -- IAM User ID
Returns:
boolean -- True if remediation is successful
"""
try:
page_user = self.client_iam.get_paginator("list_users").paginate()
for username in page_user.search(
f"Users[?UserId == '{resource_id}'].UserName"
):
self.client_iam.delete_login_profile(UserName=username)
self.logging.info(f"Deleted login profile for IAM User '{username}'.")
return True
except:
self.logging.error(
f"Could not delete login profile for IAM User '{resource_id}'."
)
self.logging.error(sys.exc_info()[1])
return False
示例9: multi_region_cloud_trail_enabled
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def multi_region_cloud_trail_enabled(self, resource_id):
"""Enables multi region CloudTrail
Arguments:
resource_id {string} -- CloudTrail Name
Returns:
boolean -- True if remediation is successful
"""
try:
self.client_cloudtrail.update_trail(
Name=resource_id, IsMultiRegionTrail=True
)
self.logging.info(
f"Enabled multi region trail for CloudTrail '{resource_id}'."
)
return True
except:
self.logging.error(
f"Could not enable multi region trail for CloudTrail '{resource_id}'."
)
self.logging.error(sys.exc_info()[1])
return False
示例10: s3_bucket_public_read_prohibited
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def s3_bucket_public_read_prohibited(self, resource_id):
"""Sets the S3 Bucket ACL to "private" to prevent the Bucket from being publicly read.
Arguments:
resource_id {string} -- S3 Bucket Name
Returns:
boolean -- True if remediation was successful
"""
try:
self.client_s3.put_bucket_acl(ACL="private", Bucket=resource_id)
self.logging.info(f"ACL set to 'private' for S3 Bucket '{resource_id}'.")
return True
except:
self.logging.error(
f"Could not set ACL set to 'private' for S3 Bucket '{resource_id}'."
)
self.logging.error(sys.exc_info()[1])
return False
示例11: s3_bucket_public_write_prohibited
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def s3_bucket_public_write_prohibited(self, resource_id):
"""Sets the S3 Bucket ACL to "private" to prevent the Bucket from being publicly written to.
Arguments:
resource_id {string} -- S3 Bucket Name
Returns:
boolean -- True if remediation was successful
"""
try:
self.client_s3.put_bucket_acl(ACL="private", Bucket=resource_id)
self.logging.info(f"ACL set to 'private' for S3 Bucket '{resource_id}'.")
return True
except:
self.logging.error(
f"Could not set ACL set to 'private' for S3 Bucket '{resource_id}'."
)
self.logging.error(sys.exc_info()[1])
return False
示例12: receive_message
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def receive_message(self, queue_url):
"""Retrieves 10 messeges from an SQS Queue
Arguments:
queue_url {string} -- SQS Queue URL
Returns:
dictionary -- Dictionary of SQS messeges
"""
try:
return self.client_sqs.receive_message(
QueueUrl=queue_url,
MessageAttributeNames=["try_count"],
MaxNumberOfMessages=10,
)
except:
self.logging.error(
f"Could not retrieve Messages from SQS Queue URL '{queue_url}'."
)
self.logging.error(sys.exc_info()[1])
return {}
示例13: get_current_stacks
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def get_current_stacks(self):
"""Retrieve a list of all CloudFormation Stacks currently deployed your AWS accont and region
Returns:
list -- List of currently deployed AWS Config Rules
"""
try:
resources = self.client_cloudformation.list_stacks().get("StackSummaries")
except:
self.logging.error(sys.exc_info()[1])
return None
existing_stacks = []
for resource in resources:
if resource.get("StackStatus") not in ("DELETE_COMPLETE"):
existing_stacks.append(resource.get("StackName"))
return existing_stacks
示例14: get_settings
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def get_settings(self):
"""Return the DynamoDB aws-auto-remediate-settings table in a Python dict format
Returns:
dict -- aws-auto-remediate-settings table
"""
settings = {}
try:
for record in self.client_dynamodb.scan(
TableName=os.environ["SETTINGSTABLE"]
)["Items"]:
record_json = dynamodb_json.loads(record, True)
if "key" in record_json and "value" in record_json:
settings[record_json.get("key")] = record_json.get("value")
except:
self.logging.error(
f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'."
)
self.logging.error(sys.exc_info()[1])
return settings
示例15: get_caller_module_dict
# 需要导入模块: import sys [as 别名]
# 或者: from sys import exc_info [as 别名]
def get_caller_module_dict(levels):
try:
raise RuntimeError
except RuntimeError:
e,b,t = sys.exc_info()
f = t.tb_frame
while levels > 0:
f = f.f_back
levels -= 1
ldict = f.f_globals.copy()
if f.f_globals != f.f_locals:
ldict.update(f.f_locals)
return ldict
# -----------------------------------------------------------------------------
# _funcs_to_names()
#
# Given a list of regular expression functions, this converts it to a list
# suitable for output to a table file
# -----------------------------------------------------------------------------