def _determine_emitter(self, request): """ Simple return first emmiter. """ emiters_dict = dict((e.media_type, e) for e in as_tuple(self.emitters)) types = emiters_dict.keys() accept = request.META.get('HTTP_ACCEPT', '*/*') if accept != '*/*': base_format = mimeparse.best_match(types, request.META['HTTP_ACCEPT']) if base_format: return emiters_dict.get(base_format) or self.default_emitter return self.default_emitter
def authenticate(self): """ Attempt to authenticate the request, returning an authentication context or None. An authentication context may be any object, although in many cases it will simply be a :class:`User` instance. """ # Attempt authentication against each authenticator in turn, auth_result = True for authenticator in as_tuple(self.authenticators): self.auth = authenticator(self) auth_result = self.auth.authenticate() if auth_result: break else: raise HttpError("Authorization required.", status=status.HTTP_401_UNAUTHORIZED) return auth_result
# Get the appropriate create/read/update/delete function func = getattr(self, self.callmap.get(method, None)) # Get function data content = func(request, *args, **resources) response = Response(content) except HttpError, e: response = Response(e.message, status=e.status) except Exception, e: response = self.handle_exception(e) # Always add these headers response.headers['Allow'] = ', '.join(as_tuple(self.allowed_methods)) response.headers['Vary'] = 'Authenticate, Accept' # Serialize response emitter = JSONEmitter if method == 'OPTIONS' else None response = self.emit(request, response, emitter=emitter) # Send finished signal api_request_finished.send(self, request=self.request, response=response) return response def check_method_allowed(self, method): """ Ensure the request method is permitted for this resource, raising a ResourceException if it is not. """ if not method in self.callmap.keys():