當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.ImportError方法代碼示例

本文整理匯總了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() 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:7,代碼來源:test_import_pep328.py

示例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')
            ) 
開發者ID:calston,項目名稱:tensor,代碼行數:63,代碼來源:postgresql.py


注:本文中的exceptions.ImportError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。