本文整理汇总了Python中treq.get方法的典型用法代码示例。如果您正苦于以下问题:Python treq.get方法的具体用法?Python treq.get怎么用?Python treq.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treq
的用法示例。
在下文中一共展示了treq.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get(self):
"""
Attempt to retrieve and remove an object from the queue.
@return: a L{Deferred} which fires with the next object available in
the queue.
@raise QueueUnderflow: Too many (more than C{backlog})
L{Deferred}s are already waiting for an object from this queue.
"""
if self.pending:
return succeed(self.pending.pop(0))
elif self.backlog is None or len(self.waiting) < self.backlog:
d = Deferred(canceller=self._cancelGet)
self.waiting.append(d)
return d
else:
raise QueueUnderflow()
示例2: acceptance_yaml_for_test
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def acceptance_yaml_for_test(test_case):
"""
Load configuration from a yaml file specified in an environment variable.
Raises a SkipTest exception if the environment variable is not specified.
"""
_ENV_VAR = 'ACCEPTANCE_YAML'
filename = environ.get(_ENV_VAR)
if not filename:
test_case.skip(
'Must set {} to an acceptance.yaml file ('
'http://doc-dev.clusterhq.com/gettinginvolved/appendix.html#acceptance-testing-configuration' # noqa
') plus additional keys in order to run this test.'.format(
_ENV_VAR))
with open(filename) as f:
config = yaml.safe_load(f)
return config
示例3: extract_substructure_for_test
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def extract_substructure_for_test(test_case, substructure, config):
"""
Extract the keys from the config in substructure, which may be a nested
dictionary.
Raises a ``unittest.SkipTest`` if the substructure is not found in the
configuration.
This can be used to load credentials all at once for testing purposes.
"""
try:
return extract_substructure(config, substructure)
except MissingConfigError as e:
yaml.add_representer(
Optional,
lambda d, x: d.represent_scalar(u'tag:yaml.org,2002:str', repr(x)))
test_case.skip(
'Skipping test: could not get configuration: {}\n\n'
'In order to run this test, add ensure file at $ACCEPTANCE_YAML '
'has structure like:\n\n{}'.format(
e.message,
yaml.dump(substructure, default_flow_style=False))
)
示例4: register_endpoints
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def register_endpoints(app, config, auth, csrf):
@app.route('/healthcheck')
def healthcheck(request):
upstream = 'http://{!s}/healthcheck'.format(os.getenv("STETHOSCOPE_LOGIN_HOST",
"127.0.0.1:5002"))
deferred = treq.get(upstream, timeout=0.1, headers={'Host': request.getHost().host})
deferred.addCallback(check_upstream_response, request)
deferred.addErrback(handle_upstream_error, request)
return deferred
# gather hooks to external loggers
log_hooks = stethoscope.plugins.utils.instantiate_plugins(config,
namespace='stethoscope.plugins.logging.request')
logger.debug("loaded request logging hooks: {!r}", [hook.name for hook in log_hooks])
with app.subroute('/api/v1'):
register_device_api_endpoints(app, config, auth, log_hooks=log_hooks)
register_event_api_endpoints(app, config, auth, log_hooks=log_hooks)
register_account_api_endpoints(app, config, auth, log_hooks=log_hooks)
register_notification_api_endpoints(app, config, auth, log_hooks=log_hooks)
register_feedback_api_endpoints(app, config, auth, csrf, log_hooks=log_hooks)
# temporarily disabled: userinfo is not in use
# register_userinfo_api_endpoints(app, config, auth, log_hooks=log_hooks)
示例5: get_storage_servers
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get_storage_servers(self):
yaml_data = self._read_servers_yaml()
if not yaml_data:
return {}
storage = yaml_data.get("storage")
if not storage or not isinstance(storage, dict):
return {}
results = {}
for server, server_data in storage.items():
ann = server_data.get("ann")
if not ann:
continue
results[server] = {
"anonymous-storage-FURL": ann.get("anonymous-storage-FURL")
}
nickname = ann.get("nickname")
if nickname:
results[server]["nickname"] = nickname
return results
示例6: load_magic_folders
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def load_magic_folders(self):
data = {}
yaml_path = os.path.join(self.nodedir, "private", "magic_folders.yaml")
try:
with open(yaml_path) as f:
data = yaml.safe_load(f)
except OSError:
pass
folders_data = data.get("magic-folders")
if folders_data:
for key, value in folders_data.items(): # to preserve defaultdict
self.magic_folders[key] = value
for folder in self.magic_folders:
admin_dircap = self.get_admin_dircap(folder)
if admin_dircap:
self.magic_folders[folder]["admin_dircap"] = admin_dircap
return self.magic_folders
示例7: create_client
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def create_client(self, **kwargs):
if os.path.exists(self.nodedir):
raise FileExistsError(
"Nodedir already exists: {}".format(self.nodedir)
)
args = ["create-client", "--webport=tcp:0:interface=127.0.0.1"]
for key, value in kwargs.items():
if key in (
"nickname",
"introducer",
"shares-needed",
"shares-happy",
"shares-total",
):
args.extend(["--{}".format(key), str(value)])
elif key in ["needed", "happy", "total"]:
args.extend(["--shares-{}".format(key), str(value)])
elif key == "hide-ip":
args.append("--hide-ip")
yield self.command(args)
storage_servers = kwargs.get("storage")
if storage_servers and isinstance(storage_servers, dict):
self.add_storage_servers(storage_servers)
示例8: get_grid_status
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get_grid_status(self):
if not self.nodeurl:
return None
try:
resp = yield treq.get(self.nodeurl + "?t=json")
except ConnectError:
return None
if resp.code == 200:
content = yield treq.content(resp)
content = json.loads(content.decode("utf-8"))
servers_connected = 0
servers_known = 0
available_space = 0
if "servers" in content:
servers = content["servers"]
servers_known = len(servers)
for server in servers:
if server["connection_status"].startswith("Connected"):
servers_connected += 1
if server["available_space"]:
available_space += server["available_space"]
return servers_connected, servers_known, available_space
return None
示例9: restore_magic_folder
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def restore_magic_folder(self, folder_name, dest):
data = self.remote_magic_folders[folder_name]
admin_dircap = data.get("admin_dircap")
collective_dircap = data.get("collective_dircap")
upload_dircap = data.get("upload_dircap")
if not collective_dircap or not upload_dircap:
raise TahoeError(
'The capabilities needed to restore the folder "{}" could '
"not be found. This probably means that the folder was "
"never completely uploaded to begin with -- or worse, "
"that your rootcap was corrupted somehow after the fact.\n"
"\nYou will need to remove this folder and upload it "
"again.".format(folder_name)
)
yield self.create_magic_folder(
os.path.join(dest, folder_name),
"{}+{}".format(collective_dircap, upload_dircap),
admin_dircap,
)
示例10: ensure_recovery
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def ensure_recovery(self, settings):
settings_path = os.path.join(
self.gateway.nodedir, "private", "settings.json"
)
if settings.get("rootcap"):
self.update_progress.emit("Loading Recovery Key...")
with atomic_write(
self.gateway.rootcap_path, mode="w", overwrite=True
) as f:
f.write(settings["rootcap"])
with atomic_write(settings_path, mode="w", overwrite=True) as f:
f.write(json.dumps(settings))
else:
self.update_progress.emit("Generating Recovery Key...")
try:
settings["rootcap"] = yield self.gateway.create_rootcap()
except OSError: # XXX Rootcap file already exists
pass
with atomic_write(settings_path, mode="w", overwrite=True) as f:
f.write(json.dumps(settings))
settings_cap = yield self.gateway.upload(settings_path)
yield self.gateway.link(
self.gateway.rootcap, "settings.json", settings_cap
)
示例11: treq_get
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def treq_get(dispatcher, intent):
"""
Performer to execute an HTTP GET.
:param dispatcher: The dispatcher used to dispatch this performance.
:param HTTPGet intent: The intent to be performed.
"""
action = startAction(action_type=u"flocker:provision:_effect:treq_get")
with action.context():
Message.log(url=intent.url)
# Do not use persistent HTTP connections, because they will not be
# cleaned up by the end of the test.
d = DeferredContext(get(intent.url, persistent=False))
d.addActionFinish()
return d.result
示例12: get_dataset_backend
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get_dataset_backend(test_case):
"""
Get the volume backend the acceptance tests are running as.
:param test_case: The ``TestCase`` running this unit test.
:return BackendDescription: The configured backend.
:raise SkipTest: if the backend is specified.
"""
backend = environ.get("FLOCKER_ACCEPTANCE_VOLUME_BACKEND")
if backend is None:
raise SkipTest(
"Set acceptance testing volume backend using the " +
"FLOCKER_ACCEPTANCE_VOLUME_BACKEND environment variable.")
return backend_loader.get(backend)
示例13: get_backend_api
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get_backend_api(cluster_id):
"""
Get an appropriate BackendAPI for the specified dataset backend.
Note this is a backdoor that is useful to be able to interact with cloud
APIs in tests. For many dataset backends this does not make sense, but it
provides a convenient means to interact with cloud backends such as EBS or
cinder.
:param cluster_id: The unique cluster_id, used for backend APIs that
require this in order to be constructed.
"""
backend_config_filename = environ.get(
"FLOCKER_ACCEPTANCE_TEST_VOLUME_BACKEND_CONFIG")
if backend_config_filename is None:
raise SkipTest(
'This test requires the ability to construct an IBlockDeviceAPI '
'in order to verify construction. Please set '
'FLOCKER_ACCEPTANCE_TEST_VOLUME_BACKEND_CONFIG to a yaml filepath '
'with the dataset configuration.')
backend_name = environ.get("FLOCKER_ACCEPTANCE_VOLUME_BACKEND")
if backend_name is None:
raise SkipTest(
"Set acceptance testing volume backend using the " +
"FLOCKER_ACCEPTANCE_VOLUME_BACKEND environment variable.")
if backend_name in ('loopback', 'zfs'):
# XXX If we ever want to setup loopback acceptance tests running on the
# same node as the tests themselves, we will want to adjust this.
raise SkipTest(
"The loopback backend API can't be used remotely.")
backend_config_filepath = FilePath(backend_config_filename)
full_backend_config = yaml.safe_load(
backend_config_filepath.getContent())
backend_config = full_backend_config.get(backend_name)
if 'backend' in backend_config:
backend_config.pop('backend')
backend = backend_loader.get(backend_name)
return get_api(backend, pmap(backend_config), reactor, cluster_id)
示例14: skip_distribution
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def skip_distribution(unsupported, reason):
"""
Create decorator that skips a test if the distribution doesn't support the
operations required by the test.
:param supported: List of supported volume backends for this test.
:param reason: The reason the backend isn't supported.
"""
def decorator(test_method):
"""
:param test_method: The test method that should be skipped.
"""
@wraps(test_method)
def wrapper(test_case, *args, **kwargs):
distribution = environ.get("FLOCKER_ACCEPTANCE_DISTRIBUTION")
if distribution in unsupported:
raise SkipTest(
"Distribution not supported: "
"'{distribution}' ({reason}).".format(
distribution=distribution,
reason=reason,
)
)
return test_method(test_case, *args, **kwargs)
return wrapper
return decorator
示例15: get_default_volume_size
# 需要导入模块: import treq [as 别名]
# 或者: from treq import get [as 别名]
def get_default_volume_size():
"""
:returns int: the default volume size (in bytes) supported by the
backend the acceptance tests are using.
"""
default_volume_size = environ.get("FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE")
if default_volume_size is None:
raise SkipTest(
"Set acceptance testing default volume size using the " +
"FLOCKER_ACCEPTANCE_DEFAULT_VOLUME_SIZE environment variable.")
return int(default_volume_size)