]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/util.py
Merge pull request #226 from hugovk/master
[z_archive/twitter.git] / twitter / util.py
index f4a5dd5bff7d3ec4a4af3e0394b278f4c33fe3aa..7831939a2c1e2a24b2e40573cefe5a92c16d72de 100644 (file)
@@ -10,6 +10,7 @@ from __future__ import print_function
 import contextlib
 import re
 import sys
+import textwrap
 import time
 import socket
 
@@ -142,3 +143,12 @@ def parse_host_list(list_of_hosts):
         m.group(1) for m in re.finditer("\s*([^,\s]+)\s*,?\s*", list_of_hosts))
     return p
 
+
+def align_text(text, left_margin=17, max_width=160):
+    lines = []
+    for line in text.split('\n'):
+        temp_lines = textwrap.wrap(line, max_width - left_margin)
+        temp_lines = [(' ' * left_margin + line) for line in temp_lines]
+        lines.append('\n'.join(temp_lines))
+    ret = '\n'.join(lines)
+    return ret.lstrip()