Exemplo n.º 1
0
 def __call__(self, environ, start_response):
     path_info = environ.get('PATH_INFO', '')
     if not path_info:
         return self.add_slash(environ, start_response)
     if path_info == '/':
         # @@: This should obviously be configurable
         filename = 'index.html'
     else:
         filename = request.path_info_pop(environ)
     resource = os.path.normpath(self.resource_name + '/' + filename)
     if self.root_resource is not None and not resource.startswith(self.root_resource):
         # Out of bounds
         return self.not_found(environ, start_response)
     if not self.egg.has_resource(resource):
         return self.not_found(environ, start_response)
     if self.egg.resource_isdir(resource):
         # @@: Cache?
         child_root = self.root_resource is not None and self.root_resource or \
             self.resource_name
         return self.__class__(self.egg, resource, self.manager,
                               root_resource=child_root)(environ, start_response)
     if environ.get('PATH_INFO') and environ.get('PATH_INFO') != '/':
         return self.error_extra_path(environ, start_response)
     
     type, encoding = mimetypes.guess_type(resource)
     if not type:
         type = 'application/octet-stream'
     # @@: I don't know what to do with the encoding.
     try:
         file = self.egg.get_resource_stream(self.manager, resource)
     except (IOError, OSError), e:
         exc = httpexceptions.HTTPForbidden(
             'You are not permitted to view this file (%s)' % e)
         return exc.wsgi_application(environ, start_response)
Exemplo n.º 2
0
 def __call__(self, environ, start_response):
     """Stream a tarball from a bazaar branch."""
     # Tried to re-use code from downloadui, not very successful
     if not self._branch.export_tarballs:
         raise httpexceptions.HTTPForbidden(
             "Tarball downloads are not allowed")
     archive_format = "tgz"
     history = self._history
     self.args = self.get_args(environ)
     if len(self.args):
         revid = history.fix_revid(self.args[0])
         version_part = '-r' + self.args[0]
     else:
         revid = self.get_revid()
         version_part = ''
     # XXX: Perhaps some better suggestion based on the URL or path?
     #
     # TODO: Perhaps set the tarball suggested mtime to the revision
     # mtime.
     root = self._branch.friendly_name or 'branch'
     filename = root + version_part + '.' + archive_format
     encoded_filename = self.encode_filename(filename)
     headers = [
         ('Content-Type', 'application/octet-stream'),
         ('Content-Disposition',
             "attachment; filename*=utf-8''%s" % (encoded_filename,)),
         ]
     start_response('200 OK', headers)
     tree = history._branch.repository.revision_tree(revid)
     return tree.archive(root=root, format=archive_format, name=filename)
Exemplo n.º 3
0
 def new_application(environ, start_response):
     try:
         return application(environ, start_response)
     except (IOError, OSError), e:
         import errno
         from paste import httpexceptions
         if e.errno == errno.ENOENT:
             raise httpexceptions.HTTPNotFound()
         elif e.errno == errno.EACCES:
             raise httpexceptions.HTTPForbidden()
         else:
             raise
Exemplo n.º 4
0
 def debug(self, environ, start_response):
     assert request.path_info_pop(environ) == '_debug'
     next_part = request.path_info_pop(environ)
     method = getattr(self, next_part, None)
     if not method:
         exc = httpexceptions.HTTPNotFound(
             '%r not found when parsing %r' %
             (next_part, wsgilib.construct_url(environ)))
         return exc.wsgi_application(environ, start_response)
     if not getattr(method, 'exposed', False):
         exc = httpexceptions.HTTPForbidden('%r not allowed' % next_part)
         return exc.wsgi_application(environ, start_response)
     return method(environ, start_response)
Exemplo n.º 5
0
 def forbidden_exception(self, environ, start_response, debug_message=None):
     """add???
     
     :param environ: add???
     :param start_response: add??
     :param debug_message: add???. Default value is ``None``
     :returns: add???
     """
     exc = httpexceptions.HTTPForbidden(
             'The resource at %s could not be viewed'
             % paste_request.construct_url(environ),
             comment='SCRIPT_NAME=%r; PATH_INFO=%r; debug: %s'
             % (environ.get('SCRIPT_NAME'), environ.get('PATH_INFO'),
                debug_message or '(none)'))
     return exc.wsgi_application(environ, start_response)
Exemplo n.º 6
0
 def kill(self, environ, start_response):
     if not self.allow_kill:
         exc = httpexceptions.HTTPForbidden(
             'Killing threads has not been enabled.  Shame on you '
             'for trying!')
         return exc(environ, start_response)
     vars = parse_formvars(environ)
     thread_id = int(vars['thread_id'])
     thread_pool = environ['paste.httpserver.thread_pool']
     if thread_id not in thread_pool.worker_tracker:
         exc = httpexceptions.PreconditionFailed(
             'You tried to kill thread %s, but it is not working on '
             'any requests' % thread_id)
         return exc(environ, start_response)
     thread_pool.kill_worker(thread_id)
     script_name = environ['SCRIPT_NAME'] or '/'
     exc = httpexceptions.HTTPFound(
         headers=[('Location', script_name+'?kill=%s' % thread_id)])
     return exc(environ, start_response)