if isinstance(other, six.integer_types): return ByteSize.Size.div_int(self, other) else: return Decimal(ByteSize.Size.true_div(self, other)) def __truediv__(self, other): if isinstance(other, six.integer_types): return Decimal(ByteSize.Size.true_div_int(self, other)) return Decimal(ByteSize.Size.true_div(self, other)) def __floordiv__(self, other): if isinstance(other, six.integer_types): return ByteSize.Size.div_int(self, other) return ByteSize.Size.div(self, other) def __mod__(self, other): return ByteSize.Size.mod(self, other) def __repr__(self): return "Size (%s)" % self.human_readable(ByteSize.Bunit.B, -1, False) def __str__(self): return self.human_readable() Size = override(Size) __all__.append("Size")
Vips.Argument = Argument class Operation(Vips.Operation): # find all the args for this op, sort into priority order # remember to ignore deprecated ones def get_args(self): args = [Argument(self, x) for x in self.props] args = [y for y in args if not y.flags & Vips.ArgumentFlags.DEPRECATED] args.sort(key = lambda x: x.priority) return args Operation = override(Operation) __all__.append('Operation') # search a list recursively for a Vips.Image object def find_image(x): if isinstance(x, Vips.Image): return x if isinstance(x, list): for i in x: y = find_image(i) if y is not None: return y return None def _call_base(name, required, optional, self = None, option_string = None): logging.debug('_call_base name=%s, required=%s optional=%s' %
return self.get_object() elif gtype == TYPE_UNICHAR: return self.get_uint() elif gtype == TYPE_GTYPE: return self.get_gtype() elif gtype == TYPE_VARIANT: return self.get_variant() elif gtype == TYPE_PYOBJECT: pass else: return None def __repr__(self): return '<Value (%s) %s>' % (self.g_type.name, self.get_value()) Value = override(Value) __all__.append('Value') def type_from_name(name): type_ = GObjectModule.type_from_name(name) if type_ == TYPE_INVALID: raise RuntimeError('unknown type name: %s' % name) return type_ __all__.append('type_from_name') def type_parent(type_): parent = GObjectModule.type_parent(type_) if parent == TYPE_INVALID:
The gi import machinery sweeps usr/lib/python*/dist-packages/gi/overrides for file matching the module name at the time of execution. This file needs to be in both python2 and python3 overrides locations. """ XApp = modules['XApp']._introspection_module __all__ = [] class GtkWindow(XApp.GtkWindow): pass class GtkButton(XApp.IconChooserButton): pass class GtkBin(XApp.StackSidebar): pass GtkWindow = override(GtkWindow) GtkButton = override(GtkButton) GtkBin = override(GtkBin) __all__.append('GtkWindow') __all__.append('GtkButton') __all__.append('GtkBin')
class ScopeResult(Unity.ScopeResult): @staticmethod def create(*args, **kwargs): if len(kwargs) > 0: result = kwargs_to_result_variant(**kwargs) return Unity.ScopeResult.create_from_variant(result) return Unity.ScopeResult.create(*args) class SearchContext(Unity.SearchContext): @staticmethod def create(search_query, search_type, filter_state, metadata_dict, result_set, cancellable): context = Unity.SearchContext.create(search_query, search_type, filter_state, None, result_set, cancellable) if metadata_dict and len(metadata_dict) > 0: metadata_variant = dict_to_variant(metadata_dict) context.set_search_metadata(Unity.SearchMetadata.create_from_variant(metadata_variant)) return context ScopeSearchBase = override(ScopeSearchBase) __all__.append("ScopeSearchBase") ResultPreviewer = override(ResultPreviewer) __all__.append("ResultPreviewer") ResultSet = override(ResultSet) __all__.append("ResultSet") ScopeResult = override(ScopeResult) __all__.append("ScopeResult") SearchContext = override(SearchContext) __all__.append("SearchContext")
"part": BlockDev.Plugin.PART, "fs": BlockDev.Plugin.FS, "s390": BlockDev.Plugin.S390, "nvdimm": BlockDev.Plugin.NVDIMM, "vdo": BlockDev.Plugin.VDO, } class ExtraArg(BlockDev.ExtraArg): def __new__(cls, opt, val=""): ret = BlockDev.ExtraArg.new(opt, val) ret.__class__ = cls return ret ExtraArg = override(ExtraArg) __all__.append("ExtraArg") def _get_extra(extra, kwargs, cmd_extra=True): # pylint: disable=no-member # pylint doesn't really get how ExtraArg with overrides work if extra: if isinstance(extra, dict): ea = [ExtraArg.new(key, val) for key, val in extra.items()] elif isinstance(extra, list) and all( isinstance(arg, BlockDev.ExtraArg) for arg in extra): ea = extra else: msg = "extra arguments can only be given as a list of ExtraArg items or a as a dict" raise ValueError(msg)
def device(self): return self._device @device.setter def device(self, device): self._device = device @property def root(self): return self._root @root.setter def root(self, dev): self._root = dev MountpointSelector = override(MountpointSelector) __all__.append('MountpointSelector') class SpokeSelector(Anaconda.SpokeSelector): def __init__(self, title=None, icon=None, status=None): Anaconda.SpokeSelector.__init__(self) if title: self.set_property("title", title) if icon: self.set_property("icon", icon) if status: self.set_property("status", status)
def __iter__ (self): itr = self.get_first_iter () last = self.get_last_iter () while itr != last: yield self.get_row(itr) itr = self.next(itr) raise StopIteration def __len__ (self): return self.get_n_rows() class ModelIter(Dee.ModelIter): def __init__(self): Dee.ModelIter.__init__(self) def __eq__ (self, other): if not isinstance (other, ModelIter): return False return repr(self) == repr(other) Model = override(Model) __all__.append('Model') ModelIter = override(ModelIter) __all__.append('ModelIter')
itr = self.get_iter_at_row(itr) return RowWrapper(self, itr) def __setitem__ (self, itr, row): max_col = self.get_n_columns () for column, value in enumerate (row): if column >= max_col: raise IndexError, "Too many columns in row assignment: %s" % column self.set_value (itr, column, value) def get_row (self, itr): return self[itr] def __iter__ (self): itr = self.get_first_iter () last = self.get_last_iter () while itr != last: yield self.get_row(itr) itr = self.next(itr) raise StopIteration def __len__ (self): return self.get_n_rows() Model = override(Model) __all__.append('Model')
from gi.overrides import override from gi.importer import modules """ The only purpose of this file is to ensure the XApp widget GType is registered at the time of import. Otherwise any user of XApp.GtkWindow would have to create a dummy widget prior to using a GtkBuilder to parse a ui file containing an XAppGtkWindow. The gi import machinery sweeps usr/lib/python*/dist-packages/gi/overrides for file matching the module name at the time of execution. This file needs to be in both python2 and python3 overrides locations. """ XApp = modules['XApp']._introspection_module __all__ = [] class GtkWindow(XApp.GtkWindow): pass GtkWindow = override(GtkWindow) __all__.append('GtkWindow')
self.set_property("size", size) if mountpoint: self.set_property("mountpoint", mountpoint) @property def size(self): # using get_property causes problems with pylint for some reason # pylint: disable-msg=E1101 return self.get_property("size") @size.setter def size(self, size): self.set_property("size", size) MountpointSelector = override(MountpointSelector) __all__.append('MountpointSelector') class SpokeSelector(Anaconda.SpokeSelector): def __init__(self, title=None, icon=None, status=None): Anaconda.SpokeSelector.__init__(self) if title: self.set_property("title", title) if icon: self.set_property("icon", icon) if status: self.set_property("status", status)
raise AttributeError if isinstance(other, six.integer_types): return ByteSize.Size.div_int(self, other) else: return Decimal(ByteSize.Size.true_div(self, other)) def __truediv__(self, other): if isinstance(other, six.integer_types): return Decimal(ByteSize.Size.true_div_int(self, other)) return Decimal(ByteSize.Size.true_div(self, other)) def __floordiv__(self, other): if isinstance(other, six.integer_types): return ByteSize.Size.div_int(self, other) return ByteSize.Size.div(self, other) def __mod__(self, other): return ByteSize.Size.mod(self, other) def __repr__(self): return "Size (%s)" % self.human_readable(ByteSize.Bunit.B, -1, False) def __str__(self): return self.human_readable() Size = override(Size) __all__.append("Size")
import sys from gi.repository import GObject from gi.overrides import override from gi.module import get_introspection_module Gwy = get_introspection_module('Gwy') __all__ = [] def match_signature(args, types): if len(args) != len(types): return False for pair in zip(args, types): if not issubclass(pair[0], pair[1]): return False return True class Unit(Gwy.Unit): def __nonzero__(self): return not self.is_empty() Unit = override(Unit) __all__.append('Unit')
@staticmethod def create(*args, **kwargs): if len(kwargs) > 0: result = kwargs_to_result_variant(**kwargs) return Unity.ScopeResult.create_from_variant(result) return Unity.ScopeResult.create(*args) class SearchContext(Unity.SearchContext): @staticmethod def create(search_query, search_type, filter_state, metadata_dict, result_set, cancellable): context = Unity.SearchContext.create(search_query, search_type, filter_state, None, result_set, cancellable) if metadata_dict and len(metadata_dict) > 0: metadata_variant = dict_to_variant(metadata_dict) context.set_search_metadata(Unity.SearchMetadata.create_from_variant(metadata_variant)) return context ScopeSearchBase = override(ScopeSearchBase) __all__.append('ScopeSearchBase') ResultPreviewer = override(ResultPreviewer) __all__.append('ResultPreviewer') ResultSet = override(ResultSet) __all__.append('ResultSet') ScopeResult = override(ScopeResult) __all__.append('ScopeResult') SearchContext = override(SearchContext) __all__.append('SearchContext')
"mpath": BlockDev.Plugin.MPATH, "kbd": BlockDev.Plugin.KBD, "part": BlockDev.Plugin.PART, "fs": BlockDev.Plugin.FS, "s390": BlockDev.Plugin.S390, "nvdimm": BlockDev.Plugin.NVDIMM, "vdo": BlockDev.Plugin.VDO, } class ExtraArg(BlockDev.ExtraArg): def __new__(cls, opt, val=""): ret = BlockDev.ExtraArg.new(opt, val) ret.__class__ = cls return ret ExtraArg = override(ExtraArg) __all__.append("ExtraArg") def _get_extra(extra, kwargs, cmd_extra=True): # pylint: disable=no-member # pylint doesn't really get how ExtraArg with overrides work if extra: if isinstance(extra, dict): ea = [ExtraArg.new(key, val) for key, val in extra.items()] elif isinstance(extra, list) and all(isinstance(arg, BlockDev.ExtraArg) for arg in extra): ea = extra else: msg = "extra arguments can only be given as a list of ExtraArg items or a as a dict" raise ValueError(msg) else: ea = []
"mpath": BlockDev.Plugin.MPATH, "kbd": BlockDev.Plugin.KBD, "part": BlockDev.Plugin.PART, "fs": BlockDev.Plugin.FS, "s390": BlockDev.Plugin.S390, } class ExtraArg(BlockDev.ExtraArg): def __new__(cls, opt, val=""): ret = BlockDev.ExtraArg.new(opt, val) ret.__class__ = cls return ret ExtraArg = override(ExtraArg) __all__.append("ExtraArg") def _get_extra(extra, kwargs): # pylint: disable=no-member # pylint doesn't really get how ExtraArg with overrides work if extra: if isinstance(extra, dict): ea = [ExtraArg.new(key, val) for key, val in extra.items()] elif isinstance(extra, list) and all( isinstance(arg, BlockDev.ExtraArg) for arg in extra): ea = extra else: msg = "extra arguments can only be given as a list of ExtraArg items or a as a dict" raise ValueError(msg)
def get_row(self, itr): return self[itr] def __iter__(self): itr = self.get_first_iter() last = self.get_last_iter() while itr != last: yield self.get_row(itr) itr = self.next(itr) raise StopIteration def __len__(self): return self.get_n_rows() class ModelIter(Dee.ModelIter): def __init__(self): Dee.ModelIter.__init__(self) def __eq__(self, other): if not isinstance(other, ModelIter): return False return repr(self) == repr(other) Model = override(Model) __all__.append('Model') ModelIter = override(ModelIter) __all__.append('ModelIter')
"swap": BlockDev.Plugin.SWAP, "mdraid": BlockDev.Plugin.MDRAID, "mpath": BlockDev.Plugin.MPATH, "kbd": BlockDev.Plugin.KBD, "part": BlockDev.Plugin.PART, "fs": BlockDev.Plugin.FS, "s390": BlockDev.Plugin.S390, } class ExtraArg(BlockDev.ExtraArg): def __new__(cls, opt, val=""): ret = BlockDev.ExtraArg.new(opt, val) ret.__class__ = cls return ret ExtraArg = override(ExtraArg) __all__.append("ExtraArg") def _get_extra(extra, kwargs): # pylint: disable=no-member # pylint doesn't really get how ExtraArg with overrides work if extra: if isinstance(extra, dict): ea = [ExtraArg.new(key, val) for key, val in extra.items()] elif isinstance(extra, list) and all(isinstance(arg, BlockDev.ExtraArg) for arg in extra): ea = extra else: msg = "extra arguments can only be given as a list of ExtraArg items or a as a dict" raise ValueError(msg) else: ea = []
elif gtype == TYPE_VARIANT: # get_variant was missing annotations # https://gitlab.gnome.org/GNOME/glib/merge_requests/492 return self.dup_variant() elif gtype == TYPE_PYOBJECT: return self.get_boxed() elif gtype == _gi.TYPE_INVALID: return None else: return _gi._gvalue_get(self) def __repr__(self): return '<Value (%s) %s>' % (self.g_type.name, self.get_value()) Value = override(Value) __all__.append('Value') def type_from_name(name): type_ = GObjectModule.type_from_name(name) if type_ == TYPE_INVALID: raise RuntimeError('unknown type name: %s' % name) return type_ __all__.append('type_from_name') def type_parent(type_): parent = GObjectModule.type_parent(type_)
if mountpoint: self.set_property("mountpoint", mountpoint) @property def size(self): # using get_property causes problems with pylint for some reason # pylint: disable-msg=E1101 return self.get_property("size") @size.setter def size(self, size): self.set_property("size", size) MountpointSelector = override(MountpointSelector) __all__.append('MountpointSelector') class SpokeSelector(Anaconda.SpokeSelector): def __init__(self, title=None, icon=None, status=None): Anaconda.SpokeSelector.__init__(self) if title: self.set_property("title", title) if icon: self.set_property("icon", icon) if status: self.set_property("status", status)