public SRE_STATE(PyString str, int start, int end, int flags) { this.str = CACHE.INSTANCE.get(str); int size = str.__len__(); this.charsize = 1; /* adjust boundaries */ if (start < 0) start = 0; else if (start > size) start = size; if (end < 0) end = 0; else if (end > size) end = size; this.start = start; this.end = end; this.pos = start; this.endpos = end; state_reset(); this.flags = flags; }
public PyObject __iternext__() { _complain_ifclosed(); PyString r = readline(); if (r.__len__() == 0) return null; return r; }
int start = indices[2], end = indices[3], n = __len__(); if (end < 0 || end < start || start > n) {
private static PyString ascii_escape(PyString pystr) { int len = pystr.__len__(); String s = pystr.getString(); StringBuilder rval = new StringBuilder(len); rval.append("\""); for (int i = 0; i < len; i++) { int c = s.charAt(i); if (c > 127) { return ascii_escape(new PyUnicode(codecs.PyUnicode_DecodeUTF8(s, null))); } _write_char(rval, c); } rval.append("\""); return new PyString(rval.toString()); }
if (end < 0 || end < start || start > __len__()) {
if (end < 0 || end < start || start > __len__()) {
@Override public Object __tojava__(Class<?> c) { if (c.isAssignableFrom(String.class)) { return getString(); } if (c == Character.TYPE || c == Character.class) { if (getString().length() == 1) { return new Character(getString().charAt(0)); } } if (c.isArray()) { if (c.getComponentType() == Byte.TYPE) { return toBytes(); } if (c.getComponentType() == Character.TYPE) { return getString().toCharArray(); } } if (c.isAssignableFrom(Collection.class)) { List<Object> list = new ArrayList(); for (int i = 0; i < __len__(); i++) { list.add(pyget(i).__tojava__(String.class)); } return list; } if (c.isInstance(this)) { return this; } return Py.NoConversion; }
/** * Read until EOF using readline() and return a list containing * the lines thus read. * @return a list of the lines. */ public PyObject readlines(long sizehint) { _complain_ifclosed(); int sizehint_int = (int)sizehint; int total = 0; PyList lines = new PyList(); PyString line = readline(); while (line.__len__() > 0) { lines.append(line); total += line.__len__(); if (0 < sizehint_int && sizehint_int <= total) break; line = readline(); } return lines; }
byte[] bytes = ByteBuffer.allocate(4).putInt(payload.__len__()).array();
/** * Sink implementation which forwards the items it receives to the Graphite. * Graphite's Pickle Protocol is used for communication between Jet and Graphite. * * @param host Graphite host * @param port Graphite port */ private static Sink<TimestampedEntry> buildGraphiteSink(String host, int port) { return sinkBuilder("graphite", instance -> new BufferedOutputStream(new Socket(host, port).getOutputStream())) .<TimestampedEntry>receiveFn((bos, entry) -> { GraphiteMetric metric = new GraphiteMetric(); metric.from(entry); PyString payload = cPickle.dumps(metric.getAsList(), 2); byte[] header = ByteBuffer.allocate(4).putInt(payload.__len__()).array(); bos.write(header); bos.write(payload.toBytes()); }) .flushFn(BufferedOutputStream::flush) .destroyFn(BufferedOutputStream::close) .build(); }
public static char py2char(PyObject o, String msg) { if (o instanceof PyString) { PyString s = (PyString) o; if (s.__len__() != 1) { throw Py.TypeError(msg); } return s.toString().charAt(0); } if (o instanceof PyInteger) { return (char) ((PyInteger) o).getValue(); } Object i = o.__tojava__(Character.TYPE); if (i == null || i == Py.NoConversion) { throw Py.TypeError(msg); } return ((Character) i).charValue(); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.bytearray___add___doc) final synchronized PyObject bytearray___add__(PyObject o) { PyByteArray sum = null; // XXX re-write using buffer API if (o instanceof BaseBytes) { BaseBytes ob = (BaseBytes)o; // Quick route: allocate the right size bytearray and copy the two parts in. sum = new PyByteArray(size + ob.size); System.arraycopy(storage, offset, sum.storage, sum.offset, size); System.arraycopy(ob.storage, ob.offset, sum.storage, sum.offset + size, ob.size); } else if (o.getType() == PyString.TYPE) { // Support bytes type, which in in Python 2.7 is an alias of str. Remove in 3.0 PyString os = (PyString)o; // Allocate the right size bytearray and copy the two parts in. sum = new PyByteArray(size + os.__len__()); System.arraycopy(storage, offset, sum.storage, sum.offset, size); sum.setslice(size, sum.size, 1, os); } else { // Unsuitable type // XXX note reversed order relative to __iadd__ may be wrong, matches Python 2.7 throw ConcatenationTypeError(TYPE, o.getType()); } return sum; }
public int __len__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__len__"); if (impl!=null) { PyObject res=impl.__get__(this,self_type).__call__(); return res.asInt(); } return super.__len__(); }
public MatchObject search(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("search", args, kws, "pattern", "pos", "endpos"); PyString string = extractPyString(ap, 0); int start = ap.getInt(1, 0); int end = ap.getInt(2, string.__len__()); SRE_STATE state = new SRE_STATE(string, start, end, flags); int status = state.SRE_SEARCH(code, 0); return _pattern_new_match(state, string, status); }
public MatchObject match(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("search", args, kws, "pattern", "pos", "endpos"); PyString string = extractPyString(ap, 0); int start = ap.getInt(1, 0); int end = ap.getInt(2, string.__len__()); SRE_STATE state = new SRE_STATE(string, start, end, flags); state.ptr = state.start; int status = state.SRE_MATCH(code, 0, 1); return _pattern_new_match(state, string, status); }
byte[] header = ByteBuffer.allocate(4).putInt(payload.__len__()).array();
int end_idx = pystr.__len__() - 1; PyList rval = new PyList();
int length = pystr.__len__(); if (idx >= length) { throw Py.StopIteration("");