@staticmethod<EOL><INDENT>def html_for_tweet(tweet, use_display_url=True, use_expanded_url=False, expand_quoted_status=False):<DEDENT>
if '<STR_LIT>' in tweet:<EOL><INDENT>tweet = tweet['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in tweet:<EOL><INDENT>tweet = tweet['<STR_LIT>']<EOL><DEDENT>orig_tweet_text = tweet.get('<STR_LIT>') or tweet['<STR_LIT:text>']<EOL>display_text_range = tweet.get('<STR_LIT>') or [<NUM_LIT:0>, len(orig_tweet_text)]<EOL>display_text_start, display_text_end = display_text_range[<NUM_LIT:0>], display_text_range[<NUM_LIT:1>]<EOL>display_text = orig_tweet_text[display_text_start:display_text_end]<EOL>prefix_text = orig_tweet_text[<NUM_LIT:0>:display_text_start]<EOL>suffix_text = orig_tweet_text[display_text_end:len(orig_tweet_text)]<EOL>if '<STR_LIT>' in tweet:<EOL><INDENT>entities = []<EOL>if '<STR_LIT>' in tweet['<STR_LIT>']:<EOL><INDENT>for entity in tweet['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>temp = {}<EOL>temp['<STR_LIT:start>'] = entity['<STR_LIT>'][<NUM_LIT:0>]<EOL>temp['<STR_LIT:end>'] = entity['<STR_LIT>'][<NUM_LIT:1>]<EOL>mention_html = '<STR_LIT>' % {'<STR_LIT>': entity['<STR_LIT>']}<EOL>if display_text_start <= temp['<STR_LIT:start>'] <= display_text_end:<EOL><INDENT>temp['<STR_LIT>'] = mention_html<EOL>temp['<STR_LIT:start>'] -= display_text_start<EOL>temp['<STR_LIT:end>'] -= display_text_start<EOL>entities.append(temp)<EOL><DEDENT>else:<EOL><INDENT>sub_expr = r'<STR_LIT>' + orig_tweet_text[temp['<STR_LIT:start>']:temp['<STR_LIT:end>']] + '<STR_LIT>'<EOL>prefix_text = re.sub(sub_expr, mention_html, prefix_text)<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in tweet['<STR_LIT>']:<EOL><INDENT>for entity in tweet['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>temp = {}<EOL>temp['<STR_LIT:start>'] = entity['<STR_LIT>'][<NUM_LIT:0>] - display_text_start<EOL>temp['<STR_LIT:end>'] = entity['<STR_LIT>'][<NUM_LIT:1>] - display_text_start<EOL>url_html = '<STR_LIT>' % {'<STR_LIT>': entity['<STR_LIT:text>']}<EOL>temp['<STR_LIT>'] = url_html<EOL>entities.append(temp)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in tweet['<STR_LIT>']:<EOL><INDENT>for entity in tweet['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>temp = {}<EOL>temp['<STR_LIT:start>'] = entity['<STR_LIT>'][<NUM_LIT:0>] - display_text_start<EOL>temp['<STR_LIT:end>'] = entity['<STR_LIT>'][<NUM_LIT:1>] - display_text_start<EOL>url_html = '<STR_LIT>' % {'<STR_LIT>': entity['<STR_LIT:text>']}<EOL>temp['<STR_LIT>'] = url_html<EOL>entities.append(temp)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in tweet['<STR_LIT>']:<EOL><INDENT>for entity in tweet['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>temp = {}<EOL>temp['<STR_LIT:start>'] = entity['<STR_LIT>'][<NUM_LIT:0>] - display_text_start<EOL>temp['<STR_LIT:end>'] = entity['<STR_LIT>'][<NUM_LIT:1>] - display_text_start<EOL>if use_display_url and entity.get('<STR_LIT>') and not use_expanded_url:<EOL><INDENT>shown_url = entity['<STR_LIT>']<EOL><DEDENT>elif use_expanded_url and entity.get('<STR_LIT>'):<EOL><INDENT>shown_url = entity['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>shown_url = entity['<STR_LIT:url>']<EOL><DEDENT>url_html = '<STR_LIT>' % (entity['<STR_LIT:url>'], shown_url)<EOL>if display_text_start <= temp['<STR_LIT:start>'] <= display_text_end:<EOL><INDENT>temp['<STR_LIT>'] = url_html<EOL>entities.append(temp)<EOL><DEDENT>else:<EOL><INDENT>suffix_text = suffix_text.replace(orig_tweet_text[temp['<STR_LIT:start>']:temp['<STR_LIT:end>']], url_html)<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in tweet['<STR_LIT>'] and len(tweet['<STR_LIT>']['<STR_LIT>']) > <NUM_LIT:0>:<EOL><INDENT>entity = tweet['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]<EOL>temp = {}<EOL>temp['<STR_LIT:start>'] = entity['<STR_LIT>'][<NUM_LIT:0>]<EOL>temp['<STR_LIT:end>'] = entity['<STR_LIT>'][<NUM_LIT:1>]<EOL>if use_display_url and entity.get('<STR_LIT>') and not use_expanded_url:<EOL><INDENT>shown_url = entity['<STR_LIT>']<EOL><DEDENT>elif use_expanded_url and entity.get('<STR_LIT>'):<EOL><INDENT>shown_url = entity['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>shown_url = entity['<STR_LIT:url>']<EOL><DEDENT>url_html = '<STR_LIT>' % (entity['<STR_LIT:url>'], shown_url)<EOL>if display_text_start <= temp['<STR_LIT:start>'] <= display_text_end:<EOL><INDENT>temp['<STR_LIT>'] = url_html<EOL>entities.append(temp)<EOL><DEDENT>else:<EOL><INDENT>suffix_text = suffix_text.replace(orig_tweet_text[temp['<STR_LIT:start>']:temp['<STR_LIT:end>']], url_html)<EOL><DEDENT><DEDENT>for entity in sorted(entities, key=lambda e: e['<STR_LIT:start>'], reverse=True):<EOL><INDENT>display_text = display_text[<NUM_LIT:0>:entity['<STR_LIT:start>']] + entity['<STR_LIT>'] + display_text[entity['<STR_LIT:end>']:]<EOL><DEDENT><DEDENT>quote_text = '<STR_LIT>'<EOL>if expand_quoted_status and tweet.get('<STR_LIT>') and tweet.get('<STR_LIT>'):<EOL><INDENT>quoted_status = tweet['<STR_LIT>']<EOL>quote_text += '<STR_LIT>''<STR_LIT>''<STR_LIT>''<STR_LIT>' %{'<STR_LIT>': Twython.html_for_tweet(quoted_status, use_display_url, use_expanded_url, False),<EOL>'<STR_LIT>': '<STR_LIT>' %<EOL>(quoted_status['<STR_LIT:user>']['<STR_LIT>'], quoted_status['<STR_LIT>']),<EOL>'<STR_LIT>': quoted_status['<STR_LIT:user>']['<STR_LIT:name>'],<EOL>'<STR_LIT>': quoted_status['<STR_LIT:user>']['<STR_LIT>']}<EOL><DEDENT>return '<STR_LIT>' % {<EOL>'<STR_LIT>': '<STR_LIT>' % prefix_text if prefix_text else '<STR_LIT>',<EOL>'<STR_LIT>': display_text,<EOL>'<STR_LIT>': '<STR_LIT>' % suffix_text if suffix_text else '<STR_LIT>',<EOL>'<STR_LIT>': quote_text<EOL>}<EOL>
Return HTML for a tweet (urls, mentions, hashtags, symbols replaced with links)

        :param tweet: Tweet object from received from Twitter API
        :param use_display_url: Use display URL to represent link
        (ex. google.com, github.com). Default: True
        :param use_expanded_url: Use expanded URL to represent link
        (e.g. http://google.com). Default False

        If use_expanded_url is True, it overrides use_display_url.
        If use_display_url and use_expanded_url is False, short url will
        be used (t.co/xxxxx)