def _patched_deserialize_iter(self, attr): if attr is None: return None if not isinstance(attr, (list, set)): raise DeserializationError( "Cannot deserialize as [{}] an object of type {}".format( type(attr).__name__, type(attr))) return [ self._deserialize.deserialize_data(a, type(a).__name__) for a in attr ]
def _as_json(self, response): """Assuming this is not empty, return the content as JSON. Result/exceptions is not determined if you call this method without testing _is_empty. :raises: DeserializationError if response body contains invalid json data. """ # Assume ClientResponse has "body", and otherwise it's a requests.Response content = response.text() if hasattr(response, "body") else response.text try: return json.loads(content) except ValueError: raise DeserializationError( "Error occurred in deserializing the response body.")
def _is_empty(self, response): """Check if response body contains meaningful content. :rtype: bool :raises: DeserializationError if response body contains invalid json data. """ if not response.content: return True try: body = response.json() return not body except ValueError: raise DeserializationError("Response json invalid")
def _is_empty(self, response): """Check if response body contains meaningful content. :rtype: bool :raises: DeserializationError if response body contains invalid json data. """ # Assume ClientResponse has "body", and otherwise it's a requests.Response content = response.text() if hasattr(response, "body") else response.text if not content: return True try: return not json.loads(content) except ValueError: raise DeserializationError( "Error occurred in deserializing the response body.")
def mock_outputs(response): body = response.json() body = {TestArmPolling.convert.sub(r'\1_\2', k).lower(): v for k, v in body.items()} properties = body.setdefault('properties', {}) if 'name' in body: properties['name'] = body['name'] if properties: properties = {TestArmPolling.convert.sub(r'\1_\2', k).lower(): v for k, v in properties.items()} del body['properties'] body.update(properties) resource = SimpleResource(**body) else: raise DeserializationError("Impossible to deserialize") resource = SimpleResource(**body) return resource