本文整理汇总了Python中snakeoil.currying.post_curry函数的典型用法代码示例。如果您正苦于以下问题:Python post_curry函数的具体用法?Python post_curry怎么用?Python post_curry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post_curry函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:veelai,项目名称:pkgcore,代码行数:34,代码来源:test_triggers.py
示例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
开发者ID:floppym,项目名称:pkgcore,代码行数:31,代码来源:engine.py
示例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
开发者ID:radhermit,项目名称:pkgcore,代码行数:33,代码来源:engine.py
示例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}))
开发者ID:vapier,项目名称:snakeoil,代码行数:31,代码来源:test_currying.py
示例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
开发者ID:radhermit,项目名称:pkgcore,代码行数:25,代码来源:test_ebuild_src.py
示例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)
开发者ID:neko259,项目名称:pkgcore,代码行数:56,代码来源:test_spawn.py
示例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])
开发者ID:den4ix,项目名称:snakeoil,代码行数:11,代码来源:test_dependant_methods.py
示例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])
开发者ID:den4ix,项目名称:snakeoil,代码行数:15,代码来源:test_dependant_methods.py
示例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)
开发者ID:den4ix,项目名称:snakeoil,代码行数:7,代码来源:test_dependant_methods.py
示例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)
开发者ID:den4ix,项目名称:snakeoil,代码行数:7,代码来源:test_dependant_methods.py
示例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
)
开发者ID:neko259,项目名称:pkgcore,代码行数:7,代码来源:ebuild_built.py
示例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)
开发者ID:chutz,项目名称:snakeoil,代码行数:8,代码来源:test_dependant_methods.py
示例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)
开发者ID:den4ix,项目名称:snakeoil,代码行数:9,代码来源:klass.py
示例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+')
开发者ID:vapier,项目名称:snakeoil,代码行数:19,代码来源:data_source.py
示例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)
开发者ID:veelai,项目名称:pkgcore,代码行数:20,代码来源:test_contents.py
示例16: itermatch
def itermatch(self, restrict, **kwds):
sorter = kwds.get("sorter", iter)
if sorter is iter:
return (match for repo in self.trees
for match in repo.itermatch(restrict, **kwds))
# ugly, and a bit slow, but works.
def f(x, y):
l = sorter([x, y])
if l[0] == y:
return 1
return -1
f = post_curry(sorted_cmp, f, key=self.zero_index_grabber)
return iter_sort(f,
*[repo.itermatch(restrict, **kwds) for repo in self.trees])
开发者ID:vapier,项目名称:pkgcore,代码行数:14,代码来源:multiplex.py
示例17: test_post_curry
def test_post_curry(self):
noop = currying.post_curry(passthrough)
assert noop() == ((), {})
assert noop('foo', 'bar') == (('foo', 'bar'), {})
assert noop(foo='bar') == ((), {'foo': 'bar'})
assert noop('foo', bar='baz') == (('foo',), {'bar': 'baz'})
one_arg = currying.post_curry(passthrough, 42)
assert one_arg() == ((42,), {})
assert one_arg('foo', 'bar') == (('foo', 'bar', 42), {})
assert one_arg(foo='bar') == ((42,), {'foo': 'bar'})
assert one_arg('foo', bar='baz') == (('foo', 42), {'bar': 'baz'})
keyword_arg = currying.post_curry(passthrough, foo=42)
assert keyword_arg() == ((), {'foo': 42})
assert keyword_arg('foo', 'bar') == (('foo', 'bar'), {'foo': 42})
assert keyword_arg(foo='bar') == ((), {'foo': 42})
assert keyword_arg('foo', bar='baz') == (('foo',), {'bar': 'baz', 'foo': 42})
both = currying.post_curry(passthrough, 42, foo=42)
assert both() == ((42,), {'foo': 42})
assert both('foo', 'bar') == (('foo', 'bar', 42), {'foo': 42})
assert both(foo='bar') == ((42,), {'foo': 42})
assert both('foo', bar='baz') == (('foo', 42), {'bar': 'baz', 'foo': 42})
开发者ID:radhermit,项目名称:snakeoil,代码行数:24,代码来源:test_currying.py
示例18: test_stage_awareness
def test_stage_awareness(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, "1")()
self.assertEqual(results, [0, 1])
getattr(o, "2")()
self.assertEqual(results, [0, 1, 2])
getattr(o, "2")()
self.assertEqual(results, [0, 1, 2])
o.__set_stage_state__(["0", "1"])
l = []
o.__stage_step_callback__ = l.append
getattr(o, "2")()
self.assertEqual(results, [0, 1, 2, 2])
self.assertEqual(l, ["2"])
开发者ID:den4ix,项目名称:snakeoil,代码行数:17,代码来源:test_dependant_methods.py
示例19: cached_property_named
def cached_property_named(name, kls=_internal_jit_attr, use_cls_setattr=False):
"""
variation of `cached_property`, just with the ability to explicitly set the attribute name
Primarily of use for when the functor it's wrapping has a generic name (
`functools.partial` instances for example).
Example Usage:
>>> from snakeoil.klass import cached_property_named
>>> class foo(object):
...
... @cached_property_named("attr")
... def attr(self):
... print("invoked")
... return 1
>>>
>>> obj = foo()
>>> print(obj.attr)
invoked
1
>>> print(obj.attr)
1
"""
return post_curry(kls, name, use_singleton=False, use_cls_setattr=False)
开发者ID:den4ix,项目名称:snakeoil,代码行数:24,代码来源:klass.py
示例20: mk_check
def mk_check(name):
return pretty_docs(post_curry(getattr, 'is_' + name, False),
extradocs=("return True if obj is an instance of :obj:`%s`, else False" % name),
name=("is" +name)
)
开发者ID:chutz,项目名称:pkgcore,代码行数:5,代码来源:fs.py
注:本文中的snakeoil.currying.post_curry函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论