本文整理汇总了Python中os.environb方法的典型用法代码示例。如果您正苦于以下问题:Python os.environb方法的具体用法?Python os.environb怎么用?Python os.environb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.environb方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_environb
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
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).
示例2: get_env_with_bytes_locale
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
def get_env_with_bytes_locale(environ=os.environb, locale=b"C.UTF-8"):
"""Return an environment dict with locale vars set (to C.UTF-8 by default).
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.
:param locale: The locale to set in the environment, 'C.UTF-8' by default.
"""
environ = {
name: value
for name, value in environ.items()
if not name.startswith(b"LC_")
}
environ.update({b"LC_ALL": locale, b"LANG": locale, b"LANGUAGE": locale})
return environ
示例3: main
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
def main():
trailers = os.environb[b'TRAILERS'].split(b'\n') if os.environb[b'TRAILERS'] else []
assert all(b':' in trailer for trailer in trailers), trailers
original_commit_message = STDIN.read().strip()
new_commit_message = rework_commit_message(original_commit_message, trailers)
STDOUT.write(new_commit_message)
示例4: setUp
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
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
示例5: tearDown
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
def tearDown(self):
os.environ.clear()
os.environ.update(self.__save)
if os.supports_bytes_environ:
os.environb.clear()
os.environb.update(self.__saveb)
示例6: init_hypothesis
# 需要导入模块: import os [as 别名]
# 或者: from os import environb [as 别名]
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