我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用os.environb()。
def test_environb(self): # os.environ -> os.environb value = 'euro\u20ac' try: value_bytes = value.encode(sys.getfilesystemencoding(), 'surrogateescape') except UnicodeEncodeError: msg = "U+20AC character is not encodable to %s" % ( sys.getfilesystemencoding(),) self.skipTest(msg) os.environ['unicode'] = value self.assertEqual(os.environ['unicode'], value) self.assertEqual(os.environb[b'unicode'], value_bytes) # os.environb -> os.environ value = b'\xff' os.environb[b'bytes'] = value self.assertEqual(os.environb[b'bytes'], value) value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape') self.assertEqual(os.environ['bytes'], value_str) # On FreeBSD < 7 and OS X < 10.6, unsetenv() doesn't return a value (issue # #13415).
def select_c_utf8_bytes_locale(environ=os.environb): """Return a dict containing an environment that uses the C.UTF-8 locale. C.UTF-8 is the new en_US.UTF-8, i.e. it's the new default locale when no other locale makes sense. This function takes a starting environment, by default that of the current process, strips away all locale and language settings (i.e. LC_* and LANG) and selects C.UTF-8 in their place. :param environ: A base environment to start from. By default this is ``os.environb``. It will not be modified. """ environ = { name: value for name, value in environ.items() if not name.startswith(b'LC_') } environ.update({ b'LC_ALL': b'C.UTF-8', b'LANG': b'C.UTF-8', b'LANGUAGE': b'C.UTF-8', }) return environ
def setUp(self): self.__save = dict(os.environ) if os.supports_bytes_environ: self.__saveb = dict(os.environb) for key, value in self._reference().items(): os.environ[key] = value
def tearDown(self): os.environ.clear() os.environ.update(self.__save) if os.supports_bytes_environ: os.environb.clear() os.environb.update(self.__saveb)
def init_hypothesis(): """Initialize hypothesis profile if hypothesis is available""" try: # pragma: no cover:w if b'HYPOTHESIS_PROFILE' in environb: from hypothesis import Settings Settings.register_profile("ci", Settings( max_examples=10000 )) Settings.load_profile(os.getenv(u'HYPOTHESIS_PROFILE', 'default')) except (ImportError, AttributeError): # pragma: no cover pass