⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 __builtin__.java

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    y=tmp[0]; z = tmp[1];                    tmp[1] = x;                    if (coerce(tmp)) {                        x=tmp[1];                        y=tmp[0];                        doit = true;                    }                }            }        }        if (x.__class__ == y.__class__ && x.__class__ == z.__class__) {            x = x.__pow__(y, z);            if (x != null)                return x;        }        throw Py.TypeError("__pow__ not defined for these operands");    }    public static PyObject range(int start, int stop, int step) {        if (step == 0)            throw Py.ValueError("zero step for range()");        int n;        if (step > 0)            n = (stop-start+step-1)/step;        else            n = (stop-start+step+1)/step;        if (n <= 0)            return new PyList();        PyObject[] l = new PyObject[n];        int j=start;        for (int i=0; i<n; i++) {            l[i] = Py.newInteger(j);            j+= step;        }        return new PyList(l);    }    public static PyObject range(int n) {        return range(0,n,1);    }    public static PyObject range(int start, int stop) {        return range(start,stop,1);    }    private static PyString readline(PyObject file) {        if (file instanceof PyFile) {            return ((PyFile)file).readline();        } else {            PyObject ret = file.invoke("readline");            if (!(ret instanceof PyString)) {                throw Py.TypeError("object.readline() returned non-string");            }            return (PyString)ret;        }    }    public static String raw_input(PyObject prompt) {        Py.print(prompt);        PyObject stdin = Py.getSystemState().stdin;        String data = readline(stdin).toString();        if (data.endsWith("\n")) {            return data.substring(0, data.length()-1);        } else {            if (data.length() == 0) {                throw Py.EOFError("raw_input()");            }        }        return data;    }    public static String raw_input() {        return raw_input(new PyString(""));    }    public static PyObject reduce(PyObject f, PyObject l, PyObject z) {        PyObject result = z;        PyObject iter = Py.iter(l, "reduce() arg 2 must support iteration");                for (PyObject item; (item = iter.__iternext__()) != null; ) {            if (result == null)                result = item;            else                result = f.__call__(result, item);        }        if (result == null) {            throw Py.TypeError(                    "reduce of empty sequence with no initial value");        }        return result;    }    public static PyObject reduce(PyObject f, PyObject l) {        return reduce(f, l, null);    }    public static PyObject reload(PyModule o) {        return imp.reload(o);    }    public static PyObject reload(PyJavaClass o) {        return imp.reload(o);    }    public static PyString repr(PyObject o) {        return o.__repr__();    }    //This seems awfully special purpose...    public static PyFloat round(double f, int digits) {        boolean neg = f < 0;        double multiple = Math.pow(10., digits);        if (neg)            f = -f;        double tmp = Math.floor(f*multiple+0.5);        if (neg)            tmp = -tmp;        return new PyFloat(tmp/multiple);    }    public static PyFloat round(double f) {        return round(f, 0);    }    public static void setattr(PyObject o, PyString n, PyObject v) {        o.__setattr__(n, v);    }    public static PySlice slice(PyObject start, PyObject stop,                                PyObject step)    {        return new PySlice(start, stop, step);    }    public static PySlice slice(PyObject start, PyObject stop) {        return slice(start, stop, Py.None);    }    public static PySlice slice(PyObject stop) {        return slice(Py.None, stop, Py.None);    }    public static PyObject iter(PyObject obj) {        return obj.__iter__();    }    public static PyObject iter(PyObject callable, PyObject sentinel) {        return new PyCallIter(callable, sentinel);    }    public static PyString str(PyObject o) {        return o.__str__();    }    public static PyString unicode(PyObject v) {        return unicode(v.__str__(), null, null);    }    public static PyString unicode(PyString v, String encoding) {        return unicode(v, encoding, null);    }    public static PyString unicode(PyString v, String encoding,                                  String errors)    {        return codecs.decode(v, encoding, errors);    }    public static PyTuple tuple(PyObject o) {        if (o instanceof PyTuple)            return (PyTuple)o;        if (o instanceof PyList) {            // always make a copy, otherwise the tuple will share the            // underlying data structure with the list object, which            // renders the tuple mutable!            PyList l = (PyList)o;            PyObject[] a = new PyObject[l.length];            System.arraycopy(l.list, 0, a, 0, a.length);            return new PyTuple(a);        }        return new PyTuple(make_array(o));    }    public static PyClass type(PyObject o) {        if (o instanceof PyInstance) {            // was just PyInstance.class, goes with experimental            // PyMetaClass hook            return PyJavaClass.lookup(o.getClass());        } else {            return o.__class__;        }    }    public static PyObject vars(PyObject o) {        return o.__getattr__("__dict__");    }    public static PyObject vars() {        return locals();    }    public static PyObject xrange(int start, int stop, int step) {        return new PyXRange(start, stop, step);    }    public static PyObject xrange(int n) {        return xrange(0,n,1);    }    public static PyObject xrange(int start, int stop) {        return xrange(start,stop,1);    }    public static PyString __doc__zip = new PyString(      "zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]\n"+      "\n"+      "Return a list of tuples, where each tuple contains the i-th element\n"+      "from each of the argument sequences.  The returned list is\n"+      "truncated in length to the length of the shortest argument sequence."    );    public static PyObject zip(PyObject[] argstar) {        int itemsize = argstar.length;        if (itemsize < 1)            throw Py.TypeError("zip requires at least one sequence");        // Type check the arguments; they must be sequences.  Might as well        // cache the __iter__() methods.        PyObject[] iters = new PyObject[itemsize];        for (int j=0; j < itemsize; j++) {            PyObject iter = argstar[j].__iter__();            if (iter == null) {                throw Py.TypeError("zip argument #" + (j + 1) +                                   " must support iteration");            }            iters[j] = iter;        }        PyList ret = new PyList();        for (int i=0;; i++) {            PyObject[] next = new PyObject[itemsize];            PyInteger index = new PyInteger(i);            PyObject item;            for (int j=0; j < itemsize; j++) {                try {                    item = iters[j].__iternext__();                }                catch (PyException e) {                    if (Py.matchException(e, Py.StopIteration))                        return ret;                    throw e;                }                if (item == null)                    return ret;                next[j] = item;            }            ret.append(new PyTuple(next));        }    }    public static PyObject __import__(String name) {        return __import__(name, null, null, null);    }    public static PyObject __import__(String name, PyObject globals) {        return __import__(name, globals, null, null);    }    public static PyObject __import__(String name, PyObject globals,                                      PyObject locals) {        return __import__(name, globals, locals, null);    }    public static PyObject __import__(String name, PyObject globals,                                      PyObject locals,PyObject fromlist)    {        PyFrame frame = Py.getFrame();        if (frame == null)            return null;        PyObject builtins = frame.f_builtins;        if (builtins == null)            builtins = Py.getSystemState().builtins;        PyObject __import__ = builtins.__finditem__("__import__");        if (__import__ == null)            return null;        PyObject module = __import__.__call__(new PyObject[] {                Py.newString(name),                globals,                locals,                fromlist } );        return module;    }    private static PyObject[] make_array(PyObject o) {        if (o instanceof PyTuple)            return ((PyTuple)o).list;        PyObject iter = o.__iter__();        // Guess result size and allocate space.        int n = 10;        try {            n = o.__len__();        } catch (PyException exc) { }        PyObject[] objs= new PyObject[n];        int i;        for (i = 0; ; i++) {            PyObject item = iter.__iternext__();            if (item == null)                break;            if (i >= n) {                if (n < 500) {                    n += 10;                } else {                    n += 100;                }                PyObject[] newobjs = new PyObject[n];                System.arraycopy(objs, 0, newobjs, 0, objs.length);                objs = newobjs;            }            objs[i] = item;        }        // Cut back if guess was too large.        if (i < n) {            PyObject[] newobjs = new PyObject[i];            System.arraycopy(objs, 0, newobjs, 0, i);            objs = newobjs;        }        return objs;    }}class ImportFunction extends PyObject {    public ImportFunction() {}    public PyObject __call__(PyObject args[], String keywords[]) {        if (!(args.length < 1 || args[0] instanceof PyString))            throw Py.TypeError("first argument must be a string");        if (keywords.length > 0)            throw Py.TypeError("__import__() takes no keyword arguments");        int argc = args.length;        String module = args[0].__str__().toString();        PyObject globals = (argc > 1 && args[1] != null)            ? args[1] : null;        PyObject fromlist = (argc > 3 && args[3] != null)            ? args[3] : Py.EmptyTuple;        return load(module, globals, fromlist);    }    private PyObject load(String module,                          PyObject globals,                          PyObject fromlist)    {        PyObject mod = imp.importName(module.intern(),                                      fromlist.__len__() == 0,                                      globals);        return mod;    }    public String toString() {        return "<built-in function __import__>";    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -