forked from micropython/micropython-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpkg_resources.py
More file actions
28 lines (24 loc) · 726 Bytes
/
Copy pathpkg_resources.py
File metadata and controls
28 lines (24 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import io
c = {}
def resource_stream(package, resource):
if package not in c:
try:
if package:
p = __import__(package + ".R", None, None, True)
else:
p = __import__("R")
c[package] = p.R
except ImportError:
if package:
p = __import__(package)
d = p.__path__
else:
d = "."
# if d[0] != "/":
# import os
# d = os.getcwd() + "/" + d
c[package] = d + "/"
p = c[package]
if isinstance(p, dict):
return io.BytesIO(p[resource])
return open(p + resource, "rb")