The Dark Balloon

A weblog by Hao Lian.
A terrible secret guarded by golems.
A note that thanks you for being born, all those years ago.

§
If it were a cat, it would be urlgogetiturself.

What follows is part of a patch against the twitter.py file from the awesome python-twitter project. You can download the entire patch if you so choose. With it, you can have read from Twitter from Google App Engine. I have not experimented with writing (posting) yet. By default, you get problems using urllib2 on GAE, which I bypass here like a stealthy lightning ninja greased with the body fat of my enemies. It’s part of my Quo Quo status project, which I’ll release soon enough.


+    method = urlfetch.GET
+    data, params, headers = {}, {}, {}
+    if post_data:
+      method = urlfetch.POST
+      data.update(post_data)
+
+    for x in (parameters, self._default_params):
+      if x: params.update(x)
+
+    url = self._BuildUrl(url, extra_params = params)
+    if method == urlfetch.POST:
+      mime = 'application/x-www-form-urlencoded'
+      headers.update({'Content-type': mime})
+
+    # Skip the cache, we're on GAE. This hack by shadytrees.
+    data = urllib.urlencode(data)
+    url_data = urlfetch.fetch(url, payload = data,
+                              method = method,
+                              headers = headers,
+                              ).content
[(2008 May 26, 1!) .]