def join_words(words, separator, max_length=None):
    """
    words - iterator or list
    """
    if not max_length:
        return separator.join(words)
    words = iter(words)
    try:
        text = next(words)
    except StopIteration:
        return u''
    for word in words:
        if len(text + separator + word) <= max_length:
            text += separator + word
    return text[:max_length]
