]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
Unit test for previous silly regression
[z_archive/twitter.git] / twitter / util.py
index db497f9d3c569d87a6c04eff63674aa52613d0e5..8d3bd8acac7c4b165ad515e840cb49a90d367b83 100644 (file)
@@ -49,6 +49,8 @@ def printNicely(string):
     if hasattr(sys.stdout, 'buffer'):
         sys.stdout.buffer.write(string.encode('utf8'))
         print()
+        sys.stdout.buffer.flush()
+        sys.stdout.flush()
     else:
         print(string.encode('utf8'))
 
@@ -120,15 +122,22 @@ def follow_redirects(link, sites= None):
     try:
         with contextlib.closing(opener.open(req,timeout=1)) as site:
             return site.url
-    except (urllib2.HTTPError, urllib2.URLError, socket.timeout):
+    except:
         return redirect_handler.last_url if redirect_handler.last_url else link
 
 def expand_line(line, sites):
     """Expand the links in the line for the given sites."""
-    l = line.strip()
-    msg_format, links = find_links(l)
-    args = tuple(follow_redirects(l, sites) for l in links)
-    return msg_format % args
+    try:
+        l = line.strip()
+        msg_format, links = find_links(l)
+        args = tuple(follow_redirects(l, sites) for l in links)
+        line = msg_format % args
+    except Exception as e:
+        try:
+            err("expanding line %s failed due to %s" % (line, unicode(e)))
+        except:
+            pass
+    return line
 
 def parse_host_list(list_of_hosts):
     """Parse the comma separated list of hosts."""