# Path: pubs/bibstruct.py
# TYPE_KEY = 'ENTRYTYPE'


import copy
import logging
import pyparsing
import bibtexparser
    import bibtexparser as bp
import yaml
from .bibstruct import TYPE_KEY
        def __init__(self, error_msg, bibdata):
            """
            :param error_msg: specific message about what went wrong
            :param bibdata:   the data that was unsuccessfully decoded.
            """
            super(Exception, self).__init__(error_msg)  # make `str(self)` work.
            self.data = bibdata

    bwriter = bp.bwriter.BibTexWriter()
    bwriter.display_order = BIBFIELD_ORDER

    def encode_metadata(self, metadata):
        return yaml.safe_dump(metadata, allow_unicode=True,
                              encoding=None, indent=4)

    def decode_metadata(self, metadata_raw):
        return yaml.safe_load(metadata_raw)

    def encode_bibdata(self, bibdata, ignore_fields=[]):
        """Encode bibdata """
        bpdata = bp.bibdatabase.BibDatabase()
        bpdata.entries = [self._entry_to_bp_entry(k, copy.copy(bibdata[k]),
                                                  ignore_fields=ignore_fields)
                          for k in bibdata]
        return self.bwriter.write(bpdata)

    def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
        """Convert back entries to the format expected by bibtexparser."""
        entry[BP_ID_KEY] = key
        # Convert internal 'type' to bibtexparser entrytype key

# Path: pubs/bibstruct.py
# TYPE_KEY = 'ENTRYTYPE'


# Path: pubs/endecoder.py
import copy
import logging
import pyparsing
import bibtexparser
    import bibtexparser as bp
import yaml
from .bibstruct import TYPE_KEY

        def __init__(self, error_msg, bibdata):
            """
            :param error_msg: specific message about what went wrong
            :param bibdata:   the data that was unsuccessfully decoded.
            """
            super(Exception, self).__init__(error_msg)  # make `str(self)` work.
            self.data = bibdata

    bwriter = bp.bwriter.BibTexWriter()
    bwriter.display_order = BIBFIELD_ORDER

    def encode_metadata(self, metadata):
        return yaml.safe_dump(metadata, allow_unicode=True,
                              encoding=None, indent=4)

    def decode_metadata(self, metadata_raw):
        return yaml.safe_load(metadata_raw)

    def encode_bibdata(self, bibdata, ignore_fields=[]):
        """Encode bibdata """
        bpdata = bp.bibdatabase.BibDatabase()
        bpdata.entries = [self._entry_to_bp_entry(k, copy.copy(bibdata[k]),
                                                  ignore_fields=ignore_fields)
                          for k in bibdata]
        return self.bwriter.write(bpdata)

    def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
        """Convert back entries to the format expected by bibtexparser."""
        entry[BP_ID_KEY] = key
        # Convert internal 'type' to bibtexparser entrytype key

        entry[BP_ENTRYTYPE_KEY] = entry.pop(TYPE_KEY)