[parsers] improve url construction by using stdlib's urllib instead of str concatenation
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Thu, 09 Jun 2011 10:32:34 +0200
changeset 7478 9e213becdcf4
parent 7476 4be45b64d755
child 7479 b0603fc4ed6d
[parsers] improve url construction by using stdlib's urllib instead of str concatenation fix a s/_/-/ bug on the way.
sobjects/parsers.py
--- a/sobjects/parsers.py	Thu Jun 09 10:37:01 2011 +0200
+++ b/sobjects/parsers.py	Thu Jun 09 10:32:34 2011 +0200
@@ -33,6 +33,7 @@
 
 import os.path as osp
 from datetime import datetime, timedelta
+import urllib
 
 from logilab.common.date import todate, totime
 from logilab.common.textutils import splitstrip, text_to_dict
@@ -304,10 +305,11 @@
         try:
             return self._parsed_urls[(item['cwuri'], add_relations)]
         except KeyError:
-            itemurl = item['cwuri'] + '?vid=xml'
+            query = [('vid','xml')]
             if add_relations:
                 for rtype, role, _ in self.source.mapping.get(item['cwtype'], ()):
-                    itemurl += '&relation=%s_%s' % (rtype, role)
+                    query.append(('relation','%s-%s' % (rtype, role)))
+            itemurl = item['cwuri'] + '?' + urllib.urlencode(query)
             item_rels = list(self.parse(itemurl))
             assert len(item_rels) == 1, 'url %s expected to bring back one '\
                    'and only one entity, got %s' % (itemurl, len(item_rels))