Replace shortened URLs with long URLs in the twitter status, and add the "RT" flag.
        Should be used before urlize_tweet
320010
def expand_tweet_urls(tweet):
    
    if 'retweeted_status' in tweet:
        text = 'RT @{user}: {text}'.format(user=tweet['retweeted_status']['user']['screen_name'],
                                           text=tweet['retweeted_status']['text'])
        urls = tweet['retweeted_status']['entities']['urls']
    else:
        text = tweet['text']
        urls = tweet['entities']['urls']

    for url in urls:
        text = text.replace(url['url'], '<a href="%s">%s</a>' % (url['expanded_url'], url['display_url']))
    tweet['html'] = text
    return tweet
385167
def _build_url(self, shorten=True):
        """"""
        url_order = self._get_url_params(shorten=shorten)

        # For fast ratings, switch weekday and category in url
        if self.category != 'final':
            url_order[1], url_order[2] = url_order[2], url_order[1]
        self.url = URL_FORMAT.format(*url_order)
30657
def special_links_replace(text, urls):
    '''
    
    '''
    match_number = r'([A-Za-z0-9]+)' + r'(\+*)'
    reference_list = [(r'regulations:article:' + match_number, urls['regulations']),
                      (r'regulations:regulation:' + match_number, urls['regulations']),
                      (r'guidelines:article:' + match_number, urls['guidelines']),
                      (r'guidelines:guideline:' + match_number, urls['guidelines']),
                     ]
    anchor_list = [(r'regulations:contents', urls['regulations'] + r'#contents'),
                   (r'guidelines:contents', urls['guidelines'] + r'#contents'),
                   (r'regulations:top', urls['regulations'] + r'#'),
                   (r'guidelines:top', urls['guidelines'] + r'#'),
                   (r'link:pdf', urls['pdf'] + '.pdf'),
                  ]
    retval = text
    for match, repl in reference_list:
        retval = re.sub(match, repl + r'#\1\2', retval)
    for match, repl in anchor_list:
        retval = re.sub(match, repl, retval)
    return retval
440993
private static URL fixURL(URL jarURL)
    {
        String jarURLString = jarURL.toExternalForm();
        if (StringUtils.contains(jarURLString, ' ')) {
            jarURLString = jarURLString.replace(" ", "%20");

            try {
                return new URL(jarURLString);
            } catch (MalformedURLException e) {
                // TODO: Log something ?
            }
        }

        return jarURL;
    }
1339545
def retweets(self, tweet_id):
        
        log.info("retrieving retweets of %s", tweet_id)
        url = "https://api.twitter.com/1.1/statuses/retweets/""{}.json".format(
                tweet_id)

        resp = self.get(url, params={"count": 100})
        for tweet in resp.json():
            yield tweet
71896
def url_fix(s, charset=None):
    
    if charset:
        warnings.warn("{}.url_fix() charset argument is deprecated".format(__name__), DeprecationWarning)

    scheme, netloc, path, querystring, fragment = urlsplit(s)
    path = quote(path, b'/%')
    querystring = quote_plus(querystring, b':&=')
    return urlunsplit((scheme, netloc, path, querystring, fragment))
181349
def filter(self, **params):
        
        url = 'https://stream.twitter.com/%s/statuses/filter.json' \
              % self.streamer.api_version
        self.streamer._request(url, 'POST', params=params)
720506
public function parseUrls($tweet)
    {
        foreach ($this->entities->urls as $url) {
            $tweet = $this->replaceEntityInTweet(
                $tweet,
                $url->url,
                '<a href="' . $url->url . '">' . $url->url . '</a>'
            );
        }

        return $tweet;
    }
1029291
@Override
  protected URL setURL(AnalyzedTokenReadings token) throws MalformedURLException {
    if (token != null) {
      List<AnalyzedToken> readings = token.getReadings();
      List<String> lemmas = new ArrayList<>();
      for (AnalyzedToken reading : readings) {
        String lemma = reading.getLemma();
        if (lemma != null) {
          lemmas.add(lemma);
        }
      }
      if (lemmas.size() == 1) {
        return new URL(SYNONYMS_URL + lemmas.get(0));
      }
      return new URL(SYNONYMS_URL + token.getToken());
    }
    return null;
  }
1006041
def shortened_url(url)
      raise "Only String accepted: #{url}" unless url.class == String
      short_url = MongoidShortener::ShortenedUrl.generate(url)
      short_url
    end
1033318
def format_list(self, at_char, user, list_name):
        ''''''
        return '<a href="https://twitter.com/%s/lists/%s">%s%s/%s</a>' \
               % (user, list_name, at_char, user, list_name)
51617
function WMURLShortener_shorten(longUrl,    // @arg URLString
                                callback) { // @arg Function - callback(err:Error|null, str:String):void
                                            // @ret void
//{@dev
    $args(WMURLShortener_shorten, arguments);
//}@dev
    var that = this;
    var xhr = new XHRProxy();
    var retry = WMURLShortener_shorten["bind"](that, longUrl, callback);
    xhr["on"]("load", _createListener(that, xhr, retry, function(err){
        if(!!err) return callback(err, "");
        callback(null, xhr["response"]["id"]);
    }));
    xhr["open"]('POST', 'https://www.googleapis.com/urlshortener/v1/url', true);
    xhr["setRequestHeader"]('Content-Type', 'application/json');
    xhr["responseType"] = "json";
    xhr["send"](JSON["stringify"]({'longUrl': longUrl}));
}
455338
def add_url_suffix(url):
    """"""
    url = url.rstrip('/')
    if not has_suffix(url):
        return '{0}.com'.format(url)
    return url
1282212
def replace_urls(status):
    '''
    
    '''
    text = status.text

    if not has_url(status):
        return text

    urls = [(e['indices'], e['expanded_url']) for e in status.entities['urls']]
    urls.sort(key=lambda x: x[0][0], reverse=True)

    for (start, end), url in urls:
        text = text[:start] + url + text[end:]

    return text
652292
def _shorten_url(self, text):
        ''''''

        if len(text) > self._max_url_length and self._max_url_length != -1:
            text = text[0:self._max_url_length - 3]
            amp = text.rfind('&')
            close = text.rfind(';')
            if amp != -1 and (close == -1 or close < amp):
                text = text[0:amp]

            return text + '...'

        else:
            return text
1195453
public function shorten($longUrl)
    {
        if ($this->urlCheck($longUrl)) {
            $request = array
            (
                'http'=> array
                (
                    'method'        =>  "POST",
                    'header'        =>  "Accept-language: en\r\n".
                                        "Content-Type: application/json\r\n",
                    'ignore_errors' => true,
                    'content'       => json_encode(array('longUrl' => $longUrl)),
                ),
                "ssl" => array(
                    "verify_peer" => false
                )
            );

            $params = (!empty($this->apiKey)) ? '?'.$this->apiKey : '';
            $data = $this->request($this->api.$params, $request);
            $data = json_decode($data,true);
            $data = $this->validate($data,'shorten');

            return $data['id'];
        }

        throw new InvalidApiResponseException('The URL provided for shortening is not valid or currently unavailable.');
    }
698063
def delete(ctx,tweet):
    """"""
    if not ctx.obj['DRYRUN']:
        try:
            ctx.obj['TWEETLIST'].delete(tweet)
        except ValueError as e:
            click.echo("Now tweet was found with that id.")
            ctx.exit(1)
    else:
        click.echo("Not ran due to dry-run.")