Try to coerce an object into a Response object.
320899
def make_response(obj):
    """"""
    if obj is None:
        raise TypeError("Handler return value cannot be None.")
    if isinstance(obj, Response):
        return obj
    return Response(200, body=obj)
568567
def coerce(cls, key, value):
        """"""
        self = MutationList((MutationObj.coerce(key, v) for v in value))
        self._key = key
        return self
587487
def from_response(cls, response: 'ClientResponse') -> Any:
        
        obj = cls.response_wrapper_cls(response, cls(response.headers,
                                                     response.content))
        return obj
715745
def try_to(subject, method_id, *args, &block)
      ModuleUtils.try_to subject, method_id, *args, &block
    end
1246361
def _try_coerce_result(self, result):
        
        if isinstance(result, np.ndarray):
            mask = isna(result)
            if result.dtype.kind in ['i', 'f']:
                result = result.astype('m8[ns]')
            result[mask] = tslibs.iNaT

        elif isinstance(result, (np.integer, np.float)):
            result = self._box_func(result)

        return result
794644
def _coerce_json_to_amendment(self, json_repr):
        """"""
        if isinstance(json_repr, dict):
            amendment = json_repr
        else:
            try:
                amendment = anyjson.loads(json_repr)
            except:
                _LOG.warn('> invalid JSON (failed anyjson parsing)')
                return None
        return amendment
281791
def coerce(cls, key, value):
        
        if not isinstance(value, MutableList):
            if isinstance(value, list):
                return MutableList(value)
            # this call will raise ValueError
            return Mutable.coerce(key, value)
        else:
            return value
561477
def _coerce_json_to_collection(self, json_repr):
        """"""
        if isinstance(json_repr, dict):
            collection = json_repr
        else:
            try:
                collection = anyjson.loads(json_repr)
            except:
                _LOG.warn('> invalid JSON (failed anyjson parsing)')
                return None
        return collection
1199308
def _response_item_to_object(self, resp_item):
        
        item_cls = resources.get_model_class(self.resource_type)
        properties_dict = resp_item[self.resource_type]
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        # raises exception if something goes wrong
        obj = item_cls(new_dict)
        return obj
499865
def coerce(self, value, includes=None, errors=None, resources=None, default_locale='en-US', locale=None):
        """"""

        if includes is None:
            includes = []
        if errors is None:
            errors = []

        return self._coerce_block(
            value,
            includes=includes,
            errors=errors,
            resources=resources,
            default_locale=default_locale,
            locale=locale
        )
729290
def construct(cls, attempt_number, value, has_exception):
        """"""
        fut = cls(attempt_number)
        if has_exception:
            fut.set_exception(value)
        else:
            fut.set_result(value)
        return fut
228354
def process_response(self,
                         method,
                         response,
                         response_type=None,
                         objects_type=None):
        

        try:
            response_json = response.json(
                object_hook=
                lambda x: ResponseObject(x) if isinstance(x, dict) else x)
            if response_type:
                r = response_type(self, response_json.__dict__)
                response_json = r

            if 'objects' in response_json and objects_type:
                response_json.objects = [
                    objects_type(self, obj.__dict__)
                    for obj in response_json.objects
                ]
        except ValueError:
            response_json = None

        if response.status_code == 400:
            if response_json and 'error' in response_json:
                raise ValidationError(response_json.error)
            raise ValidationError(
                'A parameter is missing or is invalid while accessing resource'
                'at: {url}'.format(url=response.url))

        if response.status_code == 401:
            if response_json and 'error' in response_json:
                raise AuthenticationError(response_json.error)
            raise AuthenticationError(
                'Failed to authenticate while accessing resource at: '
                '{url}'.format(url=response.url))

        if response.status_code == 404:
            if response_json and 'error' in response_json:
                raise ResourceNotFoundError(response_json.error)
            raise ResourceNotFoundError(
                'Resource not found at: {url}'.format(url=response.url))

        if response.status_code == 405:
            if response_json and 'error' in response_json:
                raise InvalidRequestError(response_json.error)
            raise InvalidRequestError(
                'HTTP method "{method}" not allowed to access resource at: '
                '{url}'.format(method=method, url=response.url))

        if response.status_code == 500:
            if response_json and 'error' in response_json:
                raise PlivoServerError(response_json.error)
            raise PlivoServerError(
                'A server error occurred while accessing resource at: '
                '{url}'.format(url=response.url))

        if method == 'DELETE':
            if response.status_code != 204:
                raise PlivoRestError('Resource at {url} could not be '
                                     'deleted'.format(url=response.url))

        elif response.status_code not in [200, 201, 202]:
            raise PlivoRestError(
                'Received status code {status_code} for the HTTP method '
                '"{method}"'.format(
                    status_code=response.status_code, method=method))

        return response_json
264910
def coerce(cls, key, value):
        """"""
        self = MutationDict((k,MutationObj.coerce(key, v)) for (k, v) in value.items())
        self._key = key
        return self
1084446
def responsify(error):
    """"""
    assert str(type(error).__name__) == 'Error'
    if error.error in code_to_class:
        e = code_to_class[error.error](error.error_description)
        if error.error_id:
            e.error_id = error.error_id
        if error.user_message:
            e.user_message = error.user_message
        return e.http_reply()
    elif isinstance(error, PyMacaronException):
        return error.http_reply()
    else:
        return PyMacaronException("Caught un-mapped error: %s" % error).http_reply()
1212320
def coerce(self, value):
        """"""
        if self.type == Style:
            return value
        elif self.type == list:
            return self.type(
                map(self.subtype, map(lambda x: x.strip(), value.split(',')))
            )
        elif self.type == dict:
            rv = {}
            for pair in value.split(','):
                key, val = pair.split(':')
                key = key.strip()
                val = val.strip()
                try:
                    rv[key] = self.subtype(val)
                except Exception:
                    rv[key] = val
            return rv
        return self.type(value)
366105
def coerce(cls, key, value):
        """"""
        if value is None:
            return value
        if isinstance(value, cls):
            return value
        if isinstance(value, dict):
            return NestedMutableDict.coerce(key, value)
        if isinstance(value, list):
            return NestedMutableList.coerce(key, value)
        return super(cls).coerce(key, value)
374998
def coerce(self, value, **kwargs):
        """"""

        Location = namedtuple('Location', ['lat', 'lon'])
        return Location(float(value.get('lat')), float(value.get('lon')))