Go to the documentation of this file.00001
00002
00003
00004
00005 '''rtshell
00006
00007 Copyright (C) 2009-2014
00008 Geoffrey Biggs
00009 RT-Synthesis Research Group
00010 Intelligent Systems Research Institute,
00011 National Institute of Advanced Industrial Science and Technology (AIST),
00012 Japan
00013 All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016
00017 Built-in formatters for rtprint.
00018
00019 '''
00020
00021 import inspect
00022 import rts_exceptions
00023
00024
00025
00026
00027
00028 def rawpy(data):
00029 return data.__repr__()
00030
00031
00032
00033
00034
00035 def import_formatter(form, modmgr):
00036 '''Import a formatter.
00037
00038 This function attempts to evaluate an expression specifying a function
00039 object that can be used to format a piece of data. The imported function
00040 must receive one positional argument, which is the data to format.
00041
00042 @param form The formatter expression.
00043 @param modmgr The module manager to use to evaluate @ref form.
00044
00045 '''
00046
00047 form_rpl = form
00048 if form.startswith('rtshell.'):
00049 form_rpl = 'fmt.' + form[8:]
00050 try:
00051 form_fun = modmgr.evaluate(form_rpl)
00052 except Exception, e:
00053 raise rts_exceptions.ImportFormatterError(e)
00054
00055 if type(form_fun) != type(import_formatter):
00056 raise rts_exceptions.BadFormatterError(form)
00057 args, varargs, varkw, defaults = inspect.getargspec(form_fun)
00058 if len(args) != 1 or varargs or varkw or defaults:
00059 raise BadFormatterError(form)
00060 return form_fun
00061