001: package org.python.core;
002:
003: public class PySuper extends PyObject implements PyType.Newstyle {
004: //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
005: /* type info */
006:
007: public static final String exposed_name = "super";
008:
009: public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
010: dict.__setitem__("__thisclass__", new PyGetSetDescr(
011: "__thisclass__", PySuper.class, "getThisClass", null,
012: null));
013: dict.__setitem__("__self__", new PyGetSetDescr("__self__",
014: PySuper.class, "getSelf", null, null));
015: dict.__setitem__("__self_class__", new PyGetSetDescr(
016: "__self_class__", PySuper.class, "getSelfClass", null,
017: null));
018: class exposed___getattribute__ extends PyBuiltinMethodNarrow {
019:
020: exposed___getattribute__(PyObject self,
021: PyBuiltinFunction.Info info) {
022: super (self, info);
023: }
024:
025: public PyBuiltinFunction bind(PyObject self) {
026: return new exposed___getattribute__(self, info);
027: }
028:
029: public PyObject __call__(PyObject arg0) {
030: try {
031: String name = (arg0.asName(0));
032: PyObject ret = ((PySuper) self)
033: .super ___findattr__(name);
034: if (ret == null)
035: ((PySuper) self).noAttributeError(name);
036: return ret;
037: } catch (PyObject.ConversionException e) {
038: String msg;
039: switch (e.index) {
040: case 0:
041: msg = "attribute name must be a string";
042: break;
043: default:
044: msg = "xxx";
045: }
046: throw Py.TypeError(msg);
047: }
048: }
049:
050: }
051: dict.__setitem__("__getattribute__", new PyMethodDescr(
052: "__getattribute__", PySuper.class, 1, 1,
053: new exposed___getattribute__(null, null)));
054: class exposed___get__ extends PyBuiltinMethodNarrow {
055:
056: exposed___get__(PyObject self, PyBuiltinFunction.Info info) {
057: super (self, info);
058: }
059:
060: public PyBuiltinFunction bind(PyObject self) {
061: return new exposed___get__(self, info);
062: }
063:
064: public PyObject __call__(PyObject arg0, PyObject arg1) {
065: PyObject obj = (arg0 == Py.None) ? null : arg1;
066: PyObject type = (arg1 == Py.None) ? null : arg0;
067: return ((PySuper) self).super ___get__(obj, type);
068: }
069:
070: public PyObject __call__(PyObject arg0) {
071: PyObject obj = (arg0 == Py.None) ? null : (null);
072: PyObject type = ((null) == Py.None) ? null : arg0;
073: return ((PySuper) self).super ___get__(obj, type);
074: }
075:
076: }
077: dict.__setitem__("__get__", new PyMethodDescr("__get__",
078: PySuper.class, 1, 2, new exposed___get__(null, null)));
079: class exposed___init__ extends PyBuiltinMethod {
080:
081: exposed___init__(PyObject self, PyBuiltinFunction.Info info) {
082: super (self, info);
083: }
084:
085: public PyBuiltinFunction bind(PyObject self) {
086: return new exposed___init__(self, info);
087: }
088:
089: public PyObject __call__(PyObject[] args) {
090: return __call__(args, Py.NoKeywords);
091: }
092:
093: public PyObject __call__(PyObject[] args, String[] keywords) {
094: ((PySuper) self).super _init(args, keywords);
095: return Py.None;
096: }
097:
098: }
099: dict.__setitem__("__init__",
100: new PyMethodDescr("__init__", PySuper.class, -1, -1,
101: new exposed___init__(null, null)));
102: dict.__setitem__("__new__", new PyNewWrapper(PySuper.class,
103: "__new__", -1, -1) {
104:
105: public PyObject new_impl(boolean init, PyType subtype,
106: PyObject[] args, String[] keywords) {
107: PySuper newobj;
108: if (for_type == subtype) {
109: newobj = new PySuper();
110: if (init)
111: newobj.super _init(args, keywords);
112: } else {
113: newobj = new PySuperDerived(subtype);
114: }
115: return newobj;
116: }
117:
118: });
119: }
120:
121: //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
122:
123: private static final PyType SUPERTYPE = PyType
124: .fromClass(PySuper.class);
125:
126: protected PyType this Class;
127: protected PyObject self;
128: protected PyType selfClass;
129:
130: private PyType super check(PyType type, PyObject obj) {
131: if (obj instanceof PyType && ((PyType) obj).isSubType(type)) {
132: return (PyType) obj;
133: }
134: PyType obj_type = obj.getType();
135: if (obj_type.isSubType(type))
136: return obj_type;
137: throw Py.TypeError("super(type, obj): "
138: + "obj must be an instance or subtype of type");
139: }
140:
141: public void super _init(PyObject[] args, String[] keywords) {
142: if (keywords.length != 0
143: || !PyBuiltinFunction.DefaultInfo.check(args.length, 1,
144: 2)) {
145: throw PyBuiltinFunction.DefaultInfo.unexpectedCall(
146: args.length, keywords.length != 0, "super", 1, 2);
147: }
148: if (!(args[0] instanceof PyType)) {
149: throw Py.TypeError("super: argument 1 must be type");
150: }
151: PyType type = (PyType) args[0];
152: PyObject obj = null;
153: PyType obj_type = null;
154: if (args.length == 2 && args[1] != Py.None)
155: obj = args[1];
156: if (obj != null) {
157: obj_type = super check(type, obj);
158: }
159: this .this Class = type;
160: this .self = obj;
161: this .selfClass = obj_type;
162: }
163:
164: public PySuper() {
165: this (SUPERTYPE);
166: }
167:
168: public PySuper(PyType subType) {
169: super (subType);
170: }
171:
172: public PyObject getSelf() {
173: return self;
174: }
175:
176: public PyType getSelfClass() {
177: return selfClass;
178: }
179:
180: public PyType getThisClass() {
181: return this Class;
182: }
183:
184: public PyObject __findattr__(String name) {
185: return super ___findattr__(name);
186: }
187:
188: final PyObject super ___findattr__(String name) {
189: if (selfClass != null && name != "__class__") {
190: PyObject descr = selfClass.super _lookup(this Class, name);
191: return descr.__get__(selfClass == self ? null : self,
192: selfClass);
193: }
194: return super .__findattr__(name);
195: }
196:
197: public PyObject __get__(PyObject obj, PyObject type) {
198: return super ___get__(obj, type);
199: }
200:
201: final PyObject super ___get__(PyObject obj, PyObject type) { //xxx subtype case!
202: if (obj == null || obj == Py.None || self != null)
203: return this ;
204: PyType obj_type = super check(this .this Class, obj);
205: PySuper newsuper = new PySuper();
206: newsuper.thisClass = this.thisClass;
207: newsuper.self = obj;
208: newsuper.selfClass = obj_type;
209: return newsuper;
210: }
211:
212: }
|