172 |
172 |
173 def build_url(self, *args, **kwargs): |
173 def build_url(self, *args, **kwargs): |
174 """return an absolute URL using params dictionary key/values as URL |
174 """return an absolute URL using params dictionary key/values as URL |
175 parameters. Values are automatically URL quoted, and the |
175 parameters. Values are automatically URL quoted, and the |
176 publishing method to use may be specified or will be guessed. |
176 publishing method to use may be specified or will be guessed. |
|
177 |
|
178 raises :exc:`ValueError` if None is found in arguments |
177 """ |
179 """ |
178 # use *args since we don't want first argument to be "anonymous" to |
180 # use *args since we don't want first argument to be "anonymous" to |
179 # avoid potential clash with kwargs |
181 # avoid potential clash with kwargs |
180 if args: |
182 if args: |
181 assert len(args) == 1, 'only 0 or 1 non-named-argument expected' |
183 assert len(args) == 1, 'only 0 or 1 non-named-argument expected' |
199 path = method |
201 path = method |
200 if not kwargs: |
202 if not kwargs: |
201 return u'%s%s' % (base_url, path) |
203 return u'%s%s' % (base_url, path) |
202 return u'%s%s?%s' % (base_url, path, self.build_url_params(**kwargs)) |
204 return u'%s%s?%s' % (base_url, path, self.build_url_params(**kwargs)) |
203 |
205 |
204 |
|
205 def build_url_params(self, **kwargs): |
206 def build_url_params(self, **kwargs): |
206 """return encoded params to incorporate them in an URL""" |
207 """return encoded params to incorporate them in an URL""" |
207 args = [] |
208 args = [] |
208 for param, values in kwargs.iteritems(): |
209 for param, values in kwargs.iteritems(): |
209 if not isinstance(values, (list, tuple)): |
210 if not isinstance(values, (list, tuple)): |
210 values = (values,) |
211 values = (values,) |
211 for value in values: |
212 for value in values: |
|
213 if value is None: |
|
214 raise ValueError(_('unauthorized value')) |
212 args.append(u'%s=%s' % (param, self.url_quote(value))) |
215 args.append(u'%s=%s' % (param, self.url_quote(value))) |
213 return '&'.join(args) |
216 return '&'.join(args) |
214 |
217 |
215 def url_quote(self, value, safe=''): |
218 def url_quote(self, value, safe=''): |
216 """urllib.quote is not unicode safe, use this method to do the |
219 """urllib.quote is not unicode safe, use this method to do the |