1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
4 # Copyright (C) 2010 Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>
5 # Copyright (C) 2011, 2012 Canonical Ltd.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 from ..module import get_introspection_module
26 from .._gi import (variant_new_tuple, variant_type_from_string, source_new,
27 source_set_callback, io_channel_read)
28 from ..overrides import override, deprecated
29 from gi import PyGIDeprecationWarning, version_info
31 GLib = get_introspection_module('GLib')
35 from gi._glib import option
37 __all__.append('option')
40 # Types and functions still needed from static bindings
41 from gi._glib import _glib
43 OptionContext = _glib.OptionContext
44 OptionGroup = _glib.OptionGroup
47 spawn_async = _glib.spawn_async
48 threads_init = _glib.threads_init
50 __all__ += ['GError', 'OptionContext', 'OptionGroup', 'Pid', 'PollFD',
51 'spawn_async', 'threads_init']
54 class _VariantCreator(object):
56 _LEAF_CONSTRUCTORS = {
57 'b': GLib.Variant.new_boolean,
58 'y': GLib.Variant.new_byte,
59 'n': GLib.Variant.new_int16,
60 'q': GLib.Variant.new_uint16,
61 'i': GLib.Variant.new_int32,
62 'u': GLib.Variant.new_uint32,
63 'x': GLib.Variant.new_int64,
64 't': GLib.Variant.new_uint64,
65 'h': GLib.Variant.new_handle,
66 'd': GLib.Variant.new_double,
67 's': GLib.Variant.new_string,
68 'o': GLib.Variant.new_object_path,
69 'g': GLib.Variant.new_signature,
70 'v': GLib.Variant.new_variant,
73 def _create(self, format, args):
74 '''Create a GVariant object from given format and argument list.
76 This method recursively calls itself for complex structures (arrays,
79 Return a tuple (variant, rest_format, rest_args) with the generated
80 GVariant, the remainder of the format string, and the remainder of the
83 If args is None, then this won't actually consume any arguments, and
84 just parse the format string and generate empty GVariant structures.
85 This is required for creating empty dictionaries or arrays.
87 # leaves (simple types)
88 constructor = self._LEAF_CONSTRUCTORS.get(format[0])
92 raise TypeError('not enough arguments for GVariant format string')
93 v = constructor(args[0])
94 return (v, format[1:], args[1:])
96 return (None, format[1:], None)
99 return self._create_tuple(format, args)
101 if format.startswith('a{'):
102 return self._create_dict(format, args)
105 return self._create_array(format, args)
107 raise NotImplementedError('cannot handle GVariant type ' + format)
109 def _create_tuple(self, format, args):
110 '''Handle the case where the outermost type of format is a tuple.'''
112 format = format[1:] # eat the '('
114 # empty value: we need to call _create() to parse the subtype
117 if rest_format.startswith(')'):
119 rest_format = self._create(rest_format, None)[1]
121 raise TypeError('tuple type string not closed with )')
123 rest_format = rest_format[1:] # eat the )
124 return (None, rest_format, None)
126 if not args or not isinstance(args[0], tuple):
127 raise TypeError('expected tuple argument')
129 builder = GLib.VariantBuilder.new(variant_type_from_string('r'))
130 for i in range(len(args[0])):
131 if format.startswith(')'):
132 raise TypeError('too many arguments for tuple signature')
134 (v, format, _) = self._create(format, args[0][i:])
137 if not format.startswith(')'):
138 raise TypeError('tuple type string not closed with )')
140 rest_format = format[1:] # eat the )
141 return (builder.end(), rest_format, args)
143 def _create_dict(self, format, args):
144 '''Handle the case where the outermost type of format is a dict.'''
147 if args is None or not args[0]:
148 # empty value: we need to call _create() to parse the subtype,
149 # and specify the element type precisely
150 rest_format = self._create(format[2:], None)[1]
151 rest_format = self._create(rest_format, None)[1]
152 if not rest_format.startswith('}'):
153 raise TypeError('dictionary type string not closed with }')
154 rest_format = rest_format[1:] # eat the }
155 element_type = format[:len(format) - len(rest_format)]
156 builder = GLib.VariantBuilder.new(variant_type_from_string(element_type))
158 builder = GLib.VariantBuilder.new(variant_type_from_string('a{?*}'))
159 for k, v in args[0].items():
160 (key_v, rest_format, _) = self._create(format[2:], [k])
161 (val_v, rest_format, _) = self._create(rest_format, [v])
163 if not rest_format.startswith('}'):
164 raise TypeError('dictionary type string not closed with }')
165 rest_format = rest_format[1:] # eat the }
167 entry = GLib.VariantBuilder.new(variant_type_from_string('{?*}'))
168 entry.add_value(key_v)
169 entry.add_value(val_v)
170 builder.add_value(entry.end())
174 return (builder.end(), rest_format, args)
176 def _create_array(self, format, args):
177 '''Handle the case where the outermost type of format is an array.'''
180 if args is None or not args[0]:
181 # empty value: we need to call _create() to parse the subtype,
182 # and specify the element type precisely
183 rest_format = self._create(format[1:], None)[1]
184 element_type = format[:len(format) - len(rest_format)]
185 builder = GLib.VariantBuilder.new(variant_type_from_string(element_type))
187 builder = GLib.VariantBuilder.new(variant_type_from_string('a*'))
188 for i in range(len(args[0])):
189 (v, rest_format, _) = self._create(format[1:], args[0][i:])
193 return (builder.end(), rest_format, args)
196 class Variant(GLib.Variant):
197 def __new__(cls, format_string, value):
198 '''Create a GVariant from a native Python object.
200 format_string is a standard GVariant type signature, value is a Python
201 object whose structure has to match the signature.
205 GLib.Variant('(is)', (1, 'hello'))
206 GLib.Variant('(asa{sv})', ([], {'foo': GLib.Variant('b', True),
207 'bar': GLib.Variant('i', 2)}))
209 creator = _VariantCreator()
210 (v, rest_format, _) = creator._create(format_string, [value])
212 raise TypeError('invalid remaining format string: "%s"' % rest_format)
213 v.format_string = format_string
220 return self.print_(True)
223 return "GLib.Variant('%s', %s)" % (self.format_string, self.print_(True))
225 def __eq__(self, other):
227 return self.equal(other)
231 def __ne__(self, other):
233 return not self.equal(other)
238 # We're not using just hash(self.unpack()) because otherwise we'll have
239 # hash collisions between the same content in different variant types,
240 # which will cause a performance issue in set/dict/etc.
241 return hash((self.get_type_string(), self.unpack()))
244 '''Decompose a GVariant into a native Python object.'''
247 'b': self.get_boolean,
250 'q': self.get_uint16,
252 'u': self.get_uint32,
254 't': self.get_uint64,
255 'h': self.get_handle,
256 'd': self.get_double,
257 's': self.get_string,
258 'o': self.get_string, # object path
259 'g': self.get_string, # signature
263 la = LEAF_ACCESSORS.get(self.get_type_string())
268 if self.get_type_string().startswith('('):
269 res = [self.get_child_value(i).unpack()
270 for i in range(self.n_children())]
274 if self.get_type_string().startswith('a{'):
276 for i in range(self.n_children()):
277 v = self.get_child_value(i)
278 res[v.get_child_value(0).unpack()] = v.get_child_value(1).unpack()
282 if self.get_type_string().startswith('a'):
283 return [self.get_child_value(i).unpack()
284 for i in range(self.n_children())]
286 # variant (just unbox transparently)
287 if self.get_type_string().startswith('v'):
288 return self.get_variant().unpack()
290 raise NotImplementedError('unsupported GVariant type ' + self.get_type_string())
293 def split_signature(klass, signature):
294 '''Return a list of the element signatures of the topmost signature tuple.
296 If the signature is not a tuple, it returns one element with the entire
297 signature. If the signature is an empty tuple, the result is [].
299 This is useful for e. g. iterating over method parameters which are
300 passed as a single Variant.
302 if signature == '()':
305 if not signature.startswith('('):
310 tail = signature[1:-1] # eat the surrounding ()
317 # prefixes, keep collecting
320 # consume until corresponding )/}
336 # otherwise we have a simple type
347 if self.get_type_string() in ['s', 'o', 'g']:
348 return len(self.get_string())
350 if self.get_type_string().startswith('a') or self.get_type_string().startswith('('):
351 return self.n_children()
352 raise TypeError('GVariant type %s does not have a length' % self.get_type_string())
354 def __getitem__(self, key):
356 if self.get_type_string().startswith('a{'):
358 val = self.lookup_value(key, variant_type_from_string('*'))
363 # lookup_value() only works for string keys, which is certainly
364 # the common case; we have to do painful iteration for other
366 for i in range(self.n_children()):
367 v = self.get_child_value(i)
368 if v.get_child_value(0).unpack() == key:
369 return v.get_child_value(1).unpack()
373 if self.get_type_string().startswith('a') or self.get_type_string().startswith('('):
376 key = self.n_children() + key
377 if key < 0 or key >= self.n_children():
378 raise IndexError('list index out of range')
379 return self.get_child_value(key).unpack()
382 if self.get_type_string() in ['s', 'o', 'g']:
383 return self.get_string().__getitem__(key)
385 raise TypeError('GVariant type %s is not a container' % self.get_type_string())
388 # Pythonic bool operations
391 def __nonzero__(self):
392 return self.__bool__()
395 if self.get_type_string() in ['y', 'n', 'q', 'i', 'u', 'x', 't', 'h', 'd']:
396 return self.unpack() != 0
397 if self.get_type_string() in ['b']:
398 return self.get_boolean()
399 if self.get_type_string() in ['s', 'o', 'g']:
400 return len(self.get_string()) != 0
402 if self.get_type_string().startswith('a') or self.get_type_string().startswith('('):
403 return self.n_children() != 0
404 if self.get_type_string() in ['v']:
405 # unpack works recursively, hence bool also works recursively
406 return bool(self.unpack())
407 # Everything else is True
411 if not self.get_type_string().startswith('a{'):
412 return TypeError, 'GVariant type %s is not a dictionary' % self.get_type_string()
415 for i in range(self.n_children()):
416 v = self.get_child_value(i)
417 res.append(v.get_child_value(0).unpack())
422 def new_tuple(cls, *elements):
423 return variant_new_tuple(elements)
426 def get_string(self):
427 value, length = GLib.Variant.get_string(self)
430 setattr(Variant, 'new_tuple', new_tuple)
431 setattr(Variant, 'get_string', get_string)
433 __all__.append('Variant')
436 def markup_escape_text(text, length=-1):
437 if isinstance(text, bytes):
438 return GLib.markup_escape_text(text.decode('UTF-8'), length)
440 return GLib.markup_escape_text(text, length)
441 __all__.append('markup_escape_text')
444 # backwards compatible names from old static bindings
445 for n in ['DESKTOP', 'DOCUMENTS', 'DOWNLOAD', 'MUSIC', 'PICTURES',
446 'PUBLIC_SHARE', 'TEMPLATES', 'VIDEOS']:
447 globals()['USER_DIRECTORY_' + n] = getattr(GLib.UserDirectory, 'DIRECTORY_' + n)
448 __all__.append('USER_DIRECTORY_' + n)
450 for n in ['ERR', 'HUP', 'IN', 'NVAL', 'OUT', 'PRI']:
451 globals()['IO_' + n] = getattr(GLib.IOCondition, n)
452 __all__.append('IO_' + n)
454 for n in ['APPEND', 'GET_MASK', 'IS_READABLE', 'IS_SEEKABLE',
455 'MASK', 'NONBLOCK', 'SET_MASK']:
456 globals()['IO_FLAG_' + n] = getattr(GLib.IOFlags, n)
457 __all__.append('IO_FLAG_' + n)
458 # spelling for the win
459 IO_FLAG_IS_WRITEABLE = GLib.IOFlags.IS_WRITABLE
460 __all__.append('IO_FLAG_IS_WRITEABLE')
462 for n in ['AGAIN', 'EOF', 'ERROR', 'NORMAL']:
463 globals()['IO_STATUS_' + n] = getattr(GLib.IOStatus, n)
464 __all__.append('IO_STATUS_' + n)
466 for n in ['CHILD_INHERITS_STDIN', 'DO_NOT_REAP_CHILD', 'FILE_AND_ARGV_ZERO',
467 'LEAVE_DESCRIPTORS_OPEN', 'SEARCH_PATH', 'STDERR_TO_DEV_NULL',
468 'STDOUT_TO_DEV_NULL']:
469 globals()['SPAWN_' + n] = getattr(GLib.SpawnFlags, n)
470 __all__.append('SPAWN_' + n)
472 for n in ['HIDDEN', 'IN_MAIN', 'REVERSE', 'NO_ARG', 'FILENAME', 'OPTIONAL_ARG',
474 globals()['OPTION_FLAG_' + n] = getattr(GLib.OptionFlags, n)
475 __all__.append('OPTION_FLAG_' + n)
477 for n in ['UNKNOWN_OPTION', 'BAD_VALUE', 'FAILED']:
478 globals()['OPTION_ERROR_' + n] = getattr(GLib.OptionError, n)
479 __all__.append('OPTION_ERROR_' + n)
482 class MainLoop(GLib.MainLoop):
483 # Backwards compatible constructor API
484 def __new__(cls, context=None):
485 return GLib.MainLoop.new(context, False)
487 # Retain classic pygobject behaviour of quitting main loops on SIGINT
488 def __init__(self, context=None):
491 loop._quit_by_sigint = True
493 # compatibility shim, keep around until we depend on glib 2.36
494 if hasattr(GLib, 'unix_signal_add'):
495 fn = GLib.unix_signal_add
497 fn = GLib.unix_signal_add_full
498 self._signal_source = fn(GLib.PRIORITY_DEFAULT, signal.SIGINT, _handler, self)
501 GLib.source_remove(self._signal_source)
504 super(MainLoop, self).run()
505 if hasattr(self, '_quit_by_sigint'):
506 # caught by _main_loop_sigint_handler()
507 raise KeyboardInterrupt
509 MainLoop = override(MainLoop)
510 __all__.append('MainLoop')
513 class MainContext(GLib.MainContext):
514 # Backwards compatible API with default value
515 def iteration(self, may_block=True):
516 return super(MainContext, self).iteration(may_block)
518 MainContext = override(MainContext)
519 __all__.append('MainContext')
522 class Source(GLib.Source):
524 # use our custom pyg_source_new() here as g_source_new() is not
526 source = source_new()
527 source.__class__ = cls
528 setattr(source, '__pygi_custom_source', True)
531 # Backwards compatible API for optional arguments
532 def attach(self, context=None):
533 id = super(Source, self).attach(context)
536 def set_callback(self, fn, user_data=None):
537 if hasattr(self, '__pygi_custom_source'):
538 # use our custom pyg_source_set_callback() if for a GSource object
539 # with custom functions
540 source_set_callback(self, fn, user_data)
542 # otherwise, for Idle and Timeout, use the standard method
543 super(Source, self).set_callback(fn, user_data)
545 def get_current_time(self):
546 return GLib.get_real_time() * 0.000001
548 get_current_time = deprecated(get_current_time,
549 'GLib.Source.get_time() or GLib.get_real_time()')
551 # as get/set_priority are introspected, we can't use the static
552 # property(get_priority, ..) here
553 def __get_priority(self):
554 return self.get_priority()
556 def __set_priority(self, value):
557 self.set_priority(value)
559 priority = property(__get_priority, __set_priority)
561 def __get_can_recurse(self):
562 return self.get_can_recurse()
564 def __set_can_recurse(self, value):
565 self.set_can_recurse(value)
567 can_recurse = property(__get_can_recurse, __set_can_recurse)
569 Source = override(Source)
570 __all__.append('Source')
574 def __new__(cls, priority=GLib.PRIORITY_DEFAULT):
575 source = GLib.idle_source_new()
576 source.__class__ = cls
579 def __init__(self, priority=GLib.PRIORITY_DEFAULT):
580 super(Source, self).__init__()
581 if priority != GLib.PRIORITY_DEFAULT:
582 self.set_priority(priority)
584 __all__.append('Idle')
587 class Timeout(Source):
588 def __new__(cls, interval=0, priority=GLib.PRIORITY_DEFAULT):
589 source = GLib.timeout_source_new(interval)
590 source.__class__ = cls
593 def __init__(self, interval=0, priority=GLib.PRIORITY_DEFAULT):
594 if priority != GLib.PRIORITY_DEFAULT:
595 self.set_priority(priority)
597 __all__.append('Timeout')
600 def user_data_varargs_shim(callback, user_data, cb_num_args=0):
601 '''Adjust callback and user_data varargs for PyGTK backwards compatibility
603 GLib only accepts exactly one user_data argument, but older pygtk
604 traditionally accepted zero or more for some specific functions. For "one
605 argument", use the actual user-supplied callback for efficiency; for all
606 others, rewire it to accept zero or more than one.
608 Return the adjusted callback and the real user data to pass to GLib.
610 if len(user_data) == 1:
611 return (callback, user_data[0])
614 return (lambda data: callback(*data), user_data)
616 return (lambda a1, a2, data: callback(a1, a2, *data), user_data)
617 raise NotImplementedError('%i number of callback arguments not supported' % cb_num_args)
620 # backwards compatible API
621 def idle_add(function, *user_data, **kwargs):
622 (fn, data) = user_data_varargs_shim(function, user_data)
623 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT_IDLE)
624 return GLib.idle_add(priority, fn, data)
626 __all__.append('idle_add')
629 def timeout_add(interval, function, *user_data, **kwargs):
630 (fn, data) = user_data_varargs_shim(function, user_data)
631 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT)
632 return GLib.timeout_add(priority, interval, fn, data)
634 __all__.append('timeout_add')
637 def timeout_add_seconds(interval, function, *user_data, **kwargs):
638 (fn, data) = user_data_varargs_shim(function, user_data)
639 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT)
640 return GLib.timeout_add_seconds(priority, interval, fn, data)
642 __all__.append('timeout_add_seconds')
645 # The real GLib API is io_add_watch(IOChannel, priority, condition, callback,
646 # user_data). This needs to take into account several historical APIs:
647 # - calling with an fd as first argument
648 # - calling with a Python file object as first argument (we keep this one as
649 # it's really convenient and does not change the number of arguments)
650 # - calling without a priority as second argument
651 # and the usual "call without or multiple user_data", in which case the
652 # callback gets the same user data arguments.
653 def io_add_watch(channel, priority_, condition, *cb_and_user_data, **kwargs):
654 if not isinstance(priority_, int) or isinstance(priority_, GLib.IOCondition):
655 warnings.warn('Calling io_add_watch without priority as second argument is deprecated',
656 PyGIDeprecationWarning)
657 # shift the arguments around
658 user_data = cb_and_user_data
660 condition = priority_
661 if not callable(callback):
662 raise TypeError('third argument must be callable')
664 # backwards compatibility: Call with priority kwarg
665 if 'priority' in kwargs:
666 warnings.warn('Calling io_add_watch with priority keyword argument is deprecated, put it as second positional argument',
667 PyGIDeprecationWarning)
668 priority_ = kwargs['priority']
670 priority_ = GLib.PRIORITY_DEFAULT
672 if len(cb_and_user_data) < 1 or not callable(cb_and_user_data[0]):
673 raise TypeError('expecting callback as fourth argument')
674 callback = cb_and_user_data[0]
675 user_data = cb_and_user_data[1:]
677 (func, user_data) = user_data_varargs_shim(callback, user_data, 2)
679 # backwards compatibility: Allow calling with fd
680 if isinstance(channel, int):
681 func_fdtransform = lambda _, cond, data: func(channel, cond, data)
682 real_channel = GLib.IOChannel.unix_new(channel)
683 elif hasattr(channel, 'fileno'):
684 # backwards compatibility: Allow calling with Python file
685 func_fdtransform = lambda _, cond, data: func(channel, cond, data)
686 real_channel = GLib.IOChannel.unix_new(channel.fileno())
688 assert isinstance(channel, GLib.IOChannel)
689 func_fdtransform = func
690 real_channel = channel
692 return GLib.io_add_watch(real_channel, priority_, condition,
693 func_fdtransform, user_data)
695 __all__.append('io_add_watch')
698 # backwards compatible API
699 class IOChannel(GLib.IOChannel):
700 def __new__(cls, filedes=None, filename=None, mode=None, hwnd=None):
701 if filedes is not None:
702 return GLib.IOChannel.unix_new(filedes)
703 if filename is not None:
704 return GLib.IOChannel.new_file(filename, mode or 'r')
706 return GLib.IOChannel.win32_new_fd(hwnd)
707 raise TypeError('either a valid file descriptor, file name, or window handle must be supplied')
709 def read(self, max_count=-1):
710 return io_channel_read(self, max_count)
712 def readline(self, size_hint=-1):
713 # note, size_hint is just to maintain backwards compatible API; the
714 # old static binding did not actually use it
715 (status, buf, length, terminator_pos) = self.read_line()
720 def readlines(self, size_hint=-1):
721 # note, size_hint is just to maintain backwards compatible API;
722 # the old static binding did not actually use it
724 status = GLib.IOStatus.NORMAL
725 while status == GLib.IOStatus.NORMAL:
726 (status, buf, length, terminator_pos) = self.read_line()
727 # note, this appends an empty line after EOF; this is
728 # bug-compatible with the old static bindings
734 def write(self, buf, buflen=-1):
735 if not isinstance(buf, bytes):
736 buf = buf.encode('UTF-8')
739 (status, written) = self.write_chars(buf, buflen)
742 def writelines(self, lines):
746 _whence_map = {0: GLib.SeekType.SET, 1: GLib.SeekType.CUR, 2: GLib.SeekType.END}
748 def seek(self, offset, whence=0):
750 w = self._whence_map[whence]
752 raise ValueError("invalid 'whence' value")
753 return self.seek_position(offset, w)
755 def add_watch(self, condition, callback, *user_data, **kwargs):
756 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT)
757 return io_add_watch(self, priority, condition, callback, *user_data)
759 add_watch = deprecated(add_watch, 'GLib.io_add_watch()')
765 (status, buf, length, terminator_pos) = self.read_line()
766 if status == GLib.IOStatus.NORMAL:
770 # Python 2.x compatibility
773 IOChannel = override(IOChannel)
774 __all__.append('IOChannel')
777 # The real GLib API is child_watch_add(priority, pid, callback, data).
778 # The old static bindings had the following API which we still need to support
780 # child_watch_add(pid, callback, data=None, priority=GLib.PRIORITY_DEFAULT)
781 # and the usual "call without user_data", in which case the callback does not
782 # get an user_data either.
783 def child_watch_add(priority_or_pid, pid_or_callback, *args, **kwargs):
784 _unspecified = object()
786 if callable(pid_or_callback):
787 warnings.warn('Calling child_watch_add without priority as first argument is deprecated',
788 PyGIDeprecationWarning)
789 pid = priority_or_pid
790 callback = pid_or_callback
792 user_data = kwargs.get('data', _unspecified)
793 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT)
796 priority = kwargs.get('priority', GLib.PRIORITY_DEFAULT)
801 raise TypeError('expected at most 4 positional arguments')
803 priority = priority_or_pid
804 pid = pid_or_callback
805 if len(args) == 0 or not callable(args[0]):
806 raise TypeError('expected callback as third argument')
809 user_data = kwargs.get('data', _unspecified)
813 if user_data is _unspecified:
814 # we have to call the callback without the user_data argument
815 func = lambda pid, status, data: callback(pid, status)
820 return GLib.child_watch_add(priority, pid, func, user_data)
822 __all__.append('child_watch_add')
825 def get_current_time():
826 return GLib.get_real_time() * 0.000001
828 get_current_time = deprecated(get_current_time, 'GLib.get_real_time()')
830 __all__.append('get_current_time')
833 # backwards compatible API with default argument, and ignoring bytes_read
835 def filename_from_utf8(utf8string, len=-1):
836 return GLib.filename_from_utf8(utf8string, len)[0]
838 __all__.append('filename_from_utf8')
841 # backwards compatible API for renamed function
842 if not hasattr(GLib, 'unix_signal_add_full'):
843 def add_full_compat(*args):
844 warnings.warn('GLib.unix_signal_add_full() was renamed to GLib.unix_signal_add()',
845 PyGIDeprecationWarning)
846 return GLib.unix_signal_add(*args)
848 GLib.unix_signal_add_full = add_full_compat
851 # obsolete constants for backwards compatibility
852 glib_version = (GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION)
853 __all__.append('glib_version')
854 pyglib_version = version_info
855 __all__.append('pyglib_version')