[PATCH evemu 2/7] python: replace event_get_value with the C implementation

Daniel Martin consume.noise at gmail.com
Fri Aug 15 00:37:42 PDT 2014


On Thu, Aug 14, 2014 at 02:00:40PM -0400, Benjamin Tissoires wrote:
> No functional change, but relying on an external lib removes the
> pain to maintain our own input.h implementation.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> ---
>  python/evemu/__init__.py | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> index 02ff3a4..0797d73 100644
> --- a/python/evemu/__init__.py
> +++ b/python/evemu/__init__.py
> @@ -35,6 +35,8 @@ __all__ = ["Device",
>             "input_prop_get_value",
>             "input_prop_get_name"]
>  
> +_libevemu = evemu.base.LibEvemu()
> +
>  def event_get_value(event_type, event_code = None):
>      """
>      Return the integer-value for the given event type and/or code string
> @@ -44,10 +46,29 @@ def event_get_value(event_type, event_code = None):
>      If an event code is passed, the event type may be given as integer or
>      string.
>      """
> -    try:
> -        return evemu.event_names._event_get_value(event_type, event_code)
> -    except KeyError:
> +    t = -1
> +    c = -1
> +
> +    if type(event_type) == str:
> +        t = _libevemu.evemu_event_type_from_name(event_type)
> +    else:
> +        t = event_type

See nitpick below.

> +    if event_code == None:
> +        if type(event_type) != str:
> +            raise TypeError("expected a string")
> +        if t < 0:
> +            return None
> +        return t
> +
> +    if type(event_code) != str:
> +        raise TypeError("expected a string")
> +
> +    c = _libevemu.evemu_event_code_from_name(t, event_code)
> +
> +    if c < 0:
>          return None
> +    return c

Nitpick:

That looks C'ish. It could become:
    return None if c < 0 else c

The same applies for the assignment to 't' above. But, as the condition
+ assignment exceeds the column limits, it would need to be wrapped:
    t = event_type if instanceof(event_type, int) else \
            _libevemu.evemu_event_type_from_name(str(event_type))
Which, on the other hand doesn't look like a benefit.


Greetings,
    Daniel


More information about the Input-tools mailing list