# Path: hq/hquery/axis.py
# class Axis(Enum):
#     # standard
#     ancestor            = 1
#     ancestor_or_self    = 2
#     attribute           = 3
#     child               = 4
#     descendant          = 5
#     descendant_or_self  = 6
#     following           = 7
#     following_sibling   = 8
#     parent              = 9
#     preceding           = 10
#     preceding_sibling   = 11
#     self                = 12
#     # extended
#     css_class           = 13
# 
# 
#     def is_reverse_order(self):
#         return self in reverse_order_axes
# 
#     def token(self):
#         return self.name.replace('_', '-')
# 
#     @classmethod
#     def abbreviations(self):
#         return _abbreviations.keys()
# 
#     @classmethod
#     def canonicalize(cls, name):
#         if name in _abbreviations.keys():
#             result = _abbreviations[name]
#         else:
#             result = name.replace('-', '_')
#         return result
# 
# Path: hq/soup_util.py
# def is_root_node(obj):
#     return obj.__class__.__name__ == 'BeautifulSoup'
# 
# def is_tag_node(obj):
#     return obj.__class__.__name__ == 'Tag'
# 
# def is_text_node(obj):
#     return obj.__class__.__name__ == 'NavigableString'
# 
# class AttributeNode:
# 
#     def __init__(self, name, value):
#         self.name = name
#         self.value = ' '.join(value) if isinstance(value, list) else value
# 
#     def __repr__(self):
#         return 'AttributeNode("{0}", "{1}")'.format(self.name, self.value)
# 
#     @classmethod
#     def enumerate(cls, node):
#         if hasattr(node, 'hq_attrs') and _isnt_root_with_odd_ghost_hq_attrs_on_it_for_reasons_i_dont_understand(node):
#             return node.hq_attrs
#         else:
#             return []
# 
# def is_attribute_node(obj):
#     return isinstance(obj, AttributeNode)
# 
# def is_any_node(obj):
#     return is_root_node(obj) or is_tag_node(obj) or is_attribute_node(obj) or is_text_node(obj) or is_comment_node(obj)
# 
# def root_tag_from_soup(soup):
#     return next(tag for tag in soup.children if is_tag_node(tag))
# 
# def is_comment_node(obj):
#     return obj.__class__.__name__ == 'Comment'


from hq.hquery.axis import Axis
from ..soup_util import is_root_node, is_tag_node, is_text_node, AttributeNode, is_attribute_node, is_any_node, root_tag_from_soup, \
    is_comment_node


    def __repr__(self):
        return self.repr


    def apply(self, axis, node):
        nodes = getattr(self, 'gather_{0}'.format(axis.name))(node)
        return [node for node in nodes if self.accept_fn(node, axis=axis)]


    def gather_ancestor(self, node):
        if hasattr(node, 'parents'):
            return list(node.parents)
        else:
            return []


    def gather_ancestor_or_self(self, node):
        result = self.gather_self(node)
        result.extend(self.gather_ancestor(node))
        return result


    def gather_attribute(self, node):
        return list(AttributeNode.enumerate(node))


    def gather_child(self, node):
        if is_root_node(node):

# Path: hq/hquery/axis.py
# class Axis(Enum):
#     # standard
#     ancestor            = 1
#     ancestor_or_self    = 2
#     attribute           = 3
#     child               = 4
#     descendant          = 5
#     descendant_or_self  = 6
#     following           = 7
#     following_sibling   = 8
#     parent              = 9
#     preceding           = 10
#     preceding_sibling   = 11
#     self                = 12
#     # extended
#     css_class           = 13
# 
# 
#     def is_reverse_order(self):
#         return self in reverse_order_axes
# 
#     def token(self):
#         return self.name.replace('_', '-')
# 
#     @classmethod
#     def abbreviations(self):
#         return _abbreviations.keys()
# 
#     @classmethod
#     def canonicalize(cls, name):
#         if name in _abbreviations.keys():
#             result = _abbreviations[name]
#         else:
#             result = name.replace('-', '_')
#         return result
# 
# Path: hq/soup_util.py
# def is_root_node(obj):
#     return obj.__class__.__name__ == 'BeautifulSoup'
# 
# def is_tag_node(obj):
#     return obj.__class__.__name__ == 'Tag'
# 
# def is_text_node(obj):
#     return obj.__class__.__name__ == 'NavigableString'
# 
# class AttributeNode:
# 
#     def __init__(self, name, value):
#         self.name = name
#         self.value = ' '.join(value) if isinstance(value, list) else value
# 
#     def __repr__(self):
#         return 'AttributeNode("{0}", "{1}")'.format(self.name, self.value)
# 
#     @classmethod
#     def enumerate(cls, node):
#         if hasattr(node, 'hq_attrs') and _isnt_root_with_odd_ghost_hq_attrs_on_it_for_reasons_i_dont_understand(node):
#             return node.hq_attrs
#         else:
#             return []
# 
# def is_attribute_node(obj):
#     return isinstance(obj, AttributeNode)
# 
# def is_any_node(obj):
#     return is_root_node(obj) or is_tag_node(obj) or is_attribute_node(obj) or is_text_node(obj) or is_comment_node(obj)
# 
# def root_tag_from_soup(soup):
#     return next(tag for tag in soup.children if is_tag_node(tag))
# 
# def is_comment_node(obj):
#     return obj.__class__.__name__ == 'Comment'


# Path: hq/hquery/node_test.py
from hq.hquery.axis import Axis
from ..soup_util import is_root_node, is_tag_node, is_text_node, AttributeNode, is_attribute_node, is_any_node, root_tag_from_soup, \
    is_comment_node



    def __repr__(self):
        return self.repr


    def apply(self, axis, node):
        nodes = getattr(self, 'gather_{0}'.format(axis.name))(node)
        return [node for node in nodes if self.accept_fn(node, axis=axis)]


    def gather_ancestor(self, node):
        if hasattr(node, 'parents'):
            return list(node.parents)
        else:
            return []


    def gather_ancestor_or_self(self, node):
        result = self.gather_self(node)
        result.extend(self.gather_ancestor(node))
        return result


    def gather_attribute(self, node):
        return list(AttributeNode.enumerate(node))


    def gather_child(self, node):
        if is_root_node(node):

            return [root_tag_from_soup(node)]