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

Method _parse_items

httpie/cli/argparser.py:448–490  ·  view source on GitHub ↗

Parse `args.request_items` into `args.headers`, `args.data`, `args.params`, and `args.files`.

(self)

Source from the content-addressed store, hash-verified

446 self.args.method = HTTP_POST if has_data else HTTP_GET
447
448 def _parse_items(self):
449 """
450 Parse `args.request_items` into `args.headers`, `args.data`,
451 `args.params`, and `args.files`.
452
453 """
454 try:
455 request_items = RequestItems.from_args(
456 request_item_args=self.args.request_items,
457 request_type=self.args.request_type,
458 )
459 except ParseError as e:
460 if self.args.traceback:
461 raise
462 self.error(e.args[0])
463 else:
464 self.args.headers = request_items.headers
465 self.args.data = request_items.data
466 self.args.files = request_items.files
467 self.args.params = request_items.params
468 self.args.multipart_data = request_items.multipart_data
469
470 if self.args.files and not self.args.form:
471 # `http url @/path/to/file`
472 request_file = None
473 for key, file in self.args.files.items():
474 if key != '':
475 self.error(
476 'Invalid file fields (perhaps you meant --form?):'
477 f' {",".join(self.args.files.keys())}')
478 if request_file is not None:
479 self.error("Can't read request from multiple files")
480 request_file = file
481
482 fn, fd, ct = request_file
483 self.args.files = {}
484
485 self._body_from_file(fd)
486
487 if 'Content-Type' not in self.args.headers:
488 content_type = get_content_type(fn)
489 if content_type:
490 self.args.headers['Content-Type'] = content_type
491
492 def _process_output_options(self):
493 """Apply defaults to output options, or validate the provided ones.

Callers 1

parse_argsMethod · 0.95

Calls 5

errorMethod · 0.95
_body_from_fileMethod · 0.95
get_content_typeFunction · 0.85
from_argsMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected