本文整理汇总了Python中munch.Munch.get方法的典型用法代码示例。如果您正苦于以下问题:Python Munch.get方法的具体用法?Python Munch.get怎么用?Python Munch.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类munch.Munch
的用法示例。
在下文中一共展示了Munch.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_arguments
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [as 别名]
def _get_arguments(argv, environ):
from .__version__ import __version__
from docopt import docopt
from munch import Munch
project_default = "[default: {}]".format(environ["JISSUE_PROJECT"]) if "JISSUE_PROJECT" in environ else ""
version_default = "[default: {}]".format(environ["JISSUE_VERSION"]) if "JISSUE_VERSION" in environ else ""
component_default = "[default: {}]".format(environ["JISSUE_COMPONENT"]) if "JISSUE_COMPONENT" in environ else ""
issue_default = "[default: {}]".format(environ["JISSUE_ISSUE"]) if "JISSUE_ISSUE" in environ else ""
doc_with_defaults = __doc__.format(
project_default=project_default,
version_default=version_default,
component_default=component_default,
issue_default=issue_default,
issue="[<issue>]" if issue_default else "<issue>",
project="[<project>]" if project_default else "<project>",
)
arguments = Munch(docopt(doc_with_defaults, argv=argv, help=True, version=__version__))
if environ.get("JISSUE_PROJECT") and not arguments.get("<project>"):
arguments["<project>"] = environ["JISSUE_PROJECT"]
if environ.get("JISSUE_VERSION") and not arguments.get("--fix-version"):
arguments["--fix-version"] = environ["JISSUE_VERSION"]
if environ.get("JISSUE_COMPONENT") and not arguments.get("<component>"):
arguments["<component>"] = environ["JISSUE_COMPONENT"]
if environ.get("JISSUE_ISSUE") and not arguments.get("<issue>"):
arguments["<issue>"] = environ["JISSUE_ISSUE"]
return arguments
示例2: _get_arguments
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [as 别名]
def _get_arguments(argv, environ):
from .__version__ import __version__
from docopt import docopt
from munch import Munch
project_default = "[default: {}]".format(environ["JISSUE_PROJECT"]) if "JISSUE_PROJECT" in environ else ""
version_default = "[default: {}]".format(environ["JISSUE_VERSION"]) if "JISSUE_VERSION" in environ else ""
doc_with_defaults = __doc__.format(project_default=project_default, version_default=version_default,
project="[--project=PROJECT]" if project_default else "--project=PROJECT",
version="[--release=RELEASE]" if version_default else "--release=RELEASE")
arguments = Munch(docopt(doc_with_defaults, argv=argv, help=True, version=__version__))
if environ.get("JISSUE_PROJECT") and not arguments.get("--project"):
arguments["--project"] = environ["JISSUE_PROJECT"]
if environ.get("JISSUE_VERSION") and not arguments.get("--release"):
arguments["--release"] = environ["JISSUE_VERSION"]
return arguments
示例3: identify
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [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
示例4: write_to_couchdb
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [as 别名]
def write_to_couchdb(tender_data):
# Запис у CouchDB
tender = client.get_tender(tender_data.get('id')).data
tender['_id'] = tender['id']
# Якщо тендер існує - копіюємо його версію
if db.doc_exist(tender['_id']):
tender_from_couch = Munch(db.open_doc(tender['_id']))
tender['_rev'] = tender_from_couch.get('_rev')
db.save_doc(tender)
# Якщо ні - створюємо його у базі
else:
db.save_doc(tender)
示例5: cinder_context
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [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: APINode
# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import get [as 别名]
class APINode(Munch):
"""Represents a node retrieved via the JSON export API
"""
def __init__(self, id, attrs):
self.id = id
self.attrs = Munch(attrs)
if "nodename" in attrs:
del self.attrs["nodename"]
self.name = attrs.get("nodename")
else:
self.name = None
@classmethod
def from_dict(self, d):
return APINode(d["id"], d["attributes"])
def __repr__(self):
return "APINode #{}".format(self.id)
def __getitem__(self, key):
try:
return super(APINode, self).__getitem__(key)
except KeyError:
return self.attrs[key]
def get(self, key, default=None):
return self.attrs.get(key, default)
def toJSON(self, **kwargs):
# returns escaped str by default, we want unicode
kwargs["ensure_ascii"] = False
return super(APINode, self).toJSON(**kwargs)
def toYAML(self, **kwargs):
# returns escaped str by default, we want unicode
if "allow_unicode" not in kwargs:
kwargs["allow_unicode"] = True
if "encoding" not in kwargs:
kwargs["encoding"] = None
return super(APINode, self).toYAML(**kwargs)