summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-08-25 15:38:39 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-08-25 15:38:39 +0200
commit4f40e0bb2aec380d883e5ac0845c85ca53950303 (patch)
treef4633924191cc684a07860b4dac98ec3954ac6a7
parenteb7f568ba9104cad4094fd6a5a6860ac53cdd1a1 (diff)
downloadlogilab-common-4f40e0bb2aec380d883e5ac0845c85ca53950303.tar.gz
new split_url_or_path function into textutils
-rw-r--r--textutils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/textutils.py b/textutils.py
index 16926f0..db69d3b 100644
--- a/textutils.py
+++ b/textutils.py
@@ -45,6 +45,7 @@ __docformat__ = "restructuredtext en"
import sys
import re
+import os.path as osp
from unicodedata import normalize as _uninormalize
try:
from os import linesep
@@ -251,6 +252,15 @@ def splitstrip(string, sep=','):
get_csv = deprecated()(splitstrip)
+def split_url_or_path(url_or_path):
+ """return the latest component of a string containing either an url of the
+ form <scheme>://<path> or a local file system path
+ """
+ if '://' in url_or_path:
+ return url_or_path.rstrip('/').rsplit('/', 1)
+ return osp.split(url_or_path.rstrip(osp.sep))
+
+
def text_to_dict(text):
"""parse multilines text containing simple 'key=value' lines and return a
dict of {'key': 'value'}. When the same key is encountered multiple time,