# Path: spdx/writers/json.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/yaml.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/rdf.py
# class BaseWriter(object):
# class LicenseWriter(BaseWriter):
# class FileWriter(LicenseWriter):
# class SnippetWriter(LicenseWriter):
# class ReviewInfoWriter(BaseWriter):
# class AnnotationInfoWriter(BaseWriter):
# class RelationshipInfoWriter(BaseWriter):
# class CreationInfoWriter(BaseWriter):
# class ExternalDocumentRefWriter(BaseWriter):
# class PackageWriter(LicenseWriter):
# class PackageExternalRefWriter(BaseWriter):
# class Writer(
#     CreationInfoWriter,
#     ReviewInfoWriter,
#     FileWriter,
#     PackageWriter,
#     PackageExternalRefWriter,
#     ExternalDocumentRefWriter,
#     AnnotationInfoWriter,
#     RelationshipInfoWriter,
#     SnippetWriter,
# ):
#     def __init__(self, document, out):
#     def create_checksum_node(self, chksum):
#     def to_special_value(self, value):
#     def __init__(self, document, out):
#     def licenses_from_tree_helper(self, current, licenses):
#     def licenses_from_tree(self, tree):
#     def create_conjunction_node(self, conjunction):
#     def create_disjunction_node(self, disjunction):
#     def create_license_helper(self, lic):
#     def create_extracted_license(self, lic):
#     def create_license_node(self, lic):
#     def license_or_special(self, lic):
#     def __init__(self, document, out):
#     def create_file_node(self, doc_file):
#     def files(self):
#     def add_file_dependencies_helper(self, doc_file):
#     def add_file_dependencies(self):
#     def __init__(self, document, out):
#     def create_snippet_node(self, snippet):
#     def snippets(self):
#     def __init__(self, document, out):
#     def create_review_node(self, review):
#     def reviews(self):
#     def __init__(self, document, out):
#     def create_annotation_node(self, annotation):
#     def annotations(self):
#     def __init__(self, document, out):
#     def create_relationship_node(self, relationship):
#     def relationships(self):
#     def __init__(self, document, out):
#     def creators(self):
#     def create_creation_info(self):
#     def __init__(self, document, out):
#     def create_external_document_ref_node(self, ext_document_references):
#     def ext_doc_refs(self):
#     def __init__(self, document, out):
#     def package_verif_node(self, package):
#     def handle_package_literal_optional(self, package, package_node, predicate, field):
#     def handle_pkg_optional_fields(self, package, package_node):
#     def create_package_node(self, package):
#     def packages(self):
#     def handle_package_has_file_helper(self, pkg_file):
#     def handle_package_has_file(self, package, package_node):
#     def __init__(self, document, out):
#     def create_package_external_ref_node(self, pkg_ext_refs):
#     def pkg_ext_refs(self):
#     def __init__(self, document, out):
#     def create_doc(self):
#     def write(self):
# def write_document(document, out, validate=True):
#     FILE_TYPES = {
#         file.FileType.SOURCE: "fileType_source",
#         file.FileType.OTHER: "fileType_other",
#         file.FileType.BINARY: "fileType_binary",
#         file.FileType.ARCHIVE: "fileType_archive",
#     }
# 
# Path: spdx/writers/xml.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/tagvalue.py
# class InvalidDocumentError(Exception):
# def write_separators(out):
# def format_verif_code(package):
# def write_value(tag, value, out):
# def write_text_value(tag, value, out):
# def write_creation_info(creation_info, out):
# def write_review(review, out):
# def write_annotation(annotation, out):
# def write_relationship(relationship_term, out):
# def write_file_type(ftype, out):
# def write_file(spdx_file, out):
# def write_snippet(snippet, out):
# def write_package(package, out):
# def write_extracted_licenses(lics, out):
# def write_document(document, out, validate=True):
#     VALUES = {
#         spdx_file.FileType.SOURCE: "SOURCE",
#         spdx_file.FileType.OTHER: "OTHER",
#         spdx_file.FileType.BINARY: "BINARY",
#         spdx_file.FileType.ARCHIVE: "ARCHIVE",
#     }
# 
# Path: spdx/parsers/builderexceptions.py
# class FileTypeError(BuilderException):
#     def __init__(self,msg):
#         self.msg = msg


from spdx.writers import json
from spdx.writers import yaml
from spdx.writers import rdf
from spdx.writers import xml
from spdx.writers import tagvalue
from spdx.parsers.builderexceptions import FileTypeError
# Copyright (c) spdx contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




def write_file(doc, fn):
    out_mode = "w"
    if fn.endswith(".rdf") or fn.endswith(".rdf.xml") or fn.endswith(".spdx"):
        writer_module = rdf
        out_mode = "wb"
    elif fn.endswith(".tag"):
        writer_module = tagvalue
    elif fn.endswith(".json"):
        writer_module = json

# Path: spdx/writers/json.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/yaml.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/rdf.py
# class BaseWriter(object):
# class LicenseWriter(BaseWriter):
# class FileWriter(LicenseWriter):
# class SnippetWriter(LicenseWriter):
# class ReviewInfoWriter(BaseWriter):
# class AnnotationInfoWriter(BaseWriter):
# class RelationshipInfoWriter(BaseWriter):
# class CreationInfoWriter(BaseWriter):
# class ExternalDocumentRefWriter(BaseWriter):
# class PackageWriter(LicenseWriter):
# class PackageExternalRefWriter(BaseWriter):
# class Writer(
#     CreationInfoWriter,
#     ReviewInfoWriter,
#     FileWriter,
#     PackageWriter,
#     PackageExternalRefWriter,
#     ExternalDocumentRefWriter,
#     AnnotationInfoWriter,
#     RelationshipInfoWriter,
#     SnippetWriter,
# ):
#     def __init__(self, document, out):
#     def create_checksum_node(self, chksum):
#     def to_special_value(self, value):
#     def __init__(self, document, out):
#     def licenses_from_tree_helper(self, current, licenses):
#     def licenses_from_tree(self, tree):
#     def create_conjunction_node(self, conjunction):
#     def create_disjunction_node(self, disjunction):
#     def create_license_helper(self, lic):
#     def create_extracted_license(self, lic):
#     def create_license_node(self, lic):
#     def license_or_special(self, lic):
#     def __init__(self, document, out):
#     def create_file_node(self, doc_file):
#     def files(self):
#     def add_file_dependencies_helper(self, doc_file):
#     def add_file_dependencies(self):
#     def __init__(self, document, out):
#     def create_snippet_node(self, snippet):
#     def snippets(self):
#     def __init__(self, document, out):
#     def create_review_node(self, review):
#     def reviews(self):
#     def __init__(self, document, out):
#     def create_annotation_node(self, annotation):
#     def annotations(self):
#     def __init__(self, document, out):
#     def create_relationship_node(self, relationship):
#     def relationships(self):
#     def __init__(self, document, out):
#     def creators(self):
#     def create_creation_info(self):
#     def __init__(self, document, out):
#     def create_external_document_ref_node(self, ext_document_references):
#     def ext_doc_refs(self):
#     def __init__(self, document, out):
#     def package_verif_node(self, package):
#     def handle_package_literal_optional(self, package, package_node, predicate, field):
#     def handle_pkg_optional_fields(self, package, package_node):
#     def create_package_node(self, package):
#     def packages(self):
#     def handle_package_has_file_helper(self, pkg_file):
#     def handle_package_has_file(self, package, package_node):
#     def __init__(self, document, out):
#     def create_package_external_ref_node(self, pkg_ext_refs):
#     def pkg_ext_refs(self):
#     def __init__(self, document, out):
#     def create_doc(self):
#     def write(self):
# def write_document(document, out, validate=True):
#     FILE_TYPES = {
#         file.FileType.SOURCE: "fileType_source",
#         file.FileType.OTHER: "fileType_other",
#         file.FileType.BINARY: "fileType_binary",
#         file.FileType.ARCHIVE: "fileType_archive",
#     }
# 
# Path: spdx/writers/xml.py
# def write_document(document, out, validate=True):
# 
# Path: spdx/writers/tagvalue.py
# class InvalidDocumentError(Exception):
# def write_separators(out):
# def format_verif_code(package):
# def write_value(tag, value, out):
# def write_text_value(tag, value, out):
# def write_creation_info(creation_info, out):
# def write_review(review, out):
# def write_annotation(annotation, out):
# def write_relationship(relationship_term, out):
# def write_file_type(ftype, out):
# def write_file(spdx_file, out):
# def write_snippet(snippet, out):
# def write_package(package, out):
# def write_extracted_licenses(lics, out):
# def write_document(document, out, validate=True):
#     VALUES = {
#         spdx_file.FileType.SOURCE: "SOURCE",
#         spdx_file.FileType.OTHER: "OTHER",
#         spdx_file.FileType.BINARY: "BINARY",
#         spdx_file.FileType.ARCHIVE: "ARCHIVE",
#     }
# 
# Path: spdx/parsers/builderexceptions.py
# class FileTypeError(BuilderException):
#     def __init__(self,msg):
#         self.msg = msg


# Path: spdx/writers/write_anything.py
from spdx.writers import json
from spdx.writers import yaml
from spdx.writers import rdf
from spdx.writers import xml
from spdx.writers import tagvalue
from spdx.parsers.builderexceptions import FileTypeError

# Copyright (c) spdx contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.




def write_file(doc, fn):
    out_mode = "w"
    if fn.endswith(".rdf") or fn.endswith(".rdf.xml") or fn.endswith(".spdx"):
        writer_module = rdf
        out_mode = "wb"
    elif fn.endswith(".tag"):
        writer_module = tagvalue
    elif fn.endswith(".json"):
        writer_module = json

    elif fn.endswith(".xml"):