KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > PyNewWrapper


1 package org.python.core;
2
3 public abstract class PyNewWrapper extends PyBuiltinFunctionWide {
4
5     protected PyType for_type;
6
7     public PyNewWrapper(Class JavaDoc c, String JavaDoc name, int minargs, int maxargs) {
8         super(new DefaultInfo(name, minargs, maxargs));
9         for_type = PyType.fromClass(c);
10     }
11
12     public PyObject getSelf() {
13         return for_type;
14     }
15
16     protected PyBuiltinFunction makeBound(PyObject self) {
17         throw Py.SystemError("__new__ wrappers are already bound");
18     }
19
20     public PyObject inst_call(PyObject self, PyObject[] args) {
21         throw Py.SystemError("__new__ wrappers are already bound");
22     }
23
24     public PyObject inst_call(
25         PyObject self,
26         PyObject[] args,
27         String JavaDoc[] keywords) {
28         throw Py.SystemError("__new__ wrappers are already bound");
29     }
30
31     public PyObject __call__(PyObject[] args) {
32         return __call__(args, Py.NoKeywords);
33     }
34
35     public PyObject __call__(PyObject[] args, String JavaDoc[] keywords) {
36         int nargs = args.length;
37         if (nargs < 1 || nargs == keywords.length) {
38             throw Py.TypeError(
39                 for_type.fastGetName() + ".__new__(): not enough arguments");
40         }
41         PyObject arg0 = args[0];
42         if (!(arg0 instanceof PyType)) {
43             throw Py.TypeError(
44                 for_type.fastGetName()
45                     + ".__new__(X): X is not a type object ("
46                     + arg0.getType().fastGetName()
47                     + ")");
48         }
49         PyType subtype = (PyType) arg0;
50         if (!subtype.isSubType(for_type)) {
51             throw Py.TypeError(
52                 for_type.fastGetName()
53                     + ".__new__("
54                     + subtype.fastGetName()
55                     + "): "
56                     + subtype.fastGetName()
57                     + " is not a subtype of "
58                     + for_type.fastGetName());
59         }
60         
61         if (subtype.getStatic() != for_type) {
62             throw Py.TypeError(
63                 for_type.fastGetName()
64                     + ".__new__("
65                     + subtype.fastGetName()
66                     + ") is not safe, use "
67                     + subtype.fastGetName()
68                     + ".__new__()");
69         }
70         
71         PyObject[] rest = new PyObject[nargs-1];
72         System.arraycopy(args,1,rest,0,nargs-1);
73         return new_impl(false,subtype,rest,keywords);
74     }
75
76     // init true => invoke subtype.__init__(...) unless it is known to be unnecessary
77
public abstract PyObject new_impl(boolean init,PyType subtype, PyObject[] args, String JavaDoc[] keywords);
78
79 }
80
81
82
Popular Tags