Guest User

Untitled

a guest
Apr 26th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. --- twitter.py 2008-05-26 12:01:47.015625000 -0400
  2. +++ w:\quoquo\twitter.py 2008-05-26 10:35:13.921875000 -0400
  3. @@ -7,7 +7,7 @@
  4. __author__ = 'dewitt@google.com'
  5. __version__ = '0.6-devel'
  6.  
  7. -
  8. +from google.appengine.api import urlfetch
  9. import base64
  10. import md5
  11. import os
  12. @@ -898,7 +898,7 @@
  13. input_encoding: The encoding used to encode input strings. [optional]
  14. request_header: A dictionary of additional HTTP request headers. [optional]
  15. '''
  16. - self._cache = _FileCache()
  17. + self._cache = None # GAE hack by shadytrees.
  18. self._urllib = urllib2
  19. self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
  20. self._InitializeRequestHeaders(request_headers)
  21. @@ -1428,42 +1428,25 @@
  22. Returns:
  23. A string containing the body of the response.
  24. '''
  25. - # Build the extra parameters dict
  26. - extra_params = {}
  27. - if self._default_params:
  28. - extra_params.update(self._default_params)
  29. - if parameters:
  30. - extra_params.update(parameters)
  31. -
  32. - # Add key/value parameters to the query string of the url
  33. - url = self._BuildUrl(url, extra_params=extra_params)
  34. -
  35. - # Get a url opener that can handle basic auth
  36. - opener = self._GetOpener(url, username=self._username, password=self._password)
  37. -
  38. - encoded_post_data = self._EncodePostData(post_data)
  39. -
  40. - # Open and return the URL immediately if we're not going to cache
  41. - if encoded_post_data or no_cache or not self._cache or not self._cache_timeout:
  42. - url_data = opener.open(url, encoded_post_data).read()
  43. - else:
  44. - # Unique keys are a combination of the url and the username
  45. - if self._username:
  46. - key = self._username + ':' + url
  47. - else:
  48. - key = url
  49. -
  50. - # See if it has been cached before
  51. - last_cached = self._cache.GetCachedTime(key)
  52.  
  53. - # If the cached version is outdated then fetch another and store it
  54. - if not last_cached or time.time() >= last_cached + self._cache_timeout:
  55. - url_data = opener.open(url, encoded_post_data).read()
  56. - self._cache.Set(key, url_data)
  57. - else:
  58. - url_data = self._cache.Get(key)
  59. -
  60. - # Always return the latest version
  61. + method = urlfetch.GET
  62. + data = {}
  63. + if post_data:
  64. + method = urlfetch.POST
  65. + data.update(post_data)
  66. +
  67. + params = {}
  68. + for x in (parameters, self._default_params):
  69. + if x: params.update(x)
  70. +
  71. + url = self._BuildUrl(url, extra_params = params)
  72. + headers = {}
  73. + if method == urlfetch.POST:
  74. + headers.update({'Content-type':'application/x-www-form-urlencoded'})
  75. +
  76. + # Skip the cache, we're on GAE. This hack by shadytrees.
  77. + url_data = urlfetch.fetch(url, payload = urllib.urlencode(data),
  78. + method = method, headers = headers).content
  79. return url_data
  80.  
  81. class _FileCacheError(Exception):
  82. @@ -1518,6 +1501,7 @@
  83.  
  84. def _GetUsername(self):
  85. '''Attempt to find the username in a cross-platform fashion.'''
  86. + return 'nobody' # GAE hack by shadytrees.
  87. try:
  88. return os.getenv('USER') or \
  89. os.getenv('LOGNAME') or \
Add Comment
Please, Sign In to add comment