Package org.python.core

Examples of org.python.core.PyString


        }


        final private void load_short_binstring() {
            int len = file.read(1).charAt(0);
            push(new PyString(file.read(len)));
        }
View Full Code Here


        final private PyObject find_class(String module, String name) {
            if (find_global != null) {
               if (find_global == Py.None)
                   throw new PyException(UnpicklingError,
                         "Global and instance pickles are not supported.");
               return find_global.__call__(new PyString(module), new PyString(name));
            }

            PyObject modules = Py.getSystemState().modules;
            PyObject mod = modules.__finditem__(module.intern());
            if (mod == null) {
View Full Code Here

            ModuleInfo mi = findFromSource(name, p.toString(), false, true);
            if(mi == null) {
                continue;
            }
            return new PyTuple(mi.file,
                               new PyString(mi.filename),
                               new PyTuple(new PyString(mi.suffix),
                                           new PyString(mi.mode),
                                           Py.newInteger(mi.type)));
        }
        throw Py.ImportError("No module named " + name);
    }
View Full Code Here

                    m.__dict__.__setitem__("__path__", new PyList(new PyObject[] {filename}));
                    m.__dict__.__setitem__("__file__", filename);
                    ModuleInfo mi = findFromSource(name, filename.toString(), true, true);
                    type = mi.type;
                    file = mi.file;
                    filename = new PyString(mi.filename);
                    break;
                default:
                    throw Py.ImportError("No module named " + name);
            }
        }
View Full Code Here

        modules.__setitem__(name.intern(), mod);
        return mod;
    }

    public static PyObject get_suffixes() {
        return new PyList(new PyObject[] {new PyTuple(new PyString(".py"),
                                                      new PyString("r"),
                                                      Py.newInteger(PY_SOURCE)),
                                          new PyTuple(new PyString("$py.class"),
                                                      new PyString("rb"),
                                                      Py.newInteger(PY_COMPILED)),});
    }
View Full Code Here

        // Add line terminator.
        if (!join_append_lineterminator()) {
            return false;
        }

        writeline.__call__(new PyString(rec.toString()));
        return true;
    }
View Full Code Here

        return (PyDialect)PyDialect.TYPE.__call__(dialectArgs, keywords);
    }

    private static PyObject exceptionNamespace() {
        PyObject dict = new PyStringMap();
        dict.__setitem__("__module__", new PyString("_csv"));
        return dict;
    }
View Full Code Here

        for (Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
             zipEntries.hasMoreElements();) {
            ZipEntry zipEntry = zipEntries.nextElement();
            String name = zipEntry.getName().replace('/', File.separatorChar);

            PyObject __file__ = new PyString(archive + File.separator + name);
            PyObject compress = Py.newInteger(zipEntry.getMethod());
            PyObject data_size = new PyLong(zipEntry.getCompressedSize());
            PyObject file_size = new PyLong(zipEntry.getSize());
            // file_offset is a CPython optimization; it's used to seek directly to the
            // file when reading it later. Jython doesn't do this nor is the offset
            // available
            PyObject file_offset = Py.newInteger(-1);
            PyObject time = new PyInteger(epochToDosTime(zipEntry.getTime()));
            PyObject date = new PyInteger(epochToDosDate(zipEntry.getTime()));
            PyObject crc = new PyLong(zipEntry.getCrc());

            PyTuple entry = new PyTuple(__file__, compress, data_size, file_size, file_offset,
                                        time, date, crc);
            files.__setitem__(new PyString(name), entry);
        }
    }
View Full Code Here

    public static final PyObject Incomplete = Py.makeClass("Incomplete", Py.Exception,
                                                           exceptionNamespace());

    public static PyObject exceptionNamespace() {
        PyObject dict = new PyStringMap();
        dict.__setitem__("__module__", new PyString("binascii"));
        return dict;
    }
View Full Code Here

    public static PyString a2b_uu(String ascii_data) {
        int leftbits = 0;
        int leftchar = 0;

        if (ascii_data.length() == 0)
            return new PyString("");
       
        StringBuilder bin_data = new StringBuilder();

        char this_ch;
        int i;

        int ascii_len = ascii_data.length()-1;

        int bin_len = (ascii_data.charAt(0) - ' ') & 077;

        for (i = 0; bin_len > 0 && ascii_len > 0; i++, ascii_len--) {
            this_ch = ascii_data.charAt(i+1);
            if (this_ch == '\n' || this_ch == '\r' || ascii_len <= 0) {
                // Whitespace. Assume some spaces got eaten at
                // end-of-line. (We check this later)
                this_ch = 0;
            } else {
                // Check the character for legality
                // The 64 in stead of the expected 63 is because
                // there are a few uuencodes out there that use
                // '@' as zero instead of space.
                if ( this_ch < ' ' || this_ch > (' ' + 64)) {
                    throw new PyException(Error, "Illegal char");
                }
                this_ch = (char)((this_ch - ' ') & 077);
            }
            // Shift it in on the low end, and see if there's
            // a byte ready for output.
            leftchar = (leftchar << 6) | (this_ch);
            leftbits += 6;
            if (leftbits >= 8) {
                leftbits -= 8;
                bin_data.append((char)((leftchar >> leftbits) & 0xff));
                leftchar &= ((1 << leftbits) - 1);
                bin_len--;
            }
        }
       
        // Finally, check that if there's anything left on the line
        // that it's whitespace only.
        while (ascii_len-- > 0) {
            this_ch = ascii_data.charAt(++i);
            // Extra '@' may be written as padding in some cases
            if (this_ch != ' ' && this_ch != '@' &&
                     this_ch != '\n' && this_ch != '\r') {
                throw new PyException(Error, "Trailing garbage");
            }
        }
       
        // finally, if we haven't decoded enough stuff, fill it up with zeros
        for (; i<bin_len; i++)
          bin_data.append((char)0);
       
        return new PyString(bin_data.toString());
    }
View Full Code Here

TOP

Related Classes of org.python.core.PyString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.