File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -5414,25 +5414,22 @@ procedure TPythonEngine.RaiseError;
54145414function TPythonEngine.PyObjectAsString ( obj : PPyObject ) : string;
54155415var
54165416 S : PPyObject;
5417- W : UnicodeString;
54185417begin
54195418 Result := ' ' ;
54205419 if not Assigned( obj ) then
54215420 Exit;
54225421
54235422 if PyUnicode_Check(obj) then
5423+ Result := string(PyUnicodeAsString(obj))
5424+ else if PyBytes_Check(obj) then
5425+ Result := string(UTF8ToString(PyBytesAsAnsiString(obj)))
5426+ else
54245427 begin
5425- W := PyUnicodeAsString(obj);
5426- Result := string(W);
5427- Exit;
5428- end ;
5429- S := PyObject_Str( obj );
5430- if Assigned(S) and PyUnicode_Check(S) then
5431- begin
5432- W := PyUnicodeAsString(S);
5433- Result := string(W);
5428+ S := PyObject_Str( obj );
5429+ if Assigned(S) and PyUnicode_Check(S) then
5430+ Result := string(PyUnicodeAsString(S));
5431+ Py_XDECREF(S);
54345432 end ;
5435- Py_XDECREF(S);
54365433end ;
54375434
54385435procedure TPythonEngine.DoRedirectIO ;
Original file line number Diff line number Diff line change @@ -2033,8 +2033,16 @@ function SimplePythonToValue(PyValue: PPyObject; TypeInfo: PTypeInfo;
20332033 end
20342034 else
20352035 ErrMsg := rs_ErrPythonToValue;
2036- tkString, tkWString, tkUString,
2037- tkLString, tkChar, tkWChar:
2036+ tkString, tkLString, tkChar:
2037+ begin
2038+ if GetPythonEngine.PyBytes_Check(PyValue) then
2039+ V := TValue.From(GetPythonEngine.PyBytesAsAnsiString(PyValue))
2040+ else
2041+ V := GetPythonEngine.PyObjectAsString(PyValue);
2042+ Value := V.Cast(TypeInfo);
2043+ Result := True;
2044+ end ;
2045+ tkWString, tkUString, tkWChar:
20382046 begin
20392047 V := GetPythonEngine.PyObjectAsString(PyValue);
20402048 Value := V.Cast(TypeInfo);
You can’t perform that action at this time.
0 commit comments