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
0ed66df5
Commit
0ed66df5
authored
May 17, 2018
by
Barry Warsaw
Committed by
GitHub
May 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33537: Add an __all__ to importlib.resources (#6920)
parent
dff46758
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
Lib/importlib/resources.py
Lib/importlib/resources.py
+20
-8
No files found.
Lib/importlib/resources.py
View file @
0ed66df5
...
@@ -2,7 +2,6 @@ import os
...
@@ -2,7 +2,6 @@ import os
import
tempfile
import
tempfile
from
.
import
abc
as
resources_abc
from
.
import
abc
as
resources_abc
from
builtins
import
open
as
builtins_open
from
contextlib
import
contextmanager
,
suppress
from
contextlib
import
contextmanager
,
suppress
from
importlib
import
import_module
from
importlib
import
import_module
from
importlib.abc
import
ResourceLoader
from
importlib.abc
import
ResourceLoader
...
@@ -15,6 +14,19 @@ from typing.io import BinaryIO, TextIO
...
@@ -15,6 +14,19 @@ from typing.io import BinaryIO, TextIO
from
zipimport
import
ZipImportError
from
zipimport
import
ZipImportError
__all__
=
[
'Package'
,
'Resource'
,
'contents'
,
'is_resource'
,
'open_binary'
,
'open_text'
,
'path'
,
'read_binary'
,
'read_text'
,
]
Package
=
Union
[
str
,
ModuleType
]
Package
=
Union
[
str
,
ModuleType
]
Resource
=
Union
[
str
,
os
.
PathLike
]
Resource
=
Union
[
str
,
os
.
PathLike
]
...
@@ -82,7 +94,7 @@ def open_binary(package: Package, resource: Resource) -> BinaryIO:
...
@@ -82,7 +94,7 @@ def open_binary(package: Package, resource: Resource) -> BinaryIO:
package_path
=
os
.
path
.
dirname
(
absolute_package_path
)
package_path
=
os
.
path
.
dirname
(
absolute_package_path
)
full_path
=
os
.
path
.
join
(
package_path
,
resource
)
full_path
=
os
.
path
.
join
(
package_path
,
resource
)
try
:
try
:
return
builtins_
open
(
full_path
,
mode
=
'rb'
)
return
open
(
full_path
,
mode
=
'rb'
)
except
OSError
:
except
OSError
:
# Just assume the loader is a resource loader; all the relevant
# Just assume the loader is a resource loader; all the relevant
# importlib.machinery loaders are and an AttributeError for
# importlib.machinery loaders are and an AttributeError for
...
@@ -116,8 +128,7 @@ def open_text(package: Package,
...
@@ -116,8 +128,7 @@ def open_text(package: Package,
package_path
=
os
.
path
.
dirname
(
absolute_package_path
)
package_path
=
os
.
path
.
dirname
(
absolute_package_path
)
full_path
=
os
.
path
.
join
(
package_path
,
resource
)
full_path
=
os
.
path
.
join
(
package_path
,
resource
)
try
:
try
:
return
builtins_open
(
return
open
(
full_path
,
mode
=
'r'
,
encoding
=
encoding
,
errors
=
errors
)
full_path
,
mode
=
'r'
,
encoding
=
encoding
,
errors
=
errors
)
except
OSError
:
except
OSError
:
# Just assume the loader is a resource loader; all the relevant
# Just assume the loader is a resource loader; all the relevant
# importlib.machinery loaders are and an AttributeError for
# importlib.machinery loaders are and an AttributeError for
...
@@ -248,10 +259,10 @@ def contents(package: Package) -> Iterable[str]:
...
@@ -248,10 +259,10 @@ def contents(package: Package) -> Iterable[str]:
return
os
.
listdir
(
package_directory
)
return
os
.
listdir
(
package_directory
)
# Private implementation of ResourceReader and get_resource_reader()
for
# Private implementation of ResourceReader and get_resource_reader()
called
#
zipimport. Don't use these directly! We're implementing these in Pytho
n
#
from zipimport.c. Don't use these directly! We're implementing these i
n
#
because 1) it's easier, 2) zipimport will likel
y get rewritten in Python
#
Python because 1) it's easier, 2) zipimport ma
y get rewritten in Python
# itself at some point, so doing this all in C would
just be
a waste of
# itself at some point, so doing this all in C would
difficult and
a waste of
# effort.
# effort.
class
_ZipImportResourceReader
(
resources_abc
.
ResourceReader
):
class
_ZipImportResourceReader
(
resources_abc
.
ResourceReader
):
...
@@ -322,6 +333,7 @@ class _ZipImportResourceReader(resources_abc.ResourceReader):
...
@@ -322,6 +333,7 @@ class _ZipImportResourceReader(resources_abc.ResourceReader):
yield
parent_name
yield
parent_name
# Called from zipimport.c
def
_zipimport_get_resource_reader
(
zipimporter
,
fullname
):
def
_zipimport_get_resource_reader
(
zipimporter
,
fullname
):
try
:
try
:
if
not
zipimporter
.
is_package
(
fullname
):
if
not
zipimporter
.
is_package
(
fullname
):
...
...
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