# Path: chemdataextractor/utils.py
# def flatten(x):
#     """Return a single flat list containing elements from nested lists."""
#     result = []
#     for el in x:
#         if hasattr(el, '__iter__') and not isinstance(el, six.string_types):
#             result.extend(flatten(el))
#         else:
#             result.append(el)
#     return result
# 
# Path: chemdataextractor/scrape/csstranslator.py
# class CssHTMLTranslator(TranslatorMixin, HTMLTranslator):
#     pass
# 
# class CssXmlTranslator(TranslatorMixin, GenericTranslator):
#     pass


from collections import Sequence
from copy import deepcopy
from bs4 import UnicodeDammit
from lxml.etree import XMLParser, fromstring, tostring
from lxml.html import HTMLParser
from ..utils import flatten
from .csstranslator import CssHTMLTranslator, CssXmlTranslator
import logging
import re
import six
        if namespaces is not None:
            self.namespaces.update(namespaces)

    def __eq__(self, other):
        if isinstance(other, Selector):
            return self._root == other._root
        return NotImplemented

    @classmethod
    def from_text(cls, text, base_url=None, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=None, encoding=None):
        log.debug('Parsing {} with {}'.format(fmt, parser))
        root = fromstring(text, parser=parser(recover=True, encoding=cls._get_encoding(text, encoding)), base_url=base_url)
        if base_url and hasattr(root, 'make_links_absolute'):
            root.make_links_absolute()
        return cls(root, translator=translator, fmt=fmt, namespaces=namespaces)

    @classmethod
    def from_html_text(cls, text, base_url=None, namespaces=None, encoding=None):
        return cls.from_text(text, base_url=base_url, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=namespaces, encoding=encoding)

    @classmethod
    def from_xml_text(cls, text, base_url=None, namespaces=None, encoding=None):
        return cls.from_text(text, base_url=base_url, parser=XMLParser, translator=CssXmlTranslator, fmt='xml', namespaces=namespaces, encoding=encoding)

    @classmethod
    def from_response(cls, response, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=None):
        return cls.from_text(response.content, response.url, parser, translator, fmt, namespaces=namespaces, encoding=response.encoding)

    @classmethod
    def from_html(cls, response, namespaces=None):

# Path: chemdataextractor/utils.py
# def flatten(x):
#     """Return a single flat list containing elements from nested lists."""
#     result = []
#     for el in x:
#         if hasattr(el, '__iter__') and not isinstance(el, six.string_types):
#             result.extend(flatten(el))
#         else:
#             result.append(el)
#     return result
# 
# Path: chemdataextractor/scrape/csstranslator.py
# class CssHTMLTranslator(TranslatorMixin, HTMLTranslator):
#     pass
# 
# class CssXmlTranslator(TranslatorMixin, GenericTranslator):
#     pass


# Path: chemdataextractor/scrape/selector.py
from collections import Sequence
from copy import deepcopy
from bs4 import UnicodeDammit
from lxml.etree import XMLParser, fromstring, tostring
from lxml.html import HTMLParser
from ..utils import flatten
from .csstranslator import CssHTMLTranslator, CssXmlTranslator
import logging
import re
import six

        if namespaces is not None:
            self.namespaces.update(namespaces)

    def __eq__(self, other):
        if isinstance(other, Selector):
            return self._root == other._root
        return NotImplemented

    @classmethod
    def from_text(cls, text, base_url=None, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=None, encoding=None):
        log.debug('Parsing {} with {}'.format(fmt, parser))
        root = fromstring(text, parser=parser(recover=True, encoding=cls._get_encoding(text, encoding)), base_url=base_url)
        if base_url and hasattr(root, 'make_links_absolute'):
            root.make_links_absolute()
        return cls(root, translator=translator, fmt=fmt, namespaces=namespaces)

    @classmethod
    def from_html_text(cls, text, base_url=None, namespaces=None, encoding=None):
        return cls.from_text(text, base_url=base_url, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=namespaces, encoding=encoding)

    @classmethod
    def from_xml_text(cls, text, base_url=None, namespaces=None, encoding=None):
        return cls.from_text(text, base_url=base_url, parser=XMLParser, translator=CssXmlTranslator, fmt='xml', namespaces=namespaces, encoding=encoding)

    @classmethod
    def from_response(cls, response, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=None):
        return cls.from_text(response.content, response.url, parser, translator, fmt, namespaces=namespaces, encoding=response.encoding)

    @classmethod
    def from_html(cls, response, namespaces=None):

        return cls.from_response(response, parser=HTMLParser, translator=CssHTMLTranslator, fmt='html', namespaces=namespaces)