Clean strings returned from API resources and endpoints:
        - remove newlines and leading whitespace
        - replace colons with &#58; to avoid problems with RAML validation
        - remove things like: <pale.fields.string.StringField object at 0x106edbed0>
        - replace double spaces with single spaces
        - if there is not a period, comma, question mark or exclamation point at the end of a string,
          add a period

def clean_description(string):
    """Clean strings returned from API resources and endpoints:
        - remove newlines and leading whitespace
        - replace colons with &#58; to avoid problems with RAML validation
        - remove things like: <pale.fields.string.StringField object at 0x106edbed0>
        - replace double spaces with single spaces
        - if there is not a period, comma, question mark or exclamation point at the end of a string,
          add a period
    """

    leading_whitespace = re.compile(r"(\A\s+)")
    multiple_spaces = re.compile(r"(\s+\s+)")
    newlines = re.compile(r"\n")
    colons = re.compile(r":(?!//)")
    machine_code = re.compile(r"(<.+>)")
    trailing_whitespace = re.compile(r"(\s+\Z)")
    punctuation = re.compile(r"([\.!?,])\s*\Z")

    result = leading_whitespace.sub("", string, 0)
    result = newlines.sub(" ", result, 0)
    result = colons.sub('=', result, 0)
    result = machine_code.sub("", result, 0)
    result = multiple_spaces.sub(" ", result, 0)
    result = trailing_whitespace.sub("", result, 0)
    has_punctuation = punctuation.search(result) != None

    if not has_punctuation and result != "":
        result = result + "."
    else:
        result = result

    return result