utils.py
changeset 8682 20bd1cdf86ae
parent 7998 9ef285eb20f4
child 8795 772cd62e1295
--- a/utils.py	Wed Jan 23 17:58:49 2013 +0100
+++ b/utils.py	Fri Jan 25 13:28:23 2013 +0100
@@ -33,6 +33,7 @@
 from uuid import uuid4
 from warnings import warn
 from threading import Lock
+from urlparse import urlparse
 
 from logging import getLogger
 
@@ -574,6 +575,25 @@
     return dict1
 
 
+def parse_repo_uri(uri):
+    """ transform a command line uri into a (protocol, hostport, appid), e.g:
+    <myapp>                      -> 'inmemory', None, '<myapp>'
+    inmemory://<myapp>           -> 'inmemory', None, '<myapp>'
+    pyro://[host][:port]         -> 'pyro', 'host:port', None
+    zmqpickle://[host][:port]    -> 'zmqpickle', 'host:port', None
+    """
+    parseduri = urlparse(uri)
+    scheme = parseduri.scheme
+    if scheme == '':
+        return ('inmemory', None, parseduri.path)
+    if scheme == 'inmemory':
+        return (scheme, None, parseduri.netloc)
+    if scheme in ('pyro', 'pyroloc') or scheme.startswith('zmqpickle-'):
+        return (scheme, parseduri.netloc, parseduri.path)
+    raise NotImplementedError('URI protocol not implemented for `%s`' % uri)
+
+
+
 logger = getLogger('cubicweb.utils')
 
 class QueryCache(object):