]> jfr.im git - z_archive/twitter.git/commitdiff
0.4.3 - fix for broken POST requests
authormverdone <redacted>
Sat, 22 Nov 2008 19:50:28 +0000 (19:50 +0000)
committermverdone <redacted>
Sat, 22 Nov 2008 19:50:28 +0000 (19:50 +0000)
git-svn-id: http://svn.mike.verdone.ca/pyprojects/twitter/trunk@186 d723f978-dc38-0410-87ed-da353333cdcc

README
setup.py
twitter/api.py

diff --git a/README b/README
index 27cb31480dad81ffd233216b3a4f4efbfaea1357..e28beb36c3229795e490725c5a033e722793841f 100644 (file)
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ on the go.
 
 Also included is a twitter command-line tool for getting your friends'
 tweets and setting your own tweet from the safety and security of your
-favorite shell and an IRC bot that can announce Twitter updated to an
+favorite shell and an IRC bot that can announce Twitter updates to an
 IRC channel.
 
 For more information:
index 7a66c7d91ef5c1c06166d7b109578e56ff9e8728..d76de4c5fd7ff4d4a1e1b2b38915cf4cbde298e0 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,20 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '0.4.2'
+version = '0.4.3'
 
 setup(name='twitter',
       version=version,
       description="An API and command-line toolset for Twitter (twitter.com)",
-      long_description="""\
-An API and command-line toolset for Twitter (twitter.com). Includes:
-
-  * a lightweight Twitter API access class.
-  * a twitter command-line tool for setting your status and getting your
-    friends' status
-  * a twitter IRC bot for announcing status updates to an IRC channel
-
-""",
+      long_description=open("./README", "r").read(),
       # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       classifiers=[
           "Development Status :: 5 - Production/Stable",
index f2c841722c1caa0bbc890f43865da1c25597f5f6..ad956e41918ecef8c0cf70e039cf1ea77d0f99b6 100644 (file)
@@ -42,28 +42,37 @@ class TwitterCall(object):
             or self.uri.endswith('create')
             or self.uri.endswith('destroy')):
             method = "POST"
+        
+        encoded_kwargs = urlencode(kwargs.items())
         argStr = ""
-        if kwargs:
-            argStr = "?" + urlencode(kwargs.items())
+        if kwargs and (method == "GET"):
+            argStr = "?" + encoded_kwargs
+
+        headers = {}
+        if (self.username):
+            headers["Authorization"] = "Basic " + b64encode("%s:%s" %(
+                self.username, self.password))
+        if method == "POST":
+            headers["Content-type"] = "application/x-www-form-urlencoded"
+            headers["Content-length"] = len(encoded_kwargs)
+        
         c = httplib.HTTPConnection("twitter.com")
         try:
-            c.putrequest(method, "/%s.%s%s" %(
+            c.putrequest(method, "%s.%s%s" %(
                 self.uri, self.format, argStr))
-            if (self.username):
-                c.putheader(
-                    "Authorization", "Basic " + b64encode("%s:%s" %(
-                        self.username, self.password)))
-            if (method == "POST"):
-                # TODO specify charset
-                pass
+            for item in headers.iteritems():
+                c.putheader(*item)
             c.endheaders()
+            if method == "POST":
+                c.send(encoded_kwargs)
             r = c.getresponse()
+
             if (r.status == 304):
                 return []
             elif (r.status != 200):
                 raise TwitterError("Twitter sent status %i: %s" %(
                     r.status, r.read()))
-            if ("json" == self.format):
+            if "json" == self.format:
                 return json.loads(r.read())
             else:
                 return r.read()
@@ -131,4 +140,4 @@ class Twitter(TwitterCall):
             raise TwitterError("Unknown data format '%s'" %(format))
         TwitterCall.__init__(self, email, password, format)
 
-__all__ = ["Twitter"]
+__all__ = ["Twitter", "TwitterError"]