def wrapname(name, wrapper): module, name = name.rsplit(b'.', 1) module = sys.modules[module] func = getattr(module, name) def f(*args, **kwds): return wrapper(func, args, kwds) f.__name__ = func.__name__ setattr(module, name, f)
def vfsinit(orig, self, othervfs): orig(self, othervfs) # copy lfs related options for k, v in othervfs.options.items(): if k.startswith(b'lfs'): self.options[k] = v # also copy lfs blobstores. note: this can run before reposetup, so lfs # blobstore attributes are not always ready at this time. for name in [b'lfslocalblobstore', b'lfsremoteblobstore']: if util.safehasattr(othervfs, name): setattr(self, name, getattr(othervfs, name))
def replacefilecache(cls, propname, replacement): """Replace a filecache property with a new class. This allows changing the cache invalidation condition.""" origcls = cls assert callable(replacement) while cls is not object: if propname in cls.__dict__: orig = cls.__dict__[propname] setattr(cls, propname, replacement(orig)) break cls = cls.__bases__[0] if cls is object: raise AttributeError( _(b"type '%s' has no property '%s'") % (origcls, propname))
def __init__(self, **opts): opts = pycompat.byteskwargs(opts) for k, v in pycompat.iteritems(self.defaults): setattr(self, k, opts.get(k, v))
def decorator(func): setattr(cls, func.__name__, func) return func