Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6a57c08d
Kaydet (Commit)
6a57c08d
authored
May 11, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1326: document and test zipimporter.archive and zipimporter.prefix.
üst
ae98f50e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
13 deletions
+55
-13
zipimport.rst
Doc/library/zipimport.rst
+14
-11
test_zipimport.py
Lib/test/test_zipimport.py
+32
-0
zipimport.c
Modules/zipimport.c
+9
-2
No files found.
Doc/library/zipimport.rst
Dosyayı görüntüle @
6a57c08d
...
...
@@ -65,17 +65,14 @@ zipimporter Objects
.. class:: zipimporter(archivepath)
Create a new zipimporter instance. *archivepath* must be a path to a ZIP file.
Create a new zipimporter instance. *archivepath* must be a path to a ZIP
file, or to a specific path within a ZIP file. For example, an *archivepath*
of :file:`foo/bar.zip/lib` will look for modules in the :file:`lib` directory
inside the ZIP file :file:`foo/bar.zip` (provided that it exists).
:exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP
archive.
*archivepath* can also contain a path within the ZIP file -- the importer
object will then look under that path instead of the ZIP file root. For
example, an *archivepath* of :file:`foo/bar.zip/lib` will look for modules
in the :file:`lib` directory inside the ZIP file :file:`foo/bar.zip`
(provided that it exists).
.. method:: find_module(fullname[, path])
Search for a module specified by *fullname*. *fullname* must be the fully
...
...
@@ -120,13 +117,19 @@ zipimporter Objects
.. attribute:: archive
The file name of the importer's associated ZIP file.
The file name of the importer's associated ZIP file, without a possible
subpath.
.. attribute:: prefix
The path within the ZIP file where modules are searched; see
:class:`zipimporter` for details.
The subpath within the ZIP file where modules are searched. This is the
empty string for zipimporter objects which point to the root of the ZIP
file.
The :attr:`archive` and :attr:`prefix` attributes, when combined with a
slash, equal the original *archivepath* argument given to the
:class:`zipimporter` constructor.
.. _zipimport-examples:
...
...
Lib/test/test_zipimport.py
Dosyayı görüntüle @
6a57c08d
...
...
@@ -212,6 +212,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
z
.
close
()
zi
=
zipimport
.
zipimporter
(
TEMP_ZIP
)
self
.
assertEquals
(
zi
.
archive
,
TEMP_ZIP
)
self
.
assertEquals
(
zi
.
is_package
(
TESTPACK
),
True
)
zi
.
load_module
(
TESTPACK
)
...
...
@@ -232,6 +233,37 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
z
.
close
()
os
.
remove
(
TEMP_ZIP
)
def
testZipImporterMethodsInSubDirectory
(
self
):
packdir
=
TESTPACK
+
os
.
sep
packdir2
=
packdir
+
TESTPACK2
+
os
.
sep
files
=
{
packdir2
+
"__init__"
+
pyc_ext
:
(
NOW
,
test_pyc
),
packdir2
+
TESTMOD
+
pyc_ext
:
(
NOW
,
test_pyc
)}
z
=
ZipFile
(
TEMP_ZIP
,
"w"
)
try
:
for
name
,
(
mtime
,
data
)
in
files
.
items
():
zinfo
=
ZipInfo
(
name
,
time
.
localtime
(
mtime
))
zinfo
.
compress_type
=
self
.
compression
z
.
writestr
(
zinfo
,
data
)
z
.
close
()
zi
=
zipimport
.
zipimporter
(
TEMP_ZIP
+
os
.
sep
+
packdir
)
self
.
assertEquals
(
zi
.
archive
,
TEMP_ZIP
)
self
.
assertEquals
(
zi
.
prefix
,
packdir
)
self
.
assertEquals
(
zi
.
is_package
(
TESTPACK2
),
True
)
zi
.
load_module
(
TESTPACK2
)
self
.
assertEquals
(
zi
.
is_package
(
TESTPACK2
+
os
.
sep
+
'__init__'
),
False
)
self
.
assertEquals
(
zi
.
is_package
(
TESTPACK2
+
os
.
sep
+
TESTMOD
),
False
)
mod_name
=
TESTPACK2
+
os
.
sep
+
TESTMOD
mod
=
__import__
(
module_path_to_dotted_name
(
mod_name
))
self
.
assertEquals
(
zi
.
get_source
(
TESTPACK2
),
None
)
self
.
assertEquals
(
zi
.
get_source
(
mod_name
),
None
)
finally
:
z
.
close
()
os
.
remove
(
TEMP_ZIP
)
def
testGetData
(
self
):
z
=
ZipFile
(
TEMP_ZIP
,
"w"
)
z
.
compression
=
self
.
compression
...
...
Modules/zipimport.c
Dosyayı görüntüle @
6a57c08d
...
...
@@ -555,8 +555,15 @@ PyDoc_STRVAR(zipimporter_doc,
"zipimporter(archivepath) -> zipimporter object
\n
\
\n
\
Create a new zipimporter instance. 'archivepath' must be a path to
\n
\
a zipfile. ZipImportError is raised if 'archivepath' doesn't point to
\n
\
a valid Zip archive."
);
a zipfile, or to a specific path inside a zipfile. For example, it can be
\n
\
'/tmp/myimport.zip', or '/tmp/myimport.zip/mydirectory', if mydirectory is a
\n
\
valid directory inside the archive.
\n
\
\n
\
'ZipImportError is raised if 'archivepath' doesn't point to a valid Zip
\n
\
archive.
\n
\
\n
\
The 'archive' attribute of zipimporter objects contains the name of the
\n
\
zipfile targeted."
);
#define DEFERRED_ADDRESS(ADDR) 0
...
...
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