1# -*- coding: utf8 -*-
2
3try:
4    import platform
5    IS_PYPY = platform.python_implementation() == 'PyPy'
6except (ImportError, AttributeError):
7    IS_PYPY = False
8
9ustring_a = u'a'
10ustring_ascii = u'abc'
11ustring_nonascii = u'àöé\u0888'
12
13
14def accept_kwargs(a, b, c=1, **kwargs):
15    """
16    >>> accept_kwargs(1, 2, 3)
17    (1, 2, 3, {})
18    >>> accept_kwargs(1, 2, 3, d=5)
19    (1, 2, 3, {'d': 5})
20
21    >>> accept_kwargs(1, 2, 3, **{ustring_a: 5})
22    Traceback (most recent call last):
23    TypeError: accept_kwargs() got multiple values for keyword argument 'a'
24
25    >>> if not IS_PYPY: a, b, c, kwargs = accept_kwargs(1, 2, 3, **{ustring_ascii: 5})
26    >>> IS_PYPY and (1,2,3,1) or (a,b,c,len(kwargs))
27    (1, 2, 3, 1)
28    >>> IS_PYPY and 5 or kwargs[ustring_ascii]
29    5
30
31    >>> if not IS_PYPY: a, b, c, kwargs = accept_kwargs(1, 2, 3, **{ustring_nonascii: 5})
32    >>> IS_PYPY and (1,2,3,1) or (a,b,c,len(kwargs))
33    (1, 2, 3, 1)
34    >>> IS_PYPY and 5 or kwargs[ustring_nonascii]
35    5
36
37    >>> if not IS_PYPY: a, b, c, kwargs = accept_kwargs(1, 2, 3, **{ustring_nonascii: 5, ustring_ascii: 6})
38    >>> IS_PYPY and (1,2,3,2) or (a,b,c,len(kwargs))
39    (1, 2, 3, 2)
40    >>> IS_PYPY and 5 or kwargs[ustring_nonascii]
41    5
42    >>> IS_PYPY and 6 or kwargs[ustring_ascii]
43    6
44    """
45    return a, b, c, kwargs
46
47def unexpected_kwarg(a, b, c=1):
48    """
49    >>> unexpected_kwarg(1, b=2)
50    (1, 2, 1)
51    >>> unexpected_kwarg(1, 2, **{ustring_ascii: 5})
52    Traceback (most recent call last):
53    TypeError: unexpected_kwarg() got an unexpected keyword argument 'abc'
54    >>> unexpected_kwarg(1, 2, 3, d=5)
55    Traceback (most recent call last):
56    TypeError: unexpected_kwarg() got an unexpected keyword argument 'd'
57    """
58    return a, b, c
59