本文整理汇总了Python中exceptions.ImportError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ImportError方法的具体用法?Python exceptions.ImportError怎么用?Python exceptions.ImportError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exceptions
的用法示例。
在下文中一共展示了exceptions.ImportError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_module
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import ImportError [as 别名]
def load_module(self, fullname):
# Masquerade as the loader matching fullname
self.assertEqual(fullname, self.fullname)
# Signal success, disguised as an ImportError
raise TestImportFunctionSuccess()
示例2: get
# 需要导入模块: import exceptions [as 别名]
# 或者: from exceptions import ImportError [as 别名]
def get(self):
try:
p = adbapi.ConnectionPool('psycopg2',
database='postgres',
host=self.host,
port=self.port,
user=self.user,
password=self.password)
cols = (
('xact_commit', 'commits'),
('xact_rollback', 'rollbacks'),
('blks_read', 'disk.read'),
('blks_hit', 'disk.cache'),
('tup_returned', 'returned'),
('tup_fetched', 'selects'),
('tup_inserted', 'inserts'),
('tup_updated', 'updates'),
('tup_deleted', 'deletes'),
('deadlocks', 'deadlocks')
)
keys, names = zip(*cols)
q = yield p.runQuery(
'SELECT datname,numbackends,%s FROM pg_stat_database' % (
','.join(keys))
)
for row in q:
db = row[0]
threads = row[1]
if db not in ('template0', 'template1'):
self.queueBack(self.createEvent('ok',
'threads: %s' % threads,
threads,
prefix='%s.threads' % db)
)
for i, col in enumerate(row[2:]):
self.queueBack(self.createEvent('ok',
'%s: %s' % (names[i], col),
col,
prefix='%s.%s' % (db, names[i]),
aggregation=Counter64)
)
yield p.close()
defer.returnValue(self.createEvent('ok', 'Connection ok', 1,
prefix='state'))
except exceptions.ImportError:
log.msg('tensor.sources.database.postgresql.PostgreSQL'
' requires psycopg2')
defer.returnValue(None)
except Exception as e:
defer.returnValue(self.createEvent('critical',
'Connection error: %s' % str(e).replace('\n',' '),
0, prefix='state')
)