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
e260ba2d
Kaydet (Commit)
e260ba2d
authored
Ock 06, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1325: Add docs and tests for zipimporter.archive and zipimporter.prefix.
üst
516787dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
18 deletions
+34
-18
zipimport.rst
Doc/library/zipimport.rst
+29
-18
test_zipimport.py
Lib/test/test_zipimport.py
+5
-0
No files found.
Doc/library/zipimport.rst
Dosyayı görüntüle @
e260ba2d
...
...
@@ -33,21 +33,6 @@ Using the built-in :func:`reload` function will fail if called on a module
loaded from a ZIP archive; it is unlikely that :func:`reload` would be needed,
since this would imply that the ZIP has been altered during runtime.
The available attributes of this module are:
.. exception:: ZipImportError
Exception raised by zipimporter objects. It's a subclass of :exc:`ImportError`,
so it can be caught as :exc:`ImportError`, too.
.. class:: zipimporter
The class for importing ZIP files. See section :ref:`zipimporter-objects`
for constructor details.
.. seealso::
`PKZIP Application Note <http://www.pkware.com/business_and_developers/developer/appnote/>`_
...
...
@@ -63,18 +48,33 @@ The available attributes of this module are:
The PEP to add the import hooks that help this module work.
This module defines an exception:
.. exception:: ZipImportError
Exception raised by zipimporter objects. It's a subclass of :exc:`ImportError`,
so it can be caught as :exc:`ImportError`, too.
.. _zipimporter-objects:
zipimporter Objects
-------------------
:class:`zipimporter` is the class for importing ZIP files.
.. 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.
: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:: zipimporter.find_module(fullname[, path])
...
...
@@ -116,11 +116,22 @@ zipimporter Objects
:exc:`ZipImportError` if it wasn't found.
Examples
--------
.. attribute:: zipimporter.archive
The file name of the importer's associated ZIP file.
.. attribute:: zipimporter.prefix
The path within the ZIP file where modules are searched; see
:class:`zipimporter` for details.
.. _zipimport-examples:
Examples
--------
Here is an example that imports a module from a ZIP archive - note that the
:mod:`zipimport` module is not explicitly used. ::
...
...
Lib/test/test_zipimport.py
Dosyayı görüntüle @
e260ba2d
...
...
@@ -223,6 +223,11 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
mod
=
__import__
(
module_path_to_dotted_name
(
mod_name
))
self
.
assertEquals
(
zi
.
get_source
(
TESTPACK
),
None
)
self
.
assertEquals
(
zi
.
get_source
(
mod_name
),
None
)
# test prefix and archivepath members
zi2
=
zipimport
.
zipimporter
(
TEMP_ZIP
+
os
.
sep
+
TESTPACK
)
self
.
assertEquals
(
zi2
.
archive
,
TEMP_ZIP
)
self
.
assertEquals
(
zi2
.
prefix
,
TESTPACK
+
os
.
sep
)
finally
:
z
.
close
()
os
.
remove
(
TEMP_ZIP
)
...
...
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