_dup.py 1001 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Joshua Bronson. All Rights Reserved.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. """Provides bidict duplication policies and the :class:`_OnDup` class."""
  8. from collections import namedtuple
  9. from ._marker import _Marker
  10. _OnDup = namedtuple('_OnDup', 'key val kv')
  11. class DuplicationPolicy(_Marker):
  12. """Base class for bidict's duplication policies.
  13. *See also* :ref:`basic-usage:Values Must Be Unique`
  14. """
  15. __slots__ = ()
  16. #: Raise an exception when a duplication is encountered.
  17. RAISE = DuplicationPolicy('DUP_POLICY.RAISE')
  18. #: Overwrite an existing item when a duplication is encountered.
  19. OVERWRITE = DuplicationPolicy('DUP_POLICY.OVERWRITE')
  20. #: Keep the existing item and ignore the new item when a duplication is encountered.
  21. IGNORE = DuplicationPolicy('DUP_POLICY.IGNORE')