# Path: eulfedora/util.py
# def force_bytes(s, encoding='utf-8'):
#     if isinstance(s, bytes):
#         if encoding == 'utf-8':
#             return s
#         else:
#             return s.decode('utf-8').encode(encoding)
# 
#     if not isinstance(s, six.string_types):
#         if six.PY3:
#             return six.text_type(s).encode(encoding)
#         else:
#             return bytes(s)
#     else:
#         return s.encode(encoding)
# 
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


import binascii
import hashlib
import io
import logging
import math
import re
import six
    import progressbar
from six.moves.urllib.parse import urlparse
from eulfedora.util import force_bytes, force_text

    # archive export needs additional processing to handle large binary content
    elif export_context in ['archive', 'archive-xml']:
        export = ArchiveExport(src_obj, dest_repo,
            progress_bar=pbar, requires_auth=requires_auth,
            xml_only=(export_context == 'archive-xml'),
            verify=verify)
        # NOTE: should be possible to pass BytesIO to be read, but that is failing
        export_data = export.object_data().getvalue()

    else:
        raise Exception('Unsupported export context %s', export_context)

    # wipe checksums from FOXML if flagged in options
    if omit_checksums:
        checksum_re = re.compile(b'<foxml:contentDigest.+?/>')
        try:
            # export data is either a string
            export_data = checksum_re.sub(b'', export_data)
        except TypeError:
            export_data = (re.sub(checksum_re, '', chunk)
                           for chunk in export_data)

    if overwrite and dest_obj.exists:
        logger.debug('Overwriting %s in destination repository', src_obj.pid)
        dest_repo.purge_object(src_obj.pid)

    result = dest_repo.ingest(export_data)
    if pbar:
        pbar.finish()

# Path: eulfedora/util.py
# def force_bytes(s, encoding='utf-8'):
#     if isinstance(s, bytes):
#         if encoding == 'utf-8':
#             return s
#         else:
#             return s.decode('utf-8').encode(encoding)
# 
#     if not isinstance(s, six.string_types):
#         if six.PY3:
#             return six.text_type(s).encode(encoding)
#         else:
#             return bytes(s)
#     else:
#         return s.encode(encoding)
# 
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


# Path: eulfedora/syncutil.py
import binascii
import hashlib
import io
import logging
import math
import re
import six
    import progressbar
from six.moves.urllib.parse import urlparse
from eulfedora.util import force_bytes, force_text


    # archive export needs additional processing to handle large binary content
    elif export_context in ['archive', 'archive-xml']:
        export = ArchiveExport(src_obj, dest_repo,
            progress_bar=pbar, requires_auth=requires_auth,
            xml_only=(export_context == 'archive-xml'),
            verify=verify)
        # NOTE: should be possible to pass BytesIO to be read, but that is failing
        export_data = export.object_data().getvalue()

    else:
        raise Exception('Unsupported export context %s', export_context)

    # wipe checksums from FOXML if flagged in options
    if omit_checksums:
        checksum_re = re.compile(b'<foxml:contentDigest.+?/>')
        try:
            # export data is either a string
            export_data = checksum_re.sub(b'', export_data)
        except TypeError:
            export_data = (re.sub(checksum_re, '', chunk)
                           for chunk in export_data)

    if overwrite and dest_obj.exists:
        logger.debug('Overwriting %s in destination repository', src_obj.pid)
        dest_repo.purge_object(src_obj.pid)

    result = dest_repo.ingest(export_data)
    if pbar:
        pbar.finish()

    return force_text(result)