sobjects/cwxmlparser.py
changeset 10603 65ad6980976e
parent 10515 70ed2067fdb5
child 10662 10942ed172de
equal deleted inserted replaced
10602:4845012cfc8e 10603:65ad6980976e
    30    }
    30    }
    31 
    31 
    32 """
    32 """
    33 
    33 
    34 from datetime import datetime, time
    34 from datetime import datetime, time
    35 import urlparse
       
    36 import urllib
    35 import urllib
       
    36 
       
    37 from six.moves.urllib.parse import urlparse, urlunparse, parse_qs
    37 
    38 
    38 from logilab.common.date import todate, totime
    39 from logilab.common.date import todate, totime
    39 from logilab.common.textutils import splitstrip, text_to_dict
    40 from logilab.common.textutils import splitstrip, text_to_dict
    40 from logilab.common.decorators import classproperty
    41 from logilab.common.decorators import classproperty
    41 
    42 
   240         entity.cw_edited.update(attrs)
   241         entity.cw_edited.update(attrs)
   241 
   242 
   242     def normalize_url(self, url):
   243     def normalize_url(self, url):
   243         """overridden to add vid=xml if vid is not set in the qs"""
   244         """overridden to add vid=xml if vid is not set in the qs"""
   244         url = super(CWEntityXMLParser, self).normalize_url(url)
   245         url = super(CWEntityXMLParser, self).normalize_url(url)
   245         purl = urlparse.urlparse(url)
   246         purl = urlparse(url)
   246         if purl.scheme in ('http', 'https'):
   247         if purl.scheme in ('http', 'https'):
   247             params = urlparse.parse_qs(purl.query)
   248             params = parse_qs(purl.query)
   248             if 'vid' not in params:
   249             if 'vid' not in params:
   249                 params['vid'] = ['xml']
   250                 params['vid'] = ['xml']
   250                 purl = list(purl)
   251                 purl = list(purl)
   251                 purl[4] = urllib.urlencode(params, doseq=True)
   252                 purl[4] = urllib.urlencode(params, doseq=True)
   252                 return urlparse.urlunparse(purl)
   253                 return urlparse.urlunparse(purl)
   261         of a given type as in 'http://mysite.org/EntityType'.
   262         of a given type as in 'http://mysite.org/EntityType'.
   262 
   263 
   263         If `known_relations` is given, it should be a dictionary of already
   264         If `known_relations` is given, it should be a dictionary of already
   264         known relations, so they don't get queried again.
   265         known relations, so they don't get queried again.
   265         """
   266         """
   266         purl = urlparse.urlparse(url)
   267         purl = urlparse(url)
   267         params = urlparse.parse_qs(purl.query)
   268         params = parse_qs(purl.query)
   268         if etype is None:
   269         if etype is None:
   269             etype = purl.path.split('/')[-1]
   270             etype = purl.path.split('/')[-1]
   270         try:
   271         try:
   271             etype = self._cw.vreg.case_insensitive_etypes[etype.lower()]
   272             etype = self._cw.vreg.case_insensitive_etypes[etype.lower()]
   272         except KeyError:
   273         except KeyError:
   276             if known_relations and rtype in known_relations.get('role', ()):
   277             if known_relations and rtype in known_relations.get('role', ()):
   277                 continue
   278                 continue
   278             relations.add('%s-%s' % (rtype, role))
   279             relations.add('%s-%s' % (rtype, role))
   279         purl = list(purl)
   280         purl = list(purl)
   280         purl[4] = urllib.urlencode(params, doseq=True)
   281         purl[4] = urllib.urlencode(params, doseq=True)
   281         return urlparse.urlunparse(purl)
   282         return urlunparse(purl)
   282 
   283 
   283     def complete_item(self, item, rels):
   284     def complete_item(self, item, rels):
   284         try:
   285         try:
   285             return self._parsed_urls[item['cwuri']]
   286             return self._parsed_urls[item['cwuri']]
   286         except KeyError:
   287         except KeyError: