# Path: hq/hquery/object_type.py
# def is_sequence(obj):
#     return isinstance(obj, list)
# 
# Path: hq/soup_util.py
# def is_text_node(obj):
#     return obj.__class__.__name__ == 'NavigableString'
# 
# def is_attribute_node(obj):
#     return isinstance(obj, AttributeNode)
# 
# def is_comment_node(obj):
#     return obj.__class__.__name__ == 'Comment'
# 
# def is_tag_node(obj):
#     return obj.__class__.__name__ == 'Tag'
# 
# def derive_text_from_node(obj, preserve_space=False):
#     if is_tag_node(obj) or is_root_node(obj):
#         result = u''
#         strings = list(obj.strings)
#         cursor = 0
#         for run in (strings if preserve_space else obj.stripped_strings):
#             if preserve_space:
#                 add_space = False
#             else:
#                 while cursor < len(strings):
#                     if run in strings[cursor]:
#                         break
#                     else:
#                         cursor += 1
#                 if cursor < len(strings):
#                     add_space = strings[cursor][0].isspace() or (cursor > 0 and strings[cursor - 1][-1].isspace())
#                 else:
#                     add_space = False
#             result += u'{0}{1}'.format(' ' if add_space else '', run)
#     elif is_attribute_node(obj):
#         result = obj.value
#     elif is_text_node(obj):
#         result = str(obj)
#     else:
#         raise RuntimeError("don't know how to derive test from {0}".format(debug_dump_node(obj)))
# 
#     if not preserve_space:
#         result = re.sub(u'\u00a0', ' ', result)
#         result = re.sub(r'\s+', ' ', result).strip()
# 
#     return result
# 
# def is_root_node(obj):
#     return obj.__class__.__name__ == 'BeautifulSoup'


from builtins import str
from .hquery.object_type import is_sequence
from .soup_util import is_text_node, is_attribute_node, is_comment_node, is_tag_node, derive_text_from_node, \
    is_root_node



def convert_results_to_output_text(results, pretty=True, preserve_space=False):
    if is_sequence(results):
        return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
    else:
        return value_object_to_text(results, pretty, preserve_space)


def value_object_to_text(obj, pretty, preserve_space):
    if is_comment_node(obj):
        return u'<!-- {0} -->'.format(str(obj).strip())

# Path: hq/hquery/object_type.py
# def is_sequence(obj):
#     return isinstance(obj, list)
# 
# Path: hq/soup_util.py
# def is_text_node(obj):
#     return obj.__class__.__name__ == 'NavigableString'
# 
# def is_attribute_node(obj):
#     return isinstance(obj, AttributeNode)
# 
# def is_comment_node(obj):
#     return obj.__class__.__name__ == 'Comment'
# 
# def is_tag_node(obj):
#     return obj.__class__.__name__ == 'Tag'
# 
# def derive_text_from_node(obj, preserve_space=False):
#     if is_tag_node(obj) or is_root_node(obj):
#         result = u''
#         strings = list(obj.strings)
#         cursor = 0
#         for run in (strings if preserve_space else obj.stripped_strings):
#             if preserve_space:
#                 add_space = False
#             else:
#                 while cursor < len(strings):
#                     if run in strings[cursor]:
#                         break
#                     else:
#                         cursor += 1
#                 if cursor < len(strings):
#                     add_space = strings[cursor][0].isspace() or (cursor > 0 and strings[cursor - 1][-1].isspace())
#                 else:
#                     add_space = False
#             result += u'{0}{1}'.format(' ' if add_space else '', run)
#     elif is_attribute_node(obj):
#         result = obj.value
#     elif is_text_node(obj):
#         result = str(obj)
#     else:
#         raise RuntimeError("don't know how to derive test from {0}".format(debug_dump_node(obj)))
# 
#     if not preserve_space:
#         result = re.sub(u'\u00a0', ' ', result)
#         result = re.sub(r'\s+', ' ', result).strip()
# 
#     return result
# 
# def is_root_node(obj):
#     return obj.__class__.__name__ == 'BeautifulSoup'


# Path: hq/output.py
from builtins import str
from .hquery.object_type import is_sequence
from .soup_util import is_text_node, is_attribute_node, is_comment_node, is_tag_node, derive_text_from_node, \
    is_root_node




def convert_results_to_output_text(results, pretty=True, preserve_space=False):
    if is_sequence(results):
        return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
    else:
        return value_object_to_text(results, pretty, preserve_space)


def value_object_to_text(obj, pretty, preserve_space):
    if is_comment_node(obj):
        return u'<!-- {0} -->'.format(str(obj).strip())

    elif is_tag_node(obj) or is_root_node(obj):