Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 153ca05

Browse files
committed
Fixed to output html on Windows avoiding print() function
1 parent ab37185 commit 153ca05

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

hyper/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Command line interface for Hyper inspired by Httpie.
77
"""
88
import json
9+
import locale
910
import logging
1011
import sys
1112
from argparse import ArgumentParser, RawTextHelpFormatter
@@ -20,7 +21,7 @@
2021

2122
log = logging.getLogger('hyper')
2223

23-
FILESYSTEM_ENCODING = sys.getfilesystemencoding()
24+
PREFERRED_ENCODING = locale.getpreferredencoding()
2425

2526
# Various separators used in args
2627
SEP_HEADERS = ':'
@@ -166,7 +167,7 @@ def set_request_data(args):
166167
args.url.path += '?' + urlencode(params)
167168

168169
if body:
169-
content_type = 'application/json; charset=%s' % FILESYSTEM_ENCODING
170+
content_type = 'application/json; charset=%s' % PREFERRED_ENCODING
170171
headers.setdefault('content-type', content_type)
171172
args.body = json.dumps(body)
172173

@@ -224,7 +225,10 @@ def request(args):
224225
def main(argv=None):
225226
args = parse_argument(argv)
226227
log.debug('Commandline Argument: %s', args)
227-
print(request(args))
228+
data = request(args)
229+
sys.stdout.buffer.write(data.encode(PREFERRED_ENCODING, errors='replace'))
230+
sys.stdout.buffer.write(b'\n')
231+
sys.stdout.buffer.flush()
228232

229233

230234
if __name__ == '__main__': # pragma: no cover

test/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from hyper.cli import FILESYSTEM_ENCODING as FENC, KeyValue
6+
from hyper.cli import PREFERRED_ENCODING as PENC, KeyValue
77
from hyper.cli import get_content_type_and_charset, main, parse_argument
88
from hyper.cli import set_request_data, set_url_info
99

@@ -155,7 +155,7 @@ def test_get_content_type_and_charset(response, expected):
155155
KeyValue('data2', 'test2', '=', ''),
156156
]}
157157
),
158-
{'headers': {'content-type': 'application/json; charset=%s' % FENC},
158+
{'headers': {'content-type': 'application/json; charset=%s' % PENC},
159159
'method': 'POST',
160160
'body': json.dumps({'data1': 'test1', 'data2': 'test2'}),
161161
}

0 commit comments

Comments
 (0)