Author: neal.norwitz
Date: Sun Aug 26 07:08:21 2007
New Revision: 57500

Modified:
   python/branches/py3k/Modules/zipimport.c
Log:
Use unicode (and bytes as appropriate)

Modified: python/branches/py3k/Modules/zipimport.c
==============================================================================
--- python/branches/py3k/Modules/zipimport.c    (original)
+++ python/branches/py3k/Modules/zipimport.c    Sun Aug 26 07:08:21 2007
@@ -144,11 +144,11 @@
                }
        }
 
-       self->archive = PyString_FromString(buf);
+       self->archive = PyUnicode_FromString(buf);
        if (self->archive == NULL)
                return -1;
 
-       self->prefix = PyString_FromString(prefix);
+       self->prefix = PyUnicode_FromString(prefix);
        if (self->prefix == NULL)
                return -1;
 
@@ -180,10 +180,10 @@
        char *archive = "???";
        char *prefix = "";
 
-       if (self->archive != NULL && PyString_Check(self->archive))
-               archive = PyString_AsString(self->archive);
-       if (self->prefix != NULL && PyString_Check(self->prefix))
-               prefix = PyString_AsString(self->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);
@@ -249,7 +249,7 @@
 
        subname = get_subname(fullname);
 
-       len = make_filename(PyString_AsString(self->prefix), subname, path);
+       len = make_filename(PyUnicode_AsString(self->prefix), subname, path);
        if (len < 0)
                return MI_ERROR;
 
@@ -322,12 +322,12 @@
                /* add __path__ to the module *before* the code gets
                   executed */
                PyObject *pkgpath, *fullpath;
-               char *prefix = PyString_AsString(self->prefix);
+               char *prefix = PyUnicode_AsString(self->prefix);
                char *subname = get_subname(fullname);
                int err;
 
-               fullpath = PyString_FromFormat("%s%c%s%s",
-                                       PyString_AsString(self->archive),
+               fullpath = PyUnicode_FromFormat("%s%c%s%s",
+                                       PyUnicode_AsString(self->archive),
                                        SEP,
                                        *prefix ? prefix : "",
                                        subname);
@@ -404,9 +404,9 @@
        }
        path = buf;
 #endif
-       len = PyString_Size(self->archive);
+       len = PyUnicode_GET_SIZE(self->archive);
        if ((size_t)len < strlen(path) &&
-           strncmp(path, PyString_AsString(self->archive), len) == 0 &&
+           strncmp(path, PyUnicode_AsString(self->archive), len) == 0 &&
            path[len] == SEP) {
                path = path + len + 1;
        }
@@ -416,7 +416,7 @@
                PyErr_SetFromErrnoWithFilename(PyExc_IOError, path);
                return NULL;
        }
-       return get_data(PyString_AsString(self->archive), toc_entry);
+       return get_data(PyUnicode_AsString(self->archive), toc_entry);
 }
 
 static PyObject *
@@ -453,7 +453,7 @@
        }
        subname = get_subname(fullname);
 
-       len = make_filename(PyString_AsString(self->prefix), subname, path);
+       len = make_filename(PyUnicode_AsString(self->prefix), subname, path);
        if (len < 0)
                return NULL;
 
@@ -466,7 +466,7 @@
 
        toc_entry = PyDict_GetItemString(self->files, path);
        if (toc_entry != NULL) {
-               PyObject *bytes = get_data(PyString_AsString(self->archive), 
toc_entry);
+               PyObject *bytes = get_data(PyUnicode_AsString(self->archive), 
toc_entry);
                PyObject *res = PyUnicode_FromString(PyBytes_AsString(bytes));
                Py_XDECREF(bytes);
                return res;
@@ -794,7 +794,7 @@
        Py_ssize_t bytes_read = 0;
        long l;
        char *datapath;
-       long compress, data_size, file_size, file_offset;
+       long compress, data_size, file_size, file_offset, bytes_size;
        long time, date, crc;
 
        if (!PyArg_ParseTuple(toc_entry, "slllllll", &datapath, &compress,
@@ -826,13 +826,16 @@
            PyMarshal_ReadShortFromFile(fp);    /* local header size */
        file_offset += l;       /* Start of file data */
 
-       raw_data = PyString_FromStringAndSize((char *)NULL, compress == 0 ?
-                                             data_size : data_size + 1);
+       bytes_size = compress == 0 ? data_size : data_size + 1;
+       if (bytes_size == 0)
+               bytes_size++;
+       raw_data = PyBytes_FromStringAndSize((char *)NULL, bytes_size);
+                                            
        if (raw_data == NULL) {
                fclose(fp);
                return NULL;
        }
-       buf = PyString_AsString(raw_data);
+       buf = PyBytes_AsString(raw_data);
 
        err = fseek(fp, file_offset, 0);
        if (err == 0)
@@ -1041,7 +1044,7 @@
 {
        PyObject *data, *code;
        char *modpath;
-       char *archive = PyString_AsString(self->archive);
+       char *archive = PyUnicode_AsString(self->archive);
 
        if (archive == NULL)
                return NULL;
@@ -1050,7 +1053,7 @@
        if (data == NULL)
                return NULL;
 
-       modpath = PyString_AsString(PyTuple_GetItem(toc_entry, 0));
+       modpath = PyUnicode_AsString(PyTuple_GetItem(toc_entry, 0));
 
        if (isbytecode) {
                code = unmarshal_code(modpath, data, mtime);
@@ -1075,7 +1078,7 @@
 
        subname = get_subname(fullname);
 
-       len = make_filename(PyString_AsString(self->prefix), subname, path);
+       len = make_filename(PyUnicode_AsString(self->prefix), subname, path);
        if (len < 0)
                return NULL;
 
@@ -1085,7 +1088,7 @@
                strcpy(path + len, zso->suffix);
                if (Py_VerboseFlag > 1)
                        PySys_WriteStderr("# trying %s%c%s\n",
-                                         PyString_AsString(self->archive),
+                                         PyUnicode_AsString(self->archive),
                                          SEP, path);
                toc_entry = PyDict_GetItemString(self->files, path);
                if (toc_entry != NULL) {
@@ -1107,7 +1110,7 @@
                                continue;
                        }
                        if (code != NULL && p_modpath != NULL)
-                               *p_modpath = PyString_AsString(
+                               *p_modpath = PyUnicode_AsString(
                                        PyTuple_GetItem(toc_entry, 0));
                        return code;
                }
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to