'The superdefault :term:`traversal` algorithm that :app:`Pyramid` uses
is explained in :ref:`traversal_algorithm`.  Though it is rarely
necessary, this default algorithm can be swapped out selectively for
a different traversal pattern via configuration.  The section
entitled :ref:`changing_the_traverser` details how to create a
traverser class.
For example, to override the superdefault traverser used by Pyramid,
you might do something like this:
.. code-block:: python
from myapp.traversal import MyCustomTraverser
config.add_traverser(MyCustomTraverser)
This would cause the Pyramid superdefault traverser to never be used;
instead all traversal would be done using your ``MyCustomTraverser``
class, no matter which object was returned by the :term:`root
factory` of this application.  Note that we passed no arguments to
the ``iface`` keyword parameter.  The default value of ``iface``,
``None`` represents that the registered traverser should be used when
no other more specific traverser is available for the object returned
by the root factory.
However, more than one traversal algorithm can be active at the same
time.  The traverser used can depend on the result of the :term:`root
factory`.  For instance, if your root factory returns more than one
type of object conditionally, you could claim that an alternate
traverser adapter should be used against one particular class or
interface returned by that root factory.  When the root factory
returned an object that implemented that class or interface, a custom
traverser would be used.  Otherwise, the default traverser would be
used.  The ``iface`` argument represents the class of the object that
the root factory might return or an :term:`interface` that the object
might implement.
To use a particular traverser only when the root factory returns a
particular class:
.. code-block:: python
config.add_traverser(MyCustomTraverser, MyRootClass)
When more than one traverser is active, the "most specific" traverser
will be used (the one that matches the class or interface of the
value returned by the root factory most closely).
Note that either ``adapter`` or ``iface`` can be a :term:`dotted
Python name` or a Python object.
See :ref:`changing_the_traverser` for more information.'

@action_method
def add_traverser(self, adapter, iface=None):

    iface = self.maybe_dotted(iface)
    adapter = self.maybe_dotted(adapter)
    def register(iface=iface):
        if (iface is None):
            iface = Interface
        self.registry.registerAdapter(adapter, (iface,), ITraverser)
    discriminator = ('traverser', iface)
    intr = self.introspectable('traversers', discriminator, ('traverser    for    %r' % iface), 'traverser')
    intr['adapter'] = adapter
    intr['iface'] = iface
    self.action(discriminator, register, introspectables=(intr,))
