Python httplib.NOT_FOUND Examples
The following are 30
code examples of httplib.NOT_FOUND().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
httplib
, or try the search function
.
Example #1
Source File: blockables.py From upvote with Apache License 2.0 | 6 votes |
def get(self, blockable_id): # pylint: disable=g-bad-name """View of single blockable, accessible to anyone with URL.""" blockable_id = blockable_id.lower() logging.info( 'Blockable handler get method called with ID: %s', blockable_id) blockable = binary_models.Blockable.get_by_id(blockable_id) if not blockable: self.abort(httplib.NOT_FOUND, explanation='Blockable not found') # Augment the response dict with related voting data. blockable_dict = blockable.to_dict() allowed, reason = voting_api.IsVotingAllowed(blockable.key) blockable_dict['is_voting_allowed'] = allowed blockable_dict['voting_prohibited_reason'] = reason self.respond_json(blockable_dict)
Example #2
Source File: users.py From upvote with Apache License 2.0 | 6 votes |
def get(self, user_id=None): # pylint: disable=g-bad-name logging.info('UserHandler GET method called with ID: %s', user_id) if not user_id or self.user.email == user_id: user = self.user else: user = self._get_another_user(user_id) if user: user_info = user.to_dict() user_info.update({ 'name': user.nickname, 'permissions': user.permissions, 'is_admin': user.is_admin, }) self.respond_json(user_info) else: self.abort(httplib.NOT_FOUND, explanation='User not found')
Example #3
Source File: rules.py From upvote with Apache License 2.0 | 6 votes |
def get(self, rule_key): logging.info('Rule handler get method called with key: %s', rule_key) key = datastore_utils.GetKeyFromUrlsafe(rule_key) if not key: self.abort( httplib.BAD_REQUEST, explanation='Rule key %s could not be parsed' % rule_key) rule = key.get() if rule: response = rule.to_dict() response['target_id'] = rule.key.parent().id() self.respond_json(response) else: self.abort(httplib.NOT_FOUND, explanation='Rule not found') # The Webapp2 routes defined for these handlers.
Example #4
Source File: playground.py From cloud-playground with Apache License 2.0 | 6 votes |
def post(self): # pylint:disable-msg=invalid-name """Handles HTTP POST requests.""" if not users.is_current_user_admin(): self.response.set_status(httplib.UNAUTHORIZED) return project_id = self.request.data['project_id'] if not project_id: Abort(httplib.BAD_REQUEST, 'project_id required') project = model.GetProject(project_id) if not project: Abort(httplib.NOT_FOUND, 'failed to retrieve project {}'.format(project_id)) repo_url = project.template_url repo = model.GetRepo(repo_url) model.CreateRepoAsync(owner=model.GetOrCreateUser(repo.owner), repo_url=repo.key.id(), html_url=repo.html_url, name=repo.name, description=repo.description, show_files=repo.show_files, read_only_files=repo.read_only_files, read_only_demo_url=repo.read_only_demo_url)
Example #5
Source File: proxy.py From ryu with Apache License 2.0 | 6 votes |
def get_flows(address, dpid): assert type(dpid) == int flows = [] try: path = '%s%d' % (_FLOW_PATH_BASE, dpid) flows = json.loads(_do_request(address, path).read())[str(dpid)] except IOError as e: LOG.error('REST API(%s) is not available.', address) raise except httplib.HTTPException as e: if e[0].status == httplib.NOT_FOUND: pass # switch already deleted else: LOG.error('REST API(%s, path=%s) request error.', address, path) raise return flows
Example #6
Source File: shared.py From cloud-playground with Apache License 2.0 | 6 votes |
def HasProjectWriteAccess(environ): """Assert that the current user has project write permissions. Args: environ: the current WSGI environ Returns: True if the current user as write access to the current project. """ project = environ['playground.project'] if not project: Abort(httplib.NOT_FOUND, 'requested write access to non-existent project') if users.is_current_user_admin(): return True user = environ.get('playground.user') if user and user.key.id() in project.writers: return True return False
Example #7
Source File: shared.py From cloud-playground with Apache License 2.0 | 6 votes |
def HasProjectReadAccess(environ): """Assert that the current user has project read permissions. Args: environ: the current WSGI environ Returns: True if the current user has read access to the current project. """ project = environ['playground.project'] if not project: Abort(httplib.NOT_FOUND, 'requested read access to non-existent project') access_key = environ.get('mimic.access_key') if access_key and access_key == project.access_key: return True if users.is_current_user_admin(): return True user = environ.get('playground.user', None) if user and user.key.id() in project.writers: return True if settings.PUBLIC_PROJECT_TEMPLATE_OWNER in project.writers: return True if settings.MANUAL_PROJECT_TEMPLATE_OWNER in project.writers: return True return False
Example #8
Source File: api.py From cascade-server with Apache License 2.0 | 6 votes |
def investigate_event(session, event, user=None): """ :type session: cascade.session.Session :type user: User """ session = Session.objects.with_id(session) if not session: return None, httplib.NOT_FOUND event = DataModelEvent.objects.with_id(event) if event is None or session.id not in {_.id for _ in event.sessions}: return None, httplib.NOT_FOUND job = InvestigateJob.update_existing(session=session, event=event, user=user) job.submit() return None, httplib.OK
Example #9
Source File: api.py From cascade-server with Apache License 2.0 | 6 votes |
def automate_session(session, user=None): """ :type session: cascade.session.Session :type user: User """ session = Session.objects.with_id(session) if not session: return None, httplib.NOT_FOUND if isinstance(request.json, dict): if request.json.get('analytics') is not None: requested_analytics = request.json['analytics'] for requested_analytic in requested_analytics: analytic = Analytic.objects.with_id(requested_analytic['_id']) if analytic: mode = requested_analytic.get('mode', analytic.mode) config = AnalyticConfiguration(analytic=analytic, mode=mode) session.update(add_to_set__state__analytics=config) job = AnalyticJob.update_existing(analytic=analytic, user=user, session=session, mode=mode) job.submit() return len(requested_analytics), httplib.OK return 0, httplib.BAD_REQUEST
Example #10
Source File: stub_dispatcher.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def _handle_head(gcs_stub, filename): """Handle HEAD request.""" filestat = gcs_stub.head_object(filename) if not filestat: return _FakeUrlFetchResult(httplib.NOT_FOUND, {}, '') http_time = common.posix_time_to_http(filestat.st_ctime) response_headers = { 'x-goog-stored-content-length': filestat.st_size, 'content-length': 0, 'content-type': filestat.content_type, 'etag': filestat.etag, 'last-modified': http_time } if filestat.metadata: response_headers.update(filestat.metadata) return _FakeUrlFetchResult(httplib.OK, response_headers, '')
Example #11
Source File: api.py From cascade-server with Apache License 2.0 | 6 votes |
def query_job(job, user=None): """ :type job: Job :type user: User """ job = Job.objects.with_id(job), httplib.OK if job is None: return None, httplib.NOT_FOUND if request.method == 'GET': return job, httplib.OK elif request.method == 'POST': return job.modify(**request.json), httplib.OK elif job and request.method == 'DELETE': job.delete() return None, httplib.OK
Example #12
Source File: api_test.py From luci-py with Apache License 2.0 | 6 votes |
def test_get_config_by_hash(self): self.mock(storage, 'get_configs_by_hashes_async', mock.Mock()) storage.get_configs_by_hashes_async.return_value = future({ 'deadbeef': 'some content', }) req = {'content_hash': 'deadbeef'} resp = self.call_api('get_config_by_hash', req).json_body self.assertEqual(resp, { 'content': base64.b64encode('some content'), }) storage.get_configs_by_hashes_async.return_value = future({ 'deadbeef': None, }) with self.call_should_fail(httplib.NOT_FOUND): self.call_api('get_config_by_hash', req) ############################################################################## # get_projects
Example #13
Source File: api.py From cascade-server with Apache License 2.0 | 6 votes |
def query_session_hosts(session, user=None): """ :type session: Session :type user: User """ session = Session.objects.with_id(session) if not session: return None, httplib.NOT_FOUND host_ids = set() for event in DataModelEvent.objects(sessions=session): event.update_host() if event.host: host_ids.add(event.host.id) host_list = [Host.objects.with_id(_) for _ in host_ids] return host_list, httplib.OK
Example #14
Source File: experiment_store.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _promote_draft_model_callback(searchinfo): """ a closure function that take the necessary info to clone a model within the same namespace. Args: searchinfo: Returns: (func) a callback to copy_model that takes model_name <string> as an argument """ def callback(model_name): draft_model_name = get_experiment_draft_model_name(model_name) try: return copy_model(searchinfo, draft_model_name, searchinfo, model_name) except ModelNotFoundException as e: cexc.log_traceback() logger.error(e) raise SplunkRestProxyException("%s: %s" % (str(e), draft_model_name), logging.ERROR, httplib.NOT_FOUND) return callback
Example #15
Source File: middleware.py From cloud-playground with Apache License 2.0 | 5 votes |
def _AssertCollaboratingAppIdAccessCheck(self, environ): if environ['PATH_INFO'] in common.CONTROL_PATHS_REQUIRING_TREE: if not shared.ThisIsPlaygroundApp(): Abort(httplib.FORBIDDEN, 'playground service is not available in this app id') else: if shared.ThisIsPlaygroundApp(): Abort(httplib.NOT_FOUND, 'mimic execution playground is not available in this app id')
Example #16
Source File: rules_test.py From upvote with Apache License 2.0 | 5 votes |
def testAdminGetUnknownKey(self): """Admin gets a single rule by an unknown ID.""" key = self.rule_3.key.urlsafe() self.rule_3.key.delete() with self.LoggedInUser(admin=True): self.testapp.get(self.ROUTE % key, status=httplib.NOT_FOUND)
Example #17
Source File: votes_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_User_UnknownBlockable(self): params = {'wasYesVote': 'true'} with self.LoggedInUser(email_addr=self.user_2.email): self.testapp.post( self.ROUTE % 'notablockable', params, status=httplib.NOT_FOUND)
Example #18
Source File: votes_test.py From upvote with Apache License 2.0 | 5 votes |
def testAdminGetUnknownID(self): """Admin gets a vote by an unknown ID.""" key = self.vote_3.key.urlsafe() self.vote_3.key.delete() with self.LoggedInUser(admin=True): self.testapp.get(self.ROUTE % key, status=httplib.NOT_FOUND)
Example #19
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_HostNotFound(self): with self.LoggedInUser(): self.testapp.post( self.ROUTE % 'invalid_host_id', status=httplib.NOT_FOUND)
Example #20
Source File: exemptions_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_ExemptionNotFound(self): other_host_key = test_utils.CreateSantaHost().key other_host_id = other_host_key.id() with self.LoggedInUser(admin=True): self.testapp.post(self.ROUTE % other_host_id, status=httplib.NOT_FOUND)
Example #21
Source File: votes_test.py From upvote with Apache License 2.0 | 5 votes |
def testPost_BlockableNotFoundError(self, mock_vote): with self.LoggedInUser(): self.testapp.post( self.ROUTE % test_utils.RandomSHA256(), params={'wasYesVote': 'true'}, status=httplib.NOT_FOUND)
Example #22
Source File: validation_error_handler.py From flasgger with MIT License | 5 votes |
def validation_error_404(err, data, schema): """ Custom validation error handler which produces 404 Not Found response in case validation fails instead of 400 Bad Request """ abort(Response(status=HTTPStatus.NOT_FOUND))
Example #23
Source File: resource_snapshot.py From citest with Apache License 2.0 | 5 votes |
def __elem_exists(self, agent, resource_type, elem, aggregated): """Determine if a pending delete on an instance has completed or not.""" context = ExecutionContext() params = {} if aggregated: name = elem[1] param_name, param_value = elem[0].split('/', 1) if param_name[-1] == 's': param_name = param_name[:-1] # Just because the aggregation returned a parameter # does not mean the get API takes it. Confirm before adding. if (agent.resource_type_to_discovery_info(resource_type) .get('methods', {}).get('get', {}).get('parameters', {}) .get(param_name)): params[param_name] = param_value name = elem[1] if aggregated else elem try: agent.get_resource(context, resource_type, resource_id=name, **params) return True except HttpError as http_error: if http_error.resp.status == HTTPStatus.NOT_FOUND: return False if http_error.resp.status in self.__RETRYABLE_DELETE_HTTP_CODES: return True print('Unexpected error while waiting for delete: {0} {1}={2}'.format( resource_type, name, http_error)) return False
Example #24
Source File: dispatcher.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def dispatcher(handlers): """Accepts handlers and returns a WSGI app that dispatches requests to them. Args: handlers: a list of handlers as produced by wsgi_utils.load_user_scripts_into_handlers: a list of tuples of (url_re, app). Returns: A WSGI app that dispatches to the user apps specified in the input. """ # Transforms wsgi_env, start_response args into request @wrappers.Request.application def dispatch(request): """Handle one request.""" for url_re, app in handlers: matcher = re.match(url_re, request.path) if matcher and matcher.end() == len(request.path): if app is not None: # Send a response via the app specified in the handler. return app else: # The import must have failed. This will have been logged # at import time. Send a 500 error response. return response_for_error(httplib.INTERNAL_SERVER_ERROR) logging.error('No handler found for %s', request.path) return response_for_error(httplib.NOT_FOUND) return dispatch
Example #25
Source File: middleware.py From cloud-playground with Apache License 2.0 | 5 votes |
def __call__(self, environ, start_response): project_id = mimic.GetProjectId(environ, False) if project_id and shared.ThisIsPlaygroundApp(): project = model.GetProject(project_id) if self._assert_project_existence: if not project: Abort(httplib.NOT_FOUND, 'project_id {} not found'.format(project_id)) environ['playground.project'] = project or settings.NO_SUCH_PROJECT return self._app(environ, start_response)
Example #26
Source File: wsgi_test.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def test_notfound(self): response = self.client.get('/notfound') self.assertEqual(response.status_code, httplib.NOT_FOUND)
Example #27
Source File: wsgi_test.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def test_static_file_wildcard_404(self): response = self.client.get('/wildcard_statics/no_file') self.assertEqual(response.status_code, httplib.NOT_FOUND)
Example #28
Source File: wsgi_test.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def test_static_file_wildcard_directory_traversal(self): # Try to fetch some files outside of the "upload" regex using path # traversal response = self.client.get('/wildcard_statics/../../setup.py') self.assertEqual(response.status_code, httplib.NOT_FOUND) response = self.client.get('/wildcard_statics/../__init__.py') self.assertEqual(response.status_code, httplib.NOT_FOUND)
Example #29
Source File: stub_dispatcher.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def _handle_delete(gcs_stub, filename): """Handle DELETE object.""" if gcs_stub.delete_object(filename): return _FakeUrlFetchResult(httplib.NO_CONTENT, {}, '') else: return _FakeUrlFetchResult(httplib.NOT_FOUND, {}, '')
Example #30
Source File: static_files_handler.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def _not_found_404(environ, start_response): status = httplib.NOT_FOUND start_response('%d %s' % (status, httplib.responses[status]), [('Content-Type', 'text/plain')]) return ['%s not found' % environ['PATH_INFO']]