]> granicus.if.org Git - python/commitdiff
Issue #9425: zipimporter_repr() uses unicode
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 17 Aug 2010 00:04:48 +0000 (00:04 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 17 Aug 2010 00:04:48 +0000 (00:04 +0000)
Modules/zipimport.c

index a1ee70b765f2346f2bff8b3c599d182e323a2fde..d1c939f984f5d185658196cd81da24704c0993d2 100644 (file)
@@ -188,19 +188,14 @@ zipimporter_dealloc(ZipImporter *self)
 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] */