utils.py
changeset 8682 20bd1cdf86ae
parent 7998 9ef285eb20f4
child 8795 772cd62e1295
equal deleted inserted replaced
8677:a75bb09d6d19 8682:20bd1cdf86ae
    31 from inspect import getargspec
    31 from inspect import getargspec
    32 from itertools import repeat
    32 from itertools import repeat
    33 from uuid import uuid4
    33 from uuid import uuid4
    34 from warnings import warn
    34 from warnings import warn
    35 from threading import Lock
    35 from threading import Lock
       
    36 from urlparse import urlparse
    36 
    37 
    37 from logging import getLogger
    38 from logging import getLogger
    38 
    39 
    39 from logilab.mtconverter import xml_escape
    40 from logilab.mtconverter import xml_escape
    40 from logilab.common.deprecation import deprecated
    41 from logilab.common.deprecation import deprecated
   572     dict1 = dict(dict1)
   573     dict1 = dict(dict1)
   573     dict1.update(dict2)
   574     dict1.update(dict2)
   574     return dict1
   575     return dict1
   575 
   576 
   576 
   577 
       
   578 def parse_repo_uri(uri):
       
   579     """ transform a command line uri into a (protocol, hostport, appid), e.g:
       
   580     <myapp>                      -> 'inmemory', None, '<myapp>'
       
   581     inmemory://<myapp>           -> 'inmemory', None, '<myapp>'
       
   582     pyro://[host][:port]         -> 'pyro', 'host:port', None
       
   583     zmqpickle://[host][:port]    -> 'zmqpickle', 'host:port', None
       
   584     """
       
   585     parseduri = urlparse(uri)
       
   586     scheme = parseduri.scheme
       
   587     if scheme == '':
       
   588         return ('inmemory', None, parseduri.path)
       
   589     if scheme == 'inmemory':
       
   590         return (scheme, None, parseduri.netloc)
       
   591     if scheme in ('pyro', 'pyroloc') or scheme.startswith('zmqpickle-'):
       
   592         return (scheme, parseduri.netloc, parseduri.path)
       
   593     raise NotImplementedError('URI protocol not implemented for `%s`' % uri)
       
   594 
       
   595 
       
   596 
   577 logger = getLogger('cubicweb.utils')
   597 logger = getLogger('cubicweb.utils')
   578 
   598 
   579 class QueryCache(object):
   599 class QueryCache(object):
   580     """ a minimalist dict-like object to be used by the querier
   600     """ a minimalist dict-like object to be used by the querier
   581     and native source (replaces lgc.cache for this very usage)
   601     and native source (replaces lgc.cache for this very usage)