mercurial/thirdparty/zope/interface/_flatten.py
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 11 May 2021 12:22:26 -0700
changeset 47191 b338d831d18c
parent 37178 68ee61822182
permissions -rw-r--r--
templates: fix `revset('parents()') % ...` in amend message template I don't understand why, but putting `revset('parents()') % {desc}` in the commit message template for amend resulted in a crash because `memctx.hex()` did `hex(self.node())` and its node was None. This patch fixes that. Martin von Zweigbergk <martinvonz@google.com> Differential Revision: https://phab.mercurial-scm.org/D10707
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37176
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
##############################################################################
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright (c) 2002 Zope Foundation and Contributors.
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
# All Rights Reserved.
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
#
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# This software is subject to the provisions of the Zope Public License,
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
# FOR A PARTICULAR PURPOSE.
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
#
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
##############################################################################
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
"""Adapter-style interface registry
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
See Adapter class.
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
"""
37178
68ee61822182 thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37176
diff changeset
    18
68ee61822182 thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37176
diff changeset
    19
from __future__ import absolute_import
68ee61822182 thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37176
diff changeset
    20
68ee61822182 thirdparty: port zope.interface to relative imports
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37176
diff changeset
    21
from .interface import Declaration
37176
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
def _flatten(implements, include_None=0):
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
    try:
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
        r = implements.flattened()
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
    except AttributeError:
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
        if implements is None:
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
            r=()
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
        else:
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
            r = Declaration(implements).flattened()
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
    if not include_None:
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
        return r
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
    r = list(r)
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
    r.append(None)
943d77fc07a3 thirdparty: vendor zope.interface 4.4.3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
    return r