當前位置: 首頁>>代碼示例>>Java>>正文


Java PyString類代碼示例

本文整理匯總了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;
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:24,代碼來源:EtlJob.java

示例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;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:25,代碼來源:PyDictionaryWrapper.java

示例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());
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:17,代碼來源:PyObjectWrappersManager.java

示例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&lt;Class&lt;? extends Object&gt;&gt;</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);

}
 
開發者ID:firm1,項目名稱:zest-writer,代碼行數:18,代碼來源:TestMarkdown.java

示例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;
}
 
開發者ID:stefanoberdoerfer,項目名稱:exmatrikulator,代碼行數:33,代碼來源:GradeScriptController.java

示例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;
}
 
開發者ID:stefanoberdoerfer,項目名稱:exmatrikulator,代碼行數:36,代碼來源:GradeScriptController.java

示例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;
        }
    }
}
 
開發者ID:antivo,項目名稱:Parallel-Machine-Simulator,代碼行數:18,代碼來源:ParallelMachineSimulator.java

示例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("!", "")));
    }
  }
}
 
開發者ID:linkedin,項目名稱:WhereHows,代碼行數:23,代碼來源:EtlJob.java

示例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);
}
 
開發者ID:Talend,項目名稱:components,代碼行數:21,代碼來源:PythonRowDoFn.java

示例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);
        }
    }
}
 
開發者ID:Talend,項目名稱:components,代碼行數:25,代碼來源:PythonRowDoFn.java

示例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();
	}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:25,代碼來源:MiniSelection.java

示例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();
	}
 
開發者ID:srcc-msu,項目名稱:octotron_core,代碼行數:26,代碼來源:ExecutionService.java

示例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);
}
 
開發者ID:cpburnz,項目名稱:minecraft-mod-python,代碼行數:22,代碼來源:JavaMod.java

示例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;
    }
}
 
開發者ID:nickthecoder,項目名稱:itchy,代碼行數:27,代碼來源:PythonLanguage.java

示例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);
}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:8,代碼來源:NifiClientFactory.java


注:本文中的org.python.core.PyString類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。