Represents a set of stylistic options that are used when deciding which stream should be used.
| 8 | |
| 9 | |
| 10 | class ProcessingOptions(NamedTuple): |
| 11 | """Represents a set of stylistic options |
| 12 | that are used when deciding which stream |
| 13 | should be used.""" |
| 14 | |
| 15 | debug: bool = False |
| 16 | traceback: bool = False |
| 17 | |
| 18 | stream: bool = False |
| 19 | style: str = AUTO_STYLE |
| 20 | prettify: Union[List[str], PrettyOptions] = PRETTY_STDOUT_TTY_ONLY |
| 21 | |
| 22 | response_mime: Optional[str] = None |
| 23 | response_charset: Optional[str] = None |
| 24 | |
| 25 | json: bool = False |
| 26 | format_options: Dict[str, Any] = PARSED_DEFAULT_FORMAT_OPTIONS |
| 27 | |
| 28 | def get_prettify(self, env: Environment) -> List[str]: |
| 29 | if self.prettify is PRETTY_STDOUT_TTY_ONLY: |
| 30 | return PRETTY_MAP['all' if env.stdout_isatty else 'none'] |
| 31 | else: |
| 32 | return self.prettify |
| 33 | |
| 34 | @classmethod |
| 35 | def from_raw_args(cls, options: argparse.Namespace) -> 'ProcessingOptions': |
| 36 | fetched_options = { |
| 37 | option: getattr(options, option) |
| 38 | for option in cls._fields |
| 39 | } |
| 40 | return cls(**fetched_options) |
| 41 | |
| 42 | @property |
| 43 | def show_traceback(self): |
| 44 | return self.debug or self.traceback |