class ExternalDocumentRef(object):
class License(object):
class LicenseConjunction(License):
class LicenseDisjunction(License):
class ExtractedLicense(License):
class Document(object):
    def __init__(
        self, external_document_id=None, spdx_document_uri=None, check_sum=None
    ):
    def __eq__(self, other):
    def __lt__(self, other):
    def validate(self, messages):
    def validate_ext_doc_id(self, messages):
    def validate_spdx_doc_uri(self, messages):
    def validate_checksum(self, messages):
def _add_parens(required, text):
    def __init__(self, full_name, identifier):
    def from_identifier(cls, identifier):
    def from_full_name(cls, full_name):
    def url(self):
    def full_name(self):
    def full_name(self, value):
    def set_full_name(self, value):
    def identifier(self):
    def identifier(self, value):
    def set_identifier(self, value):
    def __eq__(self, other):
    def __lt__(self, other):
    def __str__(self):
    def __hash__(self):
    def __init__(self, license_1, license_2):
    def full_name(self):
    def identifier(self):
    def __init__(self, license_1, license_2):
    def full_name(self):
    def identifier(self):
    def __init__(self, identifier):
    def __eq__(self, other):
    def __lt__(self, other):
    def add_xref(self, ref):
    def validate(self, messages):
    def __init__(
        self,
        version=None,
        data_license=None,
        name=None,
        spdx_id=None,
        namespace=None,
        comment=None,
        package=None,
        license_list_version=None,
    ):
    def add_review(self, review):
    def add_annotation(self, annotation):
    def add_relationships(self, relationship):
    def add_extr_lic(self, lic):
    def add_ext_document_reference(self, ext_doc_ref):
    def add_snippet(self, snip):
    def add_package(self, package):
    def package(self):
    def package(self, value):
    def files(self):
    def files(self, value):
    def has_comment(self):
    def validate(self, messages=None):
    def validate_version(self, messages):
    def validate_data_lics(self, messages):
    def validate_name(self, messages):
    def validate_namespace(self, messages):
    def validate_spdx_id(self, messages):
    def validate_ext_document_references(self, messages):
    def validate_reviews(self, messages):
    def validate_annotations(self, messages):
    def validate_relationships(self, messages):
    def validate_snippet(self, messages=None):
    def validate_creation_info(self, messages):
    def validate_packages(self, messages):
    def validate_package(self, messages):
    def validate_extracted_licenses(self, messages): class LicenseConjunction(License):
    """
    A conjunction of two licenses.
    """

    def __init__(self, license_1, license_2):
        self.license_1 = license_1
        self.license_2 = license_2
        super(LicenseConjunction, self).__init__(self.full_name, self.identifier)

    @property
    def full_name(self):
        license_1_complex = type(self.license_1) == LicenseDisjunction
        license_2_complex = type(self.license_2) == LicenseDisjunction

        return "{0} AND {1}".format(
            _add_parens(license_1_complex, self.license_1.full_name),
            _add_parens(license_2_complex, self.license_2.full_name),
        )

    @property
    def identifier(self):
        license_1_complex = type(self.license_1) == LicenseDisjunction
        license_2_complex = type(self.license_2) == LicenseDisjunction

        return "{0} AND {1}".format(
            _add_parens(license_1_complex, self.license_1.identifier),
            _add_parens(license_2_complex, self.license_2.identifier),
        ) class LicenseDisjunction(License):
    """
    A disjunction of two licenses.
    """

    def __init__(self, license_1, license_2):
        self.license_1 = license_1
        self.license_2 = license_2
        super(LicenseDisjunction, self).__init__(self.full_name, self.identifier)

    @property
    def full_name(self):
        license_1_complex = type(self.license_1) == LicenseConjunction
        license_2_complex = type(self.license_2) == LicenseConjunction

        return "{0} OR {1}".format(
            _add_parens(license_1_complex, self.license_1.full_name),
            _add_parens(license_2_complex, self.license_2.full_name),
        )

    @property
    def identifier(self):
        license_1_complex = type(self.license_1) == LicenseConjunction
        license_2_complex = type(self.license_2) == LicenseConjunction

        return "{0} OR {1}".format(
            _add_parens(license_1_complex, self.license_1.identifier),
            _add_parens(license_2_complex, self.license_2.identifier),
        ) class SPDXValueError(BuilderException):
    def __init__(self, msg):
        self.msg = msg class CardinalityError(BuilderException):
    def __init__(self, msg):
        self.msg = msg class OrderError(BuilderException):
    def __init__(self, msg):
        self.msg = msg ERROR_MESSAGES = {
    "DOC_VERS_VALUE": "Invalid specVersion '{0}' must be SPDX-M.N where M and N are numbers.",
    "DOC_D_LICS": "Invalid dataLicense '{0}' must be http://spdx.org/licenses/CC0-1.0.",
    "DOC_SPDX_ID_VALUE": "Invalid SPDXID value, SPDXID must be the document namespace appended "
    'by "#SPDXRef-DOCUMENT", line: {0}',
    "DOC_NAMESPACE_VALUE": 'Invalid DocumentNamespace value {0}, must contain a scheme (e.g. "https:") '
    'and should not contain the "#" delimiter.',
    "LL_VALUE": "Invalid licenseListVersion '{0}' must be of the format N.N where N is a number",
    "CREATED_VALUE": "Invalid created value '{0}' must be date in ISO 8601 format.",
    "CREATOR_VALUE": "Invalid creator value '{0}' must be Organization, Tool or Person.",
    "EXT_DOC_REF_VALUE": "Failed to extract {0} from ExternalDocumentRef.",
    "PKG_SPDX_ID_VALUE": 'SPDXID must be "SPDXRef-[idstring]" where [idstring] is a unique string containing '
    'letters, numbers, ".", "-".',
    "PKG_SUPPL_VALUE": "Invalid package supplier value '{0}' must be Organization, Person or NOASSERTION.",
    "PKG_ORIGINATOR_VALUE": "Invalid package supplier value '{0}'  must be Organization, Person or NOASSERTION.",
    "PKG_DOWN_LOC": "Invalid package download location value '{0}'  must be a url or NONE or NOASSERTION",
    "PKG_FILES_ANALYZED_VALUE": "FilesAnalyzed must be a boolean value, line: {0}",
    "PKG_CONC_LIST": "Package concluded license list must have more than one member",
    "LICS_LIST_MEMBER": "Declaritive or Conjunctive license set member must be a license url or identifier",
    "PKG_SINGLE_LICS": "Package concluded license must be a license url or spdx:noassertion or spdx:none.",
    "PKG_LICS_INFO_FILES": "Package licenseInfoFromFiles must be a license or spdx:none or spdx:noassertion",
    "FILE_SPDX_ID_VALUE": 'SPDXID must be "SPDXRef-[idstring]" where [idstring] is a unique string containing '
    'letters, numbers, ".", "-".',
    "PKG_EXT_REF_CATEGORY": '\'{0}\' must be "SECURITY", "PACKAGE-MANAGER", or "OTHER".',
    "PKG_EXT_REF_TYPE": '{0} must be a unique string containing letters, numbers, ".", or "-".',
    "FILE_TYPE": "File type must be binary, other, source or archive term.",
    "FILE_SINGLE_LICS": "File concluded license must be a license url or spdx:noassertion or spdx:none.",
    "REVIEWER_VALUE": "Invalid reviewer value '{0}' must be Organization, Tool or Person.",
    "REVIEW_DATE": "Invalid review date value '{0}' must be date in ISO 8601 format.",
    "ANNOTATOR_VALUE": "Invalid annotator value '{0}' must be Organization, Tool or Person.",
    "ANNOTATION_DATE": "Invalid annotation date value '{0}' must be date in ISO 8601 format.",
    "SNIPPET_SPDX_ID_VALUE": 'SPDXID must be "SPDXRef-[idstring]" where [idstring] is a unique string '
    'containing letters, numbers, ".", "-".',
    "SNIPPET_SINGLE_LICS": "Snippet Concluded License must be a license url or spdx:noassertion or spdx:none.",
    "SNIPPET_LIC_INFO": "License Information in Snippet must be a license url or a reference "
    "to the license, denoted by LicenseRef-[idstring] or spdx:noassertion or spdx:none.",
    "RELATIONSHIP": "relationship type must be of supported type",
}
    LICS_REF_REGEX = re.compile("LicenseRef-.+", re.UNICODE)
class BaseParser(object):
class LicenseParser(BaseParser):
class PackageParser(LicenseParser):
class FileParser(LicenseParser):
class SnippetParser(LicenseParser):
class ReviewParser(BaseParser):
class AnnotationParser(BaseParser):
class RelationshipParser(BaseParser):
class Parser(
    PackageParser,
    FileParser,
    SnippetParser,
    ReviewParser,
    AnnotationParser,
    RelationshipParser,
):
    def __init__(self, builder, logger):
    def more_than_one_error(self, field):
    def value_error(self, key, bad_value):
    def to_special_value(self, value):
    def __init__(self, builder, logger):
    def handle_lics(self, lics):
    def get_extr_license_ident(self, extr_lic):
    def get_extr_license_text(self, extr_lic):
    def get_extr_lic_name(self, extr_lic):
    def get_extr_lics_xref(self, extr_lic):
    def get_extr_lics_comment(self, extr_lics):
    def parse_only_extr_license(self, extr_lic):
    def handle_extracted_license(self, extr_lic):
    def _handle_license_list(self, lics_set, cls=None):
    def handle_conjunctive_list(self, lics_set):
    def handle_disjunctive_list(self, lics_set):
    def __init__(self, builder, logger):
    def parse_package(self, p_term):
    def p_pkg_cr_text(self, p_term, predicate):
    def p_pkg_summary(self, p_term, predicate):
    def p_pkg_descr(self, p_term, predicate):
    def p_pkg_comment(self, p_term, predicate):
    def p_pkg_attribution_text(self, p_term, predicate):
    def p_pkg_comments_on_lics(self, p_term, predicate):
    def p_pkg_lics_info_from_files(self, p_term, predicate):
    def p_pkg_lic_decl(self, p_term, predicate):
    def handle_pkg_lic(self, p_term, predicate, builder_func):
    def p_pkg_lic_conc(self, p_term, predicate):
    def p_pkg_verif_code(self, p_term, predicate):
    def p_pkg_src_info(self, p_term, predicate):
    def p_pkg_chk_sum(self, p_term, predicate):
    def p_pkg_homepg(self, p_term, predicate):
    def p_pkg_down_loc(self, p_term, predicate):
    def p_pkg_files_analyzed(self, p_term, predicate):
    def p_pkg_originator(self, p_term, predicate):
    def p_pkg_suppl(self, p_term, predicate):
    def p_pkg_fname(self, p_term, predicate):
    def p_pkg_vinfo(self, p_term, predicate):
    def __init__(self, builder, logger):
    def parse_file(self, f_term):
    def get_file_name(self, f_term):
    def p_file_depends(self, f_term, predicate):
    def p_file_contributor(self, f_term, predicate):
    def p_file_notice(self, f_term, predicate):
    def p_file_comment(self, f_term, predicate):
    def p_file_attribution_text(self, f_term, predicate):
    def p_file_artifact(self, f_term, predicate):
    def p_file_project(self, project):
    def p_file_cr_text(self, f_term, predicate):
    def p_file_comments_on_lics(self, f_term, predicate):
    def p_file_lic_info(self, f_term, predicate):
    def p_file_spdx_id(self, f_term, predicate):
    def p_file_type(self, f_term, predicate):
    def p_file_chk_sum(self, f_term, predicate):
    def p_file_lic_conc(self, f_term, predicate):
    def __init__(self, builder, logger):
    def parse_snippet(self, snippet_term):
    def __init__(self, builder, logger):
    def parse_review(self, r_term):
    def get_review_comment(self, r_term):
    def get_review_date(self, r_term):
    def get_reviewer(self, r_term):
    def __init__(self, builder, logger):
    def parse_annotation(self, r_term):
    def get_annotation_type(self, r_term):
    def get_annotation_comment(self, r_term):
    def get_annotation_date(self, r_term):
    def get_annotator(self, r_term):
    def __init__(self, builder, logger):
    def parse_relationship(self, subject_term, relation_term):
    def get_relationship(self, subject_term, relation_term):
    def get_relationship_comment(self, relation_term):
    def __init__(self, builder, logger):
    def parse(self, fil):
    def parse_creation_info(self, ci_term):
    def parse_doc_fields(self, doc_term):
    def parse_ext_doc_ref(self, ext_doc_ref_term):
    def parse_pkg_ext_ref(self, pkg_ext_term): class ErrorMessages:

    def __init__(self):
        self.messages = []
        self.context = []
    
    def push_context(self, context):
        """push some context information to better indentify where is the problem"""
        self.context.append(context)

    def pop_context(self):
        """pop the last context information"""
        self.context.pop()
    
    def append(self, message, *args, **kwargs):
        """add a message with standard python format
        the current context is prefixed to the message
        """
        message = message.format(*args, **kwargs)
        message = "".join([c + ": " for c in self.context if c]) + message
        self.messages.append(message)

    def __iter__(self):
        return self.messages.__iter__()

    def __bool__(self):
        return len(self.messages)>0

    def __nonzero__(self):
        return len(self.messages)>0
    
    def __eq__(self, b):
        if isinstance(b, ErrorMessages):
            return self.messages == b.messages
        return self.messages == b def datetime_iso_format(date):
def datetime_from_iso_format(string):
    def to_value(self):
    def __str__(self):
    def to_value(self):
    def __str__(self):
    def __repr__(self):
    def __eq__(self, other):
    def to_value(self):
    def __str__(self):
    def t_LP(self, t):
    def t_RP(self, t):
    def t_AND(self, t):
    def t_OR(self, t):
    def t_whitespace(self, t):
    def t_LICENSE(self, t):
    def t_error(self, t):
    def input(self, data):
    def token(self):
    def build(self, **kwargs):
    def __init__(self):
    def p_disjunction_1(self, p):
    def p_disjunction_2(self, p):
    def p_conjunction_1(self, p):
    def p_conjunction_2(self, p):
    def p_license_atom_1(self, p):
    def p_license_atom_2(self, p):
    def p_error(self, p):
    def build(self, **kwargs):
    def parse(self, data):
DATE_ISO_REGEX = re.compile(
    r"(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z", re.UNICODE
)
DATE_ISO_YEAR_GRP = 1
DATE_ISO_MONTH_GRP = 2
DATE_ISO_DAY_GRP = 3
DATE_ISO_HOUR_GRP = 4
DATE_ISO_MIN_GRP = 5
DATE_ISO_SEC_GRP = 6
class NoAssert(object):
class UnKnown(object):
class SPDXNone(object):
class LicenseListLexer(object):
class LicenseListParser(object): class UnKnown(object):
    """
    Represent SPDX UNKNOWN value.
    """

    def to_value(self):
        return "UNKNOWN"

    def __str__(self):
        return self.to_value()

    def __repr__(self):
        return self.to_value()

    def __eq__(self, other):
        return self.to_value() == other.to_value()
from spdx import document
from spdx.document import LicenseConjunction
from spdx.document import LicenseDisjunction
from spdx.parsers.builderexceptions import SPDXValueError, CardinalityError, OrderError
from spdx.parsers import rdf
from spdx.parsers.loggers import ErrorMessages
from spdx import utils
from spdx.utils import UnKnown
        """
        if isinstance(file_type, str):
            try:
                return self.builder.set_file_type(self.document, file_type)
            except SPDXValueError:
                self.value_error("FILE_TYPE", file_type)
            except CardinalityError:
                self.more_than_one_error("FILE_TYPE")
            except OrderError:
                self.order_error("FILE_TYPE", "FILE_NAME")
        else:
            self.value_error("FILE_TYPE", file_type)

    def parse_file_concluded_license(self, concluded_license):
        """
        Parse File concluded license
        - concluded_license: Python str/unicode
        """
        if isinstance(concluded_license, str):
            lic_parser = utils.LicenseListParser()
            lic_parser.build(write_tables=0, debug=0)
            license_object = self.replace_license(lic_parser.parse(concluded_license))
            try:
                return self.builder.set_concluded_license(self.document, license_object)
            except SPDXValueError:
                self.value_error("FILE_SINGLE_LICS", concluded_license)
            except CardinalityError:
                self.more_than_one_error("FILE_SINGLE_LICS")
            except OrderError:
                self.order_error("FILE_SINGLE_LICS", "FILE_NAME")
        else:
            self.value_error("FILE_SINGLE_LICS", concluded_license)

    def parse_file_license_info_from_files(self, license_info_from_files):
        """
        Parse File license information from files
        - license_info_from_files: Python list of licenses information from files (str/unicode)
        """
        if isinstance(license_info_from_files, list):
            for license_info_from_file in license_info_from_files:
                if isinstance(license_info_from_file, str):
                    lic_parser = utils.LicenseListParser()
                    lic_parser.build(write_tables=0, debug=0)
                    license_object = self.replace_license(
                        lic_parser.parse(license_info_from_file)
                    )
                    try:
                        self.builder.set_file_license_in_file(
                            self.document, license_object
                        )
                    except SPDXValueError:
                        self.value_error("FILE_LIC_FRM_FILES", license_info_from_file)
                    except OrderError:
                        self.order_error("FILE_LIC_FRM_FILES", "FILE_NAME")
                else:
                    self.value_error("FILE_LIC_FRM_FILES", license_info_from_file)
        else:
            self.value_error("FILE_LIC_FRM_FILES_FIELD", license_info_from_files)

    def parse_file_license_comments(self, license_comments):
        """
        Parse File license comments
        - license_comments: Python str/unicode
        """
        if isinstance(license_comments, str):
            try:
                return self.builder.set_file_license_comment(
                    self.document, license_comments
                )
            except CardinalityError:
                self.more_than_one_error("FILE_LIC_COMMENTS")
            except OrderError:
                self.order_error("FILE_LIC_COMMENTS", "FILE_NAME")
        elif license_comments is not None:
            self.value_error("FILE_LIC_COMMENTS", license_comments)

    def parse_file_attribution_text(self, file_attribution_texts):
        """
        Parse File attribution texts
        - file_attribution_texts : list in yaml, json and string in xml format
        """
        if isinstance(file_attribution_texts, list) or isinstance(
            file_attribution_texts, str
        ):
            for file_attribution_text in file_attribution_texts:
                try:
                    return self.builder.set_file_attribution_text(
                        self.document, file_attribution_texts
                    )
                except CardinalityError:
                    self.more_than_one_error("FILE_ATTRIBUTION_TEXT")
                except OrderError:
                    self.order_error("FILE_ATTRIBUTION_TEXT", "FILE_NAME")
            else:
                self.value_error("FILE_ATTRIBUTION_TEXT", file_attribution_texts)

    def parse_file_copyright_text(self, copyright_text):
        """
        Parse File copyright text
        - copyright_text: Python str/unicode
        """
        if isinstance(copyright_text, str):
            try:
                return self.builder.set_file_copyright(self.document, copyright_text)
            except CardinalityError:
                self.more_than_one_error("FILE_COPYRIGHT_TEXT")
            except OrderError:
                self.order_error("FILE_COPYRIGHT_TEXT", "FILE_NAME")
        else:
            self.value_error("FILE_COPYRIGHT_TEXT", copyright_text)

    def parse_file_artifacts(self, file_artifacts):
        """
        Parse File artifacts
        - file_artifacts: Python list of dict('name':str/unicode, 'homePage':str/unicode, 'projectUri':str/unicode)
        """
        if isinstance(file_artifacts, list):
            for artifact in file_artifacts:
                if isinstance(artifact, dict):
                    self.builder.set_file_atrificat_of_project(

                        self.document, "name", artifact.get("name", UnKnown())