human
Complete this python program:
def _get_modulestore_branch_setting():
assistant
#Here is the Python code you requested.

    """Returns the branch setting for the module store from the current Django request if configured,
    else returns the branch value from the configuration settings if set,
    else returns None
    The value of the branch setting is cached in a thread-local variable so it is not repeatedly recomputed
    """
    def get_branch_setting():
        '\n                                Finds    and    returns    the    branch    setting    based    on    the    Django    request    and    the    configuration    settings\n                                '
        branch = None
        hostname = get_current_request_hostname()
        if hostname:
            mappings = getattr(settings, 'HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', None)
            if mappings:
                for key in mappings.iterkeys():
                    if re.match(key, hostname):
                        return mappings[key]
        if (branch is None):
            branch = getattr(settings, 'MODULESTORE_BRANCH', None)
        return branch
    return get_branch_setting()