diff --git a/pkg_resources/pkg_resources.py b/pkg_resources/pkg_resources.py index b7488f04..8dd1897e 100644 --- a/pkg_resources/pkg_resources.py +++ b/pkg_resources/pkg_resources.py @@ -1,9 +1,27 @@ -import os -import os.path +import uio + +c = {} def resource_stream(package, resource): - p = __import__(package) - d = os.path.dirname(p.__file__) - if d[0] != "/": - d = os.getcwd() + "/" + d - return open(d + "/" + resource, "rb") + 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 uos + d = uos.getcwd() + "/" + d + c[package] = d + "/" + + p = c[package] + if isinstance(p, dict): + return uio.BytesIO(p[resource]) + return open(p + resource, "rb")