text
stringlengths 0
828
|
---|
return ret"
|
4957,"def is_instance_running(self, instance_id):
|
""""""Checks if the instance is up and running.
|
:param str instance_id: instance identifier
|
:return: bool - True if running, False otherwise
|
""""""
|
self._restore_from_storage(instance_id)
|
if self._start_failed:
|
raise Exception('is_instance_running for node %s: failing due to'
|
' previous errors.' % instance_id)
|
try:
|
v_m = self._qualified_name_to_vm(instance_id)
|
if not v_m:
|
raise Exception(""Can't find instance_id %s"" % instance_id)
|
except Exception:
|
log.error(traceback.format_exc())
|
raise
|
return v_m._power_state == 'Started'"
|
4958,"def _save_or_update(self):
|
""""""Save or update the private state needed by the cloud provider.
|
""""""
|
with self._resource_lock:
|
if not self._config or not self._config._storage_path:
|
raise Exception(""self._config._storage path is undefined"")
|
if not self._config._base_name:
|
raise Exception(""self._config._base_name is undefined"")
|
if not os.path.exists(self._config._storage_path):
|
os.makedirs(self._config._storage_path)
|
path = self._get_cloud_provider_storage_path()
|
with open(path, 'wb') as storage:
|
pickle.dump(self._config, storage, pickle.HIGHEST_PROTOCOL)
|
pickle.dump(self._subscriptions, storage,
|
pickle.HIGHEST_PROTOCOL)"
|
4959,"def split_iter(src, sep=None, maxsplit=None):
|
""""""Splits an iterable based on a separator, *sep*, a max of
|
*maxsplit* times (no max by default). *sep* can be:
|
* a single value
|
* an iterable of separators
|
* a single-argument callable that returns True when a separator is
|
encountered
|
``split_iter()`` yields lists of non-separator values. A separator will
|
never appear in the output.
|
>>> list(split_iter(['hi', 'hello', None, None, 'sup', None, 'soap', None]))
|
[['hi', 'hello'], ['sup'], ['soap']]
|
Note that ``split_iter`` is based on :func:`str.split`, so if
|
*sep* is ``None``, ``split()`` **groups** separators. If empty lists
|
are desired between two contiguous ``None`` values, simply use
|
``sep=[None]``:
|
>>> list(split_iter(['hi', 'hello', None, None, 'sup', None]))
|
[['hi', 'hello'], ['sup']]
|
>>> list(split_iter(['hi', 'hello', None, None, 'sup', None], sep=[None]))
|
[['hi', 'hello'], [], ['sup'], []]
|
Using a callable separator:
|
>>> falsy_sep = lambda x: not x
|
>>> list(split_iter(['hi', 'hello', None, '', 'sup', False], falsy_sep))
|
[['hi', 'hello'], [], ['sup'], []]
|
See :func:`split` for a list-returning version.
|
""""""
|
if not is_iterable(src):
|
raise TypeError('expected an iterable')
|
if maxsplit is not None:
|
maxsplit = int(maxsplit)
|
if maxsplit == 0:
|
yield [src]
|
return
|
if callable(sep):
|
sep_func = sep
|
elif not is_scalar(sep):
|
sep = frozenset(sep)
|
sep_func = lambda x: x in sep
|
else:
|
sep_func = lambda x: x == sep
|
cur_group = []
|
split_count = 0
|
for s in src:
|
if maxsplit is not None and split_count >= maxsplit:
|
sep_func = lambda x: False
|
if sep_func(s):
|
if sep is None and not cur_group:
|
# If sep is none, str.split() ""groups"" separators
|
# check the str.split() docs for more info
|
continue
|
split_count += 1
|
yield cur_group
|
cur_group = []
|
else:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.