dulwich.web module¶
HTTP server for dulwich that implements the git smart HTTP protocol.
-
class
dulwich.web.GunzipFilter(application)¶ Bases:
objectWSGI middleware that unzips gzip-encoded requests before passing on to the underlying application.
-
class
dulwich.web.HTTPGitApplication(backend, dumb=False, handlers=None, fallback_app=None)¶ Bases:
objectClass encapsulating the state of a git WSGI application.
Variables: backend – the Backend object backing this application -
services= {('GET', re.compile('/HEAD$')): <function get_text_file>, ('GET', re.compile('/info/refs$')): <function get_info_refs>, ('GET', re.compile('/objects/info/alternates$')): <function get_text_file>, ('GET', re.compile('/objects/info/http-alternates$')): <function get_text_file>, ('GET', re.compile('/objects/info/packs$')): <function get_info_packs>, ('GET', re.compile('/objects/([0-9a-f]{2})/([0-9a-f]{38})$')): <function get_loose_object>, ('GET', re.compile('/objects/pack/pack-([0-9a-f]{40})\\.pack$')): <function get_pack_file>, ('GET', re.compile('/objects/pack/pack-([0-9a-f]{40})\\.idx$')): <function get_idx_file>, ('POST', re.compile('/git-upload-pack$')): <function handle_service_request>, ('POST', re.compile('/git-receive-pack$')): <function handle_service_request>}¶
-
-
class
dulwich.web.HTTPGitRequest(environ, start_response, dumb=False, handlers=None)¶ Bases:
objectClass encapsulating the state of a single git HTTP request.
Variables: environ – the WSGI environment for the request. -
add_header(name, value)¶ Add a header to the response.
-
cache_forever()¶ Set the response to be cached forever by the client.
-
error(message)¶ Begin a HTTP 500 response and return the text of a message.
-
forbidden(message)¶ Begin a HTTP 403 response and return the text of a message.
-
nocache()¶ Set the response to never be cached by the client.
-
not_found(message)¶ Begin a HTTP 404 response and return the text of a message.
-
respond(status='200 OK', content_type=None, headers=None)¶ Begin a response with the given status and other headers.
-
-
class
dulwich.web.LimitedInputFilter(application)¶ Bases:
objectWSGI middleware that limits the input length of a request to that specified in Content-Length.
-
class
dulwich.web.ServerHandlerLogger(stdin, stdout, stderr, environ, multithread=True, multiprocess=False)¶ Bases:
wsgiref.simple_server.ServerHandlerServerHandler that uses dulwich’s logger for logging exceptions.
-
log_error(*args)¶
-
log_exception(exc_info)¶ Log the ‘exc_info’ tuple in the server log
Subclasses may override to retarget the output or change its format.
-
log_message(format, *args)¶
-
-
class
dulwich.web.WSGIRequestHandlerLogger(request, client_address, server)¶ Bases:
wsgiref.simple_server.WSGIRequestHandlerWSGIRequestHandler that uses dulwich’s logger for logging exceptions.
-
handle()¶ Handle a single HTTP request
-
log_error(*args)¶ Log an error.
This is called when a request cannot be fulfilled. By default it passes the message on to log_message().
Arguments are the same as for log_message().
XXX This should go to the separate error log.
-
log_exception(exc_info)¶
-
log_message(format, *args)¶ Log an arbitrary message.
This is used by all other logging functions. Override it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).
The client ip and current date/time are prefixed to every message.
-
-
class
dulwich.web.WSGIServerLogger(server_address, RequestHandlerClass, bind_and_activate=True)¶ Bases:
wsgiref.simple_server.WSGIServerConstructor. May be extended, do not override.
-
handle_error(request, client_address)¶ Handle an error.
-
-
dulwich.web.date_time_string(timestamp=None)¶
-
dulwich.web.get_idx_file(req, backend, mat)¶
-
dulwich.web.get_info_packs(req, backend, mat)¶
-
dulwich.web.get_info_refs(req, backend, mat)¶
-
dulwich.web.get_loose_object(req, backend, mat)¶
-
dulwich.web.get_pack_file(req, backend, mat)¶
-
dulwich.web.get_repo(backend, mat)¶ Get a Repo instance for the given backend and URL regex match.
-
dulwich.web.get_text_file(req, backend, mat)¶
-
dulwich.web.handle_service_request(req, backend, mat)¶
-
dulwich.web.main(argv=['/usr/bin/sphinx-build-3', '-b', 'html', '-d', 'py3/doctrees', '.', 'py3/html'])¶ Entry point for starting an HTTP git server.
-
dulwich.web.make_wsgi_chain(*args, **kwargs)¶ Factory function to create an instance of HTTPGitApplication, correctly wrapped with needed middleware.
-
dulwich.web.send_file(req, f, content_type)¶ Send a file-like object to the request output.
Parameters: - req – The HTTPGitRequest object to send output to.
- f – An open file-like object to send; will be closed.
- content_type – The MIME type for the file.
Returns: Iterator over the contents of the file, as chunks.
-
dulwich.web.url_prefix(mat)¶ Extract the URL prefix from a regex match.
Parameters: mat – A regex match object. Returns: The URL prefix, defined as the text before the match in the original string. Normalized to start with one leading slash and end with zero.