# Path: src/eutils/_internal/utils.py
# def xml_get_text_or_none(node, xpath):
#     try:
#         return xml_get_text(node, xpath)
#     except IndexError:    # xpath search found 0 matches
#         return None
# 
# Path: src/eutils/_internal/xmlfacades/base.py
# class Base(object):
#     """Root class for all xmlfacade classes.
# 
#     This class is instantiated only by subclasses.
# 
#     xmlfacades must be instantiated with an XML document, passed
#     either as XML text or as the root of a parsed XML document.
# 
#     _root_tag must be defined by the subclass. It is used to validate
#     the node type upon instantiation of the subclass.
# 
#     """
# 
#     _root_tag = None
# 
#     def __init__(self, xml):
#         if isinstance(xml, lxml.etree._Element):
#             self._xml_root = xml
#         elif isinstance(xml, str) or isinstance(xml, bytes):
#             self._xml_root = lxml.etree.XML(xml)
#         else:
#             raise EutilsError("Cannot create object from type " + type(xml).__name__)
# 
#         if self._root_tag is None:
#             raise EutilsError("_root_tag not defined for class {}".format(type(self).__name__))
#         elif self._root_tag != self._xml_root.tag:
#             raise EutilsError("XML for {} object must be a {} element (got {})".format(
#                 type(self).__name__, self._root_tag, self._xml_root.tag))
# 
# Path: src/eutils/_internal/xmlfacades/medlinecitation.py
# class MedlineCitation(Base):
# 
#     _root_tag = "MedlineCitation"
# 
#     @property
#     def abstract(self):
#         # return self._xml_root.findtext("Article/Abstract/AbstractText")
#         return " ".join(["".join(at.itertext()) for at in self._xml_root.findall('Article/Abstract/AbstractText')])
# 
#     @property
#     def authors(self):
#         # N.B. Citations may have 0 authors. e.g., pmid:7550356
#         # Citations may also have a "CollectiveName" author instead of one with a forename, lastname, and initials
#         def _format_author(au):
#             if au.find("CollectiveName") is not None:
#                 return au.find("CollectiveName").text
#             elif au.find("LastName") is not None and au.find("Initials") is not None:
#                 return au.find("LastName").text + " " + au.find("Initials").text
#             else:
#                 return au.find("LastName").text
# 
#         return [_format_author(au) for au in self._xml_root.xpath("Article/AuthorList/Author")]
# 
#     @property
#     def chemicals(self):
#         return self._xml_root.xpath("ChemicalList/Chemical/NameOfSubstance/text()")
# 
#     @property
#     def issue(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/Issue")
# 
#     @property
#     def jrnl(self):
#         return self._xml_root.findtext("Article/Journal/ISOAbbreviation") or self._xml_root.findtext(
#             "Article/Journal/Title")
# 
#     @property
#     def mesh_headings(self):
#         return self._xml_root.xpath("MeshHeadingList/MeshHeading/DescriptorName/text()")
# 
#     @property
#     def mesh_qualifiers(self):
#         return self._xml_root.xpath("MeshHeadingList/MeshHeading/QualifierName/text()")
# 
#     @property
#     def pages(self):
#         return self._xml_root.findtext("Article/Pagination/MedlinePgn")
# 
#     @property
#     def pmid(self):
#         return self._xml_root.findtext("PMID")
# 
#     @property
#     def pub_types(self):
#         return self._xml_root.xpath("Article/PublicationTypeList/PublicationType/text()")
# 
#     @property
#     def title(self):
#         return self._xml_root.findtext("Article/ArticleTitle")
# 
#     @property
#     def volume(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/Volume")
# 
#     @property
#     def year(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/Year") \
#           or self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/Year") \
#           or self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/MedlineDate")


from ..utils import xml_get_text_or_none
from .base import Base
from .medlinecitation import MedlineCitation
    from .xmlfacades.pubmedarticleset import PubmedArticleSet
    import lxml.etree as le
    import os
    @property
    def pmid(self):
        return self._medline_citation.pmid

    @property
    def pub_types(self):
        return self._medline_citation.pub_types

    @property
    def title(self):
        return self._medline_citation.title

    @property
    def volume(self):
        return self._medline_citation.volume

    @property
    def year(self):
        return self._medline_citation.year

    @property
    def doi(self):
        return xml_get_text_or_none(self._xml_root, 'PubmedData/ArticleIdList/ArticleId[@IdType="doi"]')

    @property
    def pii(self):
        return xml_get_text_or_none(self._xml_root, 'PubmedData/ArticleIdList/ArticleId[@IdType="pii"]')

    @property
    def pmc(self):

# Path: src/eutils/_internal/utils.py
# def xml_get_text_or_none(node, xpath):
#     try:
#         return xml_get_text(node, xpath)
#     except IndexError:    # xpath search found 0 matches
#         return None
# 
# Path: src/eutils/_internal/xmlfacades/base.py
# class Base(object):
#     """Root class for all xmlfacade classes.
# 
#     This class is instantiated only by subclasses.
# 
#     xmlfacades must be instantiated with an XML document, passed
#     either as XML text or as the root of a parsed XML document.
# 
#     _root_tag must be defined by the subclass. It is used to validate
#     the node type upon instantiation of the subclass.
# 
#     """
# 
#     _root_tag = None
# 
#     def __init__(self, xml):
#         if isinstance(xml, lxml.etree._Element):
#             self._xml_root = xml
#         elif isinstance(xml, str) or isinstance(xml, bytes):
#             self._xml_root = lxml.etree.XML(xml)
#         else:
#             raise EutilsError("Cannot create object from type " + type(xml).__name__)
# 
#         if self._root_tag is None:
#             raise EutilsError("_root_tag not defined for class {}".format(type(self).__name__))
#         elif self._root_tag != self._xml_root.tag:
#             raise EutilsError("XML for {} object must be a {} element (got {})".format(
#                 type(self).__name__, self._root_tag, self._xml_root.tag))
# 
# Path: src/eutils/_internal/xmlfacades/medlinecitation.py
# class MedlineCitation(Base):
# 
#     _root_tag = "MedlineCitation"
# 
#     @property
#     def abstract(self):
#         # return self._xml_root.findtext("Article/Abstract/AbstractText")
#         return " ".join(["".join(at.itertext()) for at in self._xml_root.findall('Article/Abstract/AbstractText')])
# 
#     @property
#     def authors(self):
#         # N.B. Citations may have 0 authors. e.g., pmid:7550356
#         # Citations may also have a "CollectiveName" author instead of one with a forename, lastname, and initials
#         def _format_author(au):
#             if au.find("CollectiveName") is not None:
#                 return au.find("CollectiveName").text
#             elif au.find("LastName") is not None and au.find("Initials") is not None:
#                 return au.find("LastName").text + " " + au.find("Initials").text
#             else:
#                 return au.find("LastName").text
# 
#         return [_format_author(au) for au in self._xml_root.xpath("Article/AuthorList/Author")]
# 
#     @property
#     def chemicals(self):
#         return self._xml_root.xpath("ChemicalList/Chemical/NameOfSubstance/text()")
# 
#     @property
#     def issue(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/Issue")
# 
#     @property
#     def jrnl(self):
#         return self._xml_root.findtext("Article/Journal/ISOAbbreviation") or self._xml_root.findtext(
#             "Article/Journal/Title")
# 
#     @property
#     def mesh_headings(self):
#         return self._xml_root.xpath("MeshHeadingList/MeshHeading/DescriptorName/text()")
# 
#     @property
#     def mesh_qualifiers(self):
#         return self._xml_root.xpath("MeshHeadingList/MeshHeading/QualifierName/text()")
# 
#     @property
#     def pages(self):
#         return self._xml_root.findtext("Article/Pagination/MedlinePgn")
# 
#     @property
#     def pmid(self):
#         return self._xml_root.findtext("PMID")
# 
#     @property
#     def pub_types(self):
#         return self._xml_root.xpath("Article/PublicationTypeList/PublicationType/text()")
# 
#     @property
#     def title(self):
#         return self._xml_root.findtext("Article/ArticleTitle")
# 
#     @property
#     def volume(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/Volume")
# 
#     @property
#     def year(self):
#         return self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/Year") \
#           or self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/Year") \
#           or self._xml_root.findtext("Article/Journal/JournalIssue/PubDate/MedlineDate")


# Path: src/eutils/_internal/xmlfacades/pubmedarticle.py
from ..utils import xml_get_text_or_none
from .base import Base
from .medlinecitation import MedlineCitation
    from .xmlfacades.pubmedarticleset import PubmedArticleSet
    import lxml.etree as le
    import os

    @property
    def pmid(self):
        return self._medline_citation.pmid

    @property
    def pub_types(self):
        return self._medline_citation.pub_types

    @property
    def title(self):
        return self._medline_citation.title

    @property
    def volume(self):
        return self._medline_citation.volume

    @property
    def year(self):
        return self._medline_citation.year

    @property
    def doi(self):
        return xml_get_text_or_none(self._xml_root, 'PubmedData/ArticleIdList/ArticleId[@IdType="doi"]')

    @property
    def pii(self):
        return xml_get_text_or_none(self._xml_root, 'PubmedData/ArticleIdList/ArticleId[@IdType="pii"]')

    @property
    def pmc(self):

        pmc = xml_get_text_or_none(self._xml_root, 'PubmedData/ArticleIdList/ArticleId[@IdType="pmc"]')