Python exceptions.ImportError() Examples

The following are 3 code examples of exceptions.ImportError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module exceptions , or try the search function .
Example #1
Source File: test_import_pep328.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def load_module(self, fullname):
        # Masquerade as the loader matching fullname
        self.assertEqual(fullname, self.fullname)
        # Signal success, disguised as an ImportError
        raise TestImportFunctionSuccess() 
Example #2
Source File: test_import_pep328.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def load_module(self, fullname):
        # Masquerade as the loader matching fullname
        self.assertEqual(fullname, self.fullname)
        # Signal success, disguised as an ImportError
        raise TestImportFunctionSuccess() 
Example #3
Source File: postgresql.py    From tensor with MIT License 4 votes vote down vote up
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')
            )