spyceException.py :  » Web-Frameworks » Spyce » spyce-2.1 » 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 » Web Frameworks » Spyce 
Spyce » spyce 2.1 » spyceException.py
##################################################
# SPYCE - Python-based HTML Scripting
# Copyright (c) 2002 Rimon Barr.
#
# Refer to spyce.py
##################################################

__doc__ = '''Various Spyce-related exceptions'''

import sys, string
import spyceUtil

class HandlerError(Exception):
  def __init__(self, element=None, description=None):
    self.element = element
    self.description = description
  def __str__(self):
    return repr(self)
  def __repr__(self):
    return 'HandlerError(%r, %r)' % (self.element, self.description)
  
class CompoundHandlerError(HandlerError):
  def __init__(self, sub_errors = None):
    if sub_errors is None:
      sub_errors = []
    self.sub_errors = sub_errors
  def add(self, err):
    self.sub_errors.append(err)
  def __len__(self):
    return len(self.sub_errors)
  def __repr__(self):
    return 'CompoundHandlerError(%r)' % self.sub_errors

##################################################
# Syntax errors
#

class pythonSyntaxError:
  "Generate string out of current pythonSyntaxError exception"
  def __repr__(self):
    return self.str
  def __init__(self, spycewrap):
    self.str = ''
    type, error, _ = sys.exc_info()
    if type is type(SyntaxError):
      raise 'instantiate pythonSyntaxError only when SyntaxError raised: %s' % `type`
    if spycewrap.getCodeRefs().has_key(error.lineno):
      begin, end, text, filename = spycewrap.getCodeRefs()[error.lineno]
      if begin[0]==end[0]:
        linestr = str(begin[0])
      else:
        linestr = '%d-%d' % (begin[0], end[0])
      self.str = 'Python syntax error at %s:%s - %s\n  %s\n' % (filename, linestr, error.msg, text)
    else:
      self.str = spyceUtil.exceptionString()

class spyceSyntaxError:
  "Generate string out of current spyceSyntaxError exception"
  def __init__(self, msg, info=None):
    self.msg = msg
    self.info = info
  def __repr__(self):
    s = 'Spyce syntax error'
    if self.info:
      (begin, _), (end, _), text, filename = self.info
      if begin==end:
        linestr = str(begin)
      else:
        linestr = '%d-%d' % (begin, end)
      s = s + ' at %s:%s - %s\n  %s\n' % (filename, linestr, self.msg, text)
    else:
      s = s + ': '+self.msg
    return s

##################################################
# Runtime errors
#

class spyceRuntimeException:
  "Generate string out of current SpyceException exception."
  # useful fields: str, type, value, traceback, msg
  def __repr__(self):
    return self.str
  def __init__(self, spycewrap=None):
    import spyce, spyceCompile
    import traceback, string
    e1, e2, tb = sys.exc_info()
    tb = traceback.extract_tb(tb)
    self.str = ''
    self.type, self.value, self.traceback = e1, e2, tb
    if e1 == spyceRuntimeException:
      self.msg = str(e2)
    else:
      self.msg = string.join(traceback.format_exception_only(e1, e2))
    for i in range(len(tb)):
      filename, lineno, funcname, text = tb[i]
      coderefs = None
      if filename == '<string>' and spycewrap and spycewrap.getCodeRefs().has_key(lineno):
        if funcname == spyceCompile.SPYCE_PROCESS_FUNC:
          funcname = '(main)'
        coderefs = spycewrap.getCodeRefs()
      else:
        try:
          coderefs = spyce.getServer().module_coderefs[filename]
        except KeyError:
          pass
      if coderefs:
        try:
          begin, end, text, filename = coderefs[lineno]
        except KeyError:
          spyce.DEBUG('coderefs are %s' % coderefs)
          lineno = '%s???' % lineno
        else:
          if begin[0]==end[0]:
            lineno = str(begin[0])
          else:
            lineno = '%d-%d' % (begin[0], end[0])
      lineno=str(lineno)
      tb[i] = filename, lineno, funcname, text
    for i in range(len(tb)):
      self.str = self.str + '  %s:%s, in %s: \n    %s\n' % tb[i]
    self.str = self.str + self.msg

class spyceNotFound:
  "Exception class to signal that Spyce file does not exist."
  def __init__(self, file):
    self.file = file
  def __repr__(self):
    return 'spyceNotFound exception: could not find "%s"' % self.file

class spyceForbidden:
  "Exception class to signal that Spyce file has access problems."
  def __init__(self, file):
    self.file = file
  def __repr__(self):
    return 'spyceForbidden exception: could not read "%s"' % self.file

##################################################
# Special control-flow exceptions
#

class spyceRedirect:
  "Exception class to signal an internal redirect."
  def __init__(self, filename):
    self.filename = filename
  def __repr__(self):
    return 'spyceRedirect: "%s"' % self.filename

class spyceDone:
  "Exception class to immediately jump to the end of the spyceProcess method"
  pass

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.