Commit 9c6399bb authored by Simon Feltman's avatar Simon Feltman
Browse files

Fix IOChannel unittests for python 2.7

Use __future__ unicode_literals to minimize difference
between python 2.7 and 3. Comparisons need to encode arguments as
'UTF-8' for testing readline operations.
Add backwards compatible "next" to support the python 2.7 iteration.
Change isinstance(channel, file) to hasattr(channel, 'fileno') to
support all python versions (and duck typing).
parent 0f94a0a4
......@@ -628,7 +628,7 @@ def io_add_watch(channel, priority, condition, callback=_unspecified, user_data=
func_fdtransform = lambda _, cond, data: func(channel, cond, data)
real_channel = GLib.IOChannel.unix_new(channel)
elif isinstance(channel, file):
elif hasattr(channel, 'fileno'):
# backwards compatibility: Allow calling with Python file
warnings.warn('Calling io_add_watch with a file object is deprecated; call it with a GLib.IOChannel object',
......@@ -717,6 +717,8 @@ class IOChannel(GLib.IOChannel):
return buf
raise StopIteration
# Python 2.x compatibility
next = __next__
IOChannel = override(IOChannel)
# -*- Mode: Python -*-
# encoding: UTF-8
from __future__ import unicode_literals
import unittest
import tempfile
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment