dulwich.web module

HTTP server for dulwich that implements the git smart HTTP protocol.

class dulwich.web.ChunkReader(f)

Bases: object

read(n)
class dulwich.web.GunzipFilter(application)

Bases: object

WSGI middleware that unzips gzip-encoded requests before passing on to the underlying application.

class dulwich.web.HTTPGitApplication(backend, dumb: bool = False, handlers=None, fallback_app=None)

Bases: object

Class encapsulating the state of a git WSGI application.

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: bool = False, handlers=None)

Bases: object

Class encapsulating the state of a single git HTTP request.

environ

the WSGI environment for the request.

add_header(name, value)

Add a header to the response.

cache_forever() None

Set the response to be cached forever by the client.

error(message: str) bytes

Begin a HTTP 500 response and return the text of a message.

forbidden(message: str) bytes

Begin a HTTP 403 response and return the text of a message.

nocache() None

Set the response to never be cached by the client.

not_found(message: str) bytes

Begin a HTTP 404 response and return the text of a message.

respond(status: str = '200 OK', content_type: Optional[str] = None, headers: Optional[List[Tuple[str, str]]] = None)

Begin a response with the given status and other headers.

class dulwich.web.LimitedInputFilter(application)

Bases: object

WSGI 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: ServerHandler

ServerHandler 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: WSGIRequestHandler

WSGIRequestHandler 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.

Unicode control characters are replaced with escaped hex before writing the output to stderr.

class dulwich.web.WSGIServerLogger(server_address, RequestHandlerClass, bind_and_activate=True)

Bases: WSGIServer

Constructor. May be extended, do not override.

handle_error(request, client_address)

Handle an error.

dulwich.web.cache_forever_headers(now=None)
dulwich.web.date_time_string(timestamp: Optional[float] = None) str
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) BaseRepo

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', '-b', 'html', '-d', 'build/doctrees', '.', 'build/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) str

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.