mercurial/thirdparty/zope/interface/_flatten.py
author Joerg Sonnenberger <joerg@bec.de>
Fri, 30 Apr 2021 02:11:58 +0200
changeset 47043 12450fbea288
parent 37178 68ee61822182
permissions -rw-r--r--
manifests: push down expected node length into the parser This strictly enforces the node length in the manifest lines according to what the repository expects. One test case moves large hash testing into the non-treemanifest part as treemanifests don't provide an interface for overriding just the node length for now. Differential Revision: https://phab.mercurial-scm.org/D10533
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