DTExcept.py :  » Database » PyDO » skunkweb-3.4.4 » pylibs » DT » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyDO 
PyDO » skunkweb 3.4.4 » pylibs » DT » DTExcept.py
#  
#  Copyright (C) 2001 Andrew T. Csillag <drew_csillag@geocities.com>
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
#   
"""
Class implementing DT exceptions. All exceptions raised inside templates 
SHOULD inherit from these exceptions
"""

import string

import SkunkExcept
import ErrorHandler
import string

class DTCompileError ( SkunkExcept.SkunkCustomError ):
    """
    This is a general purpose error, to be raised during compilation stage of
    a template
    """
    def __init__ ( self, tag, desc ):
        SkunkExcept.SkunkCustomError.__init__(self, desc)
        self._tag = tag
        self._desc = desc

    def format ( self ):
        """
        Print self nicely
        """
        ret = ErrorHandler._error

        ret = ret + 'Cannot compile template %s\n' % self._tag.filename()
        ret = ret + 'Template: %s, line %d\n' % (self._tag.filename(), 
                                                 self._tag.lineno())
        ret = ret + 'Tag: %s\n' % self._tag
        ret = ret + 'Error: %s\n' % self._desc 
        ret = ret + ErrorHandler._close

        return ret

class DTLexicalError ( SkunkExcept.SkunkCustomError ):
    # XXX Now, doesn't always pass in 'name' - Drew, please fix if you can
    def __init__(self, lineno, msg, name = None, tagtext=''):
        SkunkExcept.SkunkCustomError.__init__ ( self, msg )
        self.msg=msg
        self.tagtext=tagtext
        self.startoff=-1
        self.lineno=lineno
        self.name=name

    def format(self):
        ret = ErrorHandler._error

        ret = ret + 'Cannot compile template %s\n' % self.name

        # XXX Should *always* supply name and line number
        ret = ret + 'Template: %s, line %d\n' % (self.name, self.lineno)
        if self.tagtext:
            ret = ret + 'Tag: <:%s:>\n' % self.tagtext
        ret = ret + 'Error: %s\n' % self.msg
        ret = ret + ErrorHandler._close

        return ret

    def __repr__(self):
        return self.format()

    def __str__(self):
        return repr(self)
    

class DTRuntimeError ( SkunkExcept.SkunkCustomError ):
    """
    This exception should be raised if an error happens during an evaluation of
    a tag. 
    """
    def __init__ ( self, tag, fileline, *args ):
        apply ( SkunkExcept.SkunkCustomError.__init__, 
                (self,) + args ) 

        # Tag is the string represenation of the tag, lineno is the
        # component:line string
        self._filename, self._lineno = tuple ( string.split ( fileline, ':' ))
        self._tag = tag

    def format ( self ):
        """
        This is the actual function which will be used to generate the error
        message
        """
        ret = ErrorHandler._error
        ret = ret + 'Template: %s, line %d\n' % ( self._filename, self._lineno )
        ret = ret + 'Tag: %s\n' % self._tag
        ret = ret + 'Error: %s\n' % str(self.args[0])
        ret = ret + ErrorHandler._close

        return ret

#
# This is a special case exception
#
class DTHaltError ( DTRuntimeError ):

    def __init__ ( self, tag, fileline, *args ):
        apply ( DTRuntimeError.__init__, (self, tag, fileline) + args )

    def format ( self ):
        ret = ErrorHandler._error
        ret = ret + 'Halt exception uncatched! This is an AED internal error\n'
        ret = ret + 'Template: %s, line %d\n' % ( self._filename, self._lineno )
        ret = ret + 'Tag: %s\n' % self._tag
        ret = ret + 'Text: %s\n' % str(self.args[0])
        
        return ret

#
# This is a helper function to generate exception raising code during runtime
# of a template 
#
def raiseRuntime ( output, indent, msg ):
     """
     Generate a code which raises a runtime exception. DTExcept should be 
     preloaded in __h
     """
     output.write ( indent, 'raise __h.DTExcept.DTRuntimeError ( '
                            '__d.CURRENT_TAG, __d.CURRENT_LINENO, "%s")' % msg )

def raiseHalt ( output, indent, msg = 'generic halt' ):
     """
     Helper function to do halt
     """
     output.write ( indent, 'raise __h.DTExcept.DTHaltError ( '
                            '__d.CURRENT_TAG, __d.CURRENT_LINENO, "%s")' % msg )
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.