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
30e507df
Unverified
Kaydet (Commit)
30e507df
authored
Mar 27, 2018
tarafından
Barry Warsaw
Kaydeden (comit)
GitHub
Mar 27, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33151: Handle submodule resources (GH-6268)
üst
da1734c5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
+37
-6
resources.py
Lib/importlib/resources.py
+5
-3
test_read.py
Lib/test/test_importlib/test_read.py
+11
-2
test_resource.py
Lib/test/test_importlib/test_resource.py
+21
-1
No files found.
Lib/importlib/resources.py
Dosyayı görüntüle @
30e507df
...
...
@@ -267,11 +267,12 @@ class _ZipImportResourceReader(resources_abc.ResourceReader):
self
.
fullname
=
fullname
def
open_resource
(
self
,
resource
):
path
=
f
'{self.fullname}/{resource}'
fullname_as_path
=
self
.
fullname
.
replace
(
'.'
,
'/'
)
path
=
f
'{fullname_as_path}/{resource}'
try
:
return
BytesIO
(
self
.
zipimporter
.
get_data
(
path
))
except
OSError
:
raise
FileNotFoundError
raise
FileNotFoundError
(
path
)
def
resource_path
(
self
,
resource
):
# All resources are in the zip file, so there is no path to the file.
...
...
@@ -282,7 +283,8 @@ class _ZipImportResourceReader(resources_abc.ResourceReader):
def
is_resource
(
self
,
name
):
# Maybe we could do better, but if we can get the data, it's a
# resource. Otherwise it isn't.
path
=
f
'{self.fullname}/{name}'
fullname_as_path
=
self
.
fullname
.
replace
(
'.'
,
'/'
)
path
=
f
'{fullname_as_path}/{name}'
try
:
self
.
zipimporter
.
get_data
(
path
)
except
OSError
:
...
...
Lib/test/test_importlib/test_read.py
Dosyayı görüntüle @
30e507df
import
unittest
from
importlib
import
resources
from
importlib
import
import_module
,
resources
from
.
import
data01
from
.
import
util
...
...
@@ -46,7 +46,16 @@ class ReadDiskTests(ReadTests, unittest.TestCase):
class
ReadZipTests
(
ReadTests
,
util
.
ZipSetup
,
unittest
.
TestCase
):
pass
def
test_read_submodule_resource
(
self
):
submodule
=
import_module
(
'ziptestdata.subdirectory'
)
result
=
resources
.
read_binary
(
submodule
,
'binary.file'
)
self
.
assertEqual
(
result
,
b
'
\0\1\2\3
'
)
def
test_read_submodule_resource_by_name
(
self
):
result
=
resources
.
read_binary
(
'ziptestdata.subdirectory'
,
'binary.file'
)
self
.
assertEqual
(
result
,
b
'
\0\1\2\3
'
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/test_resource.py
Dosyayı görüntüle @
30e507df
...
...
@@ -4,7 +4,7 @@ import unittest
from
.
import
data01
from
.
import
zipdata02
from
.
import
util
from
importlib
import
resources
from
importlib
import
resources
,
import_module
class
ResourceTests
:
...
...
@@ -109,6 +109,26 @@ class ResourceFromZipsTest(util.ZipSetupBase, unittest.TestCase):
set
(
resources
.
contents
(
'ziptestdata.two'
)),
{
'__init__.py'
,
'resource2.txt'
})
def
test_is_submodule_resource
(
self
):
submodule
=
import_module
(
'ziptestdata.subdirectory'
)
self
.
assertTrue
(
resources
.
is_resource
(
submodule
,
'binary.file'
))
def
test_read_submodule_resource_by_name
(
self
):
self
.
assertTrue
(
resources
.
is_resource
(
'ziptestdata.subdirectory'
,
'binary.file'
))
def
test_submodule_contents
(
self
):
submodule
=
import_module
(
'ziptestdata.subdirectory'
)
self
.
assertEqual
(
set
(
resources
.
contents
(
submodule
)),
{
'__init__.py'
,
'binary.file'
})
def
test_submodule_contents_by_name
(
self
):
self
.
assertEqual
(
set
(
resources
.
contents
(
'ziptestdata.subdirectory'
)),
{
'__init__.py'
,
'binary.file'
})
class
NamespaceTest
(
unittest
.
TestCase
):
def
test_namespaces_cant_have_resources
(
self
):
...
...
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