当前位置: 首页>>代码示例>>Python>>正文


Python NamespaceMap.addAlias方法代码示例

本文整理汇总了Python中openid.message.NamespaceMap.addAlias方法的典型用法代码示例。如果您正苦于以下问题:Python NamespaceMap.addAlias方法的具体用法?Python NamespaceMap.addAlias怎么用?Python NamespaceMap.addAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openid.message.NamespaceMap的用法示例。


在下文中一共展示了NamespaceMap.addAlias方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_onealias

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
 def test_onealias(self):
     nsm = NamespaceMap()
     uri = 'http://example.com/foo'
     alias = "foo"
     nsm.addAlias(uri, alias)
     self.assertEqual(nsm.getNamespaceURI(alias), uri)
     self.assertEqual(nsm.getAlias(uri), alias)
开发者ID:ziima,项目名称:python-openid,代码行数:9,代码来源:test_message.py

示例2: parseExtensionArgs

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
    def parseExtensionArgs(self, ax_args):
        """Given attribute exchange arguments, populate this FetchRequest.

        @param ax_args: Attribute Exchange arguments from the request.
            As returned from L{Message.getArgs<openid.message.Message.getArgs>}.
        @type ax_args: dict

        @raises KeyError: if the message is not consistent in its use
            of namespace aliases.

        @raises NotAXMessage: If ax_args does not include an Attribute Exchange
            mode.

        @raises AXError: If the data to be parsed does not follow the
            attribute exchange specification. At least when
            'if_available' or 'required' is not specified for a
            particular attribute type.
        """
        # Raises an exception if the mode is not the expected value
        self._checkMode(ax_args)

        aliases = NamespaceMap()

        for key, value in ax_args.iteritems():
            if key.startswith('type.'):
                alias = key[5:]
                type_uri = value
                aliases.addAlias(type_uri, alias)

                count_key = 'count.' + alias
                count_s = ax_args.get(count_key)
                if count_s:
                    try:
                        count = int(count_s)
                        if count <= 0:
                            raise AXError("Count %r must be greater than zero, got %r" % (count_key, count_s,))
                    except ValueError:
                        if count_s != UNLIMITED_VALUES:
                            raise AXError("Invalid count value for %r: %r" % (count_key, count_s,))
                        count = count_s
                else:
                    count = 1

                self.add(AttrInfo(type_uri, alias=alias, count=count))

        required = toTypeURIs(aliases, ax_args.get('required'))

        for type_uri in required:
            self.requested_attributes[type_uri].required = True

        if_available = toTypeURIs(aliases, ax_args.get('if_available'))
        self.update_url = ax_args.get('update_url')
开发者ID:arhibot,项目名称:python-openid,代码行数:54,代码来源:ax.py

示例3: test_getExtensionArgs_nonempty

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
 def test_getExtensionArgs_nonempty(self):
     aliases = NamespaceMap()
     aliases.addAlias(self.type_a, self.alias_a)
     msg = ax.StoreRequest(aliases=aliases)
     msg.setValues(self.type_a, ['foo', 'bar'])
     args = msg.getExtensionArgs()
     expected_args = {
         'mode': 'store_request',
         'type.' + self.alias_a: self.type_a,
         'count.' + self.alias_a: '2',
         'value.%s.1' % (self.alias_a,): 'foo',
         'value.%s.2' % (self.alias_a,): 'bar',
     }
     self.assertEqual(args, expected_args)
开发者ID:ziima,项目名称:python-openid,代码行数:16,代码来源:test_ax.py

示例4: ToTypeURIsTest

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
class ToTypeURIsTest(unittest.TestCase):
    def setUp(self):
        self.aliases = NamespaceMap()

    def test_empty(self):
        for empty in [None, '']:
            uris = ax.toTypeURIs(self.aliases, empty)
            self.assertEqual(uris, [])

    def test_undefined(self):
        self.assertRaises(KeyError, ax.toTypeURIs, self.aliases, 'http://janrain.com/')

    def test_one(self):
        uri = 'http://janrain.com/'
        alias = 'openid_hackers'
        self.aliases.addAlias(uri, alias)
        uris = ax.toTypeURIs(self.aliases, alias)
        self.assertEqual(uris, [uri])

    def test_two(self):
        uri1 = 'http://janrain.com/'
        alias1 = 'openid_hackers'
        self.aliases.addAlias(uri1, alias1)

        uri2 = 'http://jyte.com/'
        alias2 = 'openid_hack'
        self.aliases.addAlias(uri2, alias2)

        uris = ax.toTypeURIs(self.aliases, ','.join([alias1, alias2]))
        self.assertEqual(uris, [uri1, uri2])
开发者ID:ziima,项目名称:python-openid,代码行数:32,代码来源:test_ax.py

示例5: getExtensionArgs

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [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
开发者ID:arhibot,项目名称:python-openid,代码行数:51,代码来源:ax.py

示例6: NamespaceMap

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
    'nickname': 'Username',
    'fullname': ' Full name',
    'email': 'Email address',
    'timezone': 'Time zone',
    'language': 'Preferred language',
}

AX_URI_FULL_NAME = 'http://axschema.org/namePerson'
AX_URI_NICKNAME = 'http://axschema.org/namePerson/friendly'
AX_URI_EMAIL = 'http://axschema.org/contact/email'
AX_URI_TIMEZONE = 'http://axschema.org/timezone'
AX_URI_LANGUAGE = 'http://axschema.org/language/pref'
AX_URI_ACCOUNT_VERIFIED = 'http://ns.login.ubuntu.com/2013/validation/account'

AX_DATA_FIELDS = NamespaceMap()
AX_DATA_FIELDS.addAlias(AX_URI_FULL_NAME, 'fullname')
AX_DATA_FIELDS.addAlias(AX_URI_NICKNAME, 'nickname')
AX_DATA_FIELDS.addAlias(AX_URI_EMAIL, 'email')
AX_DATA_FIELDS.addAlias(AX_URI_TIMEZONE, 'timezone')
AX_DATA_FIELDS.addAlias(AX_URI_LANGUAGE, 'language')
AX_DATA_FIELDS.addAlias(AX_URI_ACCOUNT_VERIFIED, 'account_verified')

AX_DATA_LABELS = {
    'fullname': 'Full name',
    'nickname': 'Username',
    'email': 'Email address',
    'timezone': 'Time zone',
    'language': 'Preferred language',
    'account_verified': 'Account verified',
}
开发者ID:miing,项目名称:mci_migo,代码行数:32,代码来源:const.py

示例7: AXKeyValueMessage

# 需要导入模块: from openid.message import NamespaceMap [as 别名]
# 或者: from openid.message.NamespaceMap import addAlias [as 别名]
class AXKeyValueMessage(AXMessage):
    """An abstract class that implements a message that has attribute
    keys and values. It contains the common code between
    fetch_response and store_request.
    """

    # This class is abstract, so it's OK that it doesn't override the
    # abstract method in Extension:
    #
    #pylint:disable-msg=W0223

    def __init__(self):
        AXMessage.__init__(self)
        self.data = {}
        self.aliases = None

    def addValue(self, type_uri, value):
        """Add a single value for the given attribute type to the
        message. If there are already values specified for this type,
        this value will be sent in addition to the values already
        specified.

        @param type_uri: The URI for the attribute

        @param value: The value to add to the response to the relying
            party for this attribute
        @type value: unicode

        @returns: None
        """
        try:
            values = self.data[type_uri]
        except KeyError:
            values = self.data[type_uri] = []

        values.append(value)

    def setValues(self, type_uri, values):
        """Set the values for the given attribute type. This replaces
        any values that have already been set for this attribute.

        @param type_uri: The URI for the attribute

        @param values: A list of values to send for this attribute.
        @type values: [unicode]
        """

        self.data[type_uri] = values

    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
            ax_args['count.' + alias] = str(len(values))

            for i, value in enumerate(values):
                key = 'value.%s.%d' % (alias, i + 1)
                ax_args[key] = value

        return ax_args

    def parseExtensionArgs(self, ax_args):
        """Parse attribute exchange key/value arguments into this
        object.

        @param ax_args: The attribute exchange fetch_response
            arguments, with namespacing removed.
        @type ax_args: {unicode:unicode}

        @returns: None

        @raises ValueError: If the message has bad values for
            particular fields

        @raises KeyError: If the namespace mapping is bad or required
            arguments are missing
        """
        self._checkMode(ax_args)

        if not self.aliases:
            self.aliases = NamespaceMap()

        for key, value in ax_args.iteritems():
            if key.startswith('type.'):
                type_uri = value
                alias = key[5:]
                checkAlias(alias)
                self.aliases.addAlias(type_uri, alias)
#.........这里部分代码省略.........
开发者ID:andrei1089,项目名称:python-openid,代码行数:103,代码来源:ax.py


注:本文中的openid.message.NamespaceMap.addAlias方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。