本文整理汇总了Python中boltons.iterutils.remap方法的典型用法代码示例。如果您正苦于以下问题:Python iterutils.remap方法的具体用法?Python iterutils.remap怎么用?Python iterutils.remap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boltons.iterutils
的用法示例。
在下文中一共展示了iterutils.remap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pop
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def pop(self, key: str) -> Any:
"""Delete and return value at key.
Args:
key (str): Key to pop.
Returns:
Any: Popped value.
"""
path, target = self.parse_key(key)
value = self.get(key)
remapped = iterutils.remap(self._config, lambda p, k,
v: False if p == path and k == target else True)
self._config = remapped
self.log.debug(f"popped config value {value} <- [{key}]")
return self.sync()
示例2: get_file_report
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def get_file_report(file_sha256, report_url, environment_id, type_, apikey, secret, verify):
user_agent = {'User-agent': 'VxStream Sandbox'}
params = {'apikey': apikey, 'secret': secret, 'environmentId': environment_id, 'type': type_}
resource_url = '%s/%s' % (report_url, file_sha256)
try:
res = requests.get(resource_url, headers=user_agent, params=params, verify=verify)
if res.status_code == 200:
# walk entire json blob to fix
# the keys known to cause issues
remapped = remap(res.json(), visit=visit)
return remapped
else:
print('Error code: {}, returned when getting report: {}'.format(res.status_code, file_sha256))
return res
except requests.exceptions.HTTPError as err:
print(err)
示例3: pretty
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def pretty(self, attrs='class="table"'):
return display(
HTML(j2h.convert(json=remap(self, visit=visit), table_attributes=attrs))
)
示例4: dict_match_mocks
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def dict_match_mocks(self, d1):
from unittest.mock import Mock
# Mocks
remapped = iterutils.remap(d1, lambda p, k, v: (
k, "MOCKED_VALUE") if isinstance(v, Mock) else True)
return remapped
示例5: permute_nested_values
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def permute_nested_values(dicts: "List[dict]", gen_val: "Callable[[int], Any]"):
"""
This function permutes the values of a nested mapping, for testing that out merge
method work regardless of the values types.
Assumes the intial dictionary had integers for values.
"""
dicts = deepcopy(dicts)
initial_values = [
x[1] for x in research(dicts, query=lambda p, k, v: isinstance(v, int))
]
mapping = {k: gen_val(k) for k in initial_values}
return [remap(d, exit=partial(map_values, mapping)) for d in dicts]
示例6: _item_to_csv
# 需要导入模块: from boltons import iterutils [as 别名]
# 或者: from boltons.iterutils import remap [as 别名]
def _item_to_csv(self, item):
from boltons.iterutils import remap
output = io.BytesIO()
writer = self._create_csv_writer(output)
item = remap(item, visit=self._encode_string)
writer.writerow(item)
return output.getvalue().rstrip()