本文整理汇总了Python中six.get_unbound_function函数的典型用法代码示例。如果您正苦于以下问题:Python get_unbound_function函数的具体用法?Python get_unbound_function怎么用?Python get_unbound_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_unbound_function函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_same_url
def test_same_url(self):
class TestSameUrlSpider(Spider):
name = 'test_same_url'
def __init__(self, *args, **kwargs):
super(TestSameUrlSpider, self).__init__(*args, **kwargs)
self.visited = 0
def start_requests(s):
return self.conman.from_spider(s, self.results)
def parse_first(self, response):
self.visited += 1
return TestItem()
def parse_second(self, response):
self.visited += 1
return TestItem()
with MockServer() as mockserver:
contract_doc = '@url {}'.format(mockserver.url('/status?n=200'))
get_unbound_function(TestSameUrlSpider.parse_first).__doc__ = contract_doc
get_unbound_function(TestSameUrlSpider.parse_second).__doc__ = contract_doc
crawler = CrawlerRunner().create_crawler(TestSameUrlSpider)
yield crawler.crawl()
self.assertEqual(crawler.spider.visited, 2)
开发者ID:ArturGaspar,项目名称:scrapy,代码行数:30,代码来源:test_contracts.py
示例2: getdefiningclass
def getdefiningclass(m, owner_class):
"""Resolves the class (e.g. one of the superclasses) that defined a method."""
m = six.get_unbound_function(m)
last_defining = owner_class
for superclass in tf_inspect.getmro(owner_class):
if hasattr(superclass, m.__name__):
superclass_m = getattr(superclass, m.__name__)
if six.get_unbound_function(superclass_m) == m:
last_defining = superclass
return last_defining
开发者ID:bikong2,项目名称:tensorflow,代码行数:10,代码来源:inspect_utils.py
示例3: get_validator
def get_validator(self, name, **kwargs):
attr_name = '%s_validator' % name
attr = getattr(self.meta, attr_name)
if inspect.ismethod(attr):
return six.get_unbound_function(attr)(**kwargs)
else:
return attr(**kwargs)
开发者ID:Frozenball,项目名称:wtforms-alchemy,代码行数:7,代码来源:generator.py
示例4: monkey_mix
def monkey_mix(cls, mixin, methods=None):
"""
Mixes a mixin into existing class.
Does not use actual multi-inheritance mixins, just monkey patches methods.
Mixin methods can call copies of original ones stored in `_no_monkey` proxy:
class SomeMixin(object):
def do_smth(self, arg):
... do smth else before
self._no_monkey.do_smth(self, arg)
... do smth else after
"""
assert '_no_monkey' not in cls.__dict__, 'Multiple monkey mix not supported'
cls._no_monkey = MonkeyProxy(cls)
if methods is None:
# NOTE: there no such thing as unbound method in Python 3, it uses naked functions,
# so we use some six based altering here
isboundmethod = inspect.isfunction if six.PY3 else inspect.ismethod
methods = inspect.getmembers(mixin, isboundmethod)
else:
methods = [(m, getattr(mixin, m)) for m in methods]
for name, method in methods:
if hasattr(cls, name):
setattr(cls._no_monkey, name, getattr(cls, name))
# NOTE: remember, there is no bound methods in Python 3
setattr(cls, name, six.get_unbound_function(method))
开发者ID:gorillamania,项目名称:django-cacheops,代码行数:28,代码来源:utils.py
示例5: _is_known_loaded_type
def _is_known_loaded_type(f, module_name, entity_name):
"""Tests whether the function or method is an instance of a known type."""
if (module_name not in sys.modules or
not hasattr(sys.modules[module_name], entity_name)):
return False
type_entity = getattr(sys.modules[module_name], entity_name)
if isinstance(f, type_entity):
# The method if of this type. Example:
#
# o = ClassType()
# function(o.method)()
return True
if tf_inspect.ismethod(f):
f = six.get_unbound_function(f)
# The the unbound method if of this type. Example:
#
# class ClassType:
# @function
# def method(self):
# ...
# o = ClassType()
# o.method()
if isinstance(f, type_entity):
return True
return False
开发者ID:kylin9872,项目名称:tensorflow,代码行数:25,代码来源:api.py
示例6: _update_class
def _update_class(oldclass, newclass):
"""Update a class object."""
# XXX What about __slots__?
olddict = oldclass.__dict__
newdict = newclass.__dict__
oldnames = set(olddict)
newnames = set(newdict)
for name in newnames - oldnames:
setattr(oldclass, name, newdict[name])
# Note: We do not delete attributes, because various ZCML directives,
# grokkers and other wiring add class attributes during startup that
# would get lost if we did this. Note that attributes will still be
# overwritten if they've changed.
#
# for name in oldnames - newnames:
# delattr(oldclass, name)
for name in oldnames & newnames - CLASS_STATICS:
try:
new = getattr(newclass, name)
old = getattr(oldclass, name, None)
if isinstance(new, (types.FunctionType, types.MethodType)):
if isinstance(old, property) and not isinstance(new, property):
# Removing a decorator
setattr(oldclass, name, six.get_unbound_function(new))
elif isinstance(new, types.FunctionType):
# Under Py3 there are only functions
_update_function(old, new)
elif isinstance(new, types.MethodType):
# Py2-only
_update_method(old, new)
else:
new2 = newdict.get(name)
if new is not new2:
# Do we have some sort of descriptor? Set the underlying
# descriptor and not the result of the descriptor call
setattr(oldclass, name, new2)
else:
# Fallback to just replace the item
setattr(oldclass, name, new)
except ClosureChanged:
# If the closure changed, we need to replace the entire function
setattr(oldclass, name, six.get_unbound_function(new))
return oldclass
开发者ID:plone,项目名称:plone.reload,代码行数:46,代码来源:xreload.py
示例7: on_bound
def on_bound(cls, app):
# Set up celery beat entry after celery app initialization is done.
enabled = cls._enabled
if callable(enabled):
enabled = get_unbound_function(enabled)(app.app_config)
if enabled and cls._schedule:
app.conf.CELERYBEAT_SCHEDULE.update(cls.beat_config())
开发者ID:amjadm61,项目名称:ichnaea,代码行数:8,代码来源:task.py
示例8: test_namreply_no_channel
def test_namreply_no_channel(self):
"""
If channel is '*', _on_namreply should not crash.
Regression test for #22
"""
event = irc.client.Event(type=None, source=None, target=None, arguments=["*", "*", "nick"])
_on_namreply = six.get_unbound_function(irc.bot.SingleServerIRCBot._on_namreply)
_on_namreply(None, None, event)
开发者ID:abadger,项目名称:irc,代码行数:9,代码来源:test_bot.py
示例9: test_taskset_inheritance
def test_taskset_inheritance(self):
def t1(l):
pass
class MyBaseTaskSet(TaskSet):
tasks = [t1]
host = ""
class MySubTaskSet(MyBaseTaskSet):
@task
def t2(self):
pass
l = MySubTaskSet(self.locust)
self.assertEqual(2, len(l.tasks))
self.assertEqual([t1, six.get_unbound_function(MySubTaskSet.t2)], l.tasks)
开发者ID:fordhurley,项目名称:locust,代码行数:14,代码来源:test_locust_class.py
示例10: fetch_cls_init
def fetch_cls_init(cls):
"""Return reference to the class.__init__() method if it is defined.
:param cls: Class instance
:type cls: type
:return: Reference to the class.__init__() if any, or None otherwise.
:rtype: unbound method | None
"""
try:
cls_init = six.get_unbound_function(cls.__init__)
assert cls_init is not _OBJECT_INIT
except (AttributeError, AssertionError):
return None
else:
return cls_init
开发者ID:JA-VON,项目名称:python-dependency-injector,代码行数:16,代码来源:utils.py
示例11: __call__
def __call__(self, wrapped):
if isinstance(wrapped, six.class_types):
cls = wrapped
try:
cls_init = six.get_unbound_function(cls.__init__)
assert cls_init is not OBJECT_INIT
except (AttributeError, AssertionError):
raise DiError('Class %s has no __init__ to inject' % cls)
cls.__init__ = self(cls_init)
return cls
if not any([self.args, self.kwargs]):
self.injectables = self.di.get_deps(wrapped)
else:
self.injectables = []
if self.args:
self.injectables.extend(self.args)
if self.kwargs:
self.injectables.extend(self.kwargs.values())
self.di.depends_on(*self.injectables)(wrapped)
return self.decorate(wrapped)
开发者ID:gitter-badger,项目名称:mainline,代码行数:22,代码来源:injection.py
示例12: __init__
def __init__(self, doc_object):
self.doc_object = doc_object
self.description = dedent(self.doc_object.__doc__)
try:
if isinstance(self.doc_object, type):
func = six.get_unbound_function(self.doc_object.__init__)
elif (hasattr(self.doc_object, '__call__')
and not isinstance(self.doc_object, types.FunctionType)):
func = self.doc_object.__call__
else:
func = self.doc_object
if hasattr(func, '__paste_sig__'):
sig = func.__paste_sig__
else:
sig = inspect.getargspec(func)
sig = inspect.formatargspec(*sig)
except TypeError:
sig = None
if sig:
if self.description:
self.description = '%s\n\n%s' % (
sig, self.description)
else:
self.description = sig
开发者ID:andreesg,项目名称:collective.article,代码行数:24,代码来源:entrypoints.py
示例13: patch
def patch():
"""
Patch `bs4.Tag` to include new functionality.
:return:
"""
bs4.Tag._feature_hash = six.get_unbound_function(TagHash._feature_hash)
bs4.Tag._tag_hash = six.get_unbound_function(TagHash._tag_hash)
bs4.Tag.hash = six.get_unbound_function(TagHash._hash)
bs4.Tag.hash_compare = six.get_unbound_function(TagHash._tag_hash_compare)
bs4.Tag._recursive_structure_xpath = six.get_unbound_function(TagHash._recursive_structure_xpath)
bs4.Tag.structure_xpath = six.get_unbound_function(TagHash._structure_xpath)
bs4.Tag._tag_sibling_position = six.get_unbound_function(TagHash._tag_sibling_position)
bs4.Tag.identifying_xpath = six.get_unbound_function(TagHash._identifying_xpath)
bs4.Tag.relative_xpath = six.get_unbound_function(TagHash._relative_xpath)
bs4.Tag._recursive_count = six.get_unbound_function(TagHash._recursive_count)
bs4.Tag.count = six.get_unbound_function(TagHash._count)
bs4.Tag.lxml = TagHash._lxml
bs4.Tag.iterate = six.get_unbound_function(TagHash._iterate)
bs4.Tag.inner_text = TagHash._inner_text
bs4.Tag.level = TagHash._level
bs4.Tag.is_list = six.get_unbound_function(TagHash._is_list)
bs4.Tag.has_identical_parent = six.get_unbound_function(TagHash._has_identical_parent)
开发者ID:Murodese,项目名称:pytaghash,代码行数:27,代码来源:taghash.py
示例14: _get_object_init
def _get_object_init():
if six.PY3 or IS_PYPY:
return six.get_unbound_function(object.__init__)
开发者ID:gitter-badger,项目名称:mainline,代码行数:3,代码来源:utils.py
示例15: is_provider
import threading
import six
from dependency_injector.errors import Error
GLOBAL_LOCK = threading.RLock()
"""Dependency injector global reentrant lock.
:type: :py:class:`threading.RLock`
"""
_IS_PYPY = '__pypy__' in sys.builtin_module_names
if _IS_PYPY or six.PY3: # pragma: no cover
_OBJECT_INIT = six.get_unbound_function(object.__init__)
else: # pragma: no cover
_OBJECT_INIT = None
if six.PY2: # pragma: no cover
copy._deepcopy_dispatch[types.MethodType] = \
lambda obj, memo: type(obj)(obj.im_func,
copy.deepcopy(obj.im_self, memo),
obj.im_class)
def is_provider(instance):
"""Check if instance is provider instance.
:param instance: Instance to be checked.
:type instance: object
开发者ID:JA-VON,项目名称:python-dependency-injector,代码行数:31,代码来源:utils.py
示例16: _update_method
def _update_method(oldmeth, newmeth):
"""Update a method object."""
# XXX What if im_func is not a function?
_update_function(six.get_unbound_function(oldmeth),
six.get_unbound_function(newmeth))
return oldmeth
开发者ID:plone,项目名称:plone.reload,代码行数:6,代码来源:xreload.py
示例17: manage_addPortalFolder
@security.protected(AddPortalFolders)
def manage_addPortalFolder(self, id, title='', REQUEST=None):
"""Add a new PortalFolder object with id *id*.
"""
ob = PortalFolder(id, title)
self._setObject(id, ob, suppress_events=True)
if REQUEST is not None:
return self.folder_contents( # XXX: ick!
self, REQUEST, portal_status_message='Folder added')
InitializeClass(PortalFolder)
PortalFolderFactory = Factory(PortalFolder)
manage_addPortalFolder = get_unbound_function(
PortalFolder.manage_addPortalFolder)
class ContentFilter:
"""Represent a predicate against a content object's metadata.
"""
MARKER = []
filterSubject = []
def __init__(self, Title=MARKER, Creator=MARKER, Subject=MARKER,
Description=MARKER, created=MARKER, created_usage='range:min',
modified=MARKER, modified_usage='range:min', Type=MARKER,
portal_type=MARKER, **Ignored):
开发者ID:zopefoundation,项目名称:Products.CMFCore,代码行数:31,代码来源:PortalFolder.py
示例18: __init__
def __init__(self, likelihood, Y, tolerance):
self.likelihood, self.Y, self.tolerance = likelihood, Y, tolerance
self.is_analytic = six.get_unbound_function(likelihood.predict_density) is not\
six.get_unbound_function(GPflow.likelihoods.Likelihood.predict_density)
开发者ID:gbohner,项目名称:GPflow,代码行数:4,代码来源:test_likelihoods.py
示例19: test_get_unbound_function
def test_get_unbound_function():
class X(object):
def m(self):
pass
assert six.get_unbound_function(X.m) is X.__dict__["m"]
开发者ID:A-Maze,项目名称:A-Pc,代码行数:5,代码来源:test_six.py
注:本文中的six.get_unbound_function函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论