📄 biwsdljscodegen.py
字号:
from BiWsdlCodeGen import *import reimport itertoolsimport stringimport textwrapimport os.path"""<summary>BiWsdiJsCodeGen is a CodeGen class for generating JS files</summary>"""class BiWsdlJsCodeGen (BiWsdlCodeGenEngine): """ <summary> Constructor. </summary> """ def __init__(self): super(BiWsdlJsCodeGen, self).__init__() self.__indentLevel = 0 """ <summary> Adds validation to base's setComments. Comments is allowed to be "default" or "none". </summary> <param name="aMode">New comment mode</param> """ def setComments(self, aMode): if aMode<>"none" and aMode<>"default": raise Exception("Invalid BiJsStub comments mode: " + aMode) super(BiWsdlJsCodeGen, self).setComments(aMode) def startGen(self): self.__outStream = file(self.__outputPath, "w+") def endGen(self): self.__outStream.close() """ <summary> Emit a comment line, if comments are enabled. </summary> <param name="aEmitWhat"> Comment line to emit </param> """ def emitIndentedCommentLine(self, aEmitWhat): if self.getComments()=="default": self.emitIndentedLine(aEmitWhat) """ <summary> Emit a line indented to current indent level. </summary> <param name="aEmitWhat"> Line to emit </param> """ def emitIndentedLine(self, aEmitWhat): self.emitLine(" " * self.__indentLevel + aEmitWhat) """ <summary> Emit a line. </summary> <param name="aEmitWhat"> Line to emit </param> """ def emitLine(self, aEmitWhat): self.__outStream.writelines(aEmitWhat + "\n") def startClassCtor(self, aName, aParams, aBase, aClassDescription): self.__currentClassName = aName self.__currentClassBase = aBase # Emit class constructor header comment self.emitFnHeaderComment(aClassDescription, aParams) # Emit constructor declaration self.emitIndentedLine("function " + aName + "(" + string.join(itertools.imap((lambda lParam: lParam[0]), aParams), ", ") + ")") self.startBlock() def endClassCtor(self): self.endBlock() self.emitIndentedLine("") self.emitIndentedLine(self.__currentClassName + ".prototype = new " + self.__currentClassBase + "();") self.emitIndentedLine("") def startClassMethod(self, aName, aParams, aDescription): # Emit method header comment self.emitFnHeaderComment(aDescription, aParams) self.emitIndentedLine(self.__currentClassName + ".prototype." + aName + " = function(" + string.join(itertools.imap((lambda lParam: lParam[0]), aParams), ", ") + ")") self.startBlock() def endClassMethod(self): self.endBlock() self.emitIndentedLine("") def startBlock(self): self.emitIndentedLine("{") self.indent() def endBlock(self): self.outdent() self.emitIndentedLine("}") def emitFnHeaderComment(self, aDescription, aParams): self.emitIndentedCommentLine("/// <summary>") for lSummaryLine in textwrap.wrap(aDescription): self.emitIndentedCommentLine("/// " + lSummaryLine) self.emitIndentedCommentLine("/// </summary>") for lParam in aParams: self.emitIndentedCommentLine("/// <param name=\"" + lParam[0] + "\">" + lParam[1] + "</param>") """ <summary> Increase current indent level. </summary> """ def indent(self): self.__indentLevel = self.__indentLevel + 1 """ <summary> Decrease current indent level. </summary> """ def outdent(self): self.__indentLevel = self.__indentLevel - 1 """ <summary> Given a QName, return a JS-vaid name derived from it. </summary> <param name="aQName">QName to convert to a JS name</param> """ def convertQNameToJName(aQName): return re.search('(\[[^\]]+\])?(.*)', aQName).group(2) convertQNameToJName = staticmethod(convertQNameToJName) """ <summary> Convert free-form text to JS escaped string </summary> <param name="aText"> </param> """ def escapeJsString(aText): return re.sub("([\\\\\n\"])", "\\\\\\1", aText) escapeJsString = staticmethod(escapeJsString) """ <summary> Set the output filename for the code generator </summary> <param name="aOutputFile">Path of output file</param> """ def setOutput(self, aOutputFile): if os.path.exists(aOutputFile): raise Exception("File '" + aOutputFile + "' already exists.") self.__outputPath = aOutputFile """ <summary> Retrieve output file of engine </summary> """ def getOutput(self): return self.__outputPath
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -