MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / open_resource

Function open_resource

tests/test_code/py/pytz/__init__.py:78–108  ·  view source on GitHub ↗

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. It is possible to specify different location for zoneinfo subdir by using the PYTZ_TZDATADIR environment variable.

(name)

Source from the content-addressed store, hash-verified

76
77
78def open_resource(name):
79 """Open a resource from the zoneinfo subdir for reading.
80
81 Uses the pkg_resources module if available and no standard file
82 found at the calculated location.
83
84 It is possible to specify different location for zoneinfo
85 subdir by using the PYTZ_TZDATADIR environment variable.
86 """
87 name_parts = name.lstrip('/').split('/')
88 for part in name_parts:
89 if part == os.path.pardir or os.path.sep in part:
90 raise ValueError('Bad path segment: %r' % part)
91 zoneinfo_dir = os.environ.get('PYTZ_TZDATADIR', None)
92 if zoneinfo_dir is not None:
93 filename = os.path.join(zoneinfo_dir, *name_parts)
94 else:
95 filename = os.path.join(os.path.dirname(__file__),
96 'zoneinfo', *name_parts)
97 if not os.path.exists(filename):
98 # http://bugs.launchpad.net/bugs/383171 - we avoid using this
99 # unless absolutely necessary to help when a broken version of
100 # pkg_resources is installed.
101 try:
102 from pkg_resources import resource_stream
103 except ImportError:
104 resource_stream = None
105
106 if resource_stream is not None:
107 return resource_stream(__name__, 'zoneinfo/' + name)
108 return open(filename, 'rb')
109
110
111def resource_exists(name):

Callers 4

resource_existsFunction · 0.85
timezoneFunction · 0.85
_fillMethod · 0.85
_fillMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected