SF.net SVN: jython:[7252] trunk/jython/src/org/python/core/codecs.java

[email protected] Sun, 20 Mar 2011 19:43:03 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7252
          http://jython.svn.sourceforge.net/jython/?rev=7252&view=rev
Author:   pjenvey
Date:     2011-03-20 19:43:03 +0000 (Sun, 20 Mar 2011)

Log Message:
-----------
reuse exceptions.getEnd

Modified Paths:
--------------
    trunk/jython/src/org/python/core/codecs.java

Modified: trunk/jython/src/org/python/core/codecs.java
===================================================================
--- trunk/jython/src/org/python/core/codecs.java	2011-03-20 19:41:31 UTC (rev 7251)
+++ trunk/jython/src/org/python/core/codecs.java	2011-03-20 19:43:03 UTC (rev 7252)
@@ -252,23 +252,17 @@
     public static PyObject replace_errors(PyObject[] args, String[] kws) {
         ArgParser ap = new ArgParser("replace_errors", args, kws, "exc");
         PyObject exc = ap.getPyObject(0);
-        if (Py.isInstance(exc, Py.UnicodeDecodeError)) {
-            PyObject object = exc.__getattr__("object");
-            if (!Py.isInstance(object, PyString.TYPE) || Py.isInstance(object, PyUnicode.TYPE)) {
-                throw Py.TypeError("object attribute must be str");
-            }
-            PyObject end = exc.__getattr__("end");
-            return new PyTuple(new PyUnicode(Py_UNICODE_REPLACEMENT_CHARACTER), end);
-        } else if (Py.isInstance(exc, Py.UnicodeEncodeError)) {
-            PyObject object = exc.__getattr__("object");
-            if (!Py.isInstance(object, PyUnicode.TYPE)) {
-                throw Py.TypeError("object attribute must be unicode");
-            }
-            PyObject end = exc.__getattr__("end");
-            return new PyTuple(Py.java2py("?"), end);
+        if (Py.isInstance(exc, Py.UnicodeEncodeError)) {
+            int end = exceptions.getEnd(exc, true);
+            return new PyTuple(new PyUnicode("?"), Py.newInteger(end));
+        } else if (Py.isInstance(exc, Py.UnicodeDecodeError)) {
+            int end = exceptions.getEnd(exc, false);
+            return new PyTuple(new PyUnicode(Py_UNICODE_REPLACEMENT_CHARACTER),
+                               Py.newInteger(end));
         } else if (Py.isInstance(exc, Py.UnicodeTranslateError)) {
-            PyObject end = exc.__getattr__("end");
-            return new PyTuple(new PyUnicode(Py_UNICODE_REPLACEMENT_CHARACTER), end);
+            int end = exceptions.getEnd(exc, true);
+            return new PyTuple(new PyUnicode(Py_UNICODE_REPLACEMENT_CHARACTER),
+                               Py.newInteger(end));
         }
         throw wrong_exception_type(exc);
     }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d