本文整理汇总了Python中munch.Munch.update方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.update方法的具体用法?Python Munch.update怎么用?Python Munch.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类munch.Munch
的用法示例。
在下文中一共展示了Munch.update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: identify
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def identify(self, environ):
'''Extract information to identify a user
Retrieve either a username and password or a session_id that can be
passed on to FAS to authenticate the user.
'''
log.info('in identify()')
# friendlyform compat
if not 'repoze.who.logins' in environ:
environ['repoze.who.logins'] = 0
req = webob.Request(environ, charset='utf-8')
cookie = req.cookies.get(self.session_cookie)
# This is compatible with TG1 and it gives us a way to authenticate
# a user without making two requests
query = req.GET
form = Munch(req.POST)
form.update(query)
if form.get('login', None) == 'Login' and \
'user_name' in form and \
'password' in form:
identity = {
'login': form['user_name'],
'password': form['password']
}
keys = ('login', 'password', 'user_name')
for k in keys:
if k in req.GET:
del(req.GET[k])
if k in req.POST:
del(req.POST[k])
return identity
if cookie is None:
return None
log.info('Request identify for cookie %(cookie)s' %
{'cookie': to_bytes(cookie)})
try:
user_data = self._retrieve_user_info(
environ,
auth_params={'session_id': cookie})
except Exception as e: # pylint:disable-msg=W0703
# For any exceptions, returning None means we failed to identify
log.warning(e)
return None
if not user_data:
return None
# Preauthenticated
identity = {'repoze.who.userid': user_data[1]['username'],
'login': user_data[1]['username'],
'password': user_data[1]['password']}
return identity
示例2: update_configs
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def update_configs(directory, to_update=None):
"""Collect, combine, and return all *.yaml files in `directory`."""
confs = Path(directory).glob('*.yaml')
confs = {p.stem.upper(): p for p in confs}
if to_update is None:
to_update = Munch()
for name, conf in confs.items():
c = process_config(config=conf)
to_update.update(Munch({name: c}))
return to_update
示例3: test
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def test():
data = {
'a': 1,
'b': 2,
}
obj = Munch(**data)
assert isinstance(obj, dict)
for k, v in obj.iteritems():
print k, v
print obj.keys()
print obj.values()
assert obj.a == 1
obj.update(b=-2)
data = dict(**obj)
assert data['b'] == -2
示例4: test_base
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def test_base():
b = Munch()
b.hello = 'world'
assert b.hello == 'world'
b['hello'] += "!"
assert b.hello == 'world!'
b.foo = Munch(lol=True)
assert b.foo.lol is True
assert b.foo is b['foo']
assert sorted(b.keys()) == ['foo', 'hello']
b.update({'ponies': 'are pretty!'}, hello=42)
assert b == Munch({'ponies': 'are pretty!', 'foo': Munch({'lol': True}), 'hello': 42})
assert sorted([(k, b[k]) for k in b]) == [('foo', Munch({'lol': True})), ('hello', 42), ('ponies', 'are pretty!')]
assert "The {knights} who say {ni}!".format(**Munch(knights='lolcats', ni='can haz')) == 'The lolcats who say can haz!'
示例5: cinder_context
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def cinder_context(cls, infinisdk, pool, provisioning="thick", volume_backend_name=None):
volume_driver_config = Munch(**{item.name: item.default for item in volume_opts})
volume_driver_config.update(
san_ip=infinisdk.get_api_addresses()[0][0],
infinidat_pool_id=pool.get_id(),
san_login="admin",
san_password="123456",
infinidat_provision_type=provisioning,
config_group="infinibox-{0}-pool-{1}".format(infinisdk.get_serial(), pool.get_id()),
)
volume_driver_config.append_config_values = lambda values: None
volume_driver_config.safe_get = lambda key: volume_driver_config.get(key, None)
volume_driver = InfiniboxVolumeDriver(configuration=volume_driver_config)
volume_drive_context = Munch()
volume_driver.do_setup(cls.cinder_context)
volume_type = "[InfiniBox] {}/{}".format(infinisdk.get_name(), pool.get_name())
cls.volume_driver_by_type[volume_type] = volume_driver
yield
cls.volume_driver_by_type.pop(volume_type)
示例6: test_base
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def test_base():
b = Munch()
b.hello = "world"
assert b.hello == "world"
b["hello"] += "!"
assert b.hello == "world!"
b.foo = Munch(lol=True)
assert b.foo.lol is True
assert b.foo is b["foo"]
assert sorted(b.keys()) == ["foo", "hello"]
b.update({"ponies": "are pretty!"}, hello=42)
assert b == Munch({"ponies": "are pretty!", "foo": Munch({"lol": True}), "hello": 42})
assert sorted([(k, b[k]) for k in b]) == [("foo", Munch({"lol": True})), ("hello", 42), ("ponies", "are pretty!")]
assert (
"The {knights} who say {ni}!".format(**Munch(knights="lolcats", ni="can haz")) == "The lolcats who say can haz!"
)
示例7: _request_resource
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
def _request_resource(
self,
method: str,
url: str,
**kwargs
) -> Tuple[Union[None, Response], bool]:
"""
Performs a simple GET request to the HTTP server with headers representing the given
channel state.
"""
headers = Munch()
headers.contract_address = self.client.context.channel_manager.address
if self.channel is not None:
headers.balance = str(self.channel.balance)
headers.balance_signature = encode_hex(self.channel.balance_sig)
headers.sender_address = self.channel.sender
headers.receiver_address = self.channel.receiver
headers.open_block = str(self.channel.block)
headers = HTTPHeaders.serialize(headers)
if 'headers' in kwargs:
headers.update(kwargs['headers'])
kwargs['headers'] = headers
else:
kwargs['headers'] = headers
response = requests.Session.request(self, method, url, **kwargs)
if self.on_http_response(method, url, response, **kwargs) is False:
return response, False # user requested abort
if response.status_code == requests.codes.OK:
return response, self.on_success(method, url, response, **kwargs)
elif response.status_code == requests.codes.PAYMENT_REQUIRED:
if HTTPHeaders.NONEXISTING_CHANNEL in response.headers:
return response, self.on_nonexisting_channel(method, url, response, **kwargs)
elif HTTPHeaders.INSUF_CONFS in response.headers:
return response, self.on_insufficient_confirmations(
method,
url,
response,
**kwargs
)
elif HTTPHeaders.INVALID_PROOF in response.headers:
return response, self.on_invalid_balance_proof(method, url, response, **kwargs)
elif HTTPHeaders.CONTRACT_ADDRESS not in response.headers or not is_same_address(
response.headers.get(HTTPHeaders.CONTRACT_ADDRESS),
self.client.context.channel_manager.address
):
return response, self.on_invalid_contract_address(method, url, response, **kwargs)
elif HTTPHeaders.INVALID_AMOUNT in response.headers:
return response, self.on_invalid_amount(method, url, response, **kwargs)
else:
return response, self.on_payment_requested(method, url, response, **kwargs)
else:
return response, self.on_http_error(method, url, response, **kwargs)
示例8: MockRemote
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import update [as 别名]
class MockRemote(object):
# TODO: Refactor me!
# mock remote now do too much things
# idea: send events according to the build progress to handler
def __init__(self, builder_host, job, logger,
repos=None, opts=None):
"""
:param builder_host: builder hostname or ip
:param backend.job.BuildJob job: Job object with the following attributes::
:ivar timeout: ssh timeout
:ivar destdir: target directory to put built packages
:ivar chroot: chroot config name/base to use in the mock build
(e.g.: fedora20_i386 )
:ivar buildroot_pkgs: whitespace separated string with additional
packages that should present during build
:ivar build_id: copr build.id
:ivar pkg: pkg to build
:param repos: additional repositories for mock
:param macros: { "copr_username": ...,
"copr_projectname": ...,
"vendor": ...}
:param Munch opts: builder options, used keys::
:ivar build_user: user to run as/connect as on builder systems
:ivar do_sign: enable package signing, require configured
signer host and correct /etc/sign.conf
:ivar frontend_base_url: url to the copr frontend
:ivar results_baseurl: base url for the built results
:ivar remote_basedir: basedir on builder
:ivar remote_tempdir: tempdir on builder
# Removed:
# :param cont: if a pkg fails to build, continue to the next one--
# :param bool recurse: if more than one pkg and it fails to build,
# try to build the rest and come back to it
"""
self.opts = Munch(
do_sign=False,
frontend_base_url=None,
results_baseurl=u"",
build_user=DEF_BUILD_USER,
remote_basedir=DEF_REMOTE_BASEDIR,
remote_tempdir=None,
timeout=DEF_BUILD_TIMEOUT,
)
if opts:
self.opts.update(opts)
self.log = logger
self.job = job
self.log.info("Setting up builder: {0}".format(builder_host))
# TODO: add option "builder_log_level" to backend config
self.log.setLevel(logging.INFO)
self.builder = Builder(
opts=self.opts,
hostname=builder_host,
job=self.job,
logger=logger,
)
self.failed = []
self.finished = []
def check(self):
"""
Checks that MockRemote configuration and environment are correct.
:raises MockRemoteError: when configuration is wrong or
some expected resource is unavailable
"""
if not self.job.chroot:
raise MockRemoteError("No chroot specified!")
self.builder.check()
@property
def chroot_dir(self):
return os.path.normpath(os.path.join(self.job.destdir, self.job.chroot))
@property
def pkg(self):
return self.job.pkg
def add_pubkey(self):
"""
Adds pubkey.gpg with public key to ``chroot_dir``
using `copr_username` and `copr_projectname` from self.job.
"""
self.log.info("Retrieving pubkey ")
# TODO: sign repodata as well ?
user = self.job.project_owner
project = self.job.project_name
#.........这里部分代码省略.........