01: package org.python.core;
02:
03: public class PyBuiltinMethodSet extends PyBuiltinFunctionSet implements
04: Cloneable {
05:
06: public PyBuiltinMethodSet(String name, int index, int minargs,
07: int maxargs, String doc, Class type) {
08: super (name, index, minargs, maxargs, doc);
09: this .type = type;
10: }
11:
12: public PyObject __get__(PyObject obj, PyObject type) {
13: if (obj != null) {
14: if (this .type.isAssignableFrom(obj.getClass())) {
15: return bind(obj);
16: } else {
17: throw Py.TypeError("descriptor '" + info.getName()
18: + "' for '" + PyType.fromClass(this .type)
19: + "' objects doesn't apply to '"
20: + obj.getType() + "' object");
21: }
22: }
23: return this ;
24: }
25:
26: public PyBuiltinFunction bind(PyObject bindTo) {
27: if (__self__ == Py.None) {
28: PyBuiltinMethodSet bindable;
29: try {
30: bindable = (PyBuiltinMethodSet) clone();
31: } catch (CloneNotSupportedException e) {
32: throw new RuntimeException(
33: "Didn't expect PyBuiltinMethodSet to throw CloneNotSupported since it implements Cloneable",
34: e);
35: }
36: bindable.__self__ = bindTo;
37: return bindable;
38: }
39: return this ;
40: }
41:
42: public PyObject getSelf() {
43: return __self__;
44: }
45:
46: public String toString() {
47: return "<built-in method " + info.getName() + ">";
48: }
49:
50: private Class type;
51:
52: protected PyObject __self__ = Py.None;
53: }
|