01: package org.python.core;
02:
03: public class PyClassMethod extends PyObject implements PyType.Newstyle {
04: // xxx __init__
05:
06: //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
07: /* type info */
08:
09: public static final String exposed_name = "classmethod";
10:
11: public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
12: class exposed___get__ extends PyBuiltinMethodNarrow {
13:
14: exposed___get__(PyObject self, PyBuiltinFunction.Info info) {
15: super (self, info);
16: }
17:
18: public PyBuiltinFunction bind(PyObject self) {
19: return new exposed___get__(self, info);
20: }
21:
22: public PyObject __call__(PyObject arg0, PyObject arg1) {
23: return ((PyClassMethod) self).classmethod___get__(arg0,
24: arg1);
25: }
26:
27: public PyObject __call__(PyObject arg0) {
28: return ((PyClassMethod) self).classmethod___get__(arg0);
29: }
30:
31: }
32: dict.__setitem__("__get__", new PyMethodDescr("__get__",
33: PyClassMethod.class, 1, 2, new exposed___get__(null,
34: null)));
35: dict.__setitem__("__new__", new PyNewWrapper(
36: PyClassMethod.class, "__new__", 1, 1) {
37:
38: public PyObject new_impl(boolean init, PyType subtype,
39: PyObject[] args, String[] keywords) {
40: return classmethod_new(this , init, subtype, args,
41: keywords);
42: }
43:
44: });
45: }
46:
47: //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
48:
49: protected PyObject callable;
50:
51: public PyClassMethod(PyObject callable) {
52: if (!callable.isCallable()) {
53: throw Py.TypeError("'" + callable.getType().fastGetName()
54: + "' object is not callable");
55: }
56: this .callable = callable;
57: }
58:
59: public PyObject __get__(PyObject obj) {
60: return classmethod___get__(obj, null);
61: }
62:
63: public PyObject __get__(PyObject obj, PyObject type) {
64: return classmethod___get__(obj, type);
65: }
66:
67: final PyObject classmethod___get__(PyObject obj) {
68: return classmethod___get__(obj, null);
69: }
70:
71: final PyObject classmethod___get__(PyObject obj, PyObject type) {
72: if (type == null) {
73: type = obj.getType();
74: }
75: return new PyMethod(type, callable, type.getType());
76: }
77:
78: final static PyObject classmethod_new(PyNewWrapper new_,
79: boolean init, PyType subtype, PyObject[] args,
80: String[] keywords) {
81: if (keywords.length != 0) {
82: throw Py
83: .TypeError("classmethod does not accept keyword arguments");
84: }
85: if (args.length != 1) {
86: throw Py.TypeError("classmethod expected 1 argument, got "
87: + args.length);
88: }
89: return new PyClassMethod(args[0]);
90: }
91: }
|