# Path: neubot/six.py
# PY3 = sys.version_info[0] == 3
#     MAXSIZE = sys.maxsize
#         MAXSIZE = int((1 << 31) - 1)
#             MAXSIZE = int((1 << 31) - 1)
#             MAXSIZE = int((1 << 63) - 1)
#         class X(object):
# class _LazyDescr(object):
# class MovedModule(_LazyDescr):
# class MovedAttribute(_LazyDescr):
# class _MovedItems(types.ModuleType):
#     class Iterator(object):
#             def __len__(self):
# def _add_doc(func, doc):
# def _import_module(name):
#     def __init__(self, name):
#     def __get__(self, obj, tp):
#     def __init__(self, name, old, new=None):
#     def _resolve(self):
#     def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
#     def _resolve(self):
# def add_move(move):
# def remove_move(name):
#     def advance_iterator(it):
#     def get_unbound_function(unbound):
#     def callable(obj):
#     def get_unbound_function(unbound):
#         def next(self):
# def iterkeys(d):
# def itervalues(d):
# def iteritems(d):
#     def b(s):
#     def u(s):
#         def int2byte(i):
#     def b(s):
#     def u(s):
#     def reraise(tp, value, tb=None):
#     def exec_(code, globs=None, locs=None):
#     def print_(*args, **kwargs):
#         def write(data):
# def with_metaclass(meta, base=object):
#     def buff(string, offset, size=None):
#     def bytes_to_string(octets, encoding):
#     def bytes_to_string_safe(octets, encoding):
#     def buff(string, offset, size=None):
#     def bytes_to_string(octets, encoding):
#     def bytes_to_string_safe(octets, encoding):


import collections
import logging
import os
import sys
from neubot import six

if __name__ == "__main__":
    sys.path.insert(0, ".")


def depth_visit(prefix, components, visit):
    ''' Visit the subtree prefix/components[0]/components[1]... '''
    #
    # Append() guarantees that the result is always below prefix,
    # so the result of this function is below prefix as well.
    #
    # It is not an error to pass a component that contains one or
    # more path separators, except that subcomponents are not visited
    # in that case.
    #
    # The boolean second argument to visit is to distinguish between
    # leaf and ordinary nodes.
    #
    # This function is more strict than needed and generates an
    # error for input like '/var/www', ['a/b/c', '../d'], but we
    # don't care because that case doesn't happen in Neubot.
    #
    components = collections.deque(components)
    while components:
        prefix = append(prefix, components.popleft(), False)
        if prefix == None:
            raise RuntimeError("utils_path: depth_visit(): append() failed")
        visit(prefix, not components)
    return prefix


# Path: neubot/six.py
# PY3 = sys.version_info[0] == 3
#     MAXSIZE = sys.maxsize
#         MAXSIZE = int((1 << 31) - 1)
#             MAXSIZE = int((1 << 31) - 1)
#             MAXSIZE = int((1 << 63) - 1)
#         class X(object):
# class _LazyDescr(object):
# class MovedModule(_LazyDescr):
# class MovedAttribute(_LazyDescr):
# class _MovedItems(types.ModuleType):
#     class Iterator(object):
#             def __len__(self):
# def _add_doc(func, doc):
# def _import_module(name):
#     def __init__(self, name):
#     def __get__(self, obj, tp):
#     def __init__(self, name, old, new=None):
#     def _resolve(self):
#     def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
#     def _resolve(self):
# def add_move(move):
# def remove_move(name):
#     def advance_iterator(it):
#     def get_unbound_function(unbound):
#     def callable(obj):
#     def get_unbound_function(unbound):
#         def next(self):
# def iterkeys(d):
# def itervalues(d):
# def iteritems(d):
#     def b(s):
#     def u(s):
#         def int2byte(i):
#     def b(s):
#     def u(s):
#     def reraise(tp, value, tb=None):
#     def exec_(code, globs=None, locs=None):
#     def print_(*args, **kwargs):
#         def write(data):
# def with_metaclass(meta, base=object):
#     def buff(string, offset, size=None):
#     def bytes_to_string(octets, encoding):
#     def bytes_to_string_safe(octets, encoding):
#     def buff(string, offset, size=None):
#     def bytes_to_string(octets, encoding):
#     def bytes_to_string_safe(octets, encoding):


# Path: neubot/utils_path.py
import collections
import logging
import os
import sys
from neubot import six


if __name__ == "__main__":
    sys.path.insert(0, ".")


def depth_visit(prefix, components, visit):
    ''' Visit the subtree prefix/components[0]/components[1]... '''
    #
    # Append() guarantees that the result is always below prefix,
    # so the result of this function is below prefix as well.
    #
    # It is not an error to pass a component that contains one or
    # more path separators, except that subcomponents are not visited
    # in that case.
    #
    # The boolean second argument to visit is to distinguish between
    # leaf and ordinary nodes.
    #
    # This function is more strict than needed and generates an
    # error for input like '/var/www', ['a/b/c', '../d'], but we
    # don't care because that case doesn't happen in Neubot.
    #
    components = collections.deque(components)
    while components:
        prefix = append(prefix, components.popleft(), False)
        if prefix == None:
            raise RuntimeError("utils_path: depth_visit(): append() failed")
        visit(prefix, not components)
    return prefix


STRING_CLASS = six.u("").__class__