Back to index

moin  1.9.0~rc2
errors.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright (C) 2007 Lemur Consulting Ltd
00004 #
00005 # This program is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU General Public License as published by
00007 # the Free Software Foundation; either version 2 of the License, or
00008 # (at your option) any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 # GNU General Public License for more details.
00014 # 
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program; if not, write to the Free Software Foundation, Inc.,
00017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 r"""errors.py: Exceptions for the search engine core.
00019 
00020 """
00021 __docformat__ = "restructuredtext en"
00022 
00023 class SearchEngineError(Exception):
00024     r"""Base class for exceptions thrown by the search engine.
00025 
00026     Any errors generated by xappy itself, or by xapian, will be instances of
00027     this class or its subclasses.
00028 
00029     """
00030 
00031 class IndexerError(SearchEngineError):
00032     r"""Class used to report errors relating to the indexing API.
00033 
00034     """
00035 
00036 class SearchError(SearchEngineError):
00037     r"""Class used to report errors relating to the search API.
00038 
00039     """
00040 
00041 
00042 class XapianError(SearchEngineError):
00043     r"""Base class for exceptions thrown by the xapian.
00044 
00045     Any errors generated by xapian will be instances of this class or its
00046     subclasses.
00047 
00048     """
00049 
00050 def _rebase_xapian_exceptions():
00051     """Add new base classes for all the xapian exceptions.
00052 
00053     """
00054     import xapian
00055     for name in (
00056                  'AssertionError',
00057                  'DatabaseCorruptError',
00058                  'DatabaseCreateError',
00059                  'DatabaseError',
00060                  'DatabaseLockError',
00061                  'DatabaseModifiedError',
00062                  'DatabaseOpeningError',
00063                  'DatabaseVersionError',
00064                  'DocNotFoundError',
00065                  # We skip 'Error' because it inherits directly from exception
00066                  # and this causes problems with method resolution order.
00067                  # However, we probably don't need it anyway, because it's
00068                  # just a base class, and shouldn't ever actually be raised.
00069                  # Users can catch xappy.XapianError instead.
00070                  'FeatureUnavailableError',
00071                  'InternalError',
00072                  'InvalidArgumentError',
00073                  'InvalidOperationError',
00074                  'LogicError',
00075                  'NetworkError',
00076                  'NetworkTimeoutError',
00077                  'QueryParserError',
00078                  'RangeError',
00079                  'RuntimeError',
00080                  'UnimplementedError',
00081                  ):
00082         xapian_exception = getattr(xapian, name, None)
00083         if xapian_exception is not None:
00084             xapian_exception.__bases__ += (XapianError, )
00085             globals()['Xapian' + name] = xapian_exception
00086 
00087 _rebase_xapian_exceptions()