Пример #1
0
        def _build_parameters(self, *args, **kwargs):
            """ building parameters sending to API.
            :param *args:
            :param **kwargs:
            """
            for index, value in enumerate(args):
                if value is None:
                    continue

                try:
                    self.parameters[self.accepts_parameters[index]] = \
                        encode_string(value)
                except IndexError:
                    raise AnyDoAPIBinderError("Index Overflow")

            for key, value in kwargs.items():
                if value is None:
                    continue

                if key in self.parameters:
                    raise AnyDoAPIBinderError(
                        "Already have %s as %s" % (key, self.parameters[key])
                    )

                self.parameters[key] = encode_string(value)
Пример #2
0
    def test_encode_string(self):
        self.assertEqual(utils.encode_string('test'), 'test')
        self.assertEqual(utils.encode_string('1234'), '1234')
        self.assertEqual(utils.encode_string('test1234 Äë'), 'test1234 Äë')

        # "テスト" means "test" in Japansese.
        if sys.version_info < (3, 0):
            word = ('\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88 123eA'
                    '\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88')
        else:
            word = 'テスト 123eAテスト'
        self.assertEqual(utils.encode_string('テスト 123eAテスト'), word)