def length(text, maxval=None, encoding=None):
maxval = maxval or <NUM_LIT><EOL>try:<EOL><INDENT>assert not isinstance(text, six.binary_type)<EOL><DEDENT>except AssertionError:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return sum(<NUM_LIT:2> if ord(x) > maxval else <NUM_LIT:1> for x in unicodedata.normalize('<STR_LIT>', text))<EOL>
Count the length of a str the way Twitter does,
double-counting "wide" characters (e.g. ideographs, emoji)

Args:
    text (str): Text to count. Must be a unicode string in Python 2
    maxval (int): The maximum encoding that will be counted as 1 character.
        Defaults to 4351 (ჿ GEORGIAN LETTER LABIAL SIGN, U+10FF)

Returns:
    int