]> jfr.im git - z_archive/twitter.git/commitdiff
fixes for python 3
authorblob79 <redacted>
Wed, 1 Aug 2012 17:19:47 +0000 (19:19 +0200)
committerMike Verdone <redacted>
Fri, 3 Aug 2012 20:48:53 +0000 (22:48 +0200)
tests/test_util.py
twitter/archiver.py
twitter/follow.py
twitter/util.py

index 322d11bcd240bc14923416dbc5d8d3a8bf4eeaba..85800d14bb698069cf90d1aa2afc9ba2e080f3f0 100644 (file)
@@ -1,12 +1,17 @@
-import BaseHTTPServer
 from collections import namedtuple
 import contextlib
 import functools
 import socket
-import SocketServer
 import threading
 from twitter.util import find_links, follow_redirects, expand_line, parse_host_list
 
+try:
+    import http.server as BaseHTTPServer
+    import socketserver as SocketServer
+except ImportError:
+    import BaseHTTPServer
+    import SocketServer
+
 
 def test_find_links():
     assert find_links("nix") == ("nix", [])
@@ -35,7 +40,7 @@ def start_server(*resp):
             response = responses.pop()
             assert response.path == self.path
             self.send_response(response.code)
-            for header, value in response.headers.iteritems():
+            for header, value in list(response.headers.items()):
                 self.send_header(header, value)
             self.end_headers()
             
index 5ceefd5619ae19ccfbb5850615b6d496dd0a4369..1984eaa18d37370cdaf57a32c25f34d3cbdf210f 100644 (file)
@@ -25,9 +25,17 @@ AUTHENTICATION
 
 from __future__ import print_function
 
-import os, sys, time, calendar, urllib2, httplib, functools
+import os, sys, time, calendar, functools
 from getopt import gnu_getopt as getopt, GetoptError
 
+try:
+    import urllib.request as urllib2
+    import http.client as httplib
+except ImportError:
+    import urllib2
+    import httplib
+
+
 # T-Archiver (Twitter-Archiver) application registered by @stalkr_
 CONSUMER_KEY='d8hIyfzs7ievqeeZLjZrqQ'
 CONSUMER_SECRET='AnZmK0rnvaX7BoJ75l6XlilnbyMv7FoiDXWVmPD8'
@@ -299,7 +307,7 @@ def main(args=sys.argv[1:]):
         tweets = {}
         try:
             tweets = load_tweets(filename)
-        except Exception, e:
+        except Exception as e:
             err("Error when loading saved tweets: %s - continuing without"
                 % str(e))
 
@@ -328,7 +336,7 @@ def main(args=sys.argv[1:]):
         tweets = {}
         try:
             tweets = load_tweets(filename)
-        except Exception, e:
+        except Exception as e:
             err("Error when loading saved tweets: %s - continuing without"
                 % str(e))
 
index abc5fdabfe7a1b931e55202439f4ecdfc34c212c..335b7a0740558df166a99728638a0847a7dfa394 100644 (file)
@@ -18,9 +18,16 @@ AUTHENTICATION
 
 from __future__ import print_function
 
-import os, sys, time, calendar, urllib2, httplib
+import os, sys, time, calendar
 from getopt import gnu_getopt as getopt, GetoptError
 
+try:
+    import urllib.request as urllib2
+    import http.client as httplib
+except ImportError:
+    import urllib2
+    import httplib
+
 # T-Follow (Twitter-Follow) application registered by @stalkr_
 CONSUMER_KEY='USRZQfvFFjB6UvZIN2Edww'
 CONSUMER_SECRET='AwGAaSzZa5r0TDL8RKCDtffnI9H9mooZUdOa95nw8'
@@ -31,6 +38,7 @@ from .oauth_dance import oauth_dance
 from .auth import NoAuth
 from .util import Fail, err
 
+
 def parse_args(args, options):
     """Parse arguments from command-line to set options."""
     long_opts = ['help', 'oauth', 'followers', 'following', 'api-rate']
index 4396b07dabc3408d4f6113edb26b7687c7b2d5db..aa7a837dd2e04abf5fca12dddc12b2bf66bdacbb 100644 (file)
@@ -11,14 +11,16 @@ import contextlib
 import re
 import sys
 import time
-import urllib2
-import urlparse
 
 try:
     from html.entities import name2codepoint
     unichr = chr
+    import urllib.request as urllib2
+    import urllib.parse as urlparse
 except ImportError:
     from htmlentitydefs import name2codepoint
+    import urllib2
+    import urlparse
 
 def htmlentitydecode(s):
     return re.sub(
@@ -83,7 +85,7 @@ class Fail(object):
 def find_links(line):
     """Find all links in the given line. The function returns a sprintf style
     format string (with %s placeholders for the links) and a list of urls."""
-    l = line.replace(u"%", u"%%")
+    l = line.replace("%", "%%")
     regex = "(https?://[^ )]+)"
     return (
         re.sub(regex, "%s", l),