本文整理汇总了Python中os.unsetenv方法的典型用法代码示例。如果您正苦于以下问题:Python os.unsetenv方法的具体用法?Python os.unsetenv怎么用?Python os.unsetenv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.unsetenv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unsetenv
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def unsetenv(key):
"""Like `os.unsetenv` but takes unicode under Windows + Python 2
Args:
key (pathlike): The env var to unset
"""
key = path2fsn(key)
if is_win:
# python 3 has no unsetenv under Windows -> use our ctypes one as well
try:
del_windows_env_var(key)
except WindowsError:
pass
else:
os.unsetenv(key)
示例2: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
示例3: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
# Second override 'Popen' class with our modified version.
示例4: sign
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def sign(opts):
"""Tag the commit & sign it!"""
# We use ! at the end of the key so that gpg uses this specific key.
# Otherwise it uses the key as a lookup into the overall key and uses the
# default signing key. i.e. It will see that KEYID_RSA is a subkey of
# another key, and use the primary key to sign instead of the subkey.
cmd = ['git', 'tag', '-s', opts.tag, '-u', f'{opts.key}!',
'-m', f'repo {opts.tag}', opts.commit]
key = 'GNUPGHOME'
print('+', f'export {key}="{opts.gpgdir}"')
oldvalue = os.getenv(key)
os.putenv(key, opts.gpgdir)
util.run(opts, cmd)
if oldvalue is None:
os.unsetenv(key)
else:
os.putenv(key, oldvalue)
示例5: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
示例6: system
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def system():
import platform
# On some Windows installation (Python 2.4) platform.system() is
# broken and incorrectly returns 'Microsoft' instead of 'Windows'.
# http://mail.python.org/pipermail/patches/2007-June/022947.html
syst = platform.system()
if syst == 'Microsoft':
return 'Windows'
return syst
# Set and get environment variables does not handle unicode strings correctly
# on Windows.
# Acting on os.environ instead of using getenv()/setenv()/unsetenv(),
# as suggested in <http://docs.python.org/library/os.html#os.environ>:
# "Calling putenv() directly does not change os.environ, so it's
# better to modify os.environ." (Same for unsetenv.)
示例7: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to get original _MEIPASS2 value from PYTHONPATH
# to get --onefile and --onedir mode working.
# Last character is stripped in C-loader.
os.putenv('_MEIPASS2', sys._MEIPASS)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
示例8: testCacheDir
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def testCacheDir(self):
# No cache dir set, None is returned.
cache_dir = resolver.tfhub_cache_dir()
self.assertEqual(cache_dir, None)
# Use temp dir.
cache_dir = resolver.tfhub_cache_dir(use_temp=True)
self.assertEquals(cache_dir,
os.path.join(tempfile.gettempdir(), "tfhub_modules"))
# Use override
cache_dir = resolver.tfhub_cache_dir(default_cache_dir="/d", use_temp=True)
self.assertEqual("/d", cache_dir)
# Use a flag
FLAGS.tfhub_cache_dir = "/e"
cache_dir = resolver.tfhub_cache_dir(default_cache_dir="/d", use_temp=True)
self.assertEqual("/e", cache_dir)
FLAGS.tfhub_cache_dir = ""
# Use env variable
os.environ[resolver._TFHUB_CACHE_DIR] = "/f"
cache_dir = resolver.tfhub_cache_dir(default_cache_dir="/d", use_temp=True)
self.assertEqual("/f", cache_dir)
FLAGS.tfhub_cache_dir = "/e"
cache_dir = resolver.tfhub_cache_dir(default_cache_dir="/d", use_temp=True)
self.assertEqual("/f", cache_dir)
FLAGS.tfhub_cache_dir = ""
os.unsetenv(resolver._TFHUB_CACHE_DIR)
示例9: test_ddb_no_endpoint
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_ddb_no_endpoint(self, mresource):
safe = os.getenv("AWS_LOCAL_DYNAMODB")
try:
os.unsetenv("AWS_LOCAL_DYANMODB")
del(os.environ["AWS_LOCAL_DYNAMODB"])
DynamoDBResource(region_name="us-east-1")
assert mresource.call_args[0] == ('dynamodb',)
resource = DynamoDBResource(endpoint_url="")
assert resource.conf == {}
finally:
if safe: # pragma: nocover
os.environ["AWS_LOCAL_DYNAMODB"] = safe
示例10: test_metric_measures_show_tz
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_metric_measures_show_tz(self):
ap_name = str(uuid.uuid4())
# PREPARE AN ARCHIVE POLICY
self.gnocchi("archive-policy", params="create " + ap_name +
" --back-window 0 -d granularity:1s,points:86400")
# CREATE METRIC
metric_name = str(uuid.uuid4())
result = self.gnocchi(
u'metric', params=u"create"
u" --archive-policy-name " + ap_name + " " + metric_name)
metric = json.loads(result)
# MEASURES ADD
self.gnocchi('measures',
params=("add %s "
"-m '2015-03-06T14:33:57Z@43.11' "
"--measure '2015-03-06T16:34:12+02:00@12' ")
% metric["id"], has_output=False)
# MEASURES SHOW
def _delete_tz():
os.unsetenv("TZ")
self.addCleanup(_delete_tz)
os.putenv("TZ", "Europe/Paris")
result = self.gnocchi('measures', params="show --refresh " +
metric["id"])
measures = json.loads(result)
self.assertEqual("2015-03-06T15:33:57+01:00", measures[0]['timestamp'])
self.assertEqual("2015-03-06T15:34:12+01:00", measures[1]['timestamp'])
# MEASURES SHOW
result = self.gnocchi('measures', params="show --utc --refresh " +
metric["id"])
measures = json.loads(result)
# Check that --utc is honored
self.assertEqual("2015-03-06T14:33:57+00:00", measures[0]['timestamp'])
self.assertEqual("2015-03-06T14:34:12+00:00", measures[1]['timestamp'])
示例11: restore_env_credentials
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def restore_env_credentials():
if env_credentials:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = env_credentials
else:
os.unsetenv('GOOGLE_APPLICATION_CREDENTIALS')
示例12: test_zk_prefix_replacement
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_zk_prefix_replacement():
if os.getenv('ZOOKEEPER_PREFIX', None):
os.unsetenv('ZOOKEEPER_PREFIX')
assert load_config().zk_prefix == '/'
os.environ['ZOOKEEPER_PREFIX'] = '/'
assert load_config().zk_prefix == '/'
os.environ['ZOOKEEPER_PREFIX'] = 'test'
assert load_config().zk_prefix == '/test'
os.environ['ZOOKEEPER_PREFIX'] = '/test'
assert load_config().zk_prefix == '/test'
示例13: test_listen_no_fds
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_listen_no_fds(self):
os.unsetenv('LISTEN_FDS')
os.unsetenv('LISTEN_PID')
self.assertEqual(listen_fds_with_names(), None)
示例14: test_listen_1_fd_no_names
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_listen_1_fd_no_names(self):
os.environ['LISTEN_FDS'] = '1'
os.environ['LISTEN_PID'] = str(os.getpid())
os.unsetenv('LISTEN_FDNAMES')
self.assertEqual(listen_fds_with_names(),
{3: 'unknown'})
示例15: test_listen_3_fds_no_names
# 需要导入模块: import os [as 别名]
# 或者: from os import unsetenv [as 别名]
def test_listen_3_fds_no_names(self):
os.environ['LISTEN_FDS'] = '3'
os.environ['LISTEN_PID'] = str(os.getpid())
os.unsetenv('LISTEN_FDNAMES')
self.assertEqual(listen_fds_with_names(),
{3: 'unknown', 4: 'unknown', 5: 'unknown'})