本文整理匯總了Java中org.python.core.PyString類的典型用法代碼示例。如果您正苦於以下問題:Java PyString類的具體用法?Java PyString怎麽用?Java PyString使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PyString類屬於org.python.core包,在下文中一共展示了PyString類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configFromProperties
import org.python.core.PyString; //導入依賴的package包/類
/**
* Copy all properties into jython envirenment
* @param appId
* @param whExecId
* @param properties
* @return PySystemState A PySystemState that contain all the arguments.
*/
private PySystemState configFromProperties(Integer appId, Integer dbId, Long whExecId, Properties properties) {
this.prop = properties;
if (appId != null)
prop.setProperty(Constant.APP_ID_KEY, String.valueOf(appId));
if (dbId != null)
prop.setProperty(Constant.DB_ID_KEY, String.valueOf(dbId));
prop.setProperty(Constant.WH_EXEC_ID_KEY, String.valueOf(whExecId));
PyDictionary config = new PyDictionary();
for (String key : prop.stringPropertyNames()) {
String value = prop.getProperty(key);
config.put(new PyString(key), new PyString(value));
}
PySystemState sys = new PySystemState();
sys.argv.append(config);
return sys;
}
示例2: getNewValue
import org.python.core.PyString; //導入依賴的package包/類
/**
* Accepts Map<String, PyObject> as newValue.
*/
@Override
public PyObject getNewValue(Object newValue) {
if (!(newValue instanceof Map)){
throw new IllegalArgumentException("newValue not of type Map");
}
Map map = (Map)newValue;
Set set = map.keySet();
Iterator iter = set.iterator();
PyDictionary dict = new PyDictionary();
while (iter.hasNext()) {
Object next = iter.next();
if (!(next instanceof String))
throw new IllegalArgumentException("Key of the map is not string.");
String key = (String)next;
if (!(map.get(key) instanceof PyObject))
throw new IllegalArgumentException("Value of the item of the map is not PyObject.");
dict.__setitem__(new PyString(key), (PyObject) map.get(key));
}
return dict;
}
示例3: PyObjectWrappersManager
import org.python.core.PyString; //導入依賴的package包/類
protected PyObjectWrappersManager(){
PyObjectWrappersManager.wrappers.put(PyInteger.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(Integer.class, new PyIntegerWrapper());
PyObjectWrappersManager.wrappers.put(PyFloat.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Float.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(Double.class, new PyFloatWrapper());
PyObjectWrappersManager.wrappers.put(PyLong.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(Long.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(BigInteger.class, new PyLongWrapper());
PyObjectWrappersManager.wrappers.put(PyString.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(String.class, new PyStringWrapper());
PyObjectWrappersManager.wrappers.put(PyList.class, new PyListWrapper());
PyObjectWrappersManager.wrappers.put(PyDictionary.class, new PyDictionaryWrapper());
PyObjectWrappersManager.wrappers.put(PyTuple.class, new PyTupleWrapper());
PyObjectWrappersManager.wrappers.put(PyInstance.class, new PyInstanceWrapper());
}
示例4: test
import org.python.core.PyString; //導入依賴的package包/類
@Test
public void test() {
String strBefore = "Bonjour `Set<Class<? extends Object>>`";
String strAfter = "<p>Bonjour <code>Set<Class<? extends Object>></code></p>";
pyconsole.exec("from markdown import Markdown");
pyconsole.exec("from markdown.extensions.zds import ZdsExtension");
pyconsole.exec("from smileys_definition import smileys");
pyconsole.set("text", strBefore);
pyconsole.exec("mk_instance = Markdown(extensions=(ZdsExtension(inline=False, emoticons=smileys, js_support=False, ping_url=None),),safe_mode = 'escape', enable_attributes = False, tab_length = 4, output_format = 'html5', smart_emphasis = True, lazy_ol = True)");
pyconsole.exec("render = mk_instance.convert(text)");
PyString render = pyconsole.get("render", PyString.class);
assertEquals(render.toString(), strAfter);
}
示例5: createStudentInfoDict
import org.python.core.PyString; //導入依賴的package包/類
/**
* Creates a PyDictionary about infos about the student. The infos and their
* stored keys
* first_name: FirstName of the student
* last_name: LastName of the student
* email: email of the student
* matriculation: Matriculation number of the student.
* part_type: participation type of the student.
* @param student The student which infos should be put in the py Dict.
* @return The PyDict with student infos.
*/
private PyDictionary createStudentInfoDict(Student student) {
log.debug("createStudentInfoDict called with student " + student.getUser());
PyDictionary studentDict = new PyDictionary();
studentDict.put(new PyString(KEY_STUDENT_INFO_MATR),
student.getUser().getMatriculationNumber() == null
? new PyString("")
: new PyString(student.getUser().getMatriculationNumber()));
studentDict.put(new PyString(KEY_STUDENT_INFO_FIRST_NAME),
new PyString(student.getUser().getFirstName()));
studentDict.put(new PyString(KEY_STUDENT_INFO_LAST_NAME),
new PyString(student.getUser().getLastName()));
studentDict.put(new PyString(KEY_STUDENT_INFO_EMAIL),
new PyString(student.getUser().getEmail()));
studentDict.put(new PyString(KEY_STUDENT_INFO_PART_TYPE),
new PyString(student.getParticipationType().getName()));
return studentDict;
}
示例6: createOtherStudentGradesDict
import org.python.core.PyString; //導入依賴的package包/類
/**
* Creates a python dictionary of the other student relations of a student
* in which the currently logged in user is lecturer.
* The dictionary has as the first index the semester in which the courses were
* located, which points to a dictionary of courses during this semester.
* This dictionary uses the shortcut of a course to get a grade dictionary
* of the student in that course.
* @param otherStudentRelations The other student relations which should create
* the Python Dictionary
* @return The python dictionary with other grades indexed by semester
* and course shortcut.
*/
private PyDictionary createOtherStudentGradesDict(List<Student> otherStudentRelations) {
List<Semester> semesters = new ArrayList<>();
PyDictionary semesterDict = new PyDictionary();
for (Student otherStudent: otherStudentRelations) {
Semester semester = otherStudent.getCourse().getSemester();
if (!semesters.contains(semester)) {
semesters.add(otherStudent.getCourse().getSemester());
semesterDict.put(new PyString(semester.toString()), new PyDictionary());
}
if (!otherStudent.getCourse().equals(course)) {
PyDictionary courseDict = (PyDictionary)
semesterDict.get(new PyString(semester.toString()));
courseDict.put(new PyString(otherStudent.getCourse().getIdentifier()),
createPyGradeDict(otherStudent.getCourse().getExams(), otherStudent));
}
}
return semesterDict;
}
示例7: run
import org.python.core.PyString; //導入依賴的package包/類
@Override
public void run() {
printBanner();
invokeTraceBack();
for(boolean more = false;;) {
PyString prompt = more ? ConsoleConstants.EXPECTING_INPUT : ConsoleConstants.READY_FOR_INPUT;
String line = requestCommand(prompt, lines);
try {
assertLine(line);
more = activeInterpreter.push(line);
} catch(Exception e) {
activeInterpreter.cleanInterpreter();
pythonInterpreter.writeErr(e.getMessage() + "\n");
more = false;
}
}
}
示例8: addJythonToPath
import org.python.core.PyString; //導入依賴的package包/類
private void addJythonToPath(PySystemState pySystemState) {
Enumeration<URL> urls;
try {
urls = classLoader.getResources("jython/");
} catch (IOException e) {
log.info("Failed to get resource: {}", e.getMessage());
return;
}
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
log.debug("jython url: {}", url.getPath());
if (url != null) {
File file = new File(url.getFile());
String path = file.getPath();
if (path.startsWith("file:")) {
path = path.substring(5);
}
pySystemState.path.append(new PyString(path.replace("!", "")));
}
}
}
示例9: map
import org.python.core.PyString; //導入依賴的package包/類
private void map(IndexedRecord input, ProcessContext context) throws IOException {
// Prepare Python environment
interpretor.set("inputJSON", new PyString(input.toString()));
// Add user command
interpretor.exec(pythonFunction);
// Retrieve results
interpretor.exec("outputJSON = userFunction(inputJSON)");
PyObject output = interpretor.get("outputJSON");
if (jsonGenericRecordConverter == null) {
JsonSchemaInferrer jsonSchemaInferrer = new JsonSchemaInferrer(new ObjectMapper());
Schema jsonSchema = jsonSchemaInferrer.inferSchema(output.toString());
jsonGenericRecordConverter = new JsonGenericRecordConverter(jsonSchema);
}
GenericRecord outputRecord = jsonGenericRecordConverter.convertToAvro(output.toString());
context.output(outputRecord);
}
示例10: flatMap
import org.python.core.PyString; //導入依賴的package包/類
private void flatMap(IndexedRecord input, ProcessContext context) throws IOException {
// Prepare Python environment
interpretor.set("inputJSON", new PyString(input.toString()));
// Add user command
interpretor.exec(pythonFunction);
// Retrieve results
interpretor.exec("outputJSON = userFunction(inputJSON)");
PyObject outputList = interpretor.get("outputJSON");
if (outputList instanceof PyList) {
PyList list = (PyList) outputList;
for (Object output : list) {
if (jsonGenericRecordConverter == null) {
JsonSchemaInferrer jsonSchemaInferrer = new JsonSchemaInferrer(new ObjectMapper());
Schema jsonSchema = jsonSchemaInferrer.inferSchema(output.toString());
jsonGenericRecordConverter = new JsonGenericRecordConverter(jsonSchema);
}
GenericRecord outputRecord = jsonGenericRecordConverter.convertToAvro(output.toString());
context.output(outputRecord);
}
}
}
示例11: getCompiledCode
import org.python.core.PyString; //導入依賴的package包/類
private PyCode getCompiledCode(String pythonCode, PythonInterpreter interpreter, String selectionId) throws IOException {
String trimmedSelectionCode = pythonCode.trim();
Worksheet worksheet = workspace.getWorksheet(worksheetId);
if (trimmedSelectionCode.isEmpty()) {
trimmedSelectionCode = "return False";
}
String selectionMethodStmt = PythonTransformationHelper
.getPythonSelectionMethodDefinitionState(worksheet,
trimmedSelectionCode,selectionId);
logger.debug("Executing PySelection\n" + selectionMethodStmt);
// Prepare the Python interpreter
PythonRepository repo = PythonRepository.getInstance();
repo.compileAndAddToRepositoryAndExec(interpreter, selectionMethodStmt);
PyObject locals = interpreter.getLocals();
locals.__setitem__("workspaceid", new PyString(workspace.getId()));
locals.__setitem__("selectionName", new PyString(superSelectionName));
locals.__setitem__("command", Py.java2py(this));
return repo.getSelectionCode();
}
示例12: CreateFromPython
import org.python.core.PyString; //導入依賴的package包/類
public void CreateFromPython()
{
PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString(context.settings.GetModelPath()));
if(context.settings.GetSysPath() != null)
sys.path.append(new PyString(context.settings.GetSysPath()));
/*
// some magic to pass context to all python modules
interpreter.set("context", context);
interpreter.set("model_service", model_service);
interpreter.exec("import __builtin__");
interpreter.exec("__builtin__.context = context");
interpreter.exec("__builtin__.model_service = model_service");*/
interpreter.execfile(context.settings.GetModelPath() + '/' + context.settings.GetModelMain());
interpreter.cleanup();
UpdateDefinedSensors();
}
示例13: preInit
import org.python.core.PyString; //導入依賴的package包/類
/**
* Instantiate the python mod instance and send it the pre-initialization
* event.
*
* *event* is the pre-initialization event.
*/
public void preInit(FMLPreInitializationEvent event) {
// Instantiate python mod class.
final String moduleName = this.getPythonModuleName();
final String className = this.getPythonClassName();
final PyString pyClassName = Py.newString(className);
this.log.fine("Load %s.%s", moduleName, className);
final PyObject pyModule = PyMod.python.importModule(moduleName);
final PyObject pyModClass = pyModule.__getattr__(pyClassName);
final PyObject pyModInst = pyModClass.__call__();
this.pythonMod = (IPythonMod)pyModInst.__tojava__(IPythonMod.class);
// Call mod pre-init.
this.log.fine("Pre-initialization.");
this.pythonMod.preInit(event);
}
示例14: getAttribute
import org.python.core.PyString; //導入依賴的package包/類
@Override
public Object getAttribute( Object inst, String name ) throws ScriptException
{
try {
this.interpreter.set("__inst", inst);
Object result = this.interpreter.eval("__inst." + name);
if (result instanceof PyBoolean) {
return ((PyBoolean) result).getBooleanValue();
}
if (result instanceof PyInteger) {
return ((PyInteger) result).getValue();
} else if (result instanceof PyString) {
return ((PyString) result).toString();
} else if (result instanceof PyFloat) {
return ((PyFloat) result).getValue();
} else if (result instanceof PyLong) {
return ((PyLong) result).getValue();
} else if (result instanceof PyNone) {
return null;
}
return result;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
示例15: create
import org.python.core.PyString; //導入依賴的package包/類
public static NifiClient create(String address, int port) {
NifiClientFactory factory = new NifiClientFactory();
PyObject clientObject = factory.nifiClientClass.__call__(new PyString(address),
new PyString(Integer.toString(port)));
return (NifiClient)clientObject.__tojava__(NifiClient.class);
}