01: package org.python.core;
02:
03: public class PySlot extends PyDescriptor {
04:
05: public PySlot(PyType dtype, String name, int index) {
06: this .name = name;
07: this .dtype = dtype;
08: this .index = index;
09: }
10:
11: public boolean implements DescrSet() {
12: return true;
13: }
14:
15: public boolean isDataDescr() {
16: return true;
17: }
18:
19: public PyObject __get__(PyObject obj, PyObject type) {
20: if (obj != null) {
21: checkType((PyType) type);
22: return ((Slotted) obj).getSlot(index);
23: }
24: return this ;
25: }
26:
27: public void __set__(PyObject obj, PyObject value) {
28: checkType(obj.getType());
29: ((Slotted) obj).setSlot(index, value);
30: }
31:
32: public void __delete__(PyObject obj) {
33: checkType(obj.getType());
34: ((Slotted) obj).setSlot(index, null);
35: }
36:
37: public String toString() {
38: return "<member '" + name + "' of '" + dtype.fastGetName()
39: + "' objects>";
40: }
41:
42: private void checkType(PyType type) {
43: if (type != dtype && !type.isSubType(dtype))
44: throw get_wrongtype(type);
45: }
46:
47: private int index;
48: }
|