本文整理汇总了Python中openid.message.NamespaceMap.add方法的典型用法代码示例。如果您正苦于以下问题:Python NamespaceMap.add方法的具体用法?Python NamespaceMap.add怎么用?Python NamespaceMap.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openid.message.NamespaceMap
的用法示例。
在下文中一共展示了NamespaceMap.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getExtensionKVArgs
# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import add [as 别名]
def _getExtensionKVArgs(self, aliases=None):
"""Get the extension arguments for the key/value pairs
contained in this message.
@param aliases: An alias mapping. Set to None if you don't
care about the aliases for this request.
"""
if aliases is None:
aliases = NamespaceMap()
ax_args = {}
for type_uri, values in self.data.iteritems():
alias = aliases.add(type_uri)
ax_args['type.' + alias] = type_uri
if isinstance(values, list):
ax_args['count.' + alias] = str(len(values))
for i, value in enumerate(values):
key = 'value.%s.%d' % (alias, i + 1)
ax_args[key] = value
else:
ax_args['value.%s' % alias] = values
return ax_args
示例2: test_iteration
# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import add [as 别名]
def test_iteration(self):
nsm = NamespaceMap()
uripat = 'http://example.com/foo%r'
nsm.add(uripat % 0)
for n in range(1, 23):
self.assertIn(uripat % (n - 1), nsm)
self.assertTrue(nsm.isDefined(uripat % (n - 1)))
nsm.add(uripat % n)
for (uri, alias) in nsm.items():
self.assertEqual(uri[22:], alias[3:])
for (uri, alias) in nsm.iteritems():
self.assertEqual(uri[22:], alias[3:])
self.assertEqual(len(tuple(nsm.iterAliases())), 23)
self.assertEqual(len(tuple(nsm.iterNamespaceURIs())), 23)
示例3: getExtensionArgs
# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import add [as 别名]
def getExtensionArgs(self):
"""Get the serialized form of this attribute fetch request.
@returns: The fetch request message parameters
@rtype: {unicode:unicode}
"""
aliases = NamespaceMap()
required = []
if_available = []
ax_args = self._newArgs()
for type_uri, attribute in self.requested_attributes.iteritems():
if attribute.alias is None:
alias = aliases.add(type_uri)
else:
# This will raise an exception when the second
# attribute with the same alias is added. I think it
# would be better to complain at the time that the
# attribute is added to this object so that the code
# that is adding it is identified in the stack trace,
# but it's more work to do so, and it won't be 100%
# accurate anyway, since the attributes are
# mutable. So for now, just live with the fact that
# we'll learn about the error later.
#
# The other possible approach is to hide the error and
# generate a new alias on the fly. I think that would
# probably be bad.
alias = aliases.addAlias(type_uri, attribute.alias)
if attribute.required:
required.append(alias)
else:
if_available.append(alias)
if attribute.count != 1:
ax_args['count.' + alias] = str(attribute.count)
ax_args['type.' + alias] = type_uri
if required:
ax_args['required'] = ','.join(required)
if if_available:
ax_args['if_available'] = ','.join(if_available)
return ax_args