def _FetchUrl(self,
                url,
                post_data=None,
                parameters=None,
                no_cache=None):
    '''Fetch a URL, optionally caching for a specified time.

    Args:
      url: The URL to retrieve
      post_data: 
        A dict of (str, unicode) key/value pairs.  If set, POST will be used.
      parameters:
        A dict whose key/value pairs should encoded and added 
        to the query string. [OPTIONAL]
      no_cache: If true, overrides the cache on the current request

    Returns:
      A string containing the body of the response.
    '''
    # Build the extra parameters dict
    extra_params = {}
    if self._default_params:
      extra_params.update(self._default_params)
    if parameters:
      extra_params.update(parameters)

    # Add key/value parameters to the query string of the url
    url = self._BuildUrl(url, extra_params=extra_params)

    encoded_post_data = self._EncodePostData(post_data)

    # We can't cache in some circumstances
    if encoded_post_data or no_cache or not self._cache or not self._cache_timeout:
      should_fetch = True
      should_cache = False
    else:
      # Unique keys are a combination of the url and the username
      if self._username:
        key = self._username + ':' + url
      else:
        key = url

      # See if it has been cached before
      last_cached = self._cache.GetCachedTime(key)

      # If the cached version is outdated
      should_fetch = not last_cached or time.time() >= last_cached + self._cache_timeout
      should_cache = True

    if should_fetch:
      if self._username and self._password:
        self._AddAuthorizationHeader(self._username, self._password)
      result = urlfetch.fetch(
          url,
          payload=encoded_post_data,
          method=post_data and urlfetch.POST or urlfetch.GET,
          headers=self._request_headers)

      url_data = result.content
      if should_cache and result.status_code == 200:
        self._cache.Set(key, url_data)
    else:
      url_data = self._cache.Get(key)

    # Always return the latest version
    return url_data
dataset/ETHPy150Open CollabQ/CollabQ/vendor/twitterapi/twitter.py/Api._FetchUrl/original