|
|
--- twitter.py 2008-05-26 12:01:47.015625000 -0400
+++ w:\quoquo\twitter.py 2008-05-26 10:35:13.921875000 -0400
@@ -7,7 +7,7 @@
__author__ = 'dewitt@google.com'
__version__ = '0.6-devel'
-
+from google.appengine.api import urlfetch
import base64
import md5
import os
@@ -898,7 +898,7 @@
input_encoding: The encoding used to encode input strings. [optional]
request_header: A dictionary of additional HTTP request headers. [optional]
'''
- self._cache = _FileCache()
+ self._cache = None # GAE hack by shadytrees.
self._urllib = urllib2
self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
self._InitializeRequestHeaders(request_headers)
@@ -1428,42 +1428,25 @@
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)
-
- # Get a url opener that can handle basic auth
- opener = self._GetOpener(url, username=self._username, password=self._password)
-
- encoded_post_data = self._EncodePostData(post_data)
-
- # Open and return the URL immediately if we're not going to cache
- if encoded_post_data or no_cache or not self._cache or not self._cache_timeout:
- url_data = opener.open(url, encoded_post_data).read()
- 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 then fetch another and store it
- if not last_cached or time.time() >= last_cached + self._cache_timeout:
- url_data = opener.open(url, encoded_post_data).read()
- self._cache.Set(key, url_data)
- else:
- url_data = self._cache.Get(key)
-
- # Always return the latest version
+ method = urlfetch.GET
+ data = {}
+ if post_data:
+ method = urlfetch.POST
+ data.update(post_data)
+
+ params = {}
+ for x in (parameters, self._default_params):
+ if x: params.update(x)
+
+ url = self._BuildUrl(url, extra_params = params)
+ headers = {}
+ if method == urlfetch.POST:
+ headers.update({'Content-type':'application/x-www-form-urlencoded'})
+
+ # Skip the cache, we're on GAE. This hack by shadytrees.
+ url_data = urlfetch.fetch(url, payload = urllib.urlencode(data),
+ method = method, headers = headers).content
return url_data
class _FileCacheError(Exception):
@@ -1518,6 +1501,7 @@
def _GetUsername(self):
'''Attempt to find the username in a cross-platform fashion.'''
+ return 'nobody' # GAE hack by shadytrees.
try:
return os.getenv('USER') or \
os.getenv('LOGNAME') or \
|