Errors.py :  » Development » Pyrex » Pyrex-0.9.9 » Pyrex » Compiler » 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 » Development » Pyrex 
Pyrex » Pyrex 0.9.9 » Pyrex » Compiler » Errors.py
#
#   Pyrex - Errors
#

import sys
from Pyrex.Utils import open_new_file

warnings_issued = {}

class PyrexError(EnvironmentError):
    pass


class CompileError(PyrexError):
    
    def __init__(self, position = None, message = ""):
        self.position = position
        if position:
            pos_str = "%s:%d:%d: " % position
        else:
            pos_str = ""
        PyrexError.__init__(self, pos_str + message)


class InternalError(Exception):
    # If this is ever raised, there is a bug in the compiler.
    
    def __init__(self, message):
        Exception.__init__(self, "Internal compiler error: %s"
            % message)
            

listing_file = None
num_errors = 0
echo_file = None

def open_listing_file(path, echo_to_stderr = 1):
    # Begin a new error listing. If path is None, no file
    # is opened, the error counter is just reset.
    global listing_file, num_errors, echo_file
    if path is not None:
        listing_file = open_new_file(path)
    else:
        listing_file = None
    if echo_to_stderr:
        echo_file = sys.stderr
    else:
        echo_file = None
    num_errors = 0

def close_listing_file():
    global listing_file
    if listing_file:
        listing_file.close()
        listing_file = None

def report(position, message):
    err = CompileError(position, message)
    line = "%s\n" % err
    if listing_file:
        listing_file.write(line)
    if echo_file:
        echo_file.write(line)
    return err

def warning(position, message):
    return report(position, "Warning: %s" % message)

def one_time_warning(position, key, message):
    if key not in warnings_issued:
        warnings_issued[key] = 1
        warning(position, message)

def error(position, message):
    global num_errors
    num_errors = num_errors + 1
    return report(position, message)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.