MCPcopy
hub / github.com/httpie/cli / _setup_standard_streams

Method _setup_standard_streams

httpie/cli/argparser.py:227–267  ·  view source on GitHub ↗

Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.

(self)

Source from the content-addressed store, hash-verified

225 self.args.url = scheme + self.args.url
226
227 def _setup_standard_streams(self):
228 """
229 Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.
230
231 """
232
233 self.args.output_file_specified = bool(self.args.output_file)
234 if self.args.download:
235 # FIXME: Come up with a cleaner solution.
236 if not self.args.output_file and not self.env.stdout_isatty:
237 # Use stdout as the download output file.
238 self.args.output_file = self.env.stdout
239 # With `--download`, we write everything that would normally go to
240 # `stdout` to `stderr` instead. Let's replace the stream so that
241 # we don't have to use many `if`s throughout the codebase.
242 # The response body will be treated separately.
243 self.env.stdout = self.env.stderr
244 self.env.stdout_isatty = self.env.stderr_isatty
245
246 elif self.args.output_file:
247 # When not `--download`ing, then `--output` simply replaces
248 # `stdout`. The file is opened for appending, which isn't what
249 # we want in this case.
250 self.args.output_file.seek(0)
251 try:
252 self.args.output_file.truncate()
253 except OSError as e:
254 if e.errno == errno.EINVAL:
255 # E.g. /dev/null on Linux.
256 pass
257 else:
258 raise
259 self.env.stdout = self.args.output_file
260 self.env.stdout_isatty = False
261
262 if self.args.quiet:
263 self.env.quiet = self.args.quiet
264 self.env.stderr = self.env.devnull
265 if not (self.args.output_file_specified and not self.args.download):
266 self.env.stdout = self.env.devnull
267 self.env.apply_warnings_filter()
268
269 def _process_ssl_cert(self):
270 from httpie.ssl_ import _is_key_file_encrypted

Callers 1

parse_argsMethod · 0.95

Calls 1

apply_warnings_filterMethod · 0.80

Tested by

no test coverage detected