def test_StrLit(self): self._buildTest( Py.StringLiteral(value='abc\\n', format='ascii', quotation='single'), StrLit('abc\n')) self._buildTest( Py.StringLiteral(value='abc\'\\n', format='ascii', quotation='single'), StrLit('abc\'\n')) self._buildTest( Py.StringLiteral(value='abc\\n', format='unicode', quotation='double'), StrLit('abc\n', format='unicode', quotation='double'))
def _createMethodAST(self, codeGen): valueStmts, resultVarName = self._createValueStmtsAndResultVarName( codeGen ) JythonExceptionAST = codeGen.embeddedValue( JythonException ) sysAST = codeGen.embeddedValue( sys ) getCurrentExceptionCallAST = Schema.Call( target=Schema.AttributeRef( target=JythonExceptionAST, name='getCurrentException' ), args=[] ) getExcInfoTypeAST = Schema.Subscript( target=Schema.Call( target=Schema.AttributeRef( target=sysAST, name='exc_info' ), args=[] ), index=Schema.IntLiteral( format='decimal', numType='int', value='0' ) ) selfAST = codeGen.embeddedValue( self ) testValueAST = Schema.AttributeRef( target=selfAST, name='_testValue' ) kindExceptionAST = Schema.StringLiteral( format='ascii', quotation='single', value='exception' ) kindValueAST = Schema.StringLiteral( format='ascii', quotation='single', value='value' ) exceptStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindExceptionAST, getCurrentExceptionCallAST, getExcInfoTypeAST ] ) ) ] elseStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindValueAST, Schema.Load( name=resultVarName ) ] ) ) ] methodBody = [ Schema.TryStmt( suite=valueStmts, exceptBlocks=[ Schema.ExceptBlock( suite=exceptStmts ) ], elseSuite=elseStmts ) ] methodAST = Schema.DefStmt( name=self._methodName, decorators=[], params=[ Schema.SimpleParam( name='self' ) ], suite=methodBody ) return methodAST
def build(self): return Py.StringLiteral(value=self.valueString, format=self.format, quotation=self.quotation)