本文整理汇总了Python中os.environ.pop函数的典型用法代码示例。如果您正苦于以下问题:Python pop函数的具体用法?Python pop怎么用?Python pop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_info
def _get_info(self):
old_lang = environ.get('LANG')
environ['LANG'] = 'C'
sys_profiler_process = Popen(
["system_profiler", "SPBluetoothDataType"],
stdout=PIPE
)
stdout = sys_profiler_process.communicate()[0].decode('utf-8')
output = stdout.splitlines()
lines = []
for line in output:
if 'Bluetooth Power' not in line:
continue
lines.append(line)
if old_lang is None:
environ.pop('LANG')
else:
environ['LANG'] = old_lang
if output and len(lines) == 1:
return lines[0].split()[2]
else:
return None
开发者ID:kivy,项目名称:plyer,代码行数:27,代码来源:bluetooth.py
示例2: test_adds_authorization_header_to_response_with_cookie
def test_adds_authorization_header_to_response_with_cookie(self):
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'
class TestResource(ListResourceMixin):
def list(self, request):
request.environ['session']['test'] = 'test'
return Response()
self.test_client = self.client(
WSGIDispatcher(resources=[TestResource]), Response
)
session_store = locate(settings.SESSION_STORE)()
session = session_store.new()
session_store.save(session)
response = self.test_client.get(
'/', headers=[('Cookie', 'session_id={0}'.format(session.sid))]
)
self.assertIn('HTTP_AUTHORIZATION', response.headers)
self.assertEqual(
response.headers.get('HTTP_AUTHORIZATION'), 'Token {0}'.format(session.sid)
)
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:27,代码来源:authentication_middleware.py
示例3: _stop_acceptance_cluster
def _stop_acceptance_cluster():
"""
Stop the Flocker cluster configured for the acceptance tests.
XXX https://clusterhq.atlassian.net/browse/FLOC-1563
Flocker doesn't support using flocker-deploy along-side flocker-control and
flocker-agent. Since flocker-deploy (in it's SSH using incarnation) is
going away, we do the hack of stopping the cluster before running tests
that use flocker-deploy. This introduces an order dependency on the
acceptance test-suite.
This also removes the environment variables associated with the cluster, so
that tests attempting to use it will be skipped.
:return: A ``Deferred`` which fires when the cluster is stopped.
"""
control_node = environ.pop("FLOCKER_ACCEPTANCE_CONTROL_NODE", None)
agent_nodes_env_var = environ.pop("FLOCKER_ACCEPTANCE_AGENT_NODES", "")
agent_nodes = filter(None, agent_nodes_env_var.split(':'))
if control_node and agent_nodes:
return succeed(sync_perform(
dispatcher,
stop_cluster(control_node, agent_nodes)
))
else:
return succeed(None)
开发者ID:LaOnda,项目名称:flocker,代码行数:27,代码来源:testtools.py
示例4: unsetenv
def unsetenv(self, key):
if environ.get(key) is not None:
environ.pop(key)
if WINDOWS:
keyrm = "%s=" % key
self.msvcrt._putenv(keyrm.encode("utf-8"))
开发者ID:ViktorNova,项目名称:Carla,代码行数:7,代码来源:carla_utils.py
示例5: test_a_default_setting_can_be_overwritten
def test_a_default_setting_can_be_overwritten(self):
environ.pop('MONGOREST_SETTINGS_MODULE', None)
self.assertEqual(settings.MONGODB['URI'], '')
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.settings_test_settings'
self.assertEqual(settings.MONGODB['URI'], 'test')
开发者ID:caputomarcos,项目名称:mongorest,代码行数:8,代码来源:settings.py
示例6: test_cors_middleware_sets_correct_headers_on_other_methods
def test_cors_middleware_sets_correct_headers_on_other_methods(self):
response = self.test_client.get('/')
self.assertIn('Access-Control-Allow-Origin', response.headers)
self.assertIn('Access-Control-Allow-Methods', response.headers)
self.assertIn('Access-Control-Allow-Headers', response.headers)
self.assertIn('Access-Control-Allow-Credentials', response.headers)
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:9,代码来源:cors_middleware.py
示例7: test_raises_value_error_if_auth_collection_is_not_sub_class_of_collection
def test_raises_value_error_if_auth_collection_is_not_sub_class_of_collection(self):
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_colelction_error_settings'
self.test_client = self.client(
WSGIDispatcher(resources=[ListResourceMixin]), Response
)
with self.assertRaises(ValueError):
self.test_client.get('/')
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:11,代码来源:authentication_middleware.py
示例8: test_authentication_middleware_does_not_set_token_or_cookie_or_header_if_not_authorized
def test_authentication_middleware_does_not_set_token_or_cookie_or_header_if_not_authorized(self):
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'
self.test_client = self.client(
WSGIDispatcher(resources=[ListResourceMixin]), Response
)
response = self.test_client.get('/')
self.assertNotIn('HTTP_AUTHORIZATION', response.headers)
self.assertNotIn('Set-Cookie', response.headers)
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:caputomarcos,项目名称:mongorest,代码行数:13,代码来源:authentication_middleware.py
示例9: test_adds_authorization_header_to_response_without_token
def test_adds_authorization_header_to_response_without_token(self):
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'
self.test_client = self.client(
WSGIDispatcher(resources=[ListResourceMixin]), Response
)
response = self.test_client.get('/')
self.assertIn('HTTP_AUTHORIZATION', response.headers)
self.assertIn('Token ', response.headers.get('HTTP_AUTHORIZATION'))
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:13,代码来源:authentication_middleware.py
示例10: run
def run(args, api):
"""
run takes care of calling the action with the needed arguments parsed
using argparse.
We first try to call the action. In case the called action requires a
valid token and the api instance does not have one a TokenRequiredError
gets raised. In this case we catch the error and ask the user for a
email/password combination to create a new token. After that we call
the action again.
pycclib raises an exception any time the API does answer with a
HTTP STATUS CODE other than 200, 201 or 204. We catch these exceptions
here and stop cctrlapp using sys.exit and show the error message to the
user.
"""
# check if there is a newer version of cctrl or pycclib
try:
check_for_updates(api.check_versions()['cctrl'])
except KeyError:
pass
while True:
try:
try:
args.func(args)
except TokenRequiredError:
# check ENV for credentials first
try:
email = env.pop('CCTRL_EMAIL')
password = env.pop('CCTRL_PASSWORD')
except KeyError:
email, password = get_credentials()
try:
api.create_token(email, password)
except UnauthorizedError:
sys.exit(messages['NotAuthorized'])
else:
pass
except ParseAppDeploymentName:
sys.exit(messages['InvalidAppOrDeploymentName'])
else:
break
except UnauthorizedError, e:
if delete_tokenfile():
api.set_token(None)
else:
sys.exit(messages['NotAuthorized'])
except ForbiddenError, e:
sys.exit(messages['NotAllowed'])
开发者ID:havvg,项目名称:cctrl,代码行数:51,代码来源:common.py
示例11: main
def main():
venv_path = 'tmpvenv'
import sys
run((sys.executable, '-m', 'virtualenv', venv_path))
from os.path import join
venv_python = join(venv_path, 'bin', 'python')
from os import environ
environ.pop('__PYVENV_LAUNCHER__', None) # this thing clobbers python's sys.executable
# It's set by all OSX python executables t.t
run((venv_python, 'stage2.py'))
开发者ID:bukzor,项目名称:scratch,代码行数:14,代码来源:stage1.py
示例12: test_runtime_dir_notset
def test_runtime_dir_notset(self):
environ.pop('XDG_RUNTIME_DIR', None)
self.assertRaises(KeyError, BaseDirectory.get_runtime_dir, strict=True)
fallback = BaseDirectory.get_runtime_dir(strict=False)
assert fallback.startswith('/tmp/'), fallback
assert os.path.isdir(fallback), fallback
mode = stat.S_IMODE(os.stat(fallback).st_mode)
self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
# Calling it again should return the same directory.
fallback2 = BaseDirectory.get_runtime_dir(strict=False)
self.assertEqual(fallback, fallback2)
mode = stat.S_IMODE(os.stat(fallback2).st_mode)
self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
开发者ID:0312birdzhang,项目名称:pyxdg,代码行数:14,代码来源:test-basedirectory.py
示例13: test_wsgi_dispatcher_adds_middlewares_to_mounts
def test_wsgi_dispatcher_adds_middlewares_to_mounts(self):
environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.wsgi_test_settings'
class TestWSGIWrapper(WSGIWrapper):
endpoint = 'test'
url_map = Map([Rule('/', methods=['GET'], endpoint='test')])
def test(self, request):
return Response(status=999)
app = WSGIDispatcher(resources=[TestWSGIWrapper])
self.assertIsInstance(app.mounts['/test'], CORSMiddleware)
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:caputomarcos,项目名称:mongorest,代码行数:14,代码来源:wsgi_dispatcher.py
示例14: test_no_proxy
def test_no_proxy(self):
"""
Starting with Agent 5.0.0, there should always be a local forwarder
running and all payloads should go through it. So we should make sure
that we pass the no_proxy environment variable that will be used by requests
(See: https://github.com/kennethreitz/requests/pull/945 )
"""
from os import environ as env
env["http_proxy"] = "http://localhost:3128"
env["https_proxy"] = env["http_proxy"]
env["HTTP_PROXY"] = env["http_proxy"]
env["HTTPS_PROXY"] = env["http_proxy"]
set_no_proxy_settings()
self.assertTrue("no_proxy" in env)
self.assertEquals(env["no_proxy"], "127.0.0.1,localhost,169.254.169.254")
self.assertEquals({}, get_environ_proxies(
"http://localhost:17123/api/v1/series"))
expected_proxies = {
'http': 'http://localhost:3128',
'https': 'http://localhost:3128',
'no': '127.0.0.1,localhost,169.254.169.254'
}
environ_proxies = get_environ_proxies("https://www.google.com")
self.assertEquals(expected_proxies, environ_proxies, (expected_proxies, environ_proxies))
# Clear the env variables set
env.pop("http_proxy", None)
env.pop("https_proxy", None)
env.pop("HTTP_PROXY", None)
env.pop("HTTPS_PROXY", None)
开发者ID:alq666,项目名称:dd-agent,代码行数:35,代码来源:test_proxy.py
示例15: test_cors_middleware_sets_correct_headers_on_options
def test_cors_middleware_sets_correct_headers_on_options(self):
response = self.test_client.options('/')
self.assertIn('Access-Control-Allow-Origin', response.headers)
self.assertIn('Access-Control-Allow-Methods', response.headers)
self.assertIn('Access-Control-Allow-Headers', response.headers)
self.assertIn('Access-Control-Allow-Credentials', response.headers)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.data, b'200 OK')
self.assertEqual(response.headers.get('Content-Type'), 'text/plain')
environ.pop('MONGOREST_SETTINGS_MODULE')
开发者ID:mathvaleriano,项目名称:mongorest,代码行数:14,代码来源:cors_middleware.py
示例16: test_develop_theme
def test_develop_theme(self):
''' Check if the rules are developed
'''
# First we check the status of our environment variables
var_name = 'DIAZO_ALWAYS_CACHE_RULES'
env_had_var = var_name in environ
# and clean it up
env_var_backup = environ.pop(var_name, None)
transform = ThemeTransform(None, {})
# This evaluates to True because we set
# getConfiguration().debug_mode to True in the test setup
self.assertTrue(transform.develop_theme())
# But we can anyway force the cache
environ[var_name] = 'true'
self.assertFalse(transform.develop_theme())
# If we require to debug.diazo the variable will be ignored
transform = ThemeTransform(None, {'diazo.debug': '1'})
self.assertTrue(transform.develop_theme())
# Then we reset our env variables before leaving
if env_had_var:
environ[var_name] = env_var_backup
else:
del environ[var_name]
开发者ID:plone,项目名称:plone.app.theming,代码行数:27,代码来源:test_transform.py
示例17: test_upload_to_s3
def test_upload_to_s3(self):
environ['AWS_SESSION_TOKEN'] = 'Good Times'
environ.pop('AWS_ACCESS_KEY_ID', None)
with mock.patch('boto3.session.Session') as resource:
_upload_to_s3('oa.mbtiles', 'xxx', 'yyy', 'zzz', 'bbb', 'kkk')
self.assertEqual(len(resource.mock_calls), 4)
self.assertEqual(resource.mock_calls[0][1], ('yyy', 'zzz', 'xxx'))
self.assertEqual(resource.mock_calls[1][1], ('s3', ))
self.assertEqual(resource.mock_calls[2][0], '().resource().Bucket')
self.assertEqual(resource.mock_calls[2][1], ('bbb', ))
self.assertEqual(resource.mock_calls[3][0], '().resource().Bucket().upload_file')
self.assertEqual(resource.mock_calls[3][1], ('oa.mbtiles', 'kkk'))
self.assertEqual(environ['AWS_SESSION_TOKEN'], 'Good Times')
self.assertNotIn('AWS_ACCESS_KEY_ID', environ)
开发者ID:cbmeeks,项目名称:machine,代码行数:17,代码来源:dotmap.py
示例18: test_header6
def test_header6():
"""
Test environment variable QSTAT_HEADER_FULL
"""
delim = ':'
callbacks = [
# <cb function> <cb args (tuple) >
( cb_debug , () ),
( cb_split , (delim,) ) ]
environ.pop('CQSTAT_HEADER_FULL')
parser = ArgParse(__doc__, callbacks)
parser.parse_it(['-f']) # parse the command line
h = header_info(parser)
if h.header == ['custom','qheader','full']:
good = True
else:
good = False
assert good, "Wrong value for header: %s" % str(h.header)
开发者ID:benmcclelland,项目名称:cobalt,代码行数:19,代码来源:header_test.py
示例19: test_settings_default_values
def test_settings_default_values(self):
environ.pop('MONGOREST_SETTINGS_MODULE', None)
self.assertEqual(settings.AUTH_COLLECTION, '')
self.assertIsNotNone(settings.CORS)
self.assertEqual(
settings.CORS['Access-Control-Allow-Origin'],
'*'
)
self.assertEqual(
settings.CORS['Access-Control-Allow-Methods'],
'GET,POST,PUT,PATCH,DELETE,OPTIONS'
)
self.assertEqual(
settings.CORS['Access-Control-Allow-Headers'],
'Accept,Accept-Encoding,Authorization,Content-Length,Content-Type,'
'Origin,User-Agent,X-CSRFToken,X-Requested-With'
)
self.assertEqual(
settings.CORS['Access-Control-Allow-Credentials'], 'true'
)
self.assertEqual(settings.MIDDLEWARES, [])
self.assertIsNotNone(settings.MONGODB)
self.assertEqual(settings.MONGODB['URI'], '')
self.assertEqual(settings.MONGODB['USERNAME'], '')
self.assertEqual(settings.MONGODB['PASSWORD'], '')
self.assertEqual(settings.MONGODB['HOST'], 'localhost')
self.assertEqual(settings.MONGODB['HOSTS'], [])
self.assertEqual(settings.MONGODB['PORT'], 27017)
self.assertEqual(settings.MONGODB['PORTS'], [])
self.assertEqual(settings.MONGODB['DATABASE'], 'mongorest')
self.assertEqual(settings.MONGODB['OPTIONS'], [])
self.assertEqual(settings.RETRY_LIMIT, 5)
self.assertEqual(settings.BASE_RETRY_TIME, 2)
self.assertEqual(settings.LINEAR_RETRIES, False)
self.assertEqual(settings.SESSION_STORE, '')
开发者ID:caputomarcos,项目名称:mongorest,代码行数:41,代码来源:settings.py
示例20: _get_uid
def _get_uid(self):
old_lang = environ.get('LANG')
environ['LANG'] = 'C'
ioreg_process = Popen(["ioreg", "-l"], stdout=PIPE)
grep_process = Popen(
["grep", "IOPlatformSerialNumber"],
stdin=ioreg_process.stdout, stdout=PIPE
)
ioreg_process.stdout.close()
output = grep_process.communicate()[0]
if old_lang is None:
environ.pop('LANG')
else:
environ['LANG'] = old_lang
result = None
if output:
result = output.split()[3][1:-1]
return result
开发者ID:kivy,项目名称:plyer,代码行数:21,代码来源:uniqueid.py
注:本文中的os.environ.pop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论