Mercurial > hg > config
comparison python/quote.py @ 271:2454d5a1728b
add a email-esque quoting script
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Thu, 04 Apr 2013 19:18:01 -0700 |
| parents | |
| children | a075f8a93183 |
comparison
equal
deleted
inserted
replaced
| 270:3f89de477ff7 | 271:2454d5a1728b |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 """ | |
| 4 quote text | |
| 5 """ | |
| 6 | |
| 7 import sys | |
| 8 import textwrap | |
| 9 from subprocess import check_output as call | |
| 10 | |
| 11 def quote(text, prefix='> ', width=69): | |
| 12 """ | |
| 13 returns quoted text | |
| 14 - prefix: string to prepend quote | |
| 15 - width: final width (emacs wraps at 70) | |
| 16 """ | |
| 17 width -= len(prefix) # subtract the prefix | |
| 18 text = text.strip() # remove surrounding whitespace | |
| 19 lines = [] | |
| 20 for line in text.splitlines(): | |
| 21 line = line.strip() | |
| 22 lines.extend(textwrap.wrap(line, width)) | |
| 23 return '\n'.join(['%s%s' % (prefix, line) | |
| 24 for line in lines]) | |
| 25 | |
| 26 def main(args=sys.argv[1:]): | |
| 27 text = sys.stdin.read() | |
| 28 sys.stdout.write(quote(text)) | |
| 29 | |
| 30 if __name__ == '__main__': | |
| 31 main() |
