private void printToFileObject(PyObject file, PyObject o) { if (!(o instanceof PyUnicode)) { o = o.__str__(); } file.invoke("write", o); }
/** * Some database vendors are case sensitive on calls to DatabaseMetaData, * most notably Oracle. This callback allows a DataHandler to affect the * name. */ public String getMetaDataName(PyObject name) { return ((name == Py.None) ? null : name.__str__().toString()); }
@Override @ExposedMethod public PyString __str__() { return dict.__str__(); }
/** * Some database vendors are case sensitive on calls to DatabaseMetaData, * most notably Oracle. This callback allows a DataHandler to affect the * name. */ @Override public String getMetaDataName(PyObject name) { return ((name == Py.None) ? null : name.__str__().toString()); }
public PyUnicode __unicode__() { return new PyUnicode(__str__()); }
public PyString __str__() { return py().__str__(); } public PyUnicode __unicode__() { return py().__unicode__(); }
@Override public String toString() { String className = "?"; if (im_class != null) { className = getClassName(im_class); } if (__self__ == null) { return String.format("<unbound method %s.%s>", className, getFuncName()); } else { return String.format("<bound method %s.%s of %s>", className, getFuncName(), __self__.__str__()); } }
private String printToFile(PyFile file, PyObject o) { String s; if (o instanceof PyUnicode) { // Use the encoding and policy defined for the stream. (Each may be null.) s = ((PyUnicode)o).encode(file.encoding, file.errors); } else { s = o.__str__().toString(); } file.write(s); return s; }
@ExposedMethod(doc = BuiltinDocs.object___format___doc) final PyObject object___format__(PyObject formatSpec) { if (formatSpec != null && formatSpec instanceof PyString && !((PyString)formatSpec).getString().isEmpty()) { Py.warning(Py.PendingDeprecationWarning, "object.__format__ with a non-empty format string is deprecated"); } return __str__().__format__(formatSpec); }
private String printToFileWriter(PyFileWriter file, PyObject o) { // since we are outputting directly to a character stream, // avoid doing an encoding String s; if (o instanceof PyString) { s = ((PyString) o).getString(); } else { s = o.__str__().toString(); } file.write(s); return s; }
@Override public void write(DataOutput out) throws IOException { PyString pyString; try { pyString = cPickle.dumps(getPyObject()); } catch (PyException e) { LOG.fatal("Could not serialize wrapped Jython value: " + getPyObject().__str__()); throw e; } WritableUtils.writeString(out, pyString.getString()); }
public static PyString UnicodeDecodeError__str__(PyObject self, PyObject[] args, String[] kwargs) { int start = self.__getattr__("start").asInt(); int end = self.__getattr__("end").asInt(); // Get reason and encoding as strings, which they might not be if they've been // modified after we were contructed PyObject reason = self.__getattr__("reason").__str__(); PyObject encoding = self.__getattr__("encoding").__str__(); PyObject object = getString(self.__getattr__("object"), "object"); String result; if (start < object.__len__() && end == (start + 1)) { int badByte = (object.toString().charAt(start)) & 0xff; result = String.format("'%.400s' codec can't decode byte 0x%x in position %d: %.400s", encoding, badByte, start, reason); } else { result = String.format("'%.400s' codec can't decode bytes in position %d-%d: %.400s", encoding, start, end - 1, reason); } return Py.newString(result); }
public void __setattr__(String attr, PyObject value) { if (attr == "__mgr__") { PackageManager newMgr = Py.tojava(value, PackageManager.class); if (newMgr == null) { throw Py.TypeError("cannot set java package __mgr__ to None"); } __mgr__ = newMgr; return; } if (attr == "__file__") { __file__ = value.__str__().toString(); return; } super.__setattr__(attr,value); }
public static PyString _UnpickleableError__str__(PyObject self, PyObject[] args, String[] kwargs) { PyObject selfArgs = self.__getattr__("args"); PyObject a = selfArgs.__len__() > 0 ? selfArgs.__getitem__(0) : new PyString("(what)"); return new PyString("Cannot pickle %s objects").__mod__(a).__str__(); }
public static PyString _PickleError__str__(PyObject self, PyObject[] args, String[] kwargs) { PyObject selfArgs = self.__getattr__("args"); if (selfArgs.__len__() > 0 && selfArgs.__getitem__(0).__len__() > 0) { return selfArgs.__getitem__(0).__str__(); } else { return new PyString("(what)"); } }
public PyString __str__() { PyType self_type=getType(); PyObject impl=self_type.lookup("__str__"); if (impl!=null) { PyObject res=impl.__get__(this,self_type).__call__(); if (res instanceof PyString) return(PyString)res; throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); } return super.__str__(); }
public static PyString SyntaxError__str__(PyObject self, PyObject[] arg, String[] kwargs) { PyObject msg = self.__getattr__("msg"); PyObject str = msg.__str__(); if (!(msg instanceof PyString)) { return Py.newString(str.toString()); } PyObject filename = self.__findattr__("filename"); PyObject lineno = self.__findattr__("lineno"); boolean haveFilename = filename instanceof PyString; boolean haveLieno = lineno instanceof PyInteger; if (!haveFilename && !haveLieno) { return (PyString)str; } String result; if (haveFilename && haveLieno) { result = String.format("%s (%s, line %d)", str, basename(filename.toString()), lineno.asInt()); } else if (haveFilename) { result = String.format("%s (%s)", str, basename(filename.toString())); } else { result = String.format("%s (line %d)", str, lineno.asInt()); } return Py.newString(result); }
public void emitNum(Num node, Code code) throws Exception { if (node.getInternalN() instanceof PyInteger) { integerConstant(((PyInteger)node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyLong) { longConstant(((PyObject)node.getInternalN()).__str__().toString()).get(code); } else if (node.getInternalN() instanceof PyFloat) { floatConstant(((PyFloat)node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyComplex) { complexConstant(((PyComplex)node.getInternalN()).imag).get(code); } }
@Override public Object visitNum(Num node) throws Exception { if (node.getInternalN() instanceof PyInteger) { module.integerConstant(((PyInteger) node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyLong) { module.longConstant(((PyObject) node.getInternalN()).__str__().toString()).get(code); } else if (node.getInternalN() instanceof PyFloat) { module.floatConstant(((PyFloat) node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyComplex) { module.complexConstant(((PyComplex) node.getInternalN()).imag).get(code); } return null; }