本文整理汇总了Python中snakeoil.currying.post_curry函数的典型用法代码示例。如果您正苦于以下问题:Python post_curry函数的具体用法?Python post_curry怎么用?Python post_curry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post_curry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it
def test_it(self):
orig = contentsSet([
fs.fsFile('/cheddar', strict=False),
fs.fsFile('/sporks-suck', strict=False),
fs.fsDir('/foons-rule', strict=False),
fs.fsDir('/mango', strict=False)
])
engine = fake_engine(mode=const.INSTALL_MODE)
def run(func):
new = contentsSet(orig)
self.kls(func)(engine, {'new_cset':new})
return new
self.assertEqual(orig, run(lambda s:False))
self.assertEqual([], run(post_curry(isinstance, fs.fsDir)).dirs())
self.assertEqual(orig.files(),
run(post_curry(isinstance, fs.fsDir)).dirs(True))
# check noisyness.
info = []
engine = fake_engine(observer=fake_reporter(info=info.append),
mode=const.REPLACE_MODE)
run(lambda s:False)
self.assertFalse(info)
run(post_curry(isinstance, fs.fsDir))
self.assertEqual(len(info), 2)
# ensure only the relevant files show.
self.assertNotIn('/cheddar', ' '.join(info))
self.assertNotIn('/sporks-suck', ' '.join(info))
self.assertIn('/foons-rule', ' '.join(info))
self.assertIn('/mango', ' '.join(info))
示例2: uninstall
def uninstall(cls, tempdir, pkg, offset=None, observer=None,
disable_plugins=False):
"""
generate a MergeEngine instance configured for uninstalling a pkg
:param tempdir: tempspace for the merger to use; this space it must
control alone, no sharing.
:param pkg: :obj:`pkgcore.package.metadata.package` instance to uninstall,
must be from a livefs vdb
:param offset: any livefs offset to force for modifications
:param disable_plugins: if enabled, run just the triggers passed in
:return: :obj:`MergeEngine`
"""
hooks = {k: [y() for y in v]
for (k, v) in cls.uninstall_hooks.iteritems()}
csets = cls.uninstall_csets.copy()
if "raw_old_cset" not in csets:
csets["raw_old_cset"] = post_curry(cls.get_pkg_contents, pkg)
o = cls(UNINSTALL_MODE, tempdir, hooks, csets, cls.uninstall_csets_preserve,
observer, offset=offset, disable_plugins=disable_plugins)
if o.offset != '/':
# wrap the results of new_cset to pass through an offset generator
o.cset_sources["old_cset"] = post_curry(
o.generate_offset_cset, o.cset_sources["old_cset"])
o.old = pkg
return o
示例3: replace
def replace(cls, tempdir, old, new, offset=None, observer=None,
disable_plugins=False):
"""Generate a MergeEngine instance configured for replacing a pkg.
:param tempdir: tempspace for the merger to use; this space it must
control alone, no sharing.
:param old: :obj:`pkgcore.package.metadata.package` instance to replace,
must be from a livefs vdb
:param new: :obj:`pkgcore.package.metadata.package` instance
:param offset: any livefs offset to force for modifications
:param disable_plugins: if enabled, run just the triggers passed in
:return: :obj:`MergeEngine`
"""
hooks = {k: [y() for y in v] for (k, v) in cls.replace_hooks.items()}
csets = cls.replace_csets.copy()
csets.setdefault('raw_old_cset', post_curry(cls.get_pkg_contents, old))
csets.setdefault('raw_new_cset', post_curry(cls.get_pkg_contents, new))
o = cls(REPLACE_MODE, tempdir, hooks, csets, cls.replace_csets_preserve,
observer, offset=offset, disable_plugins=disable_plugins)
if o.offset != '/':
for k in ("raw_old_cset", "raw_new_cset"):
# wrap the results of new_cset to pass through an
# offset generator
o.cset_sources[k] = post_curry(
o.generate_offset_cset, o.cset_sources[k])
o.old = old
o.new = new
return o
示例4: test_post_curry
def test_post_curry(self):
noop = currying.post_curry(passthrough)
self.assertEqual(noop(), ((), {}))
self.assertEqual(noop('foo', 'bar'), (('foo', 'bar'), {}))
self.assertEqual(noop(foo='bar'), ((), {'foo': 'bar'}))
self.assertEqual(noop('foo', bar='baz'), (('foo',), {'bar': 'baz'}))
one_arg = currying.post_curry(passthrough, 42)
self.assertEqual(one_arg(), ((42,), {}))
self.assertEqual(one_arg('foo', 'bar'), (('foo', 'bar', 42), {}))
self.assertEqual(one_arg(foo='bar'), ((42,), {'foo': 'bar'}))
self.assertEqual(
one_arg('foo', bar='baz'), (('foo', 42), {'bar': 'baz'}))
keyword_arg = currying.post_curry(passthrough, foo=42)
self.assertEqual(keyword_arg(), ((), {'foo': 42}))
self.assertEqual(
keyword_arg('foo', 'bar'), (('foo', 'bar'), {'foo': 42}))
self.assertEqual(
keyword_arg(foo='bar'), ((), {'foo': 42}))
self.assertEqual(
keyword_arg('foo', bar='baz'),
(('foo',), {'bar': 'baz', 'foo': 42}))
both = currying.post_curry(passthrough, 42, foo=42)
self.assertEqual(both(), ((42,), {'foo': 42}))
self.assertEqual(
both('foo', 'bar'), (('foo', 'bar', 42), {'foo': 42}))
self.assertEqual(both(foo='bar'), ((42,), {'foo': 42}))
self.assertEqual(
both('foo', bar='baz'), (('foo', 42), {'bar': 'baz', 'foo': 42}))
示例5: test_get_parsed_eapi
def test_get_parsed_eapi(self, tmpdir):
def _path(self, cpv, eapi_str):
ebuild = pjoin(str(tmpdir), "temp-0.ebuild")
with open(ebuild, 'w') as f:
f.write(textwrap.dedent(f'''\
# Copyright
# License
EAPI={eapi_str}'''))
return local_source(str(ebuild))
# ebuild has a real path on the fs
for eapi_str, eapi in EAPI.known_eapis.items():
c = self.make_parent(get_ebuild_src=post_curry(_path, eapi_str))
o = self.get_pkg({'EAPI': None}, repo=c)
assert str(o.eapi) == eapi_str
def _src(self, cpv, eapi_str):
return data_source(f'EAPI={eapi_str}')
# ebuild is a faked obj
for eapi_str, eapi in EAPI.known_eapis.items():
c = self.make_parent(get_ebuild_src=post_curry(_src, eapi_str))
o = self.get_pkg({'EAPI': None}, repo=c)
assert str(o.eapi) == eapi_str
示例6: test_fakeroot
def test_fakeroot(self):
try:
l = pwd.getpwnam("nobody")
except KeyError:
raise SkipTest(
"system lacks nobody user, thus can't test fakeroot")
if 'LD_PRELOAD' in os.environ:
raise SkipTest(
"disabling test due to LD_PRELOAD setting, which "
"fakeroot relies upon")
nobody_uid = l[2]
nobody_gid = l[3]
kw = {}
if os.getuid() == 0:
kw = {"uid": l[2], "gid": l[3]}
fp2 = self.generate_script(
"pkgcore-spawn-fakeroot2.sh",
"#!%s\nimport os\ns=os.stat('/tmp')\n"
"print(s.st_uid)\nprint(s.st_gid)\n" %
spawn.find_binary("python"))
fp1 = self.generate_script(
"pkgcore-spawn-fakeroot.sh",
"#!%s\nchown %i:%i /tmp;%s;\n" % (
self.bash_path, nobody_uid, nobody_gid, fp2))
savefile = os.path.join(self.dir, "fakeroot-savefile")
self.assertNotEqual(long(os.stat("/tmp").st_uid), long(nobody_uid))
self.assertEqual(
[0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
spawn.spawn_get_output(
[self.bash_path, fp1],
spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))
self.assertNotEqual(
long(os.stat("/tmp").st_uid), long(nobody_uid),
"bad voodoo; we managed to change /tmp to nobody- "
"this shouldn't occur!")
self.assertEqual(
True, os.path.exists(savefile),
"no fakeroot file was created, either fakeroot differs or our" +
" args passed to it are bad")
# yes this is a bit ugly, but fakeroot requires an arg- so we
# have to curry it
self.assertEqual(
[0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
spawn.spawn_get_output(
[fp2],
spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))
os.unlink(fp1)
os.unlink(fp2)
os.unlink(savefile)
示例7: test_stage_depends
def test_stage_depends(self):
results = []
methods = {str(x): currying.post_curry(func, results, x) for x in range(10)}
deps = {str(x): str(x - 1) for x in xrange(1, 10)}
deps["1"] = ["0", "a"]
methods["a"] = currying.post_curry(func, results, "a")
o = self.generate_instance(methods, deps)
getattr(o, "1")()
self.assertEqual(results, [0, "a", 1])
getattr(o, "2")()
self.assertEqual(results, [0, "a", 1, 2])
示例8: test_return_checking
def test_return_checking(self):
results = []
o = self.generate_instance(
{str(x): currying.post_curry(func, results, x) for x in range(10)},
{str(x): str(x - 1) for x in xrange(1, 10)})
getattr(o, "9")()
self.assertEqual(results, range(10))
results = []
o = self.generate_instance(
{str(x): currying.post_curry(func, results, x, False) for x in range(10)},
{str(x): str(x - 1) for x in xrange(1, 10)})
getattr(o, "9")()
self.assertEqual(results, [0])
getattr(o, "9")()
self.assertEqual(results, [0, 0])
示例9: test_no_deps
def test_no_deps(self):
results = []
o = self.generate_instance(
{str(x): currying.post_curry(func, results, x) for x in range(10)},
{})
getattr(o, '2')()
self.assertEqual([2], results)
示例10: test_ignore_deps
def test_ignore_deps(self):
results = []
o = self.generate_instance(
{str(x): currying.post_curry(func, results, x) for x in range(10)},
{str(x): str(x - 1) for x in xrange(1, 10)})
getattr(o, '2')(ignore_deps=True)
self.assertEqual([2], results)
示例11: __init__
def __init__(self, *args, **kwargs):
super(package, self).__init__(*args, **kwargs)
self._get_attr.update(
(k, post_curry(wrap_inst, ebuild_src.package._config_wrappables[k], ebuild_src.package._get_attr[k]))
for k in ebuild_src.package._config_wrappables
if k in super(package, self).tracked_attributes
)
示例12: test_ignore_deps
def test_ignore_deps(self):
results = []
o = self.generate_instance(
dict((str(x), currying.post_curry(func, results, x))
for x in range(10)),
dict((str(x), str(x - 1)) for x in xrange(1, 10)))
getattr(o, '2')(ignore_deps=True)
self.assertEqual([2], results)
示例13: jit_attr_named
def jit_attr_named(stored_attr_name, use_cls_setattr=False, kls=_internal_jit_attr,
uncached_val=_uncached_singleton):
"""
Version of :py:func:`jit_attr` decorator that allows for explicit control over the
attribute name used to store the cache value.
See :py:class:`_internal_jit_attr` for documentation of the misc params.
"""
return post_curry(kls, stored_attr_name, uncached_val, use_cls_setattr)
示例14: text_fileobj
def text_fileobj(self, writable=False):
if writable and not self.mutable:
raise TypeError("data source %s is immutable" % (self,))
if self.encoding:
opener = open_file
if not compatibility.is_py3k:
opener = codecs.open
opener = post_curry(opener, buffering=self.buffering_window,
encoding=self.encoding)
else:
opener = post_curry(open_file, self.buffering_window)
if not writable:
return opener(self.path, 'r')
try:
return opener(self.path, "r+")
except IOError as ie:
if ie.errno != errno.ENOENT:
raise
return opener(self.path, 'w+')
示例15: iterobj
def iterobj(self, name, obj_class=None, forced_name=None):
s = set(getattr(self, name))
cs = contents.contentsSet(s)
if forced_name is None:
forced_name = "iter"+name
s2 = set(getattr(cs, forced_name)())
if obj_class is not None:
map(post_curry(self.assertTrue, obj_class), s2)
self.assertEqual(s, s2)
if forced_name == "__iter__":
return
# inversion tests now.
s3 = set(getattr(cs, forced_name)(invert=True))
if obj_class is not None:
map(post_curry(self.assertFalse, obj_class), s3)
self.assertEqual(s.symmetric_difference(s2), s3)