Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3c814d25
Commit
3c814d25
authored
Aug 26, 2007
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use unicode (and bytes as appropriate)
parent
8abd2e6c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
Modules/zipimport.c
Modules/zipimport.c
+27
-24
No files found.
Modules/zipimport.c
View file @
3c814d25
...
...
@@ -144,11 +144,11 @@ zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
}
}
self
->
archive
=
Py
String
_FromString
(
buf
);
self
->
archive
=
Py
Unicode
_FromString
(
buf
);
if
(
self
->
archive
==
NULL
)
return
-
1
;
self
->
prefix
=
Py
String
_FromString
(
prefix
);
self
->
prefix
=
Py
Unicode
_FromString
(
prefix
);
if
(
self
->
prefix
==
NULL
)
return
-
1
;
...
...
@@ -180,10 +180,10 @@ zipimporter_repr(ZipImporter *self)
char
*
archive
=
"???"
;
char
*
prefix
=
""
;
if
(
self
->
archive
!=
NULL
&&
Py
String
_Check
(
self
->
archive
))
archive
=
Py
String
_AsString
(
self
->
archive
);
if
(
self
->
prefix
!=
NULL
&&
Py
String
_Check
(
self
->
prefix
))
prefix
=
Py
String
_AsString
(
self
->
prefix
);
if
(
self
->
archive
!=
NULL
&&
Py
Unicode
_Check
(
self
->
archive
))
archive
=
Py
Unicode
_AsString
(
self
->
archive
);
if
(
self
->
prefix
!=
NULL
&&
Py
Unicode
_Check
(
self
->
prefix
))
prefix
=
Py
Unicode
_AsString
(
self
->
prefix
);
if
(
prefix
!=
NULL
&&
*
prefix
)
return
PyUnicode_FromFormat
(
"<zipimporter object
\"
%.300s%c%.150s
\"
>"
,
archive
,
SEP
,
prefix
);
...
...
@@ -249,7 +249,7 @@ get_module_info(ZipImporter *self, char *fullname)
subname
=
get_subname
(
fullname
);
len
=
make_filename
(
Py
String
_AsString
(
self
->
prefix
),
subname
,
path
);
len
=
make_filename
(
Py
Unicode
_AsString
(
self
->
prefix
),
subname
,
path
);
if
(
len
<
0
)
return
MI_ERROR
;
...
...
@@ -322,12 +322,12 @@ zipimporter_load_module(PyObject *obj, PyObject *args)
/* add __path__ to the module *before* the code gets
executed */
PyObject
*
pkgpath
,
*
fullpath
;
char
*
prefix
=
Py
String
_AsString
(
self
->
prefix
);
char
*
prefix
=
Py
Unicode
_AsString
(
self
->
prefix
);
char
*
subname
=
get_subname
(
fullname
);
int
err
;
fullpath
=
Py
String
_FromFormat
(
"%s%c%s%s"
,
Py
String
_AsString
(
self
->
archive
),
fullpath
=
Py
Unicode
_FromFormat
(
"%s%c%s%s"
,
Py
Unicode
_AsString
(
self
->
archive
),
SEP
,
*
prefix
?
prefix
:
""
,
subname
);
...
...
@@ -404,9 +404,9 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
}
path
=
buf
;
#endif
len
=
Py
String_Size
(
self
->
archive
);
len
=
Py
Unicode_GET_SIZE
(
self
->
archive
);
if
((
size_t
)
len
<
strlen
(
path
)
&&
strncmp
(
path
,
Py
String
_AsString
(
self
->
archive
),
len
)
==
0
&&
strncmp
(
path
,
Py
Unicode
_AsString
(
self
->
archive
),
len
)
==
0
&&
path
[
len
]
==
SEP
)
{
path
=
path
+
len
+
1
;
}
...
...
@@ -416,7 +416,7 @@ zipimporter_get_data(PyObject *obj, PyObject *args)
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
path
);
return
NULL
;
}
return
get_data
(
Py
String
_AsString
(
self
->
archive
),
toc_entry
);
return
get_data
(
Py
Unicode
_AsString
(
self
->
archive
),
toc_entry
);
}
static
PyObject
*
...
...
@@ -453,7 +453,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
}
subname
=
get_subname
(
fullname
);
len
=
make_filename
(
Py
String
_AsString
(
self
->
prefix
),
subname
,
path
);
len
=
make_filename
(
Py
Unicode
_AsString
(
self
->
prefix
),
subname
,
path
);
if
(
len
<
0
)
return
NULL
;
...
...
@@ -466,7 +466,7 @@ zipimporter_get_source(PyObject *obj, PyObject *args)
toc_entry
=
PyDict_GetItemString
(
self
->
files
,
path
);
if
(
toc_entry
!=
NULL
)
{
PyObject
*
bytes
=
get_data
(
Py
String
_AsString
(
self
->
archive
),
toc_entry
);
PyObject
*
bytes
=
get_data
(
Py
Unicode
_AsString
(
self
->
archive
),
toc_entry
);
PyObject
*
res
=
PyUnicode_FromString
(
PyBytes_AsString
(
bytes
));
Py_XDECREF
(
bytes
);
return
res
;
...
...
@@ -794,7 +794,7 @@ get_data(char *archive, PyObject *toc_entry)
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 @@ get_data(char *archive, PyObject *toc_entry)
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
=
Py
String
_AsString
(
raw_data
);
buf
=
Py
Bytes
_AsString
(
raw_data
);
err
=
fseek
(
fp
,
file_offset
,
0
);
if
(
err
==
0
)
...
...
@@ -1041,7 +1044,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
{
PyObject
*
data
,
*
code
;
char
*
modpath
;
char
*
archive
=
Py
String
_AsString
(
self
->
archive
);
char
*
archive
=
Py
Unicode
_AsString
(
self
->
archive
);
if
(
archive
==
NULL
)
return
NULL
;
...
...
@@ -1050,7 +1053,7 @@ get_code_from_data(ZipImporter *self, int ispackage, int isbytecode,
if
(
data
==
NULL
)
return
NULL
;
modpath
=
Py
String
_AsString
(
PyTuple_GetItem
(
toc_entry
,
0
));
modpath
=
Py
Unicode
_AsString
(
PyTuple_GetItem
(
toc_entry
,
0
));
if
(
isbytecode
)
{
code
=
unmarshal_code
(
modpath
,
data
,
mtime
);
...
...
@@ -1075,7 +1078,7 @@ get_module_code(ZipImporter *self, char *fullname,
subname
=
get_subname
(
fullname
);
len
=
make_filename
(
Py
String
_AsString
(
self
->
prefix
),
subname
,
path
);
len
=
make_filename
(
Py
Unicode
_AsString
(
self
->
prefix
),
subname
,
path
);
if
(
len
<
0
)
return
NULL
;
...
...
@@ -1085,7 +1088,7 @@ get_module_code(ZipImporter *self, char *fullname,
strcpy
(
path
+
len
,
zso
->
suffix
);
if
(
Py_VerboseFlag
>
1
)
PySys_WriteStderr
(
"# trying %s%c%s
\n
"
,
Py
String
_AsString
(
self
->
archive
),
Py
Unicode
_AsString
(
self
->
archive
),
SEP
,
path
);
toc_entry
=
PyDict_GetItemString
(
self
->
files
,
path
);
if
(
toc_entry
!=
NULL
)
{
...
...
@@ -1107,7 +1110,7 @@ get_module_code(ZipImporter *self, char *fullname,
continue
;
}
if
(
code
!=
NULL
&&
p_modpath
!=
NULL
)
*
p_modpath
=
Py
String
_AsString
(
*
p_modpath
=
Py
Unicode
_AsString
(
PyTuple_GetItem
(
toc_entry
,
0
));
return
code
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment