human
Complete this python program:
def _get_source_address(course_id, course_title, course_language, truncate=True):
assistant
#Here is the Python code you requested.

    """Calculates an email address to be used as the \from-address\ for sent emails.
    Makes a unique from name and address for each course, e.g.
    "COURSE_TITLE" Course Staff <course_name-no-reply@courseupdates.edx.org>
    If, when decoded to ascii, this from_addr is longer than 320 characters,
    use the course_name rather than the course title, e.g.
    "course_name" Course Staff <course_name-no-reply@courseupdates.edx.org>
    The "truncate" kwarg is only used for tests.
    """
    course_title_no_quotes = re.sub('"', '', course_title)
    course_name = re.sub('[^\\w.-]', '_', course_id.course)
    language = (course_language if course_language else settings.LANGUAGE_CODE)
    with override_language(language):
        from_addr_format = u'{name}    {email}'.format(name=_('"{course_title}"    Course    Staff'), email=u'<{course_name}-{from_email}>')
    def format_address(course_title_no_quotes):
        '\n                                Partial    function    for    formatting    the    from_addr.    Since\n                                `course_title_no_quotes`    may    be    truncated    to    make    sure    the    returned\n                                string    has    fewer    than    320    characters,    we    define    this    function    to    make\n                                it    easy    to    determine    quickly    what    the    max    length    is    for\n                                `course_title_no_quotes`.\n                                '
        return from_addr_format.format(course_title=course_title_no_quotes, course_name=course_name, from_email=configuration_helpers.get_value('email_from_address', settings.BULK_EMAIL_DEFAULT_FROM_EMAIL))
    from_addr = format_address(course_title_no_quotes)
    (__, encoded_from_addr) = forbid_multi_line_headers('from', from_addr, 'utf-8')
    escaped_encoded_from_addr = escape(encoded_from_addr)
    if ((len(escaped_encoded_from_addr) >= 320) and truncate):
        from_addr = format_address(course_name)
    return from_addr