srcanamdw/codescanner/pyinstaller/optik/errors.py
changeset 1 22878952f6e2
equal deleted inserted replaced
0:509e4801c378 1:22878952f6e2
       
     1 """optik.errors
       
     2 
       
     3 Exception classes used by Optik.
       
     4 """
       
     5 
       
     6 # Copyright (c) 2001-2004 Gregory P. Ward.  All rights reserved.
       
     7 # See the README.txt distributed with Optik for licensing terms.
       
     8 
       
     9 import string
       
    10 try:
       
    11     from gettext import gettext
       
    12 except ImportError:
       
    13     def gettext(message):
       
    14         return message
       
    15 _ = gettext
       
    16 
       
    17 __revision__ = "$Id: errors.py,v 1.1 2009/02/05 23:03:30 stechong Exp $"
       
    18 
       
    19 __all__ = ['OptikError', 'OptionError', 'OptionConflictError',
       
    20            'OptionValueError', 'BadOptionError']
       
    21 
       
    22 
       
    23 class OptikError (Exception):
       
    24     def __init__(self, msg):
       
    25         self.msg = msg
       
    26 
       
    27     def __str__(self):
       
    28         return self.msg
       
    29 
       
    30 
       
    31 class OptionError (OptikError):
       
    32     """
       
    33     Raised if an Option instance is created with invalid or
       
    34     inconsistent arguments.
       
    35     """
       
    36 
       
    37     def __init__(self, msg, option):
       
    38         self.msg = msg
       
    39         self.option_id = str(option)
       
    40 
       
    41     def __str__(self):
       
    42         if self.option_id:
       
    43             return "option %s: %s" % (self.option_id, self.msg)
       
    44         else:
       
    45             return self.msg
       
    46 
       
    47 class OptionConflictError (OptionError):
       
    48     """
       
    49     Raised if conflicting options are added to an OptionParser.
       
    50     """
       
    51 
       
    52 class OptionValueError (OptikError):
       
    53     """
       
    54     Raised if an invalid option value is encountered on the command
       
    55     line.
       
    56     """
       
    57 
       
    58 class BadOptionError (OptikError):
       
    59     """
       
    60     Raised if an invalid option is seen on the command line.
       
    61     """
       
    62     def __init__(self, opt_str):
       
    63         self.opt_str = opt_str
       
    64 
       
    65     def __str__(self):
       
    66         return _("no such option: %s") % self.opt_str
       
    67 
       
    68 class AmbiguousOptionError (BadOptionError):
       
    69     """
       
    70     Raised if an ambiguous option is seen on the command line.
       
    71     """
       
    72     def __init__(self, opt_str, possibilities):
       
    73         BadOptionError.__init__(self, opt_str)
       
    74         self.possibilities = possibilities
       
    75 
       
    76     def __str__(self):
       
    77         return (_("ambiguous option: %s (%s?)")
       
    78                 % (self.opt_str, string.join(self.possibilities, ", ")))