# -*- coding: windows-1251 -*- """ GIL Base exception classes. """ # This file is part of GIL (Global Intellectual Library). # # GIL is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # GIL is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GIL; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ---------------------------------------------------------------------------------------------- # Copyright 2005 Alexander Prikhodko (apri7@mail.ru), Natalia Prikhodko (vnatalya@pochta.ru) import types, sys, string # ================================================================================================ # Exceptions. # ================================================================================================ class GIL_ExceptionBase: def __init__(self,message=None): self.message = message def __str__(self): if not self.__dict__.has_key("message"): self.message = "No message" if self.message is None: self.message = "No message" return repr(self.message) def __unicode__(self): import gil.gil_common if gil.gil_common.system_encoding is None: try: s = unicode(self.__str__()) except: s = repr(self.message) else: try: s = self.__str__().decode(gil.gil_common.system_encoding) except: s = repr(self.message) class GIL_RuntimeError(GIL_ExceptionBase,RuntimeError): pass class GIL_RuntimeWarning(GIL_ExceptionBase,RuntimeWarning): pass # ================================================================================================ # System esceptions. # ================================================================================================ def tabs(n): try: import gil.gil_common return gil.gil_common.tabs(n) except: return " " * n class GIL_SystemException(GIL_ExceptionBase,Exception): def __init__(self,extra_message=None): GIL_ExceptionBase.__init__(self,extra_message) # self.info = sys.exc_info() def __str__(self): # if self.info[1] is None: if self.message is None: s = "No message" else: s = "(%s)" % self.message # else: base_s = self.info[0].__name__ + ": " + str(self.info[1]) if self.message is None: s = base_s else: s = "%s (%s)" % (base_s, self.message) # return s def text(self,level=0): import gil.gil_common # a = list() a.append("%sSystemException" % tabs(level) ) # message = str(self) message_a = message.split("\n") for k in range(0,len(message_a)): a.append(message_a[k]) # if self.info[2] is None: a.append("No traceback") else: tb_s = gil.gil_common.tb_text(self.info[2]) tb_a = tb_s.split("\n") for k in range(0,len(tb_a)): a.append(tb_a[k]) # return string.join(a,"\n")