python类resource_stream()的实例源码

__init__.py 文件源码 项目:SenateCaller 作者: tcash21 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename):
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        try:
            from pkg_resources import resource_stream
        except ImportError:
            resource_stream = None

        if resource_stream is not None:
            return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
pwd.py 文件源码 项目:GAMADV-X 作者: taers232c 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _open_asset_path(path, encoding=None):
    """
    :param asset_path:
        string containing absolute path to file,
        or package-relative path using format
        ``"python.module:relative/file/path"``.

    :returns:
        filehandle opened in 'rb' mode
        (unless encoding explicitly specified)
    """
    if encoding:
        return codecs.getreader(encoding)(_open_asset_path(path))
    if os.path.isabs(path):
        return open(path, "rb")
    package, sep, subpath = path.partition(":")
    if not sep:
        raise ValueError("asset path must be absolute file path "
                         "or use 'pkg.name:sub/path' format: %r" % (path,))
    return pkg_resources.resource_stream(package, subpath)


#: type aliases
__init__.py 文件源码 项目:cloud-memory 作者: onejgordon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:pmatic 作者: LarsMichelsen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename):
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        try:
            from pkg_resources import resource_stream
        except ImportError:
            resource_stream = None

        if resource_stream is not None:
            return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:enkiWS 作者: juliettef 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def open_resource(self, name):
        """Open a resource from the zoneinfo subdir for reading.

        Uses the pkg_resources module if available and no standard file
        found at the calculated location.
        """
        name_parts = name.lstrip('/').split('/')
        for part in name_parts:
            if part == os.path.pardir or os.path.sep in part:
                raise ValueError('Bad path segment: %r' % part)
        filename = os.path.join(os.path.dirname(__file__),
                                'zoneinfo', *name_parts)
        if not os.path.exists(filename) and resource_stream is not None:
            # http://bugs.launchpad.net/bugs/383171 - we avoid using this
            # unless absolutely necessary to help when a broken version of
            # pkg_resources is installed.
            return resource_stream(__name__, 'zoneinfo/' + name)
        return open(filename, 'rb')
__init__.py 文件源码 项目:FMoviesPlus.bundle 作者: coder-alpha 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename):
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        try:
            from pkg_resources import resource_stream
        except ImportError:
            resource_stream = None

        if resource_stream is not None:
            return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
index_scribe.py 文件源码 项目:piwheels 作者: bennuttall 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setup_output_path(self):
        """
        Called on task startup to copy all static resources into the output
        path (and to make sure the output path exists as a directory).
        """
        self.logger.info('setting up output path')
        try:
            self.output_path.mkdir()
        except FileExistsError:
            pass
        try:
            (self.output_path / 'simple').mkdir()
        except FileExistsError:
            pass
        for filename in resource_listdir(__name__, 'static'):
            with (self.output_path / filename).open('wb') as f:
                source = resource_stream(__name__, 'static/' + filename)
                f.write(source.read())
                source.close()
__init__.py 文件源码 项目:ebs-snapshot-scheduler 作者: awslabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:pyfiddleio 作者: priyankcommits 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:UManSysProp_public 作者: loftytopping 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _read_data(
        filename, key_conv=str, value_conv=float, key_col=0, value_col=1):
    result = {}
    cols = None
    for count, line in enumerate(
            pkg.resource_stream(__name__, filename), start=1):
        data = _parse_re.match(line.decode('utf-8')).group('data')
        if data:
            data = data.split()
            try:
                if cols is None:
                    cols = len(data)
                elif len(data) != cols:
                    raise ValueError(
                            'Unexpected number of values (expected %d)' % cols)
                key = key_conv(data[key_col])
                value = value_conv(data[value_col])
                if key in result:
                    raise ValueError(
                            'Duplicate definition for group %s' % key)
                result[key] = value
            except (IndexError, ValueError) as e:
                e.args += ('on line %d of %s' % (count, filename),)
                raise
    return result
test_prov_db.py 文件源码 项目:prov-db-connector 作者: DLR-SC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setUp(self):
        """
        Loads the test xml json and provn data

        """
        self.test_resources = {
            'xml': {'package': 'provdbconnector', 'file': '/tests/resources/primer.provx'},
            'json': {'package': 'provdbconnector', 'file': '/tests/resources/primer.json'},
            'provn': {'package': 'provdbconnector', 'file': '/tests/resources/primer.provn'}
        }
        self.test_prov_files = dict((key, pkg_resources.resource_stream(val['package'], val['file'])) for key, val in
                                    self.test_resources.items())
        self.auth_info = {"user_name": NEO4J_USER,
                          "user_password": NEO4J_PASS,
                          "host": NEO4J_HOST + ":" + NEO4J_BOLT_PORT
                          }
        self.provapi = ProvDb(api_id=1, adapter=Neo4jAdapter, auth_info=self.auth_info)
__init__.py 文件源码 项目:noobotkit 作者: nazroll 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:LSTM-GA-StockTrader 作者: MartinLidy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:alexa-spark 作者: ismailakkila 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
settings.py 文件源码 项目:vpn-porthole 作者: sourcesimian 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __ensure_config_setup(cls):
        root = cls.__default_settings_root()
        if not os.path.exists(root):
            os.makedirs(root)

        settings_file = os.path.join(root, 'settings.conf')
        if not os.path.exists(settings_file):
            with open(settings_file, 'w+b') as fh:
                content = resource_stream("vpnporthole", "resources/settings.conf").read()
                fh.write(content)
            print("* Wrote: %s" % settings_file)

        root = os.path.join(root, 'profiles')
        if not os.path.exists(root):
            os.makedirs(root)

            profile_file = os.path.join(root, 'example.conf')
            if not os.path.exists(profile_file):
                with open(profile_file, 'w+b') as fh:
                    content = resource_stream("vpnporthole", "resources/example.conf").read()
                    fh.write(content)
                print("* Wrote: %s" % profile_file)
flask.py 文件源码 项目:annotated-py-flask 作者: hhstore 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def open_resource(self, resource):
        """Opens a resource from the application's resource folder.  To see
        how this works, consider the following folder structure::

            /myapplication.py
            /schemal.sql
            /static
                /style.css
            /templates
                /layout.html
                /index.html

        If you want to open the `schema.sql` file you would do the
        following::

            with app.open_resource('schema.sql') as f:
                contents = f.read()
                do_something_with(contents)

        :param resource: the name of the resource.  To access resources within
                         subfolders use forward slashes as separator.
        """
        if pkg_resources is None:
            return open(os.path.join(self.root_path, resource), 'rb')
        return pkg_resources.resource_stream(self.import_name, resource)
__init__.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename):
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        try:
            from pkg_resources import resource_stream
        except ImportError:
            resource_stream = None

        if resource_stream is not None:
            return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
test_kiwis_pie.py 文件源码 项目:kiwis_pie 作者: amacd31 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_get_parameter_list(self, m):
        response = StringIO(BytesIO(pkg_resources.resource_string(__name__, 'test_data/bom_parameter_list.request')).read().decode('UTF-8')).read()

        m.get(
            'http://www.bom.gov.au/waterdata/services?station_no=410730&type=QueryServices&service=kisters&format=json&request=getParameterList',
            text = response
        )

        expected = pd.read_csv(
            pkg_resources.resource_stream(
                __name__,
                'test_data/bom_parameter_list.csv'
            )
        )

        df = self.k.get_parameter_list(station_no = '410730')
        expected.equals(df)
__init__.py 文件源码 项目:Chorus 作者: DonaldBough 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename):
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        try:
            from pkg_resources import resource_stream
        except ImportError:
            resource_stream = None

        if resource_stream is not None:
            return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')
__init__.py 文件源码 项目:Hawkeye 作者: tozhengxq 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def open_resource(name):
    """Open a resource from the zoneinfo subdir for reading.

    Uses the pkg_resources module if available and no standard file
    found at the calculated location.
    """
    name_parts = name.lstrip('/').split('/')
    for part in name_parts:
        if part == os.path.pardir or os.path.sep in part:
            raise ValueError('Bad path segment: %r' % part)
    filename = os.path.join(os.path.dirname(__file__),
                            'zoneinfo', *name_parts)
    if not os.path.exists(filename) and resource_stream is not None:
        # http://bugs.launchpad.net/bugs/383171 - we avoid using this
        # unless absolutely necessary to help when a broken version of
        # pkg_resources is installed.
        return resource_stream(__name__, 'zoneinfo/' + name)
    return open(filename, 'rb')


问题


面经


文章

微信
公众号

扫码关注公众号