本文整理汇总了Python中addict.Dict方法的典型用法代码示例。如果您正苦于以下问题:Python addict.Dict方法的具体用法?Python addict.Dict怎么用?Python addict.Dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addict
的用法示例。
在下文中一共展示了addict.Dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resourceOffers
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def resourceOffers(self, driver, offers):
filters = {'refuse_seconds': 5}
for offer in offers:
cpus = self.getResource(offer.resources, 'cpus')
mem = self.getResource(offer.resources, 'mem')
if cpus < TASK_CPU or mem < TASK_MEM:
continue
task = Dict()
task_id = str(uuid.uuid4())
task.task_id.value = task_id
task.agent_id.value = offer.agent_id.value
task.name = 'task {}'.format(task_id)
task.executor = self.executor
task.data = encode_data('Hello from task {}!'.format(task_id))
task.resources = [
dict(name='cpus', type='SCALAR', scalar={'value': TASK_CPU}),
dict(name='mem', type='SCALAR', scalar={'value': TASK_MEM}),
]
driver.launchTasks(offer.id, [task], filters)
示例2: launchTask
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def launchTask(self, driver, task):
def run_task(task):
update = Dict()
update.task_id.value = task.task_id.value
update.state = 'TASK_RUNNING'
update.timestamp = time.time()
driver.sendStatusUpdate(update)
print(decode_data(task.data), file=sys.stderr)
time.sleep(30)
update = Dict()
update.task_id.value = task.task_id.value
update.state = 'TASK_FINISHED'
update.timestamp = time.time()
driver.sendStatusUpdate(update)
thread = Thread(target=run_task, args=(task,))
thread.start()
示例3: __init__
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def __init__(self, sched, framework, master_uri,
use_addict=False, implicit_acknowledgements=True,
principal=None, secret=None, failover=False,
timeout=DAY):
super(MesosSchedulerDriver, self).__init__(timeout=timeout)
self.sched = sched
self.master_uri = master_uri
self._framework = framework
self.detector = None
self._conn = None
self.version = None
self._failover = failover
self._dict_cls = Dict if use_addict else dict
self.implicit_acknowledgements = implicit_acknowledgements
if principal is not None and secret is not None:
self._basic_credential = 'Basic %s' % (
b2a_base64(
('%s:%s' % (principal, secret)).encode('ascii')
).decode('ascii').strip()
)
else:
self._basic_credential = None
示例4: make_fake_offer
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def make_fake_offer(
cpu=50000, mem=50000, port_begin=31000, port_end=32000, pool="default"
):
offer = Dict(
agent_id=Dict(value="super_big_slave"),
resources=[
Dict(name="cpus", scalar=Dict(value=cpu)),
Dict(name="mem", scalar=Dict(value=mem)),
Dict(
name="ports", ranges=Dict(range=[Dict(begin=port_begin, end=port_end)])
),
],
attributes=[],
)
if pool is not None:
offer.attributes = [Dict(name="pool", text=Dict(value=pool))]
return offer
示例5: test_user_long
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def test_user_long(db_session):
test_user = (
db_session.query(models.User)
.filter_by(username="test_amazing_user_with_an_fancy_but_extremely_long_name")
.first()
)
if not test_user:
test_user = models.User(
username="test_amazing_user_with_an_fancy_but_extremely_long_name",
is_admin=False,
)
db_session.add(test_user)
db_session.commit()
return Dict(
username="test_amazing_user_with_an_fancy_but_extremely_long_name",
user_id=test_user.id,
)
示例6: oauth_client_public
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def oauth_client_public(app, db_session, oauth_user):
"""
Create a public OAuth2 client.
"""
url = "https://oauth-test-client-public.net"
client_id = "test-client-public"
test_user = db_session.query(models.User).filter_by(id=oauth_user.user_id).first()
db_session.add(
models.Client(
client_id=client_id,
user=test_user,
allowed_scopes=["openid", "user", "fence"],
redirect_uris=[url],
description="",
is_confidential=False,
name="testclient-public",
grant_types=["authorization_code", "refresh_token"],
)
)
db_session.commit()
return Dict(client_id=client_id, url=url)
示例7: encoded_jwt_no_proxy_group
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def encoded_jwt_no_proxy_group(kid, rsa_private_key, user_client, oauth_client):
"""
Return a JWT and user_id for a new user containing the claims and
encoded with the private key.
Args:
claims (dict): fixture
rsa_private_key (str): fixture
Return:
str: JWT containing claims encoded with private key
"""
headers = {"kid": kid}
return Dict(
jwt=jwt.encode(
utils.authorized_download_credentials_context_claims(
user_client["username"],
user_client["user_id"],
oauth_client["client_id"],
),
key=rsa_private_key,
headers=headers,
algorithm="RS256",
).decode("utf-8"),
user_id=user_client["user_id"],
client_id=oauth_client["client_id"],
)
示例8: new_tissue_rna
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def new_tissue_rna(*args, **kwargs):
rna = Dict(*args, **kwargs)
if 'level' not in rna:
rna.level = -1
if 'value' not in rna:
rna.value = 0
if 'unit' not in rna:
rna.unit = ''
if 'zscore' not in rna:
rna.zscore = -1
return rna
示例9: extractConfig
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def extractConfig(config_path):
return Dict(yaml.load(open(config_path)))
示例10: decodeSegmentationResults
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def decodeSegmentationResults(result_list):
decoded_results = []
for result in result_list:
result_copy = Dict(result)
encodedCounts = result_copy.segmentation.counts
result_copy.segmentation.counts = encodedCounts.decode('utf8')
decoded_results.append(result_copy)
return decoded_results
示例11: convertClassesForPanoptic
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def convertClassesForPanoptic(result_list):
converted_results = []
for result in result_list:
result_copy = Dict(result)
categoryClass = result_copy.category_id
panopticIndex = convertStuffIdToPanopticId(categoryClass)
if panopticIndex is not None:
result_copy.category_id = panopticIndex
converted_results.append(result_copy)
else:
print ('No index, skipping')
return converted_results
示例12: _extract_item
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def _extract_item(self, item):
return dictlib.Dict(item)
示例13: parse
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def parse(self, config_path):
config_dict = file_utils.load_yaml(config_path)
validator = cerberus.Validator(self._schema)
is_valid = validator.validate(config_dict)
if not is_valid:
raise exceptions.ConfigParseError(errors=validator.errors)
return dict_lib.Dict(validator.document)
示例14: __init__
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def __init__(self, id, properties, **kwargs):
super().__init__()
self.id = id
self.properties = dictlib.Dict(properties)
self.created_at = kwargs.get('created_at')
self.updated_at = kwargs.get('updated_at')
self.deleted_at = kwargs.get('deleted_at')
示例15: main
# 需要导入模块: import addict [as 别名]
# 或者: from addict import Dict [as 别名]
def main(master):
executor = Dict()
executor.executor_id.value = 'MinimalExecutor'
executor.name = executor.executor_id.value
executor.command.value = '%s %s' % (
sys.executable,
abspath(join(dirname(__file__), 'executor.py'))
)
executor.resources = [
dict(name='mem', type='SCALAR', scalar={'value': EXECUTOR_MEM}),
dict(name='cpus', type='SCALAR', scalar={'value': EXECUTOR_CPUS}),
]
framework = Dict()
framework.user = getpass.getuser()
framework.name = "MinimalFramework"
framework.hostname = socket.gethostname()
driver = MesosSchedulerDriver(
MinimalScheduler(executor),
framework,
master,
use_addict=True,
)
def signal_handler(signal, frame):
driver.stop()
def run_driver_thread():
driver.run()
driver_thread = Thread(target=run_driver_thread, args=())
driver_thread.start()
print('Scheduler running, Ctrl+C to quit.')
signal.signal(signal.SIGINT, signal_handler)
while driver_thread.is_alive():
time.sleep(1)