Пример #1
0
def classSizable(class_):
    """Monkey the class to be sizable through Five"""
    # tuck away the original method if necessary
    if hasattr(class_, "get_size") and not isFiveMethod(class_.get_size):
        class_.__five_original_get_size = class_.get_size
    class_.get_size = get_size
    # remember class for clean up
    _monkied.append(class_)
Пример #2
0
def patchMethod(class_, name, new_method):
    method = getattr(class_, name, None)
    if isFiveMethod(method):
        return
    setattr(class_, FIVE_ORIGINAL_PREFIX + name, method)
    setattr(class_, name, new_method)
    new_method.__five_method__ = True
    _monkied.append((class_, name))
Пример #3
0
def maybeCallDeprecated(method_name, ob, *args):
    """Call a deprecated method, if the framework doesn't call it already.
    """
    if hasDeprecatedMethods(ob):
        # Already deprecated through zcml
        return
    method = getattr(ob, method_name)
    if isFiveMethod(method):
        # Monkey-patched method
        return
    if deprecatedManageAddDeleteClasses:
        # Not deprecated through zcml and directives fully loaded
        class_ = ob.__class__
        warnings.warn(
            "Calling %s.%s.%s is deprecated when using Five, "
            "instead use event subscribers or "
            "mark the class with <five:deprecatedManageAddDelete/>"
            % (class_.__module__, class_.__name__, method_name),
            DeprecationWarning)
    # Note that calling the method can lead to incorrect behavior
    # but in the most common case that's better than not calling it.
    method(ob, *args)