001: package org.python.modules.time;
002:
003: import org.python.core.ArgParser;
004: import org.python.core.Py;
005: import org.python.core.PyBuiltinFunction;
006: import org.python.core.PyBuiltinMethodNarrow;
007: import org.python.core.PyGetSetDescr;
008: import org.python.core.PyInteger;
009: import org.python.core.PyList;
010: import org.python.core.PyMethodDescr;
011: import org.python.core.PyNewWrapper;
012: import org.python.core.PyObject;
013: import org.python.core.PySequence;
014: import org.python.core.PyTuple;
015: import org.python.core.PyType;
016:
017: public class PyTimeTuple extends PyTuple {
018: private PyInteger tm_year;
019: private PyInteger tm_mon;
020: private PyInteger tm_mday;
021: private PyInteger tm_hour;
022: private PyInteger tm_min;
023: private PyInteger tm_sec;
024: private PyInteger tm_wday;
025: private PyInteger tm_yday;
026: private PyInteger tm_isdst;
027:
028: //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
029: /* type info */
030:
031: public static final String exposed_name = "struct_time";
032:
033: public static final Class exposed_base = PyTuple.class;
034:
035: public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
036: dict.__setitem__("tm_year", new PyGetSetDescr("tm_year",
037: PyTimeTuple.class, "getYear", null, null));
038: dict.__setitem__("tm_mon", new PyGetSetDescr("tm_mon",
039: PyTimeTuple.class, "getMon", null, null));
040: dict.__setitem__("tm_mday", new PyGetSetDescr("tm_mday",
041: PyTimeTuple.class, "getMday", null, null));
042: dict.__setitem__("tm_hour", new PyGetSetDescr("tm_hour",
043: PyTimeTuple.class, "getHour", null, null));
044: dict.__setitem__("tm_min", new PyGetSetDescr("tm_min",
045: PyTimeTuple.class, "getMin", null, null));
046: dict.__setitem__("tm_sec", new PyGetSetDescr("tm_sec",
047: PyTimeTuple.class, "getSec", null, null));
048: dict.__setitem__("tm_wday", new PyGetSetDescr("tm_wday",
049: PyTimeTuple.class, "getWday", null, null));
050: dict.__setitem__("tm_yday", new PyGetSetDescr("tm_yday",
051: PyTimeTuple.class, "getYday", null, null));
052: dict.__setitem__("tm_isdst", new PyGetSetDescr("tm_isdst",
053: PyTimeTuple.class, "getIsdst", null, null));
054: class exposed___ne__ extends PyBuiltinMethodNarrow {
055:
056: exposed___ne__(PyObject self, PyBuiltinFunction.Info info) {
057: super (self, info);
058: }
059:
060: public PyBuiltinFunction bind(PyObject self) {
061: return new exposed___ne__(self, info);
062: }
063:
064: public PyObject __call__(PyObject arg0) {
065: PyObject ret = ((PyTimeTuple) self)
066: .struct_time___ne__(arg0);
067: if (ret == null)
068: return Py.NotImplemented;
069: return ret;
070: }
071:
072: }
073: dict.__setitem__("__ne__",
074: new PyMethodDescr("__ne__", PyTimeTuple.class, 1, 1,
075: new exposed___ne__(null, null)));
076: class exposed___eq__ extends PyBuiltinMethodNarrow {
077:
078: exposed___eq__(PyObject self, PyBuiltinFunction.Info info) {
079: super (self, info);
080: }
081:
082: public PyBuiltinFunction bind(PyObject self) {
083: return new exposed___eq__(self, info);
084: }
085:
086: public PyObject __call__(PyObject arg0) {
087: PyObject ret = ((PyTimeTuple) self)
088: .struct_time___eq__(arg0);
089: if (ret == null)
090: return Py.NotImplemented;
091: return ret;
092: }
093:
094: }
095: dict.__setitem__("__eq__",
096: new PyMethodDescr("__eq__", PyTimeTuple.class, 1, 1,
097: new exposed___eq__(null, null)));
098: class exposed___reduce__ extends PyBuiltinMethodNarrow {
099:
100: exposed___reduce__(PyObject self,
101: PyBuiltinFunction.Info info) {
102: super (self, info);
103: }
104:
105: public PyBuiltinFunction bind(PyObject self) {
106: return new exposed___reduce__(self, info);
107: }
108:
109: public PyObject __call__() {
110: return ((PyTimeTuple) self).struct_time___reduce__();
111: }
112:
113: }
114: dict.__setitem__("__reduce__", new PyMethodDescr("__reduce__",
115: PyTimeTuple.class, 0, 0, new exposed___reduce__(null,
116: null)));
117: dict.__setitem__("__new__", new PyNewWrapper(PyTimeTuple.class,
118: "__new__", -1, -1) {
119:
120: public PyObject new_impl(boolean init, PyType subtype,
121: PyObject[] args, String[] keywords) {
122: return struct_time_new(this , init, subtype, args,
123: keywords);
124: }
125:
126: });
127: }
128:
129: //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
130:
131: private static final PyType TIMETUPLETYPE = PyType
132: .fromClass(PyTimeTuple.class);
133:
134: PyTimeTuple(PyObject[] vals) {
135: super (TIMETUPLETYPE, vals);
136: tm_year = (PyInteger) vals[0];
137: tm_mon = (PyInteger) vals[1];
138: tm_mday = (PyInteger) vals[2];
139: tm_hour = (PyInteger) vals[3];
140: tm_min = (PyInteger) vals[4];
141: tm_sec = (PyInteger) vals[5];
142: tm_wday = (PyInteger) vals[6];
143: tm_yday = (PyInteger) vals[7];
144: tm_isdst = (PyInteger) vals[8];
145: }
146:
147: PyTimeTuple(PyTuple vals) {
148: super (TIMETUPLETYPE, new PyObject[] { vals.pyget(0),
149: vals.pyget(1), vals.pyget(2), vals.pyget(3),
150: vals.pyget(4), vals.pyget(5), vals.pyget(6),
151: vals.pyget(7), vals.pyget(8) });
152: tm_year = (PyInteger) vals.pyget(0);
153: tm_mon = (PyInteger) vals.pyget(1);
154: tm_mday = (PyInteger) vals.pyget(2);
155: tm_hour = (PyInteger) vals.pyget(3);
156: tm_min = (PyInteger) vals.pyget(4);
157: tm_sec = (PyInteger) vals.pyget(5);
158: tm_wday = (PyInteger) vals.pyget(6);
159: tm_yday = (PyInteger) vals.pyget(7);
160: tm_isdst = (PyInteger) vals.pyget(8);
161: }
162:
163: public PyInteger getYear() {
164: return tm_year;
165: }
166:
167: public PyInteger getMon() {
168: return tm_mon;
169: }
170:
171: public PyInteger getMday() {
172: return tm_mday;
173: }
174:
175: public PyInteger getHour() {
176: return tm_hour;
177: }
178:
179: public PyInteger getMin() {
180: return tm_min;
181: }
182:
183: public PyInteger getSec() {
184: return tm_sec;
185: }
186:
187: public PyInteger getWday() {
188: return tm_wday;
189: }
190:
191: public PyInteger getYday() {
192: return tm_yday;
193: }
194:
195: public PyInteger getIsdst() {
196: return tm_isdst;
197: }
198:
199: public synchronized PyObject __eq__(PyObject o) {
200: return struct_time___eq__(o);
201: }
202:
203: final synchronized PyObject struct_time___eq__(PyObject o) {
204: if (!(getType() == o.getType())
205: && !(getType().isSubType(o.getType()))) {
206: return null;
207: }
208: int tl = __len__();
209: int ol = o.__len__();
210: if (tl != ol) {
211: return Py.Zero;
212: }
213: int i = cmp(this , tl, o, ol);
214: return (i < 0) ? Py.One : Py.Zero;
215: }
216:
217: public synchronized PyObject __ne__(PyObject o) {
218: return struct_time___ne__(o);
219: }
220:
221: final synchronized PyObject struct_time___ne__(PyObject o) {
222: if (!(getType() == o.getType())
223: && !(getType().isSubType(o.getType()))) {
224: return null;
225: }
226: int tl = __len__();
227: int ol = o.__len__();
228: if (tl != ol) {
229: return Py.One;
230: }
231: int i = cmp(this , tl, o, ol);
232: return (i < 0) ? Py.Zero : Py.One;
233: }
234:
235: /**
236: * Used for pickling.
237: *
238: * @return a tuple of (class, tuple)
239: */
240: public PyObject __reduce__() {
241: return struct_time___reduce__();
242: }
243:
244: final PyObject struct_time___reduce__() {
245: PyTuple newargs = __getnewargs__();
246: return new PyTuple(new PyObject[] { getType(), newargs });
247: }
248:
249: public PyTuple __getnewargs__() {
250: return new PyTuple(new PyObject[] { new PyList(getArray()) });
251: }
252:
253: private static PyObject struct_time_new(PyNewWrapper wrapper,
254: boolean init, PyType subtype, PyObject[] args,
255: String[] keywords) {
256: ArgParser ap = new ArgParser("struct_time", args, keywords,
257: new String[] { "tuple" }, 1);
258: PyObject obj = ap.getPyObject(0);
259: if (obj instanceof PyTuple) {
260: if (obj.__len__() != 9) {
261: throw Py
262: .TypeError("time.struct_time() takes a 9-sequence (1-sequence given)");
263: }
264: return new PyTimeTuple((PyTuple) obj);
265: } else if (obj instanceof PySequence) {
266: PySequence seq = (PySequence) obj;
267: if (seq.__len__() != 9) {
268: throw Py
269: .TypeError("time.struct_time() takes a 9-sequence (1-sequence given)");
270: }
271: return new PyTimeTuple((PyObject[]) seq
272: .__tojava__(PyObject[].class));
273:
274: }
275: throw Py.TypeError("constructor requires a sequence");
276: }
277: }
|