class Local(Singleton): def __init__(self): xml = SimpleXML(Path.executeDirectory()) try: self.__lngSect = xml.openSection(SysConfig().lngFile) except Exception, err: raise err if self.__lngSect is None: raise BaseException("Error", "config file 'bin.xml' is not exist.")
def formatLocalText(self, _scope, _tag, **args): """ 格式化指定语言版本文本,不做编码转换,args 必须与 python 脚本编码一致 """ sect = self.__lngSect[_scope] if sect is None or sect[_tag] is None or \ sect[_tag].asString is None: raise BaseException( "Error", "language file is not contain the tag '<%s>/<%s>'." % (_scope, _tag)) text = sect[_tag].asString try: text = text % args except TypeError: raise BaseException( "Error", "format message in tag '<%s>/<%s>' in language file fial: (args='%s')" % (_scope, _tag, args)) return text
def getLocalText(self, scope, tag): """ 获取指定语言版本文本,不做编码转换,args 必须与 python 脚本编码一致 """ sect = self.__lngSect[scope] if sect is None or sect[tag] is None or \ sect[tag].asString is None: raise BaseException( "Error", "language file is not contain the tag '<%s>/<%s>'." % (scope, tag)) return sect[tag].asString
def __init__(self, msg): title = Local().formatLocalText("explain", "errTitle") BaseException.__init__(self, title, msg)
def __init__(self, tagName, **args): title = Local().formatLocalText("encoding", "errTitle") msg = Local().formatLocalText("encoding", tagName, **args) BaseException.__init__(self, title, msg)
def __init__(self, msg): title = Local().formatLocalText("dataSource", 'errTitle') BaseException.__init__(self, title, msg)
def __call__(self, dsrc, row): raise BaseException( "Error", "class %r must implement %r method" % (self.clsName, "__call__"))
def explainText(cls, text, *args, **extras): raise BaseException("Error", "%s unimplements a class method: %s" % \ (cls.__name__, 'explainText(cls, text, *args, **extras)'))
def _raiseUnImplementExcept(clsName, methodName): raise BaseException("unimplement exception", "method '%s' is not implemented.")