# Path: bakery/cookies/exceptions.py
# class InvalidRepositoryError(ValueError):
#     pass
# 
# class InvalidContentFileEncoding(ValueError):
#     pass


import json
import pytz
import uuid
import http.client
from base64 import standard_b64decode
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.timezone import make_aware
from github import Github
from bakery.cookies.exceptions import (InvalidRepositoryError,
                                       InvalidContentFileEncoding)
    :raises: ``InvalidRepositoryError`` if there was no way to
        deterministically find the mapping file.
    """
    candidates = filter_repo(repo, {'name': lambda val: val.endswith('.json')})

    if not candidates:
        raise InvalidRepositoryError('No JSON mapping file found!')

    if len(candidates) > 1:
        mapping_file = candidates.get('cookiecutter.json', None)
        if mapping_file is None:
            raise InvalidRepositoryError('Cannot decide for a mapping file! '
                                         'Multiple files found: {0}'.format(', '.join(candidates.keys)))
    else:
        mapping_file = list(candidates.values())[0]
    return repo.get_contents('/' + mapping_file['name'])


def decode_file(content_file):
    """
    Given a ``PyGithub.ContentFile`` this function will decode the file's data.

    :return dict: Returns a raw decoded string.
    :raises: ``InvalidContentFileEncoding`` raised if not suitable decoding
        is defined.
    """
    decoded = None
    if content_file.encoding == 'base64':
        decoded = standard_b64decode(content_file.content).decode('utf-8')
    if decoded is None:

# Path: bakery/cookies/exceptions.py
# class InvalidRepositoryError(ValueError):
#     pass
# 
# class InvalidContentFileEncoding(ValueError):
#     pass


# Path: bakery/utils/vcs/gh.py
import json
import pytz
import uuid
import http.client
from base64 import standard_b64decode
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.timezone import make_aware
from github import Github
from bakery.cookies.exceptions import (InvalidRepositoryError,
                                       InvalidContentFileEncoding)

    :raises: ``InvalidRepositoryError`` if there was no way to
        deterministically find the mapping file.
    """
    candidates = filter_repo(repo, {'name': lambda val: val.endswith('.json')})

    if not candidates:
        raise InvalidRepositoryError('No JSON mapping file found!')

    if len(candidates) > 1:
        mapping_file = candidates.get('cookiecutter.json', None)
        if mapping_file is None:
            raise InvalidRepositoryError('Cannot decide for a mapping file! '
                                         'Multiple files found: {0}'.format(', '.join(candidates.keys)))
    else:
        mapping_file = list(candidates.values())[0]
    return repo.get_contents('/' + mapping_file['name'])


def decode_file(content_file):
    """
    Given a ``PyGithub.ContentFile`` this function will decode the file's data.

    :return dict: Returns a raw decoded string.
    :raises: ``InvalidContentFileEncoding`` raised if not suitable decoding
        is defined.
    """
    decoded = None
    if content_file.encoding == 'base64':
        decoded = standard_b64decode(content_file.content).decode('utf-8')
    if decoded is None:

        raise InvalidContentFileEncoding(