|
4 | 4 |
|
5 | 5 | from __future__ import print_function
|
6 | 6 |
|
7 |
| -import codecs |
8 | 7 | import csv
|
9 | 8 | import os
|
10 | 9 | import subprocess
|
@@ -81,44 +80,27 @@ def _tabulate(output, headers, fmt):
|
81 | 80 | sys.exit(1)
|
82 | 81 |
|
83 | 82 |
|
84 |
| -def _is_ascii_encoding(encoding): |
85 |
| - """Checks if a given encoding is ascii.""" |
86 |
| - try: |
87 |
| - return codecs.lookup(encoding).name == 'ascii' |
88 |
| - except LookupError: |
89 |
| - return False |
90 |
| - |
91 |
| - |
92 |
| -def _get_best_encoding(stream): |
93 |
| - """Returns the default stream encoding if not found.""" |
94 |
| - rv = getattr(stream, 'encoding', None) or sys.getdefaultencoding() |
95 |
| - if _is_ascii_encoding(rv): |
96 |
| - return 'utf-8' |
97 |
| - return rv |
98 |
| - |
99 |
| - |
100 | 83 | def _echo_via_pager(pager, output):
|
101 | 84 | env = dict(os.environ)
|
102 | 85 | # When the LESS environment variable is unset, Git sets it to FRX (if
|
103 | 86 | # LESS environment variable is set, Git does not change it at all).
|
104 | 87 | if 'LESS' not in env:
|
105 | 88 | env['LESS'] = 'FRX'
|
106 | 89 |
|
107 |
| - c = subprocess.Popen(pager, shell=True, stdin=subprocess.PIPE, |
108 |
| - env=env) |
109 |
| - encoding = _get_best_encoding(c.stdin) |
| 90 | + pager = subprocess.Popen(pager.split(), stdin=subprocess.PIPE, env=env) |
| 91 | + |
| 92 | + output = six.ensure_binary(output) |
110 | 93 |
|
111 | 94 | try:
|
112 |
| - for line in output: |
113 |
| - c.stdin.write(line.encode(encoding, 'replace')) |
| 95 | + pager.communicate(input=output) |
114 | 96 | except (IOError, KeyboardInterrupt):
|
115 | 97 | pass
|
116 | 98 | else:
|
117 |
| - c.stdin.close() |
| 99 | + pager.stdin.close() |
118 | 100 |
|
119 | 101 | while True:
|
120 | 102 | try:
|
121 |
| - c.wait() |
| 103 | + pager.wait() |
122 | 104 | except KeyboardInterrupt:
|
123 | 105 | pass
|
124 | 106 | else:
|
|
0 commit comments