[Calypso] [PATCH 01/35] Add server/base_prefix setting.

Guido Günther agx at sigxcpu.org
Sun Jan 10 09:20:47 PST 2016


Hi,
On Sat, Jan 09, 2016 at 06:56:25PM +0000, Jelmer Vernooij wrote:
> From: Jelmer Vernooij <jelmer at debian.org>
> 
> ---
>  calypso/config.py |  1 +
>  calypso/paths.py  | 11 +++++++++++
>  config            |  2 ++
>  3 files changed, 14 insertions(+)
> 
> diff --git a/calypso/config.py b/calypso/config.py
> index 598d1e2..dc17eec 100644
> --- a/calypso/config.py
> +++ b/calypso/config.py
> @@ -47,6 +47,7 @@ INITIAL_CONFIG = {
>          "key": "/etc/apache2/ssl/server.key",
>          "pidfile": "/var/run/calypso.pid",
>          "user_principal": "/+%(user)s",
> +        "base_prefix": "/",
>      },
>      "encoding": {
>          "request": "utf-8",
> diff --git a/calypso/paths.py b/calypso/paths.py
> index 11640aa..d69b667 100644
> --- a/calypso/paths.py
> +++ b/calypso/paths.py
> @@ -45,6 +45,14 @@ def url_to_owner(path):
>  def data_root():
>      return os.path.expanduser(config.get("storage", "folder"))
>  
> +
> +#
> +# Return the base path for the web server.
> +#
> +
> +def base_prefix():
> +    return config.get("server", "base_prefix").rstrip("/")
> +
>  #
>  # Given a URL, convert it to an absolute path name by
>  # prepending the storage folder name
> @@ -53,12 +61,15 @@ def data_root():
>  #
>  
>  def url_to_file(url):
> +    if url.startswith(base_prefix()):
> +        url = "/" + url[len(base_prefix()):].lstrip("/")
>      tail = urllib.url2pathname(url.strip("/"))
>      # eliminate .. components, and potential double leading slashes
>      tail = posixpath.normpath('/' + tail).lstrip('/')
>      file = os.path.join(data_root(), tail)
>      return file
>  
> +
>  #
>  # Does the provided URL reference a collection? This
>  # is done by seeing if the resulting path is a directory
> diff --git a/config b/config
> index 90c739f..1ef574c 100644
> --- a/config
> +++ b/config
> @@ -23,6 +23,8 @@ key = /etc/apache2/ssl/server.key
>  # current user principal; path to the default collection for a user
>  # for clients that use it (RFC5397)
>  user_principal = /+%(user)s
> +# base URL if / is not the CalDAV root
> +base_prefix = /
>  
>  [encoding]
>  # Encoding for responding requests

ACK.

It would be great if we would add tests (e.g. as doctests) for these
kinds of changes to increase our coverage step by step but I don't think
we should make it a requirement yet.

Cheers,
 -- Guido


More information about the Calypso mailing list