[Calypso] [PATCH] Break endless loop
Guido Günther
agx at sigxcpu.org
Tue Jan 26 12:55:10 PST 2016
Hi,
On Tue, Jan 26, 2016 at 09:18:30PM +0100, Petter Reinholdtsen wrote:
> [Guido Günther]
> > parent_url() always prefixes with a '/' so it can never be None. So
> > check for that to unbreak the endless loop.
> >
> > This unbreaks calendars with Iceowl for me.
>
> Do you know what Iceowl is doing that causes the endless loop? Do you
> know how to add a test for it?
This is not iceowl related. Just look at the functions mentioned in the
commit message - I should have noticed during review that it can never
be none:
>From 6ce20d5ab8acfe63df6ce24a9bb509291cfc8320 Mon Sep 17 00:00:00 2001
Message-Id: <6ce20d5ab8acfe63df6ce24a9bb509291cfc8320.1453841603.git.agx at sigxcpu.org>
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx at sigxcpu.org>
Date: Tue, 26 Jan 2016 20:34:28 +0100
Subject: [PATCH] Add doctests for child_url and parent_url
To: calypso at keithp.com
and use docstrings instead of comments
---
calypso/paths.py | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/calypso/paths.py b/calypso/paths.py
index 429b901..197c5f5 100644
--- a/calypso/paths.py
+++ b/calypso/paths.py
@@ -86,23 +86,29 @@ def is_collection(url):
return False
urlpath, stripped = os.path.split(urlpath)
-#
-# Given a URL, return the parent URL by stripping off
-# the last path element
-#
def parent_url(path):
+ """
+ Given a URL, return the parent URL by stripping off the last path element
+ >>> parent_url("a/b/c")
+ '/a/b'
+ >>> parent_url("/")
+ '/'
+ """
path_parts = path.strip("/").split("/")
path_parent = path_parts[0:len(path_parts)-1]
new_path = "/" + "/".join(path_parent)
return new_path
-#
-# Given a URL, return the child URL, which is
-# the last path element
-#
def child_url(path):
+ """
+ Given a URL, return the child URL, which is the last path element
+ >>> child_url("a/b/c")
+ 'c'
+ >>> child_url("/")
+ ''
+ """
path_parts = path.strip("/").split("/")
return path_parts[len(path_parts)-1]
--
2.7.0.rc3
This is not meant to be applied since I need to do more cleanus before
doctests work but it should make the problem obvious.
Cheers,
-- Guido
More information about the Calypso
mailing list