Saves the result of a JMESPath expression to a file. This method only saves the query data if the response code of the parsed result is < 300.
(self, parsed, **kwargs)
| 127 | self._session.register(self._after_call_event, self.save_query) |
| 128 | |
| 129 | def save_query(self, parsed, **kwargs): |
| 130 | """Saves the result of a JMESPath expression to a file. |
| 131 | |
| 132 | This method only saves the query data if the response code of |
| 133 | the parsed result is < 300. |
| 134 | """ |
| 135 | if is_parsed_result_successful(parsed): |
| 136 | contents = jmespath.search(self.query, parsed) |
| 137 | with compat_open( |
| 138 | self.value, 'w', access_permissions=self.perm |
| 139 | ) as fp: |
| 140 | # Don't write 'None' to a file -- write ''. |
| 141 | if contents is None: |
| 142 | fp.write('') |
| 143 | else: |
| 144 | fp.write(contents) |
| 145 | # Even though the file is opened using the requested mode |
| 146 | # (e.g. 0o600), the mode is only applied if a new file is |
| 147 | # created. This means if the file already exists, its |
| 148 | # permissions will not be changed. So, the os.chmod call is |
| 149 | # retained here to preserve behavior of this argument always |
| 150 | # clobbering a preexisting file's permissions to the desired |
| 151 | # mode. |
| 152 | os.chmod(self.value, self.perm) |
| 153 | |
| 154 | |
| 155 | class NestedBlobArgumentHoister: |