[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5449 - trunk/gnue-common/src/apps
From: |
reinhard |
Subject: |
r5449 - trunk/gnue-common/src/apps |
Date: |
Sun, 21 Mar 2004 18:48:55 -0600 (CST) |
Author: reinhard
Date: 2004-03-21 18:48:54 -0600 (Sun, 21 Mar 2004)
New Revision: 5449
Modified:
trunk/gnue-common/src/apps/checktype.py
Log:
Some code cleanup.
Modified: trunk/gnue-common/src/apps/checktype.py
===================================================================
--- trunk/gnue-common/src/apps/checktype.py 2004-03-22 00:22:19 UTC (rev
5448)
+++ trunk/gnue-common/src/apps/checktype.py 2004-03-22 00:48:54 UTC (rev
5449)
@@ -21,10 +21,11 @@
#
# $Id$
-import sys
-import string
from types import *
+import string
+import sys
+
from gnue.common.apps import i18n
# -----------------------------------------------------------------------------
@@ -32,12 +33,17 @@
# -----------------------------------------------------------------------------
class TypeError (Exception):
+ """
+ Raised when L{checktype} detects a wrong type.
+ Do not raise this exception manually.
+ """
+
# -----------------------------------------------------------------------------
- def stringify (self, atype):
+ def __stringify (self, atype):
if isinstance (atype, ListType):
- return string.join ([self.stringify (t) for t in atype], ' / ')
+ return string.join ([self.__stringify (t) for t in atype], ' / ')
elif isinstance (atype, TypeType):
return str (atype)
elif isinstance (atype, ClassType):
@@ -63,20 +69,28 @@
self.value = variable # Value of variable
- message = _(
-'''"%(varname)s" is expected to be of %(expected)s
-but is of %(actual)s and has value %(value)s'''
- ) % {'varname': self.varname,
- 'expected': self.stringify (self.expected),
- 'actual': self.stringify (self.actual),
- 'value': repr (self.value)}
+ message = u_('"%(varname)s" is expected to be of %(expected)s but is of '
+ '%(actual)s and has value %(value)s') \
+ % {'varname' : self.varname,
+ 'expected': self.__stringify (self.expected),
+ 'actual' : self.__stringify (self.actual),
+ 'value' : repr (self.value)}
Exception.__init__ (self, message)
# -----------------------------------------------------------------------------
# Check type of a variable
# -----------------------------------------------------------------------------
-def __checktype (variable, validtype):
+def checktype (variable, validtype):
+ """
+ Check a varaible (for example a parameter to a function) for a correct type.
+
+ This function is available as builtin function.
+
+ @param variable: the variable to check
+ @param validtype: the type, the class, or a list of types and classes that
+ are valid
+ """
if isinstance (validtype, ListType):
for t in validtype:
if isinstance (variable, t):
@@ -91,7 +105,7 @@
# -----------------------------------------------------------------------------
import __builtin__
-__builtin__.__dict__['checktype'] = __checktype
+__builtin__.__dict__['checktype'] = checktype
# -----------------------------------------------------------------------------
# Self test code
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5449 - trunk/gnue-common/src/apps,
reinhard <=