[PATCH evemu v2 4/4] py: make Device python 3 compatible
Peter Hutterer
peter.hutterer at who-t.net
Wed Jan 15 13:45:05 PST 2014
On Wed, Jan 15, 2014 at 04:05:01PM -0500, Benjamin Tissoires wrote:
> The previous commit breaks Python 3.0 support due to devnode returning
> a bytes object.
>
> We could also force devnode to return an unicode string by using
> decode, but still, the test "if type(f) == str" will fail in Python 2.X
> because str and unicode are distinct object types.
>
> So, in order to avoid having to introduce bad quirks, just drop the test
> regarding str, and let open() telling us what is wrong in case we don't
> give it a file object.
this should read "a valid path" or something, open() doesn't take the file
object. also, afaict if you swap 3 with 4 you don't break py3 compat in the
patch set, right?
series: Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
>
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> ---
>
> v2:
> - extracted from previous v1 patch
> - removed python 2/3 crap
> - removed the test regarding the string
>
> python/evemu/__init__.py | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> index deaf95e..a914687 100644
> --- a/python/evemu/__init__.py
> +++ b/python/evemu/__init__.py
> @@ -45,12 +45,10 @@ class Device(object):
> to create a pseudo-device node.
> """
>
> - if type(f) == str:
> - self._file = open(f)
> - elif hasattr(f, "read"):
> + if hasattr(f, "read"):
> self._file = f
> else:
> - raise TypeError("expected file or file name")
> + self._file = open(f)
>
> self._is_propfile = self._check_is_propfile(self._file)
> self._libc = evemu.base.LibC()
> --
> 1.8.4.2
>
> _______________________________________________
> Input-tools mailing list
> Input-tools at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/input-tools
More information about the Input-tools
mailing list