Skip to content

Commit 55a91e4

Browse files
committed
Work on probe
1 parent 2c5bcb9 commit 55a91e4

27 files changed

+488
-100
lines changed

native/jpype_module/src/main/java/org/jpype/bridge/Backend.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import python.lang.PyComplex;
2222
import python.lang.PyDict;
2323
import python.lang.PyEnumerate;
24+
import python.lang.PyFloat;
25+
import python.lang.PyFrozenSet;
2426
import python.lang.PyList;
2527
import python.lang.PyMemoryView;
2628
import python.lang.PyObject;
@@ -34,6 +36,7 @@
3436
import python.protocol.PyCallable;
3537
import python.protocol.PyMapping;
3638
import python.protocol.PyIter;
39+
import python.protocol.PyIterable;
3740

3841
/**
3942
* Backend for all Python entry points.
@@ -56,19 +59,19 @@ public interface Backend
5659

5760
PyByteArray bytearray(Object obj);
5861

59-
PyByteArray bytearray_fromhex(CharSequence str);
62+
PyByteArray bytearrayFromHex(CharSequence str);
6063

6164
PyBytes bytes(Object obj);
6265

63-
PyBytes bytes_fromhex(CharSequence str);
66+
PyBytes bytesFromHex(CharSequence str);
6467

6568
PyObject call(PyCallable obj, PyTuple args, PyDict kwargs);
6669

6770
PyComplex complex(double r, double i);
6871

6972
void delattr(Object obj, CharSequence str);
7073

71-
public boolean delindex(PyList aThis, int indexOf);
74+
boolean delindex(PyList aThis, int indexOf);
7275

7376
PyDict dict();
7477

@@ -98,7 +101,7 @@ public interface Backend
98101

99102
PyMemoryView memoryview(Object obj);
100103

101-
PyDict newDict(Map<Object, Object> map);
104+
PyDict newDict(Map map);
102105

103106
public PySet newSet(Iterable c);
104107

@@ -184,4 +187,32 @@ public interface Backend
184187
//staticmethod()
185188
//super()
186189

190+
public PyObject sequenceGetItem(PyObject obj);
191+
192+
public PyFrozenSet newFrozenSet(Iterable c);
193+
194+
public PyComplex newComplex(double real, double imag);
195+
196+
public PyByteArray newByteArray();
197+
198+
public PyByteArray newByteArray(int i);
199+
200+
public PyByteArray newByteArray(Iterable iter);
201+
202+
public PyEnumerate newEnumerate(Iterable iterable);
203+
204+
public PyByteArray newByteArray(PyBytes bytes);
205+
206+
public PyBytes newBytes(int length);
207+
208+
public PyByteArray newBytes(Iterable<PyObject> iter);
209+
210+
public PyByteArray newBytes(PyByteArray bytes);
211+
212+
public PyFloat newInt(long value);
213+
214+
public PyFloat newDouble(double value);
215+
216+
public PyFloat newZip(PyIterable[] items);
217+
187218
}

native/jpype_module/src/main/java/org/jpype/bridge/BuiltIn.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import python.lang.PyType;
2929
import python.lang.PyZip;
3030
import python.protocol.PyCallable;
31+
import python.protocol.PyIndex;
3132
import python.protocol.PyMapping;
3233
import python.protocol.PyIter;
3334

@@ -64,7 +65,7 @@ public static void delattr(PyObject obj, CharSequence key)
6465
{
6566
Interpreter.backend.delattr(obj, key);
6667
}
67-
68+
6869
public static PyObject next(PyIter iter, PyObject stop)
6970
{
7071
return Interpreter.backend.next(iter, stop);
@@ -181,6 +182,10 @@ public static PyString repr(Object obj)
181182

182183
public static void setattr(PyObject obj, CharSequence key, Object value)
183184
{
185+
// FIXME we may want special handling for String and Boxed types to
186+
// ensure the type that appears is a Python one rather than a
187+
// Java one especially on setattr in which the object is to be
188+
// held in Python.
184189
Interpreter.backend.setattr(obj, key, value);
185190
}
186191

@@ -268,4 +273,14 @@ public static PyZip zip(PyObject... objects)
268273
return Interpreter.backend.zip(objects);
269274
}
270275

276+
public static PyInt $int(long value)
277+
{
278+
return Interpreter.backend.newInt(value);
279+
}
280+
281+
public static PyFloat $float(long value)
282+
{
283+
return Interpreter.backend.newFloat(value);
284+
}
285+
271286
}

native/jpype_module/src/main/java/python/lang/PyByteArray.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@
2323
*/
2424
public interface PyByteArray extends PyObject
2525
{
26+
/**
27+
* Create a new ByteArray with a fixed length.
28+
*
29+
* @param length
30+
* @return
31+
*/
32+
static PyByteArray of(int length)
33+
{
34+
return Interpreter.getBackend().newByteArray(length);
35+
}
36+
37+
static PyByteArray of(Iterable<PyObject> iter )
38+
{
39+
return Interpreter.getBackend().newByteArray(iter);
40+
}
41+
42+
static PyByteArray of(PyBytes bytes)
43+
{
44+
return Interpreter.getBackend().newByteArray(bytes);
45+
}
46+
47+
48+
// FIXME also needs ByteLike (Bytes, ByteArray, String)
49+
2650

2751
static PyType type()
2852
{
@@ -31,7 +55,7 @@ static PyType type()
3155

3256
static PyByteArray fromHex(CharSequence str)
3357
{
34-
return Interpreter.getBackend().bytearray_fromhex(str);
58+
return Interpreter.getBackend().bytearrayFromHex(str);
3559
}
3660

3761
PyObject decode(PyObject encoding, PyObject delete);

native/jpype_module/src/main/java/python/lang/PyBytes.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,35 @@
2323
*/
2424
public interface PyBytes extends PyObject
2525
{
26+
/**
27+
* Create a new ByteArray with a fixed length.
28+
*
29+
* @param length
30+
* @return
31+
*/
32+
static PyBytes of(int length)
33+
{
34+
return Interpreter.getBackend().newBytes(length);
35+
}
36+
37+
static PyByteArray of(Iterable<PyObject> iter )
38+
{
39+
return Interpreter.getBackend().newBytes(iter);
40+
}
2641

42+
static PyByteArray of(PyByteArray bytes)
43+
{
44+
return Interpreter.getBackend().newBytes(bytes);
45+
}
46+
2747
static PyType type()
2848
{
2949
return (PyType) BuiltIn.eval("bytes", null, null);
3050
}
3151

3252
static PyBytes fromHex(CharSequence str)
3353
{
34-
return Interpreter.getBackend().bytes_fromhex(str);
54+
return Interpreter.getBackend().bytesFromHex(str);
3555
}
3656

3757
PyObject decode(PyObject encoding, PyObject delete);

native/jpype_module/src/main/java/python/lang/PyComplex.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
package python.lang;
1717

1818
import org.jpype.bridge.BuiltIn;
19+
import org.jpype.bridge.Interpreter;
1920
import python.protocol.PyNumber;
2021

2122
/**
2223
* Java front end for concrete Python complex.
2324
*/
24-
public interface PyComplex extends PyNumber, PyObject
25+
public interface PyComplex extends PyObject, PyNumber
2526
{
26-
27+
static PyComplex of(double real, double imag)
28+
{
29+
return Interpreter.getBackend().newComplex(real, imag);
30+
}
31+
2732
static PyType type()
2833
{
2934
return (PyType) BuiltIn.eval("complex", null, null);

native/jpype_module/src/main/java/python/lang/PyDict.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package python.lang;
1717

18+
import java.util.Map;
1819
import org.jpype.bridge.BuiltIn;
20+
import org.jpype.bridge.Interpreter;
1921
import python.protocol.PyMapping;
2022

2123
/**
@@ -25,6 +27,10 @@
2527
*/
2628
public interface PyDict extends PyObject, PyMapping
2729
{
30+
static PyDict of(Map<Object, PyObject> map)
31+
{
32+
return Interpreter.getBackend().newDict(map);
33+
}
2834

2935
static PyType type()
3036
{

native/jpype_module/src/main/java/python/lang/PyEnumerate.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@
1717

1818
import python.protocol.PyGenerator;
1919
import org.jpype.bridge.BuiltIn;
20+
import org.jpype.bridge.Interpreter;
21+
import python.protocol.PyIterable;
2022

2123
/**
2224
* Java front end for concrete Python enumerate.
2325
*/
2426
public interface PyEnumerate extends PyGenerator
2527
{
2628

29+
static PyEnumerate of(Iterable<PyObject> iterable)
30+
{
31+
return Interpreter.getBackend().newEnumerate(iterable);
32+
}
33+
2734
static PyType type()
2835
{
2936
return (PyType) BuiltIn.eval("enumerate", null, null);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
3+
* use this file except in compliance with the License. You may obtain a copy of
4+
* the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under
12+
* the License.
13+
*
14+
* See NOTICE file for details.
15+
*/
16+
package python.lang;
17+
18+
import org.jpype.bridge.BuiltIn;
19+
import org.jpype.bridge.Interpreter;
20+
import python.protocol.PyNumber;
21+
22+
/**
23+
*
24+
*/
25+
public interface PyFloat extends PyObject, PyNumber
26+
{
27+
static PyFloat of(double value)
28+
{
29+
return Interpreter.getBackend().newDouble(value);
30+
}
31+
32+
static PyType type()
33+
{
34+
return (PyType) BuiltIn.eval("float", null, null);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)