1##############################################################################
2#
3# Copyright (c) 2002 Zope Foundation and Contributors.
4# All Rights Reserved.
5#
6# This software is subject to the provisions of the Zope Public License,
7# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11# FOR A PARTICULAR PURPOSE.
12#
13##############################################################################
14"""Adapter-style interface registry
15
16See Adapter class.
17"""
18from zope.interface import Declaration
19
20def _flatten(implements, include_None=0):
21
22    try:
23        r = implements.flattened()
24    except AttributeError:
25        if implements is None:
26            r=()
27        else:
28            r = Declaration(implements).flattened()
29
30    if not include_None:
31        return r
32
33    r = list(r)
34    r.append(None)
35    return r
36