org.drools.semantics.python
Class PythonInterp

java.lang.Object
  extended by org.drools.semantics.python.PythonInterp
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
PythonBlockConsequence, PythonCondition

public class PythonInterp
extends java.lang.Object
implements java.io.Serializable

Base class for Jython interpreter-based Python semantic components.

See Also:
Serialized Form

Constructor Summary
protected PythonInterp(java.lang.String text, Rule rule, java.lang.String type)
          Construct.
 
Method Summary
protected  PyCode getCode()
          Retrieve the compiled code.
protected  PyDictionary getGlobals()
           
 PyDictionary getGlobals(java.lang.String text)
          Parses a python script and returns the globals It is used to be able to inject imports and functions into code when being executed by Py.runCode(...)
protected  modType getNode()
          Retrieve the AST node.
protected  Rule getRule()
           
 java.lang.String getText()
          Retrieve the text to evaluate.
protected  PyDictionary setUpDictionary(Tuple tuple, java.util.Iterator declIter)
          Configure a PyDictionary using a Tuple for variable bindings.
protected static java.lang.String stripOuterIndention(java.lang.String text)
          Trims leading indention from the block of text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PythonInterp

protected PythonInterp(java.lang.String text,
                       Rule rule,
                       java.lang.String type)
Construct.

Method Detail

getGlobals

public PyDictionary getGlobals(java.lang.String text)
Parses a python script and returns the globals It is used to be able to inject imports and functions into code when being executed by Py.runCode(...)

Parameters:
text -
Returns:
PyDictionary globals

stripOuterIndention

protected static java.lang.String stripOuterIndention(java.lang.String text)
Trims leading indention from the block of text. Since Python relies on indention as part of its syntax, any XML indention introduced needs to be stripped out. For example, this:
 
  
  
    |   <python:consequence>
    |       if hello == 'Hello':
    |           print "Hi"
    |       else:
    |           print "Bye"
    |   </python:consequence>
  
   
  
 
is transformed into:
 
  
  
    |   <python:consequence>
    |if hello == 'Hello':
    |    print "Hi"
    |else:
    |    print "Bye"
    |   </python:consequence>
  
   
  
 

Parameters:
text - the block of text to be stripped
Returns:
the block of text stripped of its leading indention

getText

public java.lang.String getText()
Retrieve the text to evaluate.

Returns:
The text to evaluate.

getRule

protected Rule getRule()

getCode

protected PyCode getCode()
Retrieve the compiled code.

Returns:
The code.

getNode

protected modType getNode()
Retrieve the AST node.

Returns:
The node.

getGlobals

protected PyDictionary getGlobals()

setUpDictionary

protected PyDictionary setUpDictionary(Tuple tuple,
                                       java.util.Iterator declIter)
                                throws java.lang.Exception
Configure a PyDictionary using a Tuple for variable bindings.

Parameters:
tuple - Tuple containing variable bindings.
Returns:
The dictionary
Throws:
java.lang.Exception