[Python-checkins] r84121 - python/branches/py3k/Modules/zipimport.c

victor.stinner python-checkins at python.org
Tue Aug 17 02:04:48 CEST 2010


Author: victor.stinner
Date: Tue Aug 17 02:04:48 2010
New Revision: 84121

Log:
Issue #9425: zipimporter_repr() uses unicode

Modified:
   python/branches/py3k/Modules/zipimport.c

Modified: python/branches/py3k/Modules/zipimport.c
==============================================================================
--- python/branches/py3k/Modules/zipimport.c	(original)
+++ python/branches/py3k/Modules/zipimport.c	Tue Aug 17 02:04:48 2010
@@ -188,19 +188,14 @@
 static PyObject *
 zipimporter_repr(ZipImporter *self)
 {
-    char *archive = "???";
-    char *prefix = "";
-
-    if (self->archive != NULL && PyUnicode_Check(self->archive))
-        archive = _PyUnicode_AsString(self->archive);
-    if (self->prefix != NULL && PyUnicode_Check(self->prefix))
-        prefix = _PyUnicode_AsString(self->prefix);
-    if (prefix != NULL && *prefix)
-        return PyUnicode_FromFormat("<zipimporter object \"%.300s%c%.150s\">",
-                                    archive, SEP, prefix);
+    if (self->archive == NULL)
+        return PyUnicode_FromString("<zipimporter object \"???\">");
+    else if (self->prefix != NULL && PyUnicode_GET_SIZE(self->prefix) != 0)
+        return PyUnicode_FromFormat("<zipimporter object \"%.300U%c%.150U\">",
+                                    self->archive, SEP, self->prefix);
     else
-        return PyUnicode_FromFormat("<zipimporter object \"%.300s\">",
-                                    archive);
+        return PyUnicode_FromFormat("<zipimporter object \"%.300U\">",
+                                    self->archive);
 }
 
 /* return fullname.split(".")[-1] */


More information about the Python-checkins mailing list